Skip to content

Commit 5e612c2

Browse files
committed
v6.0.16872.0-Beta
1 parent ba06158 commit 5e612c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1284
-1254
lines changed

Common/Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
<Platforms>AnyCPU;x64</Platforms>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageReference Include="ITHit.FileSystem" Version="5.6.16439.0" />
13+
<PackageReference Include="ITHit.FileSystem" Version="6.0.16872.0-Beta" />
1414
</ItemGroup>
1515
</Project>

Windows/Common/Core/Commands.cs

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
using log4net;
9+
using ITHit.FileSystem.Windows;
10+
11+
12+
namespace ITHit.FileSystem.Samples.Common.Windows
13+
{
14+
/// <summary>
15+
/// Application commands.
16+
/// </summary>
17+
public class Commands
18+
{
19+
/// <summary>
20+
/// Engine instance.
21+
/// </summary>
22+
public EngineWindows Engine;
23+
24+
/// <summary>
25+
/// Remote storage monitor.
26+
/// </summary>
27+
public ISyncService RemoteStorageMonitor;
28+
29+
/// <summary>
30+
/// Log4Net logger.
31+
/// </summary>
32+
private readonly ILog log;
33+
34+
/// <summary>
35+
/// Remote storage root path.
36+
/// </summary>
37+
private readonly string remoteStorageRootPath;
38+
39+
public Commands(ILog log, string remoteStorageRootPath)
40+
{
41+
this.log = log;
42+
this.remoteStorageRootPath = remoteStorageRootPath;
43+
}
44+
45+
/// <summary>
46+
/// Start/stop the Engine and all sync services.
47+
/// </summary>
48+
public async Task StartStopEngineAsync()
49+
{
50+
switch (Engine.State)
51+
{
52+
case EngineState.Running:
53+
await Engine.StopAsync();
54+
break;
55+
56+
case EngineState.Stopped:
57+
await Engine.StartAsync();
58+
break;
59+
}
60+
}
61+
62+
/// <summary>
63+
/// Start/stop synchronization service.
64+
/// </summary>
65+
public async Task StartStopSynchronizationAsync()
66+
{
67+
switch (Engine.SyncService.SyncState)
68+
{
69+
case SynchronizationState.Disabled:
70+
if (Engine.State != EngineState.Running)
71+
{
72+
Engine.SyncService.Logger.LogError("Failed to start. The Engine must be running.");
73+
return;
74+
}
75+
await Engine.SyncService.StartAsync();
76+
break;
77+
78+
default:
79+
await Engine.SyncService.StopAsync();
80+
break;
81+
}
82+
}
83+
84+
public async Task StartStopRemoteStorageMonitorAsync()
85+
{
86+
if (RemoteStorageMonitor.SyncState == SynchronizationState.Disabled)
87+
{
88+
if (Engine.State != EngineState.Running)
89+
{
90+
log.Error("Failed to start. The Engine must be running.");
91+
//Engine.RemoteStorageMonitor.Logger.LogError("Failed to start. The Engine must be running.");
92+
return;
93+
}
94+
await RemoteStorageMonitor.StartAsync();
95+
}
96+
else
97+
{
98+
await RemoteStorageMonitor.StopAsync();
99+
}
100+
}
101+
102+
/// <summary>
103+
/// Opens path with associated application.
104+
/// </summary>
105+
/// <param name="path">Path to the file or folder.</param>
106+
public static void Open(string path)
107+
{
108+
ProcessStartInfo startInfo = new ProcessStartInfo(path);
109+
startInfo.UseShellExecute = true; // Open window only if not opened already.
110+
using (Process ufsWinFileManager = Process.Start(startInfo))
111+
{
112+
113+
}
114+
}
115+
116+
/// <summary>
117+
/// Open Windows File Manager with user file system.
118+
/// </summary>
119+
public async Task OpenFolderAsync()
120+
{
121+
Open(Engine.Path);
122+
}
123+
124+
/// <summary>
125+
/// Open remote storage.
126+
/// </summary>
127+
public async Task OpenRemoteStorageAsync()
128+
{
129+
Open(remoteStorageRootPath);
130+
}
131+
132+
/// <summary>
133+
/// Opens support portal.
134+
/// </summary>
135+
public async Task OpenSupportPortalAsync()
136+
{
137+
Open("https://www.userfilesystem.com/support/");
138+
}
139+
140+
/// <summary>
141+
/// Called on app exit.
142+
/// </summary>
143+
public async Task AppExitAsync()
144+
{
145+
await StopEngineAsync();
146+
log.Info("\n\nAll downloaded file / folder placeholders remain in file system. Restart the application to continue managing files.");
147+
log.Info("\nYou can also edit documents when the app is not running and than start the app to sync all changes to the remote storage.\n");
148+
}
149+
150+
/// <summary>
151+
/// Stop the Engine and all sync services.
152+
/// </summary>
153+
public async Task StopEngineAsync()
154+
{
155+
if (Engine?.State == EngineState.Running)
156+
{
157+
await Engine.StopAsync();
158+
}
159+
}
160+
161+
#if DEBUG
162+
/// <summary>
163+
/// Opens Windows File Manager with both remote storage and user file system for testing.
164+
/// </summary>
165+
/// <remarks>This method is provided solely for the development and testing convenience.</remarks>
166+
public void ShowTestEnvironment()
167+
{
168+
// Enable UTF8 for Console Window and set width.
169+
Console.OutputEncoding = System.Text.Encoding.UTF8;
170+
Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight / 3);
171+
Console.SetBufferSize(Console.LargestWindowWidth * 2, short.MaxValue / 2);
172+
173+
// Open Windows File Manager with user file system.
174+
Commands.Open(Engine.Path);
175+
176+
// Open remote storage.
177+
Commands.Open(remoteStorageRootPath);
178+
}
179+
#endif
180+
}
181+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<Authors>IT Hit LTD.</Authors>
66
<Product>IT Hit User File System</Product>
77
<Copyright>IT Hit LTD.</Copyright>
8-
<RootNamespace>ITHit.FileSystem.Samples.Common.Windows.Core</RootNamespace>
8+
<RootNamespace>ITHit.FileSystem.Samples.Common.Windows</RootNamespace>
99
<Platforms>AnyCPU;x64</Platforms>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<Compile Remove="ConsoleProcessor.cs" />
12+
<Compile Remove="Installer.cs" />
1313
<Compile Remove="Logger.cs" />
1414
</ItemGroup>
1515
<ItemGroup>
@@ -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="5.6.16439.0" />
24-
<PackageReference Include="ITHit.FileSystem.Windows" Version="5.6.16439.0" />
23+
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="6.0.16872.0-Beta" />
24+
<PackageReference Include="ITHit.FileSystem.Windows" Version="6.0.16872.0-Beta" />
2525
<ProjectReference Include="..\..\..\Common\Common.csproj" />
2626
</ItemGroup>
2727
</Project>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using ITHit.FileSystem.Windows;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ITHit.FileSystem.Samples.Common.Windows
9+
{
10+
/// <summary>
11+
/// Processes console commands.
12+
/// </summary>
13+
public class ConsoleProcessor
14+
{
15+
private readonly Registrar registrar;
16+
private readonly LogFormatter logFormatter;
17+
private readonly Commands commands;
18+
19+
public ConsoleProcessor(Registrar registrar, LogFormatter logFormatter, Commands commands)
20+
{
21+
this.registrar = registrar;
22+
this.logFormatter = logFormatter;
23+
this.commands = commands;
24+
}
25+
26+
/// <summary>
27+
/// Prints console commands.
28+
/// </summary>
29+
public void PrintHelp()
30+
{
31+
logFormatter.LogMessage("\n\n ----------------------------------------------------------------------------------------");
32+
logFormatter.LogMessage("\n Commands:");
33+
PrintCommandDescription("Spacebar", "Exit without unregistering (simulate reboot).");
34+
PrintCommandDescription("Esc", "Unregister file system, delete all files/folders and exit.");
35+
if (FileSystem.Windows.Package.PackageRegistrar.IsRunningWithSparsePackageIdentity())
36+
{
37+
PrintCommandDescription("Shift-Esc", "Unregister file system, delete all files/folders, unregister handlers, uninstall developer certificate, unregister sparse package and exit (simulate full uninstall).");
38+
}
39+
PrintCommandDescription("e", "Start/stop the Engine and all sync services.");
40+
PrintCommandDescription("s", "Start/stop synchronization service.");
41+
PrintCommandDescription("m", "Start/stop remote storage monitor.");
42+
PrintCommandDescription("d", "Enable/disable debug and performance logging.");
43+
PrintCommandDescription("l", $"Open log file. ({logFormatter.LogFilePath})");
44+
PrintCommandDescription("b", "Submit support tickets, report bugs, suggest features. (https://userfilesystem.com/support/)");
45+
logFormatter.LogMessage("\n ----------------------------------------------------------------------------------------");
46+
}
47+
48+
private void PrintCommandDescription(string key, string description)
49+
{
50+
logFormatter.LogMessage($"{Environment.NewLine} {key,12} - {description,-25}");
51+
}
52+
53+
/// <summary>
54+
/// Reads and processes console input.
55+
/// </summary>
56+
public async Task ProcessUserInputAsync()
57+
{
58+
do
59+
{
60+
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
61+
62+
switch (keyInfo.Key)
63+
{
64+
case ConsoleKey.F1:
65+
case ConsoleKey.H:
66+
// Print help info.
67+
PrintHelp();
68+
break;
69+
70+
case ConsoleKey.E:
71+
// Start/stop the Engine and all sync services.
72+
await commands.StartStopEngineAsync();
73+
break;
74+
75+
case ConsoleKey.S:
76+
// Start/stop synchronization.
77+
await commands.StartStopSynchronizationAsync();
78+
break;
79+
80+
case ConsoleKey.D:
81+
// Enables/disables debug logging.
82+
logFormatter.DebugLoggingEnabled = !logFormatter.DebugLoggingEnabled;
83+
break;
84+
85+
case ConsoleKey.M:
86+
// Start/stop remote storage monitor.
87+
await commands.StartStopRemoteStorageMonitorAsync();
88+
break;
89+
90+
case ConsoleKey.L:
91+
// Open log file.
92+
Commands.Open(logFormatter.LogFilePath);
93+
break;
94+
95+
case ConsoleKey.B:
96+
// Submit support tickets, report bugs, suggest features.
97+
await commands.OpenSupportPortalAsync();
98+
break;
99+
100+
case ConsoleKey.Escape:
101+
// Simulate app uninstall.
102+
await commands.StopEngineAsync();
103+
bool removeSparsePackage = keyInfo.Modifiers.HasFlag(ConsoleModifiers.Shift);
104+
await registrar.UnregisterAsync(commands.Engine, removeSparsePackage);
105+
return;
106+
107+
case ConsoleKey.Spacebar:
108+
// Simulate app restart or machine reboot.
109+
await commands.AppExitAsync();
110+
return;
111+
112+
default:
113+
break;
114+
}
115+
116+
} while (true);
117+
}
118+
}
119+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Threading.Tasks;
2+
using ITHit.FileSystem.Windows;
3+
4+
5+
namespace ITHit.FileSystem.Samples.Common.Windows
6+
{
7+
public interface ISyncService
8+
{
9+
/// <summary>
10+
/// Sync service state.
11+
/// </summary>
12+
SynchronizationState SyncState { get; }
13+
14+
/// <summary>
15+
/// Starts service.
16+
/// </summary>
17+
Task StartAsync();
18+
19+
/// <summary>
20+
/// Stops service.
21+
/// </summary>
22+
Task StopAsync();
23+
}
24+
}

0 commit comments

Comments
 (0)