HelperEAFProgramData HelperCompass HelperInfinityQS HelperSerial HelperTCP dotnet_analyzer_diagnostic
37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using File_Watcher.Models;
|
|
|
|
namespace File_Watcher.Helpers;
|
|
|
|
internal static partial class HelperEAFProgramData
|
|
{
|
|
|
|
internal static bool MoveFiles(AppSettings appSettings, ILogger<Worker> logger)
|
|
{
|
|
string checkFile;
|
|
string checkDirectory;
|
|
string source = Path.GetFullPath(appSettings.EAFProgramDataConfiguration.Source);
|
|
string[] files = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
|
|
logger.LogInformation("After {MillisecondsDelay} with search pattern '{SearchPattern}' found {files}", appSettings.MillisecondsDelay, appSettings.EAFLogConfiguration.SearchPattern, files.Length);
|
|
foreach (string file in files)
|
|
{
|
|
Thread.Sleep(500);
|
|
checkFile = file.Replace(source, appSettings.EAFProgramDataConfiguration.Destination);
|
|
if (checkFile == file)
|
|
throw new NotSupportedException("Replace failed!");
|
|
checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new NotSupportedException();
|
|
try
|
|
{
|
|
if (!Directory.Exists(checkDirectory))
|
|
_ = Directory.CreateDirectory(checkDirectory);
|
|
if (File.Exists(checkFile))
|
|
continue;
|
|
File.Move(file, checkFile);
|
|
Thread.Sleep(500);
|
|
}
|
|
catch (Exception ex)
|
|
{ logger.LogInformation(ex, "Inner loop error!"); }
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} |