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

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

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

@ -53,9 +53,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTransferServer", "FileT
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConnectionTest", "ConnectionTest", "{D5207A5A-2F27-4992-9BA5-0BDCFC59F133}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConnectionTest", "ConnectionTest", "{D5207A5A-2F27-4992-9BA5-0BDCFC59F133}"
EndProject 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|Any CPU.Build.0 = 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.ActiveCfg = Release|x64
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x64.Build.0 = Release|Any CPU {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.ActiveCfg = Release|Any CPU
{08CDD42E-E324-40A4-88C3-EDD0493AAF84}.Release|x86.Build.0 = 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 {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}.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.ActiveCfg = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|Any CPU.Build.0 = 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.ActiveCfg = Release|x64
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x64.Build.0 = Release|Any CPU {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.ActiveCfg = Release|Any CPU
{3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x86.Build.0 = Release|Any CPU {3496A688-0749-48C2-BD60-ABB42A5C17C9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection

@ -65,9 +65,19 @@ namespace ZeroLevel.Services.FileSystem
private void CheckSourceFolder() private void CheckSourceFolder()
{ {
string[] files = null;
try try
{ {
var files = GetFilesFromSource(); 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); OnStartMovingFilesToTemporary?.Invoke(files.Length);
foreach (var file in files) foreach (var file in files)
{ {
@ -82,6 +92,11 @@ namespace ZeroLevel.Services.FileSystem
try try
{ {
tempFile = MoveToTemporary(file); tempFile = MoveToTemporary(file);
if (string.IsNullOrWhiteSpace(tempFile))
{
Log.SystemWarning($"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to move file '{file}' to temporary directory '{_temporaryFolder}'. Without system error!");
continue;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -111,16 +126,8 @@ namespace ZeroLevel.Services.FileSystem
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault proceed file {file}"); 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> /// <summary>
/// Moving a file to a temporary directory /// Moving a file to a temporary directory
@ -137,9 +144,13 @@ namespace ZeroLevel.Services.FileSystem
tempFile = TrySolveCollision(tempFile); tempFile = TrySolveCollision(tempFile);
} }
File.Copy(from, tempFile, false); File.Copy(from, tempFile, false);
if (File.Exists(tempFile))
{
File.Delete(from); File.Delete(from);
return tempFile; return tempFile;
} }
return null;
}
/// <summary> /// <summary>
/// Resolving collisions in filenames in the temporary directory /// Resolving collisions in filenames in the temporary directory
@ -177,19 +188,22 @@ namespace ZeroLevel.Services.FileSystem
/// </summary> /// </summary>
private string[] GetFilesFromSource() private string[] GetFilesFromSource()
{ {
string[] files;
if (_extensions.Count > 0) if (_extensions.Count > 0)
{ {
string[] files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Where(f => _extensions.Contains(Path.GetExtension(f).ToLowerInvariant())).ToArray(); ?.Where(f => _extensions.Contains(Path.GetExtension(f).ToLowerInvariant()))
Array.Sort<string>(files, FileNameSortCompare); ?.ToArray();
return files;
} }
else 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); Array.Sort<string>(files, FileNameSortCompare);
return files;
} }
return files;
} }
/// <summary> /// <summary>

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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.