Skip to content

Commit

Permalink
v5.0.14726.0-Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Jun 3, 2022
1 parent 9535fe6 commit eb231de
Show file tree
Hide file tree
Showing 153 changed files with 1,549 additions and 5,146 deletions.
5 changes: 3 additions & 2 deletions Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>IT Hit LTD.</Authors>
<Company>IT Hit LTD.</Company>
<Product>IT Hit User File System</Product>
<Copyright>IT Hit User File System</Copyright>
<Description>Contains functionality common for all Virtual Drive samples, both for Windows and macOS.</Description>
<RootNamespace>ITHit.FileSystem.Samples.Common</RootNamespace>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem" Version="4.4.14432.0" />
<PackageReference Include="ITHit.FileSystem" Version="5.0.14726.0-Beta" />
</ItemGroup>
</Project>
10 changes: 0 additions & 10 deletions Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,5 @@ public class Settings
/// Automatically lock the file in the remote storage when a file handle is being opened for writing, unlock on close.
/// </summary>
public bool AutoLock { get; set; }

/// <summary>
/// Communication channel name is used by RPC to establish connection over named pipes.
/// </summary>
public string RpcCommunicationChannelName { get; set; }

/// <summary>
/// Gets or sets the maximum number of concurrent tasks
/// </summary>
public int MaxDegreeOfParallelism { get; set; }
}
}
12 changes: 9 additions & 3 deletions Windows/Common/Core/Common.Windows.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows10.0.18362.0</TargetFramework>
<CsWinRTWindowsMetadata>10.0.18362.0</CsWinRTWindowsMetadata>
<TargetFrameworks>net48;net5.0-windows10.0.19041.0</TargetFrameworks>
<Description>Contains functionality common for all Windows Virtual Drive samples.</Description>
<Authors>IT Hit LTD.</Authors>
<Product>IT Hit User File System</Product>
<Copyright>IT Hit LTD.</Copyright>
<RootNamespace>ITHit.FileSystem.Samples.Common.Windows.Core</RootNamespace>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<Compile Remove="ConsoleProcessor.cs" />
<Compile Remove="Logger.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.13" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows" Version="4.4.14432.0" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="5.0.14726.0-Beta" />
<ProjectReference Include="..\..\..\Common\Common.csproj" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Windows/Common/Core/FsPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;
using Windows.Storage;
using FileAttributes = System.IO.FileAttributes;
using ITHit.FileSystem.Windows;

namespace ITHit.FileSystem.Samples.Common.Windows
{
Expand Down
189 changes: 189 additions & 0 deletions Windows/Common/Core/LogFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;

using log4net;
using log4net.Config;
using log4net.Appender;

using ITHit.FileSystem.Windows;

namespace ITHit.FileSystem.Samples.Common.Windows
{
/// <summary>
/// Outputs logging.
/// </summary>
public class LogFormatter
{
/// <summary>
/// Log file path.
/// </summary>
public readonly string LogFilePath;

/// <summary>
/// Indicates if more debugging and performance information should be logged.
/// </summary>
public bool DebugLoggingEnabled
{
get { return debugLoggingEnabled; }
set
{
debugLoggingEnabled = value;
string debugLoggingState = debugLoggingEnabled ? "Enabled" : "Disabled";
log.Info($"{Environment.NewLine}Debug logging {debugLoggingState}");
}
}

public bool debugLoggingEnabled = false;

private readonly ILog log;

private readonly string appId;

/// <summary>
/// Creates instance of this class.
/// </summary>
/// <param name="log">Log4net logger.</param>
public LogFormatter(ILog log, string appId)
{
this.log = log;
this.appId = appId;
LogFilePath = ConfigureLogger();
}

/// <summary>
/// Configures log4net logger.
/// </summary>
/// <returns>Log file path.</returns>
private string ConfigureLogger()
{
// Load Log4Net for net configuration.
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "log4net.config")));

// Update log file path for msix package.
RollingFileAppender rollingFileAppender = logRepository.GetAppenders().Where(p => p.GetType() == typeof(RollingFileAppender)).FirstOrDefault() as RollingFileAppender;
if (rollingFileAppender != null && rollingFileAppender.File.Contains("WindowsApps"))
{
rollingFileAppender.File = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), appId,
Path.GetFileName(rollingFileAppender.File));
}
return rollingFileAppender?.File;
}

/// <summary>
/// Prints environment description.
/// </summary>
public void PrintEnvironmentDescription()
{
// Log environment description.
log.Info($"\n{"AppID:",-15} {appId}");
log.Info($"\n{"Engine version:",-15} {typeof(IEngine).Assembly.GetName().Version}");
log.Info($"\n{"OS version:",-15} {RuntimeInformation.OSDescription}");
log.Info($"\n{"Env version:",-15} {RuntimeInformation.FrameworkDescription} {IntPtr.Size * 8}bit.");
//log.Info($"\n{"Is UWP:",-15} {PackageRegistrar.IsRunningAsUwp()}");
log.Info($"\n{"Admin mode:",-15} {new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)}");
}

/// <summary>
/// Prints indexing state.
/// </summary>
/// <param name="path">File system path.</param>
public async Task PrintIndexingStateAsync(string path)
{
StorageFolder userFileSystemRootFolder = await StorageFolder.GetFolderFromPathAsync(path);
log.Info($"\nIndexed state: {(await userFileSystemRootFolder.GetIndexedStateAsync())}");
}

/// <summary>
/// Prints console commands.
/// </summary>
public void PrintHelp()
{
log.Info("\n\nPress Esc to unregister file system, delete all files/folders and exit (simulate uninstall).");
log.Info("\nPress Spacebar to exit without unregistering (simulate reboot).");
log.Info("\nPress 'p' to unregister sparse package.");
log.Info("\nPress 'e' to start/stop the Engine and all sync services.");
log.Info("\nPress 's' to start/stop full synchronization service.");
log.Info("\nPress 'm' to start/stop remote storage monitor.");
log.Info("\nPress 'd' to enable/disable debug and performance logging.");
log.Info($"\nPress 'l' to open log file. ({LogFilePath})");
log.Info($"\nPress 'b' to submit support tickets, report bugs, suggest features. (https://userfilesystem.com/support/)");
log.Info("\n----------------------\n");
}

public void LogError(IEngine sender, EngineErrorEventArgs e)
{
WriteLog(e, log4net.Core.Level.Error);
}

public void LogMessage(IEngine sender, EngineMessageEventArgs e)
{
WriteLog(e, log4net.Core.Level.Info);
}

public void LogDebug(IEngine sender, EngineMessageEventArgs e)
{
WriteLog(e, log4net.Core.Level.Debug);
}

/// <summary>
/// Outputs log message.
/// </summary>
/// <param name="log">log4net</param>
/// <param name="e">Message or error description.</param>
/// <param name="level">Log level.</param>
private void WriteLog(EngineMessageEventArgs e, log4net.Core.Level level)
{
string att = FsPath.Exists(e.SourcePath) ? FsPath.GetAttString(e.SourcePath) : null;
string process = null;
byte? priorityHint = null;
ulong? clientFileId = null;
string size = null;

if (e.OperationContext != null)
{
process = System.IO.Path.GetFileName(e.OperationContext.ProcessInfo?.ImagePath);
priorityHint = e.OperationContext.PriorityHint;
clientFileId = (e.OperationContext as IWindowsOperationContext).FileId;
size = FsPath.FormatBytes((e.OperationContext as IWindowsOperationContext).FileSize);
}

string message = Format(DateTimeOffset.Now.ToString("hh:mm:ss.fff"), process, priorityHint?.ToString(), e.ComponentName, e.Message, e.SourcePath, att, e.TargetPath);

if (level == log4net.Core.Level.Error)
{
Exception ex = ((EngineErrorEventArgs)e).Exception;
message += Environment.NewLine;
log.Error(message, ex);
}
else if (level == log4net.Core.Level.Info)
{
log.Info(message);
}
else if (level == log4net.Core.Level.Debug && DebugLoggingEnabled)
{
log.Debug(message);
}

}

private static string Format(string date, string process, string priorityHint, string componentName, string message, string sourcePath, string attributes, string targetPath)
{
return $"{Environment.NewLine}|{date, -12}| {process,-25}| {priorityHint,-5}| {componentName,-26}| {message,-45}| {sourcePath,-80}| {attributes, -22}| {targetPath}";
}

/// <summary>
/// Prints logging data headers.
/// </summary>
public void PrintHeader()
{
log.Info(Format("Time", "Process Name", "Prty", "Component", "Operation", "Source Path", "Attributes", "Target Path"));
log.Info(Format("----", "------------", "----", "---------", "---------", "-----------", "----------", "-----------"));
}
}
}
90 changes: 0 additions & 90 deletions Windows/Common/Core/Logger.cs

This file was deleted.

23 changes: 2 additions & 21 deletions Windows/Common/Core/Registrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace ITHit.FileSystem.Samples.Common.Windows
/// </summary>
public static class Registrar
{

/// <summary>
/// Registers sync root.
/// </summary>
Expand Down Expand Up @@ -72,6 +73,7 @@ public static async Task RegisterAsync(string syncRootId, string path, string di

StorageProviderSyncRootManager.Register(storageInfo);
}


/// <summary>
/// Ensures that minimum required properties for <see cref="StorageProviderSyncRootInfo"/> are set.
Expand Down Expand Up @@ -165,26 +167,5 @@ public static async Task UnregisterAsync(string syncRootId)
{
StorageProviderSyncRootManager.Unregister(syncRootId);
}

/// <summary>
/// Helper method to determine if the process is running in a packaged context.
/// </summary>
/// <returns>True if the application is running in a packaged context, false otherwise.</returns>
public static bool IsRunningAsUwp()
{
const long APPMODEL_ERROR_NO_PACKAGE = 15700L;

int length = 0;
return GetCurrentPackageFullName(ref length, null) != APPMODEL_ERROR_NO_PACKAGE;
}

/// <summary>
/// Gets the package full name for the calling process.
/// </summary>
/// <param name="packageFullNameLength">On input, the size of the packageFullName buffer, in characters. On output, the size of the package full name returned, in characters, including the null terminator.</param>
/// <param name="packageFullName">The package full name.</param>
/// <returns>If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code.</returns>
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullName);
}
}
Loading

0 comments on commit eb231de

Please sign in to comment.