|
@@ -15,18 +15,22 @@ namespace LJProxy.Providers
|
|
private string _fullFilepath;
|
|
private string _fullFilepath;
|
|
private string _subpath;
|
|
private string _subpath;
|
|
private FileInfo _file;
|
|
private FileInfo _file;
|
|
- private Stream _stream;
|
|
|
|
|
|
+ private FileInfo _tempFile;
|
|
|
|
+ private MemoryStream _stream;
|
|
private ILJClient _ljPool;
|
|
private ILJClient _ljPool;
|
|
private static object _syncRoot = new object();
|
|
private static object _syncRoot = new object();
|
|
- public L1SvrFileInfo(string fullFilepath, string subpath, ILJClient ljPool)
|
|
|
|
|
|
+ private string _token;
|
|
|
|
+ public L1SvrFileInfo(string fullFilepath, string subpath, ILJClient ljPool,string token)
|
|
{
|
|
{
|
|
_fullFilepath = fullFilepath;
|
|
_fullFilepath = fullFilepath;
|
|
_subpath = subpath;
|
|
_subpath = subpath;
|
|
_ljPool = ljPool;
|
|
_ljPool = ljPool;
|
|
|
|
+ _token = token;
|
|
|
|
+ _stream = new MemoryStream(); ;
|
|
if (File.Exists(_fullFilepath))
|
|
if (File.Exists(_fullFilepath))
|
|
{
|
|
{
|
|
- _file = new FileInfo(_fullFilepath);
|
|
|
|
- _stream = _file.OpenRead();
|
|
|
|
|
|
+ _tempFile = new FileInfo(_fullFilepath);
|
|
|
|
+ CheckAuthorizationOrGetRemoteFile(_tempFile.LastWriteTime, true);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -34,17 +38,12 @@ namespace LJProxy.Providers
|
|
{
|
|
{
|
|
if (File.Exists(_fullFilepath))
|
|
if (File.Exists(_fullFilepath))
|
|
{
|
|
{
|
|
- _file = new FileInfo(_fullFilepath);
|
|
|
|
- _stream = _file.OpenRead();
|
|
|
|
|
|
+ _tempFile = new FileInfo(_fullFilepath);
|
|
|
|
+ CheckAuthorizationOrGetRemoteFile(_tempFile.LastWriteTime,true);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- GetRemoteFile();
|
|
|
|
- if (File.Exists(_fullFilepath))
|
|
|
|
- {
|
|
|
|
- _file = new FileInfo(_fullFilepath);
|
|
|
|
- _stream = _file.OpenRead();
|
|
|
|
- }
|
|
|
|
|
|
+ CheckAuthorizationOrGetRemoteFile(null);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -67,21 +66,52 @@ namespace LJProxy.Providers
|
|
return _stream;
|
|
return _stream;
|
|
}
|
|
}
|
|
|
|
|
|
- public void GetRemoteFile()
|
|
|
|
|
|
+ public void CheckAuthorizationOrGetRemoteFile(DateTime? lastWriteTime, bool checkAuthorization=false)
|
|
{
|
|
{
|
|
var getFileReq = new GetFileRequest() {
|
|
var getFileReq = new GetFileRequest() {
|
|
- Filepath = _subpath
|
|
|
|
|
|
+ Filepath = _subpath,
|
|
|
|
+ token = _token,
|
|
|
|
+ checkAuthorization = checkAuthorization,
|
|
|
|
+ lastWriteTime = lastWriteTime
|
|
};
|
|
};
|
|
var responseStr = _ljPool.DoExcute(getFileReq.GetApiName(),JsonConvert.SerializeObject(getFileReq));
|
|
var responseStr = _ljPool.DoExcute(getFileReq.GetApiName(),JsonConvert.SerializeObject(getFileReq));
|
|
var response = JsonConvert.DeserializeObject<GetFileResponse>(responseStr);
|
|
var response = JsonConvert.DeserializeObject<GetFileResponse>(responseStr);
|
|
- if (string.IsNullOrEmpty(response.ErrMsg))
|
|
|
|
|
|
+ if (response.AppErrCode == "900")
|
|
{
|
|
{
|
|
- var fileDir = Path.GetDirectoryName(_fullFilepath);
|
|
|
|
- if (!Directory.Exists(fileDir)){
|
|
|
|
- Directory.CreateDirectory(fileDir);
|
|
|
|
|
|
+ if (!checkAuthorization)
|
|
|
|
+ {
|
|
|
|
+ var fileDir = Path.GetDirectoryName(_fullFilepath);
|
|
|
|
+ if (!Directory.Exists(fileDir))
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(fileDir);
|
|
|
|
+ }
|
|
|
|
+ File.WriteAllBytes(_fullFilepath, response.FileData);
|
|
}
|
|
}
|
|
- File.WriteAllBytes(_fullFilepath, response.FileData);
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if(response.FileData!=null && response.FileData.Length > 0)
|
|
|
|
+ {
|
|
|
|
+ var fileDir = Path.GetDirectoryName(_fullFilepath);
|
|
|
|
+ if (!Directory.Exists(fileDir))
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(fileDir);
|
|
|
|
+ }
|
|
|
|
+ File.WriteAllBytes(_fullFilepath, response.FileData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ _file = new FileInfo(_fullFilepath);
|
|
|
|
+ byte[] buff = new byte[1024];
|
|
|
|
+ using(var fs = _file.OpenRead())
|
|
|
|
+ {
|
|
|
|
+ int readCount = fs.Read(buff, 0, buff.Length);
|
|
|
|
+ while (readCount > 0)
|
|
|
|
+ {
|
|
|
|
+ _stream.Write(buff, 0, readCount);
|
|
|
|
+ readCount = fs.Read(buff, 0, buff.Length);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|