Skip to content

Commit

Permalink
v2.0.4465.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Mar 19, 2021
1 parent 1b0e419 commit ca45391
Show file tree
Hide file tree
Showing 113 changed files with 2,743 additions and 1,598 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Text;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Thrown when a file can not be locked. For example when a lock-token file is blocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
using System.Text;
using System.Threading.Tasks;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Custom data stored with a file or folder placeholder, such original file/folder path. Max 4KB.
/// </summary>
/// <remarks>To avoid storing metatadata and keep footprit small, this class is is using custom serialization.</remarks>
internal class CustomData
public class CustomData
{
/// <summary>
/// Keeps the original file/folder path. Used to sync file/folder from user file system to remote storage
/// if this app was not running when the file/folder was moved or renamed. This field allows to avoid
/// delete-create sequence during client to server synchronization after app failure.
/// </summary>
internal string OriginalPath = "";
public string OriginalPath = "";

/// <summary>
/// Serializes all custom data fields into the byte array.
/// </summary>
/// <returns>Byte array representing custom data.</returns>
internal byte[] Serialize()
public byte[] Serialize()
{
using (MemoryStream m = new MemoryStream())
{
Expand All @@ -42,7 +42,7 @@ internal byte[] Serialize()
/// </summary>
/// <param name="data">Byte array representing custom data.</param>
/// <returns></returns>
internal static CustomData Desserialize(byte[] data)
public static CustomData Deserialize(byte[] data)
{
if(data == null)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public static void SetCustomData(Microsoft.Win32.SafeHandles.SafeFileHandle safe
public static void SetOriginalPath(this PlaceholderItem placeholder, string originalPath)
{
byte[] customDataRaw = placeholder.GetCustomData();
CustomData customData = (customDataRaw.Length > 0) ? CustomData.Desserialize(customDataRaw) : new CustomData();
CustomData customData = (customDataRaw.Length > 0) ? CustomData.Deserialize(customDataRaw) : new CustomData();

customData.OriginalPath = originalPath;
placeholder.SetCustomData(customData.Serialize());
Expand All @@ -90,7 +90,7 @@ public static void SetOriginalPath(this PlaceholderItem placeholder, string orig
public static string GetOriginalPath(this PlaceholderItem placeholder)
{
byte[] customDataRaw = placeholder.GetCustomData();
CustomData customData = (customDataRaw.Length > 0) ? CustomData.Desserialize(customDataRaw) : new CustomData();
CustomData customData = (customDataRaw.Length > 0) ? CustomData.Deserialize(customDataRaw) : new CustomData();
return customData.OriginalPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Text;
using System.Threading.Tasks;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Provides method for reading and writing ETags.
/// </summary>
internal static class ETag
public static class ETag
{
/// <summary>
/// Creates or updates ETag associated with the file.
Expand Down Expand Up @@ -56,10 +56,10 @@ public static void DeleteETag(string userFileSystemPath)
public static string GetETagFilePath(string userFileSystemPath)
{
// Get path relative to the virtual root.
string relativePath = Path.TrimEndingDirectorySeparator(userFileSystemPath).Substring(
Path.TrimEndingDirectorySeparator(Program.Settings.UserFileSystemRootPath).Length);
string relativePath = userFileSystemPath.TrimEnd(Path.DirectorySeparatorChar).Substring(
Config.Settings.UserFileSystemRootPath.TrimEnd(Path.DirectorySeparatorChar).Length);

string path = $"{Path.TrimEndingDirectorySeparator(Program.Settings.ServerDataFolderPath)}{relativePath}.etag";
string path = $"{Config.Settings.ServerDataFolderPath.TrimEnd(Path.DirectorySeparatorChar)}{relativePath}.etag";
return path;
}

Expand All @@ -73,7 +73,7 @@ public static string GetETagFilePath(string userFileSystemPath)
/// During client->server update it is sent back to the remote storage together with a modified content.
/// This ensures the changes on the server are not overwritten if the document on the server is modified.
/// </remarks>
internal static async Task<bool> ETagEqualsAsync(string userFileSystemPath, FileSystemItemBasicInfo remoteStorageItem)
public static async Task<bool> ETagEqualsAsync(string userFileSystemPath, FileSystemItemBasicInfo remoteStorageItem)
{
string remoteStorageETag = remoteStorageItem.ETag;
string userFileSystemETag = await ETag.GetETagAsync(userFileSystemPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Collections.Generic;
using System.Text;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
///<inheritdoc cref="IFileBasicInfo"/>
internal class FileBasicInfo : FileSystemItemBasicInfo, IFileBasicInfo
public class FileBasicInfo : FileSystemItemBasicInfo, IFileBasicInfo
{
///<inheritdoc/>
public long Length { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System.IO;
using System.Text;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Represents a basic information about the file or the folder in the user file system.
/// In addition to properties provided by <see cref="IFileSystemItem"/> this class contains Etag property.
/// </summary>
internal class FileSystemItemBasicInfo : IFileSystemItemBasicInfo
public class FileSystemItemBasicInfo : IFileSystemItemBasicInfo
{
///<inheritdoc/>
public string Name { get; set; }
Expand Down Expand Up @@ -42,5 +42,10 @@ internal class FileSystemItemBasicInfo : IFileSystemItemBasicInfo
/// Indicates if the item is locked by another user in the remote storage.
/// </summary>
public bool LockedByAnotherUser { get; set; }

/// <summary>
/// Custom columns data to be displayed in the file manager.
/// </summary>
public IEnumerable<FileSystemItemPropertyData> CustomProperties { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Collections.Generic;
using System.Text;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <inheritdoc cref="IFolderBasicInfo"/>
internal class FolderBasicInfo : FileSystemItemBasicInfo, IFolderBasicInfo
public class FolderBasicInfo : FileSystemItemBasicInfo, IFolderBasicInfo
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using FileAttributes = System.IO.FileAttributes;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Provides file system operations. Helps determining file and folder existence and creating file and folder items.
Expand Down Expand Up @@ -62,15 +64,15 @@ public static bool IsRecycleBin(string path)
/// Instance of <see cref="Windows.Storage.StorageFile"/> or <see cref="Windows.Storage.StorageFolder"/>
/// that corresponds to path or null if item does not exists.
/// </returns>
public static async Task<Windows.Storage.IStorageItem> GetStorageItemAsync(string path)
public static async Task<IStorageItem> GetStorageItemAsync(string path)
{
if (File.Exists(path))
{
return await Windows.Storage.StorageFile.GetFileFromPathAsync(path);
return await StorageFile.GetFileFromPathAsync(path);
}
if (Directory.Exists(path))
{
return await Windows.Storage.StorageFolder.GetFolderFromPathAsync(path);
return await StorageFolder.GetFolderFromPathAsync(path);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows" Version="2.0.4465.0" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions ITHit.FileSystem.Samples.Common/IUserFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using ITHit.FileSystem;
using System.IO;
using System.Threading.Tasks;

namespace ITHit.FileSystem.Samples.Common
{
public interface IUserFile : IUserFileSystemItem
{
Task<byte[]> ReadAsync(long offset, long length);
Task<string> UpdateAsync(IFileBasicInfo fileInfo, Stream content = null, ServerLockInfo lockInfo = null);
Task<bool> ValidateDataAsync(long offset, long length);
}
}
12 changes: 12 additions & 0 deletions ITHit.FileSystem.Samples.Common/IUserFileSystemItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace ITHit.FileSystem.Samples.Common
{
public interface IUserFileSystemItem
{
Task DeleteAsync();
Task<ServerLockInfo> LockAsync();
Task MoveToAsync(string userFileSystemNewPath);
Task UnlockAsync(string lockToken);
}
}
15 changes: 15 additions & 0 deletions ITHit.FileSystem.Samples.Common/IUserFolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ITHit.FileSystem;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace ITHit.FileSystem.Samples.Common
{
public interface IUserFolder : IUserFileSystemItem
{
Task<string> CreateFileAsync(IFileBasicInfo fileInfo, Stream content);
Task<string> CreateFolderAsync(IFolderBasicInfo folderInfo);
Task<IEnumerable<FileSystemItemBasicInfo>> EnumerateChildrenAsync(string pattern);
Task<string> UpdateAsync(IFolderBasicInfo folderInfo, ServerLockInfo lockInfo = null);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ITHit.FileSystem;
using Microsoft.VisualBasic.FileIO;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -9,7 +8,7 @@
using System.Threading.Tasks;
using Windows.System;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Represents file lock.
Expand Down Expand Up @@ -183,17 +182,17 @@ internal bool IsNew()
return lockTokenFileStream.Length == 0;
}

internal async Task SetLockInfoAsync(LockInfo lockInfo)
internal async Task SetLockInfoAsync(ServerLockInfo lockInfo)
{
lockTokenFileStream.Seek(0, SeekOrigin.Begin);
await JsonSerializer.SerializeAsync(lockTokenFileStream, lockInfo);
lockTokenFileStream.SetLength(lockTokenFileStream.Position);
}

internal async Task<LockInfo> GetLockInfoAsync()
internal async Task<ServerLockInfo> GetLockInfoAsync()
{
lockTokenFileStream.Seek(0, SeekOrigin.Begin);
return await JsonSerializer.DeserializeAsync<LockInfo>(lockTokenFileStream);
return await JsonSerializer.DeserializeAsync<ServerLockInfo>(lockTokenFileStream);
}

/// <summary>
Expand All @@ -203,11 +202,11 @@ internal async Task<LockInfo> GetLockInfoAsync()
/// <returns>Path to the file that contains the lock mode.</returns>
private static string GetLockModeFilePath(string userFileSystemPath)
{

// Get path relative to the virtual root.
string relativePath = Path.TrimEndingDirectorySeparator(userFileSystemPath).Substring(
Path.TrimEndingDirectorySeparator(Program.Settings.UserFileSystemRootPath).Length);

string path = $"{Path.TrimEndingDirectorySeparator(Program.Settings.ServerDataFolderPath)}{relativePath}.lockmode";
string relativePath = userFileSystemPath.TrimEnd(Path.DirectorySeparatorChar).Substring(
Config.Settings.UserFileSystemRootPath.TrimEnd(Path.DirectorySeparatorChar).Length);
string path = $"{Config.Settings.ServerDataFolderPath.TrimEnd(Path.DirectorySeparatorChar)}{relativePath}.lockmode";
return path;
}

Expand All @@ -219,10 +218,10 @@ private static string GetLockModeFilePath(string userFileSystemPath)
private static string GetLockTokenFilePath(string userFileSystemPath)
{
// Get path relative to the virtual root.
string relativePath = Path.TrimEndingDirectorySeparator(userFileSystemPath).Substring(
Path.TrimEndingDirectorySeparator(Program.Settings.UserFileSystemRootPath).Length);
string relativePath = userFileSystemPath.TrimEnd(Path.DirectorySeparatorChar).Substring(
Config.Settings.UserFileSystemRootPath.TrimEnd(Path.DirectorySeparatorChar).Length);

string path = $"{Path.TrimEndingDirectorySeparator(Program.Settings.ServerDataFolderPath)}{relativePath}.locktoken";
string path = $"{Config.Settings.ServerDataFolderPath.TrimEnd(Path.DirectorySeparatorChar)}{relativePath}.locktoken";
return path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace VirtualFileSystem
namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Indicates how the file was locked and how to unlock the file.
Expand Down
41 changes: 41 additions & 0 deletions ITHit.FileSystem.Samples.Common/Locks/ServerLockInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Information about the lock returned from the remote storage as a result of the lock operation.
/// </summary>
public class ServerLockInfo
{
/// <summary>
/// Lock-token. Must be supplied during the item update and unlock operations.
/// </summary>
public string LockToken { get; set; }

/// <summary>
/// Lock expidation date/time returned by the server.
/// </summary>
public DateTimeOffset LockExpirationDateUtc { get; set; }

/// <summary>
/// Name of the user that locked the item.
/// </summary>
public string Owner { get; set; }

/// <summary>
/// True if the item is locked exclusively. False in case the item has a shared lock.
/// </summary>
public bool Exclusive { get; set; }

public IEnumerable<FileSystemItemPropertyData> GetLockProperties(string lockIconPath)
{
List<FileSystemItemPropertyData> lockProps = new List<FileSystemItemPropertyData>();
lockProps.Add(new FileSystemItemPropertyData(2, Owner, lockIconPath));
lockProps.Add(new FileSystemItemPropertyData(3, Exclusive ? "Exclusive" : "Shared"));
lockProps.Add(new FileSystemItemPropertyData(4, LockExpirationDateUtc.ToString()));
return lockProps;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using System.Text;
using System.Threading;

namespace VirtualFileSystem
using ITHit.FileSystem;

namespace ITHit.FileSystem.Samples.Common
{
/// <summary>
/// Implements unified logging.
/// </summary>
internal class Logger : ITHit.FileSystem.ILogger
public class Logger : ILogger
{
/// <summary>
/// Name of the component that is writing to the log.
Expand All @@ -26,7 +28,7 @@ internal class Logger : ITHit.FileSystem.ILogger
/// </summary>
/// <param name="componentName">Name of the component that is writing to the log.</param>
/// <param name="logger">Log4Net Logger.</param>
internal Logger(string componentName, ILog logger)
public Logger(string componentName, ILog logger)
{
this.componentName = componentName;
this.Log = logger;
Expand Down
Loading

0 comments on commit ca45391

Please sign in to comment.