Skip to content

Commit

Permalink
v1.2.3941.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Nov 19, 2020
1 parent 93f1615 commit 8bdeece
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace VirtualFileSystem.Syncronyzation
/// <summary>
/// User File System to Remote Storage synchronization.
/// </summary>
/// <remarks>In most cases you can use this class in your project without any changes.</remarks>
internal class ClientToServerSync : Logger
{
/// <summary>
Expand Down
32 changes: 32 additions & 0 deletions VirtualFileSystem/Framework/Syncronyzation/FileAttributesExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace VirtualFileSystem.Syncronyzation
{

/// <summary>
/// File attributes that are not provided by .NET, but required for
/// detecting pinned/unpinned files and synchronization.
/// </summary>
/// <remarks>
/// You can enable Attributes column in Windows File Manager to see them.
/// Some usefull file attributes reference:
///
/// 4194304 (0x400000) FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS (M)
/// 4096 (0x1000) FILE_ATTRIBUTE_OFFLINE (O)
/// 1024 (0x400) FILE_ATTRIBUTE_REPARSE_POINT (L)
/// 16 (0x10) FILE_ATTRIBUTE_DIRECTORY (D)
/// (0x00080000) FILE_ATTRIBUTE_PINNED (P)
/// (0x00100000) FILE_ATTRIBUTE_UNPINNED (U)
/// 32 (0x20) FILE_ATTRIBUTE_ARCHIVE (A)
/// 512 (0x200) FILE_ATTRIBUTE_SPARSE_FILE
/// </remarks>
[Flags]
public enum FileAttributesExt
{
Pinned = 0x00080000,
Unpinned = 0x00100000,
Offline = 0x1000
}
}
22 changes: 3 additions & 19 deletions VirtualFileSystem/Framework/Syncronyzation/FullSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,13 @@

namespace VirtualFileSystem.Syncronyzation
{

// 4194304 (0x400000) FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS (M)
// 4096 (0x1000) FILE_ATTRIBUTE_OFFLINE (O)
// 1024 (0x400) FILE_ATTRIBUTE_REPARSE_POINT (L)
// 16 (0x10) FILE_ATTRIBUTE_DIRECTORY (D)
// (0x00080000) FILE_ATTRIBUTE_PINNED (P)
// (0x00100000) FILE_ATTRIBUTE_UNPINNED (U)
// 32 (0x20) FILE_ATTRIBUTE_ARCHIVE (A)
// 512 (0x200) FILE_ATTRIBUTE_SPARSE_FILE

[Flags]
public enum FileAttributesExt
{
Pinned = 0x00080000,
Unpinned = 0x00100000,
Offline = 0x1000
}

/// <summary>
/// Doing full synchronization between client and server.
/// Doing full synchronization between the user file system and the remote storage, recursively going through all folders.
/// </summary>
/// <remarks>
/// This is a simple full synchronyzation example.
///
/// You can use this class in your project out of the box or replace with a more advanced algorithm.
/// </remarks>
internal class FullSyncService : Logger, IDisposable
{
Expand Down
24 changes: 15 additions & 9 deletions VirtualFileSystem/Framework/Syncronyzation/RemoteStorageRawItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
namespace VirtualFileSystem.Syncronyzation
{
/// <summary>
/// Provides methods for synching user file system to remote storage.
/// Creates, updates and delets files and folders based on the info from user file system.
/// Sets status icons in file manager.
/// Provides methods for synching the user file system to the remote storage.
/// Creates, updates, deletes, moves, locks and unloacks files and folders based on the info from user file system.
/// This class also іets status icons in file manager.
/// </summary>
/// <remarks>In most cases you can use this class in your project without any changes.</remarks>
public class RemoteStorageRawItem
{
/// <summary>
Expand Down Expand Up @@ -46,14 +47,19 @@ internal RemoteStorageRawItem(string userFileSystemPath, ILogger logger)
this.logger = logger;
}

/// <summary>
/// Creates a new file or folder in the remote storage.
/// </summary>
/// <param name="userFileSystemNewItemPath">Path to the file or folder in the user file system to be created in the remote storage.</param>
/// <param name="logger">Logger</param>
public static async Task CreateAsync(string userFileSystemNewItemPath, ILogger logger)
{
try
{
logger.LogMessage("Creating item in remote storage", userFileSystemNewItemPath);
logger.LogMessage("Creating item in the remote storage", userFileSystemNewItemPath);
await new RemoteStorageRawItem(userFileSystemNewItemPath, logger).CreateOrUpdateAsync(FileMode.CreateNew);
await new UserFileSystemRawItem(userFileSystemNewItemPath).ClearStateAsync();
logger.LogMessage("Created item in remote storage succesefully", userFileSystemNewItemPath);
logger.LogMessage("Created item in the remote storage succesefully", userFileSystemNewItemPath);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -354,7 +360,7 @@ internal async Task<bool> DeleteAsync()
}

/// <summary>
/// Locks file in the remote storage.
/// Locks the file in the remote storage.
/// </summary>
/// <param name="lockMode">
/// Indicates automatic or manual lock.
Expand All @@ -371,7 +377,7 @@ internal async Task LockAsync(LockMode lockMode = LockMode.Manual)
}

/// <summary>
/// Locks file in the remote storage or gets existing lock.
/// Locks the file in the remote storage or gets existing lock.
/// </summary>
/// <param name="lockFileOpenMode">
/// Indicates if a new lock should be created or existing lock file to be opened.
Expand Down Expand Up @@ -415,7 +421,7 @@ private async Task<Lock> LockAsync(FileMode lockFileOpenMode, LockMode lockMode
/// <summary>
/// Unlocks the file in the remote storage.
/// </summary>
private async Task UnlockAsync()
internal async Task UnlockAsync()
{
using (Lock fileLock = await LockAsync(FileMode.Open))
{
Expand All @@ -424,7 +430,7 @@ private async Task UnlockAsync()
}

/// <summary>
/// Unlocks the file in the remote storage.
/// Unlocks the file in the remote storage using existing <see cref="Lock"/>.
/// </summary>
/// <param name="fileLock">File lock.</param>
private async Task UnlockAsync(Lock fileLock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace VirtualFileSystem.Syncronyzation
/// <summary>
/// Synchronizes files and folders from remote storage to user file system.
/// </summary>
/// <remarks>In most cases you can use this class in your project without any changes.</remarks>
internal class ServerToClientSync : Logger
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace VirtualFileSystem.Syncronyzation
/// <remarks>
/// Windows does not provide any notifications for pinned/unpinned attributes change as well as for files/folders creation.
/// We need to monitor them using regular FileSystemWatcher.
///
/// In most cases you can use this class in your project without any changes.
/// </remarks>
internal class UserFileSystemMonitor : Logger, IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
namespace VirtualFileSystem.Syncronyzation
{
/// <summary>
/// Provides methods for synching from remote storage to user file system.
/// Creates, updates and delets placeholder files and folders based on the info from remote storage.
/// Provides methods for synching the from remote storage to the user file system.
/// Creates, updates and deletes placeholder files and folders based on the info from the remote storage.
/// </summary>
/// <remarks>In most cases you can use this class in your project without any changes.</remarks>
internal class UserFileSystemRawItem
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions VirtualFileSystem/Framework/VfsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace VirtualFileSystem
{
// In most cases you can use this class in your project without any changes.
/// <inheritdoc/>
internal class VfsEngine : EngineWindows
{
Expand Down
13 changes: 11 additions & 2 deletions VirtualFileSystem/Framework/VfsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace VirtualFileSystem
{
// In most cases you can use this class in your project without any changes.
/// <inheritdoc cref="IFile"/>
internal class VfsFile : VfsFileSystemItem, IFile
{
Expand Down Expand Up @@ -81,8 +82,16 @@ public async Task CloseAsync(IOperationContext operationContext, IResultContext

try
{
// Send content to remote storage. Unlock if auto-locked.
await new RemoteStorageRawItem(userFileSystemFilePath, Logger).UpdateAsync();
if (PlaceholderItem.GetItem(userFileSystemFilePath).IsNew())
{
// Create new file in the remote storage.
await RemoteStorageRawItem.CreateAsync(userFileSystemFilePath, Logger);
}
else
{
// Send content to remote storage. Unlock if auto-locked.
await new RemoteStorageRawItem(userFileSystemFilePath, Logger).UpdateAsync();
}
}
catch (IOException ex)
{
Expand Down
1 change: 1 addition & 0 deletions VirtualFileSystem/Framework/VfsFileSystemItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace VirtualFileSystem
{
// In most cases you can use this class in your project without any changes.
///<inheritdoc>
internal abstract class VfsFileSystemItem : IFileSystemItem
{
Expand Down
1 change: 1 addition & 0 deletions VirtualFileSystem/Framework/VfsFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace VirtualFileSystem
{
// In most cases you can use this class in your project without any changes.
//$<IFolder
/// <inheritdoc cref="IFolder"/>
internal class VfsFolder : VfsFileSystemItem, IFolder
Expand Down
17 changes: 9 additions & 8 deletions VirtualFileSystem/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
namespace VirtualFileSystem
{
/// <summary>
/// Maps user file system path to remote storage path and back.
/// Maps a user file system path to the remote storage path and back.
/// </summary>
/// <remarks>You will change methods of this class to map the user file system path to your remote storage path.</remarks>
internal static class Mapping
{
/// <summary>
/// Returns remote storage path that corresponds to user file system path.
/// Returns a remote storage path that corresponds to the user file system path.
/// </summary>
/// <param name="userFileSystemPath">Full path in user file system.</param>
/// <returns>Path in remote storage that corresponds to <paramref name="userFileSystemPath"/>.</returns>
/// <param name="userFileSystemPath">Full path in the user file system.</param>
/// <returns>Path in the remote storage that corresponds to the <paramref name="userFileSystemPath"/>.</returns>
public static string MapPath(string userFileSystemPath)
{
// Get path relative to the virtual root.
Expand All @@ -29,10 +30,10 @@ public static string MapPath(string userFileSystemPath)
}

/// <summary>
/// Returns user file system path that corresponds to remote storage path.
/// Returns a user file system path that corresponds to the remote storage path.
/// </summary>
/// <param name="remoteStoragePath">Full path in remote storage.</param>
/// <returns>Path in user file system that corresponds to <paramref name="remoteStoragePath"/>.</returns>
/// <param name="remoteStoragePath">Full path in the remote storage.</param>
/// <returns>Path in the user file system that corresponds to the <paramref name="remoteStoragePath"/>.</returns>
public static string ReverseMapPath(string remoteStoragePath)
{
// Get path relative to the virtual root.
Expand All @@ -44,7 +45,7 @@ public static string ReverseMapPath(string remoteStoragePath)
}

/// <summary>
/// Gets user file system item info from the remote storage data.
/// Gets a user file system item info from the remote storage data.
/// </summary>
/// <param name="remoteStorageItem">Remote storage item info.</param>
/// <returns>User file system item info.</returns>
Expand Down
10 changes: 5 additions & 5 deletions VirtualFileSystem/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ private static void ShowTestEnvironment()


// Open Windows File Manager with ETags and locks storage.
ProcessStartInfo serverDataInfo = new ProcessStartInfo(Program.Settings.ServerDataFolderPath);
serverDataInfo.UseShellExecute = true; // Open window only if not opened already.
using (Process serverDataWinFileManager = Process.Start(serverDataInfo))
{
//ProcessStartInfo serverDataInfo = new ProcessStartInfo(Program.Settings.ServerDataFolderPath);
//serverDataInfo.UseShellExecute = true; // Open window only if not opened already.
//using (Process serverDataWinFileManager = Process.Start(serverDataInfo))
//{

}
//}
}
#endif

Expand Down
1 change: 1 addition & 0 deletions VirtualFileSystem/UserFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace VirtualFileSystem
/// <summary>
/// Represents a file in the remote storage.
/// </summary>
/// <remarks>You will change methods of this class to read/write data from/to your remote storage.</remarks>
internal class UserFile : UserFileSystemItem
{
/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions VirtualFileSystem/UserFileSystemItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace VirtualFileSystem
/// <summary>
/// Represents a file or a folder in the remote storage. Contains methods common for both files and folders.
/// </summary>
/// <remarks>You will change methods of this class to read/write data from/to your remote storage.</remarks>
internal class UserFileSystemItem
{
/// <summary>
Expand Down Expand Up @@ -245,7 +246,7 @@ protected async Task<string> CreateOrUpdateFolderAsync(string remoteStoragePath,
/// </summary>
/// <returns>Lock info that conains lock-token returned by the remote storage.</returns>
/// <remarks>
/// Lock your item in the remote storage here and receive the lock-token.
/// Lock your item in the remote storage in this method and receive the lock-token.
/// Return a new <see cref="LockInfo"/> object with the <see cref="LockInfo.LockToken"/> being set from this function.
/// The <see cref="LockInfo"/> will become available via the <see cref="Lock"/> property when the
/// item in the remote storage should be updated. Supply the lock-token during the update request in
Expand All @@ -260,7 +261,10 @@ public async Task<LockInfo> LockAsync()
/// Unlocks the item in the remote storage.
/// </summary>
/// <param name="lockToken">Lock token to unlock the item in the remote storage.</param>
/// <remarks>Unlock your item in the remote storage using the <paramref name="lockToken"/> parameter.</remarks>
/// <remarks>
/// Unlock your item in the remote storage in this method using the
/// <paramref name="lockToken"/> parameter.
/// </remarks>
public async Task UnlockAsync(string lockToken)
{

Expand Down
1 change: 1 addition & 0 deletions VirtualFileSystem/UserFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace VirtualFileSystem
/// Represents a folder in the remote storage. Provides methods for enumerating this folder children,
/// creating files and folders and updating this folder information (creatin date, modification date, attributes, etc.).
/// </summary>
/// <remarks>You will change methods of this class to read/write data from/to your remote storage.</remarks>
internal class UserFolder : UserFileSystemItem
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion VirtualFileSystem/VirtualFileSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.7" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows" Version="1.2.3810.0" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="1.2.3941.0" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
Expand Down

0 comments on commit 8bdeece

Please sign in to comment.