88using log4net ;
99using ITHit . FileSystem . Windows ;
1010using System . IO ;
11+ using System . Collections . Concurrent ;
12+ using System . Threading ;
1113
1214
1315namespace ITHit . FileSystem . Samples . Common . Windows
1416{
1517 /// <summary>
16- /// Application commands .
18+ /// Commands sent from tray app and comnsole .
1719 /// </summary>
1820 public class Commands
1921 {
2022 /// <summary>
2123 /// Engine instance.
2224 /// </summary>
23- public EngineWindows Engine ;
25+ private readonly EngineWindows Engine ;
2426
2527 /// <summary>
2628 /// Remote storage monitor.
2729 /// </summary>
2830 public ISyncService RemoteStorageMonitor ;
2931
3032 /// <summary>
31- /// Log4Net logger .
33+ /// Remote storaage path .
3234 /// </summary>
33- private readonly ILog log ;
35+ private readonly string RemoteStorageRootPath ;
3436
3537 /// <summary>
36- /// Remote storage root path .
38+ /// Log4Net logger .
3739 /// </summary>
38- private readonly string remoteStorageRootPath ;
40+ private readonly ILog log ;
3941
40- public Commands ( ILog log , string remoteStorageRootPath )
42+ public Commands ( EngineWindows engine , string remoteStorageRootPath , ILog log )
4143 {
44+ this . Engine = engine ;
45+ this . RemoteStorageRootPath = remoteStorageRootPath ;
4246 this . log = log ;
43- this . remoteStorageRootPath = remoteStorageRootPath ;
4447 }
4548
4649 /// <summary>
@@ -70,7 +73,7 @@ public async Task StartStopSynchronizationAsync()
7073 case SynchronizationState . Disabled :
7174 if ( Engine . State != EngineState . Running )
7275 {
73- Engine . SyncService . Logger . LogError ( "Failed to start. The Engine must be running." ) ;
76+ Engine . SyncService . Logger . LogError ( "Failed to start. The Engine must be running." , Engine . Path ) ;
7477 return ;
7578 }
7679 await Engine . SyncService . StartAsync ( ) ;
@@ -84,11 +87,17 @@ public async Task StartStopSynchronizationAsync()
8487
8588 public async Task StartStopRemoteStorageMonitorAsync ( )
8689 {
90+ if ( RemoteStorageMonitor == null )
91+ {
92+ Engine . Logger . LogError ( "Remote storage monitor is null." , Engine . Path ) ;
93+ return ;
94+ }
95+
8796 if ( RemoteStorageMonitor . SyncState == SynchronizationState . Disabled )
8897 {
8998 if ( Engine . State != EngineState . Running )
9099 {
91- log . Error ( "Failed to start. The Engine must be running." ) ;
100+ Engine . Logger . LogError ( "Failed to start. The Engine must be running." , Engine . Path ) ;
92101 //Engine.RemoteStorageMonitor.Logger.LogError("Failed to start. The Engine must be running.");
93102 return ;
94103 }
@@ -115,9 +124,9 @@ public static void Open(string path)
115124 }
116125
117126 /// <summary>
118- /// Open Windows File Manager with user file system.
127+ /// Open root user file system folder in Windows Explorer .
119128 /// </summary>
120- public async Task OpenFolderAsync ( )
129+ public async Task OpenRootFolderAsync ( )
121130 {
122131 Open ( Engine . Path ) ;
123132 }
@@ -127,25 +136,26 @@ public async Task OpenFolderAsync()
127136 /// </summary>
128137 public async Task OpenRemoteStorageAsync ( )
129138 {
130- Open ( remoteStorageRootPath ) ;
139+ Open ( RemoteStorageRootPath ) ;
131140 }
132141
133142 /// <summary>
134143 /// Opens support portal.
135144 /// </summary>
136- public async Task OpenSupportPortalAsync ( )
145+ public static async Task OpenSupportPortalAsync ( )
137146 {
138147 Open ( "https://www.userfilesystem.com/support/" ) ;
139148 }
140149
141150 /// <summary>
142151 /// Called on app exit.
143152 /// </summary>
144- public async Task AppExitAsync ( )
153+ public async Task EngineExitAsync ( )
145154 {
146155 await StopEngineAsync ( ) ;
147- log . Info ( "\n \n All downloaded file / folder placeholders remain in file system. Restart the application to continue managing files." ) ;
148- log . Info ( "\n You can also edit documents when the app is not running and than start the app to sync all changes to the remote storage.\n " ) ;
156+ log . Info ( $ "\n \n { RemoteStorageRootPath } ") ;
157+ log . Info ( "\n All downloaded file / folder placeholders remain in file system. Restart the application to continue managing files." ) ;
158+ log . Info ( "\n You can edit documents when the app is not running and than start the app to sync all changes to the remote storage.\n " ) ;
149159 }
150160
151161 /// <summary>
@@ -160,47 +170,49 @@ public async Task StopEngineAsync()
160170 }
161171
162172#if DEBUG
163-
164- /// <summary>
165- /// Sets console output defaults.
166- /// </summary>
167- public void ConfigureConsole ( )
168- {
169- // Enable UTF8 for Console Window and set width.
170- Console . OutputEncoding = System . Text . Encoding . UTF8 ;
171- Console . SetWindowSize ( Console . LargestWindowWidth , Console . LargestWindowHeight / 3 ) ;
172- //Console.SetBufferSize(Console.LargestWindowWidth * 2, short.MaxValue / 2);
173- }
174-
175173 /// <summary>
176174 /// Opens Windows File Manager with both remote storage and user file system for testing.
177175 /// </summary>
178176 /// <param name="openRemoteStorage">True if the Remote Storage must be opened. False - otherwise.</param>
179177 /// <remarks>This method is provided solely for the development and testing convenience.</remarks>
180- public void ShowTestEnvironment ( bool openRemoteStorage = true )
178+ public void ShowTestEnvironment ( string userFileSystemWindowName , bool openRemoteStorage = true , CancellationToken cancellationToken = default )
181179 {
182180 // Open Windows File Manager with user file system.
183181 Commands . Open ( Engine . Path ) ;
182+ IntPtr hWndUserFileSystem = WindowManager . FindWindow ( userFileSystemWindowName , cancellationToken ) ;
183+ WindowManager . PositionFileSystemWindow ( hWndUserFileSystem , 1 , 2 ) ;
184184
185185 if ( openRemoteStorage )
186186 {
187187 // Open remote storage.
188- Commands . Open ( remoteStorageRootPath ) ;
188+ Commands . Open ( RemoteStorageRootPath ) ;
189+ string rsWindowName = Path . GetFileName ( RemoteStorageRootPath . TrimEnd ( '\\ ' ) ) ;
190+ IntPtr hWndRemoteStorage = WindowManager . FindWindow ( rsWindowName , cancellationToken ) ;
191+ WindowManager . PositionFileSystemWindow ( hWndRemoteStorage , 0 , 2 ) ;
189192 }
190193 }
194+
191195#endif
196+
192197 public void Test ( )
193198 {
194- string name = "General.docx" ;
195- var n = Engine . ServerNotifications ( Path . Combine ( Engine . Path , name ) ) ;
196- IFileSystemItemMetadata metadata = new FileMetadataExt ( ) ;
199+ string name = "Notes.txt" ;
200+ string filePath = Path . Combine ( Engine . Path , name ) ;
201+ //FileInfo fi = new FileInfo(filePath);
202+ //fi.IsReadOnly = true;
203+
204+ var n = Engine . ServerNotifications ( filePath ) ;
205+ IFileMetadata metadata = new FileMetadata ( ) ;
197206 metadata . Attributes = FileAttributes . Normal ;
198207 metadata . CreationTime = DateTimeOffset . Now ;
199208 metadata . LastWriteTime = DateTimeOffset . Now ;
200209 metadata . ChangeTime = DateTimeOffset . Now ;
201210 metadata . LastAccessTime = DateTimeOffset . Now ;
202211 metadata . Name = name ;
212+ metadata . MetadataETag = DateTimeOffset . Now . Ticks . ToString ( ) ;
213+ metadata . ContentETag = null ; //"etag1";
203214 n . UpdateAsync ( metadata ) ;
204215 }
216+
205217 }
206218}
0 commit comments