Files for dotnet framework / EAF

This commit is contained in:
2022-03-08 17:39:25 -07:00
parent 5475392c3f
commit f1bac2f5a7
13 changed files with 744 additions and 333 deletions

View File

@ -7,9 +7,10 @@ using FFMpegCore;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Threading;
namespace Adaptation.FileHandlers.DownloadJpegFile;
@ -17,6 +18,7 @@ public class FileRead : Shared.FileRead, IFileRead
{
private readonly Timer _Timer;
private readonly string _FFmpegFileName;
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) :
@ -32,6 +34,11 @@ public class FileRead : Shared.FileRead, IFileRead
if (_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
_StaticFileServer = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".StaticFileServer"));
string entryAssemblyLocationDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string ffmpegFileName = Path.Combine(entryAssemblyLocationDirectory, "ffmpeg.dll");
_FFmpegFileName = Path.Combine(entryAssemblyLocationDirectory, "ffmpeg.exe");
if (File.Exists(ffmpegFileName) && !File.Exists(_FFmpegFileName))
File.Copy(ffmpegFileName, _FFmpegFileName);
if (!Debugger.IsAttached && fileConnectorConfiguration.PreProcessingMode != FileConnectorConfiguration.PreProcessingModeEnum.Process)
_Timer = new Timer(Callback, null, (int)(fileConnectorConfiguration.FileScanningIntervalInSeconds * 1000), Timeout.Infinite);
else
@ -121,11 +128,19 @@ public class FileRead : Shared.FileRead, IFileRead
{
if (string.IsNullOrEmpty(_StaticFileServer))
throw new Exception();
_ = FFMpegArguments
.FromUrlInput(new Uri(string.Concat("rtsp://", _StaticFileServer, '/', _FileConnectorConfiguration.SourceDirectoryCloaking)))
.OutputToFile(Path.Combine(_FileConnectorConfiguration.TargetFileLocation, $"{_CellInstanceName}_{DateTime.Now.Ticks}{_FileConnectorConfiguration.TargetFileName}"))
.ProcessSynchronously(throwOnError: false);
//FFMpeg.Snapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromMinutes(1));
string fileName = $"{_CellInstanceName}_{DateTime.Now.Ticks}{_FileConnectorConfiguration.TargetFileName}";
string destFileName = Path.Combine(_FileConnectorConfiguration.TargetFileLocation, fileName);
string sourceFileName = Path.Combine(_FileConnectorConfiguration.SourceFileLocation, fileName);
if (!File.Exists(_FFmpegFileName))
File.WriteAllText(Path.ChangeExtension(destFileName, ".err"), $"<{_FFmpegFileName}> doesn't exits!");
else
{
_ = FFMpegArguments
.FromUrlInput(new Uri(string.Concat("rtsp://", _StaticFileServer, '/', _FileConnectorConfiguration.SourceDirectoryCloaking)))
.OutputToFile(sourceFileName)
.ProcessSynchronously(throwOnError: false);
File.Move(sourceFileName, destFileName);
}
}
private void Callback(object state)