pull/1/head
unknown 4 years ago
parent b2e78763e7
commit 4dbd9fcede

@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>

@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>

@ -53,9 +53,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTransferServer", "FileT
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConnectionTest", "ConnectionTest", "{D5207A5A-2F27-4992-9BA5-0BDCFC59F133}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "ConnectionTest\Client\Client.csproj", "{08CDD42E-E324-40A4-88C3-EDD0493AAF84}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "ConnectionTest\Client\Client.csproj", "{08CDD42E-E324-40A4-88C3-EDD0493AAF84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "ConnectionTest\Server\Server.csproj", "{3496A688-0749-48C2-BD60-ABB42A5C17C9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "ConnectionTest\Server\Server.csproj", "{3496A688-0749-48C2-BD60-ABB42A5C17C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -255,8 +255,8 @@ Global
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Debug|x86.Build.0 = Debug|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|Any CPU.Build.0 = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x64.ActiveCfg = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x64.Build.0 = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x64.ActiveCfg = Release|x64
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x64.Build.0 = Release|x64
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x86.ActiveCfg = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x86.Build.0 = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@ -267,8 +267,8 @@ Global
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Debug|x86.Build.0 = Debug|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|Any CPU.Build.0 = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x64.ActiveCfg = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x64.Build.0 = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x64.ActiveCfg = Release|x64
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x64.Build.0 = Release|x64
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x86.ActiveCfg = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection

@ -65,61 +65,68 @@ namespace ZeroLevel.Services.FileSystem
private void CheckSourceFolder()
{
string[] files = null;
try
{
var files = GetFilesFromSource();
OnStartMovingFilesToTemporary?.Invoke(files.Length);
foreach (var file in files)
files = GetFilesFromSource();
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to process input directory '{_sourceFolder}'");
}
if (files == null || files.Length == 0)
{
return;
}
OnStartMovingFilesToTemporary?.Invoke(files.Length);
foreach (var file in files)
{
try
{
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Find new file {file}");
if (FSUtils.IsFileLocked(new FileInfo(file)))
{
continue;
}
string tempFile;
try
{
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Find new file {file}");
if (FSUtils.IsFileLocked(new FileInfo(file)))
{
continue;
}
string tempFile;
try
{
tempFile = MoveToTemporary(file);
}
catch (Exception ex)
tempFile = MoveToTemporary(file);
if (string.IsNullOrWhiteSpace(tempFile))
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to attempt to move file '{file}' to temporary directory '{_temporaryFolder}'");
Log.SystemWarning($"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to move file '{file}' to temporary directory '{_temporaryFolder}'. Without system error!");
continue;
}
finally
{
OnMovingFileToTemporary?.Invoke();
}
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Handle file {file}");
try
{
_callback(new FileMeta(Path.GetFileName(file), tempFile));
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault callback for file '{tempFile}'");
}
if (_autoRemoveTempFileAfterCallback)
{
File.Delete(tempFile);
}
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault proceed file {file}");
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to attempt to move file '{file}' to temporary directory '{_temporaryFolder}'");
continue;
}
finally
{
OnMovingFileToTemporary?.Invoke();
}
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Handle file {file}");
try
{
_callback(new FileMeta(Path.GetFileName(file), tempFile));
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault callback for file '{tempFile}'");
}
if (_autoRemoveTempFileAfterCallback)
{
File.Delete(tempFile);
}
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault proceed file {file}");
}
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to process input directory '{_sourceFolder}'");
}
finally
{
OnCompleteMovingFilesToTemporary?.Invoke();
}
OnCompleteMovingFilesToTemporary?.Invoke();
}
/// <summary>
@ -137,8 +144,12 @@ namespace ZeroLevel.Services.FileSystem
tempFile = TrySolveCollision(tempFile);
}
File.Copy(from, tempFile, false);
File.Delete(from);
return tempFile;
if (File.Exists(tempFile))
{
File.Delete(from);
return tempFile;
}
return null;
}
/// <summary>
@ -177,19 +188,22 @@ namespace ZeroLevel.Services.FileSystem
/// </summary>
private string[] GetFilesFromSource()
{
string[] files;
if (_extensions.Count > 0)
{
string[] files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Where(f => _extensions.Contains(Path.GetExtension(f).ToLowerInvariant())).ToArray();
Array.Sort<string>(files, FileNameSortCompare);
return files;
files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
?.Where(f => _extensions.Contains(Path.GetExtension(f).ToLowerInvariant()))
?.ToArray();
}
else
{
string[] files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
}
if (files != null)
{
Array.Sort<string>(files, FileNameSortCompare);
return files;
}
return files;
}
/// <summary>

@ -22,6 +22,11 @@ namespace ZeroLevel.Services.Serialization
_reverseByteOrder = use_reverse_byte_order;
}
/// <summary>
/// End of stream
/// </summary>
public bool EOS => _stream.Position >= _stream.Length;
public MemoryStreamReader(byte[] data)
{
if (data == null)
@ -41,7 +46,7 @@ namespace ZeroLevel.Services.Serialization
/// </summary>
public bool ReadBoolean()
{
if (CheckOutOfRange(_stream, 1))
if (CheckOutOfRange(1))
throw new OutOfMemoryException("Array index out of bounds");
return BitConverter.ToBoolean(new byte[1] { ReadByte() }, 0);
}
@ -51,14 +56,14 @@ namespace ZeroLevel.Services.Serialization
/// </summary>
public byte ReadByte()
{
if (CheckOutOfRange(_stream, 1))
if (CheckOutOfRange(1))
throw new OutOfMemoryException("Array index out of bounds");
return (byte)_stream.ReadByte();
}
public char ReadChar()
{
if (CheckOutOfRange(_stream, 2))
if (CheckOutOfRange(2))
throw new OutOfMemoryException("Array index out of bounds");
var buffer = ReadBuffer(2);
return BitConverter.ToChar(buffer, 0);
@ -169,7 +174,7 @@ namespace ZeroLevel.Services.Serialization
public byte[] ReadBuffer(int count)
{
if (count == 0) return null;
if (CheckOutOfRange(_stream, count))
if (CheckOutOfRange(count))
throw new OutOfMemoryException("Array index out of bounds");
var buffer = new byte[count];
var readedCount = _stream.Read(buffer, 0, count);
@ -227,10 +232,10 @@ namespace ZeroLevel.Services.Serialization
/// <summary>
/// Check if data reading is outside the stream
/// </summary>
private bool CheckOutOfRange(Stream stream, int offset)
public bool CheckOutOfRange(int offset)
{
return (stream.Position + offset) > stream.Length;
}
return (_stream.Position + offset) > _stream.Length;
}
#region Extensions

@ -6,16 +6,16 @@
</Description>
<Authors>ogoun</Authors>
<Company>ogoun</Company>
<AssemblyVersion>3.3.4.5</AssemblyVersion>
<PackageReleaseNotes>Fix PeriodicFileSystemWatcher</PackageReleaseNotes>
<AssemblyVersion>3.3.4.6</AssemblyVersion>
<PackageReleaseNotes>Extended the MemoryStreamReader.</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/ogoun/Zero/wiki</PackageProjectUrl>
<Copyright>Copyright Ogoun 2020</Copyright>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageIconUrl></PackageIconUrl>
<RepositoryUrl>https://github.com/ogoun/Zero</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Version>3.3.4.5</Version>
<FileVersion>3.3.4.5</FileVersion>
<Version>3.3.4.6</Version>
<FileVersion>3.3.4.6</FileVersion>
<Platforms>AnyCPU;x64</Platforms>
<PackageIcon>zero.png</PackageIcon>
</PropertyGroup>

Loading…
Cancel
Save

Powered by TurnKey Linux.