Skip to content

Commit c666bfe

Browse files
committed
v7.0.22272.0-Beta
1 parent e2db0a7 commit c666bfe

File tree

11 files changed

+80
-34
lines changed

11 files changed

+80
-34
lines changed

Common/Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Platforms>AnyCPU;x64</Platforms>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22158.0-Beta" />
14-
<PackageReference Include="ITHit.FileSystem" Version="7.0.22158.0-Beta" />
13+
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22272.0-Beta" />
14+
<PackageReference Include="ITHit.FileSystem" Version="7.0.22272.0-Beta" />
1515
</ItemGroup>
1616
</Project>

Windows/Common/Core/Common.Windows.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
2121
</ItemGroup>
2222
<ItemGroup>
23-
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22158.0-Beta" />
24-
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22158.0-Beta" />
23+
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22272.0-Beta" />
24+
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22272.0-Beta" />
2525
<ProjectReference Include="..\..\..\Common\Common.csproj" />
2626
</ItemGroup>
2727
</Project>

Windows/Common/VirtualDrive/Common.Windows.VirtualDrive.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Compile Remove="IVirtualFolder.cs" />
1414
</ItemGroup>
1515
<ItemGroup>
16-
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22158.0-Beta" />
16+
<PackageReference Include="ITHit.FileSystem.Windows" Version="7.0.22272.0-Beta" />
1717
<ProjectReference Include="..\..\..\Common\Common.csproj" />
1818
<ProjectReference Include="..\Core\Common.Windows.Core.csproj" />
1919
</ItemGroup>

Windows/Common/VirtualDrive/PlaceholderItemExtensions.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,16 @@ public static async Task<bool> IsModifiedAsync(this PlaceholderItem placeholder,
3737
/// <param name="placeholder">User file system placeholder item.</param>
3838
/// <param name="remoteStorageItem">Remote storage item metadata.</param>
3939
/// <returns>A task object that can be awaited.</returns>
40-
public static async Task SavePropertiesAsync(this PlaceholderItem placeholder, FileSystemItemMetadataExt metadata, ILogger logger = null)
40+
public static async Task SavePropertiesAsync(this PlaceholderItem placeholder, FileSystemItemMetadataExt metadata)
4141
{
42-
// Save lock.
42+
// Save or remore lock.
4343
if (metadata.Lock != null)
4444
{
4545
placeholder.SetLockInfo(metadata.Lock);
4646
}
4747
else
4848
{
49-
if (placeholder.TryGetLockInfo(out _) && placeholder.TryDeleteLockInfo())
50-
{
51-
PlaceholderItem.UpdateUI(placeholder.Path);
52-
if (logger != null)
53-
{
54-
logger.LogMessage("Unlocked", placeholder.Path);
55-
}
56-
}
49+
placeholder.TryDeleteLockInfo();
5750
}
5851

5952
// Save eTag.

Windows/VirtualDrive/VirtualDrive.ShellExtension/VirtualDrive.ShellExtension.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
2020
</ItemGroup>
2121
<ItemGroup>
22-
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22158.0-Beta" />
22+
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22272.0-Beta" />
2323
</ItemGroup>
2424
<ItemGroup>
2525
<None Update="log4net.config">

Windows/VirtualDrive/VirtualDrive/VirtualDrive.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This is an advanced project with ETags support, Microsoft Office documents editi
4040
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
4141
</ItemGroup>
4242
<ItemGroup>
43-
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22158.0-Beta" />
43+
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22272.0-Beta" />
4444
<ProjectReference Include="..\..\..\Common\Common.csproj" />
4545
<ProjectReference Include="..\..\Common\VirtualDrive\Common.Windows.VirtualDrive.csproj" />
4646
</ItemGroup>
Binary file not shown.

Windows/WebDAVDrive/WebDAVDrive.ShellExtension/WebDAVDrive.ShellExtension.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Copyright>IT HIT LTD.</Copyright>
1313
</PropertyGroup>
1414
<ItemGroup>
15-
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22158.0-Beta" />
15+
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="7.0.22272.0-Beta" />
1616
</ItemGroup>
1717
<ItemGroup>
1818
<None Update="log4net.config">

Windows/WebDAVDrive/WebDAVDrive/RemoteStorageMonitor.cs

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,73 @@ private async Task RunWebSocketsAsync(CancellationToken cancellationToken)
9090
PropertyNameCaseInsensitive = true
9191
});
9292

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

102+
/// <summary>
103+
/// Verifies that the item exists in the user file system and should be updated.
104+
/// </summary>
105+
/// <param name="webSocketMessage">Information about change in the remote storage.</param>
106+
/// <returns>True if the item exists and should be updated. False otherwise.</returns>
107+
private bool ShouldUpdate(WebSocketMessage webSocketMessage)
108+
{
109+
string remoteStoragePath = Mapping.GetAbsoluteUri(webSocketMessage.ItemPath);
110+
111+
// Just in case there is more than one WebSockets server/virtual folder that
112+
// is sending notifications (like with webdavserver.net, webdavserver.com),
113+
// here we filter notifications that come from a different server/virtual folder.
114+
if (remoteStoragePath.StartsWith(Program.Settings.WebDAVServerUrl, StringComparison.InvariantCultureIgnoreCase))
115+
{
116+
Logger.LogDebug($"EventType: {webSocketMessage.EventType}", webSocketMessage.ItemPath, webSocketMessage.TargetPath);
117+
118+
string userFileSystemPath = Mapping.ReverseMapPath(remoteStoragePath);
119+
switch (webSocketMessage.EventType)
120+
{
121+
case "created":
122+
case "deleted":
123+
// Verify that parent folder exists and is not offline.
124+
string userFileSystemParentPath = Path.GetDirectoryName(userFileSystemPath);
125+
return Directory.Exists(userFileSystemParentPath)
126+
&& !new DirectoryInfo(userFileSystemParentPath).Attributes.HasFlag(FileAttributes.Offline);
127+
128+
case "moved":
129+
// Verify that source exists OR target folder exists and is not offline.
130+
if (File.Exists(userFileSystemPath))
131+
{
132+
return true;
133+
}
134+
else
135+
{
136+
string remoteStorageNewPath = Mapping.GetAbsoluteUri(webSocketMessage.TargetPath);
137+
string userFileSystemNewPath = Mapping.ReverseMapPath(remoteStorageNewPath);
138+
string userFileSystemNewParentPath = Path.GetDirectoryName(userFileSystemNewPath);
139+
return Directory.Exists(userFileSystemNewParentPath)
140+
&& !new DirectoryInfo(userFileSystemNewParentPath).Attributes.HasFlag(FileAttributes.Offline);
141+
}
142+
143+
case "updated":
144+
default:
145+
// Any other notifications.
146+
return File.Exists(userFileSystemPath);
147+
}
148+
}
149+
150+
return false;
151+
}
152+
106153
/// <summary>
107154
/// Starts monitoring changes in the remote storage.
108155
/// </summary>
109156
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
110157
public async Task StartAsync(CancellationToken cancellationToken = default)
111158
{
159+
Logger.LogDebug("Starting", webSocketServerUrl);
112160
await Task.Factory.StartNew(
113161
async () =>
114162
{
@@ -123,21 +171,19 @@ await Task.Factory.StartNew(
123171
{
124172
repeat = false;
125173

126-
Logger.LogDebug("Starting", webSocketServerUrl);
127-
128174
// Configure web sockets and connect to the server.
129175
clientWebSocket.Options.KeepAliveInterval = TimeSpan.FromSeconds(10);
130176
clientWebSocket.Options.Credentials = Engine.Credentials;
131177
clientWebSocket.Options.Cookies = new CookieContainer();
132178
clientWebSocket.Options.Cookies.Add(Engine.Cookies);
133179
clientWebSocket.Options.SetRequestHeader("InstanceId", Engine.InstanceId.ToString());
134180
await clientWebSocket.ConnectAsync(new Uri(webSocketServerUrl), cancellationToken);
135-
Logger.LogDebug("Connected", webSocketServerUrl);
181+
Logger.LogMessage("Connected", webSocketServerUrl);
136182

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

142188
Logger.LogMessage("Started", webSocketServerUrl);
143189

@@ -193,20 +239,27 @@ public async Task StopAsync()
193239
/// web sockets should not stop processing changes.
194240
/// To stop processing changes that are already received the Engine must be stopped.
195241
/// </remarks>
196-
private async Task ProcessAsync()
242+
private async Task ProcessAsync(ILogger logger = null)
197243
{
198244
try
199245
{
200-
await Engine.ServerNotifications(Engine.Path, Logger)
201-
.ProcessChangesAsync(async (metadata, userFileSystemPath) =>
202-
await Engine.Placeholders.GetItem(userFileSystemPath).SavePropertiesAsync(metadata as FileSystemItemMetadataExt, Logger));
246+
await Engine.ServerNotifications(Engine.Path, logger).ProcessChangesAsync(SavePropertiesAsync);
203247
}
204248
catch (Exception ex)
205249
{
206250
Logger.LogError("Failed to process changes", Engine.Path, null, ex);
207251
}
208252
}
209253

254+
private async Task SavePropertiesAsync(IFileSystemItemMetadata metadata, string userFileSystemPath)
255+
{
256+
if(Engine.Placeholders.TryGetItem(userFileSystemPath, out PlaceholderItem placeholderItem))
257+
{
258+
await placeholderItem.SavePropertiesAsync(metadata as FileSystemItemMetadataExt);
259+
}
260+
}
261+
262+
210263
private bool disposedValue = false; // To detect redundant calls
211264

212265
protected virtual void Dispose(bool disposing)

Windows/WebDAVDrive/WebDAVDrive/WebDAVDrive.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
4040
</ItemGroup>
4141
<ItemGroup>
42-
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22158.0-Beta" />
42+
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="7.0.22272.0-Beta" />
4343
<ProjectReference Include="..\..\Common\VirtualDrive\Common.Windows.VirtualDrive.csproj" />
4444
<ProjectReference Include="..\WebDAVDrive.UI\WebDAVDrive.UI.csproj" />
4545
</ItemGroup>

0 commit comments

Comments
 (0)