|
|
|
@ -10,8 +10,10 @@ using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Adaptation.FileHandlers.DownloadRsMFile;
|
|
|
|
|
|
|
|
|
@ -19,7 +21,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly Timer _Timer;
|
|
|
|
|
private readonly WebClient _WebClient;
|
|
|
|
|
private readonly HttpClient _HttpClient;
|
|
|
|
|
private readonly string _StaticFileServer;
|
|
|
|
|
|
|
|
|
|
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, bool useCyclicalForDescription, bool isEAFHosted) :
|
|
|
|
@ -34,7 +36,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
throw new Exception(cellInstanceConnectionName);
|
|
|
|
|
if (_IsDuplicator)
|
|
|
|
|
throw new Exception(cellInstanceConnectionName);
|
|
|
|
|
_WebClient = new WebClient();
|
|
|
|
|
_HttpClient = new();
|
|
|
|
|
_StaticFileServer = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".StaticFileServer"));
|
|
|
|
|
if (!Debugger.IsAttached && fileConnectorConfiguration.PreProcessingMode != FileConnectorConfiguration.PreProcessingModeEnum.Process)
|
|
|
|
|
_Timer = new Timer(Callback, null, (int)(fileConnectorConfiguration.FileScanningIntervalInSeconds * 1000), Timeout.Infinite);
|
|
|
|
@ -123,15 +125,16 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
throw new Exception(string.Concat("See ", nameof(Callback)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DownloadRsMFile()
|
|
|
|
|
private async Task DownloadRsMFileAsync()
|
|
|
|
|
{
|
|
|
|
|
if (_WebClient is null)
|
|
|
|
|
if (_HttpClient is null)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
if (string.IsNullOrEmpty(_StaticFileServer))
|
|
|
|
|
throw new Exception();
|
|
|
|
|
string logText;
|
|
|
|
|
string runJson;
|
|
|
|
|
string rootJson;
|
|
|
|
|
string targetJson;
|
|
|
|
|
string[] logLines;
|
|
|
|
|
string runFileName;
|
|
|
|
|
string[] logSegments;
|
|
|
|
@ -159,13 +162,13 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
_ => throw new Exception(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
rootJson = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer));
|
|
|
|
|
rootJson = await _HttpClient.GetStringAsync(string.Concat("http://", _StaticFileServer));
|
|
|
|
|
rootNginxFileSystemCollection = JsonSerializer.Deserialize<NginxFileSystem[]>(rootJson, propertyNameCaseInsensitiveJsonSerializerOptions);
|
|
|
|
|
foreach (NginxFileSystem rootNginxFileSystem in rootNginxFileSystemCollection)
|
|
|
|
|
{
|
|
|
|
|
if (!(from l in _FileConnectorConfiguration.SourceFileFilters where rootNginxFileSystem.Name == l select false).Any())
|
|
|
|
|
continue;
|
|
|
|
|
logText = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer, '/', rootNginxFileSystem.Name));
|
|
|
|
|
logText = await _HttpClient.GetStringAsync(string.Concat("http://", _StaticFileServer, '/', rootNginxFileSystem.Name));
|
|
|
|
|
logLines = logText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
|
|
|
|
|
foreach (string logLine in logLines)
|
|
|
|
|
{
|
|
|
|
@ -184,7 +187,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
runFullFileNameSegments = runFullFileName.Split('\\').ToList();
|
|
|
|
|
runFileName = runFullFileNameSegments[runFullFileNameSegments.Count - 1];
|
|
|
|
|
runFullFileNameSegments.RemoveAt(runFullFileNameSegments.Count - 1);
|
|
|
|
|
runJson = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer, '/', string.Join("/", runFullFileNameSegments)));
|
|
|
|
|
runJson = await _HttpClient.GetStringAsync(string.Concat("http://", _StaticFileServer, '/', string.Join("/", runFullFileNameSegments)));
|
|
|
|
|
runFullFileNameSegments.Add(runFileName);
|
|
|
|
|
runNginxFileSystemCollection = JsonSerializer.Deserialize<NginxFileSystem[]>(runJson, propertyNameCaseInsensitiveJsonSerializerOptions);
|
|
|
|
|
foreach (NginxFileSystem matchNginxFileSystem in runNginxFileSystemCollection)
|
|
|
|
@ -224,7 +227,8 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
File.Delete(alternateFileInfo.FullName);
|
|
|
|
|
if (targetFileInfo.Exists)
|
|
|
|
|
File.Delete(targetFileInfo.FullName);
|
|
|
|
|
_WebClient.DownloadFile(targetFileName, targetFileInfo.FullName);
|
|
|
|
|
targetJson = await _HttpClient.GetStringAsync(targetFileName);
|
|
|
|
|
File.WriteAllText(targetFileInfo.FullName, targetJson);
|
|
|
|
|
targetFileInfo.LastWriteTime = matchNginxFileSystemDateTime;
|
|
|
|
|
File.Copy(targetFileInfo.FullName, alternateFileInfo.FullName);
|
|
|
|
|
}
|
|
|
|
@ -235,7 +239,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_IsEAFHosted)
|
|
|
|
|
DownloadRsMFile();
|
|
|
|
|
_ = DownloadRsMFileAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|