Skip to content

Commit

Permalink
v7.0.22272.0-Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Jun 1, 2023
1 parent e2db0a7 commit c666bfe
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22272.0-Beta" />
<PackageReference Include="ITHit.FileSystem" Version="7.0.22272.0-Beta" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Windows/Common/Core/Common.Windows.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22272.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22272.0-Beta" />
<ProjectReference Include="..\..\..\Common\Common.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Compile Remove="IVirtualFolder.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22272.0-Beta" />
<ProjectReference Include="..\..\..\Common\Common.csproj" />
<ProjectReference Include="..\Core\Common.Windows.Core.csproj" />
</ItemGroup>
Expand Down
13 changes: 3 additions & 10 deletions Windows/Common/VirtualDrive/PlaceholderItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,16 @@ public static async Task<bool> IsModifiedAsync(this PlaceholderItem placeholder,
/// <param name="placeholder">User file system placeholder item.</param>
/// <param name="remoteStorageItem">Remote storage item metadata.</param>
/// <returns>A task object that can be awaited.</returns>
public static async Task SavePropertiesAsync(this PlaceholderItem placeholder, FileSystemItemMetadataExt metadata, ILogger logger = null)
public static async Task SavePropertiesAsync(this PlaceholderItem placeholder, FileSystemItemMetadataExt metadata)
{
// Save lock.
// Save or remore lock.
if (metadata.Lock != null)
{
placeholder.SetLockInfo(metadata.Lock);
}
else
{
if (placeholder.TryGetLockInfo(out _) && placeholder.TryDeleteLockInfo())
{
PlaceholderItem.UpdateUI(placeholder.Path);
if (logger != null)
{
logger.LogMessage("Unlocked", placeholder.Path);
}
}
placeholder.TryDeleteLockInfo();
}

// Save eTag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22272.0-Beta" />
</ItemGroup>
<ItemGroup>
<None Update="log4net.config">
Expand Down
2 changes: 1 addition & 1 deletion Windows/VirtualDrive/VirtualDrive/VirtualDrive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This is an advanced project with ETags support, Microsoft Office documents editi
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22272.0-Beta" />
<ProjectReference Include="..\..\..\Common\Common.csproj" />
<ProjectReference Include="..\..\Common\VirtualDrive\Common.Windows.VirtualDrive.csproj" />
</ItemGroup>
Expand Down
Binary file modified Windows/VirtualDrive/VirtualDrive/VirtualDrive_TemporaryKey.pfx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Copyright>IT HIT LTD.</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22272.0-Beta" />
</ItemGroup>
<ItemGroup>
<None Update="log4net.config">
Expand Down
83 changes: 68 additions & 15 deletions Windows/WebDAVDrive/WebDAVDrive/RemoteStorageMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,73 @@ private async Task RunWebSocketsAsync(CancellationToken cancellationToken)
PropertyNameCaseInsensitive = true
});

string remoteStoragePath = Mapping.GetAbsoluteUri(webSocketMessage.ItemPath);

// Just in case there is more than one WebSockets server/virtual folder that
// is sending notifications (like with webdavserver.net, webdavserver.com),
// here we filter notifications that come from a different server/virtual folder.
if (remoteStoragePath.StartsWith(Program.Settings.WebDAVServerUrl, StringComparison.InvariantCultureIgnoreCase))
// Because of the on-demand loading, item or its parent may not exists or be offline.
// We can ignore notifiction in this case and avoid many requests to the remote storage.
if (ShouldUpdate(webSocketMessage))
{
Logger.LogDebug($"EventType: {webSocketMessage.EventType}", webSocketMessage.ItemPath, webSocketMessage.TargetPath);
await ProcessAsync();
}
}
}

/// <summary>
/// Verifies that the item exists in the user file system and should be updated.
/// </summary>
/// <param name="webSocketMessage">Information about change in the remote storage.</param>
/// <returns>True if the item exists and should be updated. False otherwise.</returns>
private bool ShouldUpdate(WebSocketMessage webSocketMessage)
{
string remoteStoragePath = Mapping.GetAbsoluteUri(webSocketMessage.ItemPath);

// Just in case there is more than one WebSockets server/virtual folder that
// is sending notifications (like with webdavserver.net, webdavserver.com),
// here we filter notifications that come from a different server/virtual folder.
if (remoteStoragePath.StartsWith(Program.Settings.WebDAVServerUrl, StringComparison.InvariantCultureIgnoreCase))
{
Logger.LogDebug($"EventType: {webSocketMessage.EventType}", webSocketMessage.ItemPath, webSocketMessage.TargetPath);

string userFileSystemPath = Mapping.ReverseMapPath(remoteStoragePath);
switch (webSocketMessage.EventType)
{
case "created":
case "deleted":
// Verify that parent folder exists and is not offline.
string userFileSystemParentPath = Path.GetDirectoryName(userFileSystemPath);
return Directory.Exists(userFileSystemParentPath)
&& !new DirectoryInfo(userFileSystemParentPath).Attributes.HasFlag(FileAttributes.Offline);

case "moved":
// Verify that source exists OR target folder exists and is not offline.
if (File.Exists(userFileSystemPath))
{
return true;
}
else
{
string remoteStorageNewPath = Mapping.GetAbsoluteUri(webSocketMessage.TargetPath);
string userFileSystemNewPath = Mapping.ReverseMapPath(remoteStorageNewPath);
string userFileSystemNewParentPath = Path.GetDirectoryName(userFileSystemNewPath);
return Directory.Exists(userFileSystemNewParentPath)
&& !new DirectoryInfo(userFileSystemNewParentPath).Attributes.HasFlag(FileAttributes.Offline);
}

case "updated":
default:
// Any other notifications.
return File.Exists(userFileSystemPath);
}
}

return false;
}

/// <summary>
/// Starts monitoring changes in the remote storage.
/// </summary>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
public async Task StartAsync(CancellationToken cancellationToken = default)
{
Logger.LogDebug("Starting", webSocketServerUrl);
await Task.Factory.StartNew(
async () =>
{
Expand All @@ -123,21 +171,19 @@ await Task.Factory.StartNew(
{
repeat = false;

Logger.LogDebug("Starting", webSocketServerUrl);

// Configure web sockets and connect to the server.
clientWebSocket.Options.KeepAliveInterval = TimeSpan.FromSeconds(10);
clientWebSocket.Options.Credentials = Engine.Credentials;
clientWebSocket.Options.Cookies = new CookieContainer();
clientWebSocket.Options.Cookies.Add(Engine.Cookies);
clientWebSocket.Options.SetRequestHeader("InstanceId", Engine.InstanceId.ToString());
await clientWebSocket.ConnectAsync(new Uri(webSocketServerUrl), cancellationToken);
Logger.LogDebug("Connected", webSocketServerUrl);
Logger.LogMessage("Connected", webSocketServerUrl);

// After esteblishing connection with a server we must get all changes from the remote storage.
// This is required on Engine start, server recovery, network recovery, etc.
Logger.LogDebug("Getting all changes from server", webSocketServerUrl);
await ProcessAsync();
await ProcessAsync(Logger);

Logger.LogMessage("Started", webSocketServerUrl);

Expand Down Expand Up @@ -193,20 +239,27 @@ public async Task StopAsync()
/// web sockets should not stop processing changes.
/// To stop processing changes that are already received the Engine must be stopped.
/// </remarks>
private async Task ProcessAsync()
private async Task ProcessAsync(ILogger logger = null)
{
try
{
await Engine.ServerNotifications(Engine.Path, Logger)
.ProcessChangesAsync(async (metadata, userFileSystemPath) =>
await Engine.Placeholders.GetItem(userFileSystemPath).SavePropertiesAsync(metadata as FileSystemItemMetadataExt, Logger));
await Engine.ServerNotifications(Engine.Path, logger).ProcessChangesAsync(SavePropertiesAsync);
}
catch (Exception ex)
{
Logger.LogError("Failed to process changes", Engine.Path, null, ex);
}
}

private async Task SavePropertiesAsync(IFileSystemItemMetadata metadata, string userFileSystemPath)
{
if(Engine.Placeholders.TryGetItem(userFileSystemPath, out PlaceholderItem placeholderItem))
{
await placeholderItem.SavePropertiesAsync(metadata as FileSystemItemMetadataExt);
}
}


private bool disposedValue = false; // To detect redundant calls

protected virtual void Dispose(bool disposing)
Expand Down
2 changes: 1 addition & 1 deletion Windows/WebDAVDrive/WebDAVDrive/WebDAVDrive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22158.0-Beta" />
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22272.0-Beta" />
<ProjectReference Include="..\..\Common\VirtualDrive\Common.Windows.VirtualDrive.csproj" />
<ProjectReference Include="..\WebDAVDrive.UI\WebDAVDrive.UI.csproj" />
</ItemGroup>
Expand Down
Binary file modified Windows/WebDAVDrive/WebDAVDrive/WebDAVDrive_TemporaryKey.pfx
Binary file not shown.

0 comments on commit c666bfe

Please sign in to comment.