1515namespace ITHit . FileSystem . Samples . Common . Windows
1616{
1717 /// <summary>
18- /// Commands sent from tray app and comnsole .
18+ /// Commands sent from tray app and console .
1919 /// </summary>
2020 public class Commands
2121 {
@@ -30,7 +30,7 @@ public class Commands
3030 public ISyncService RemoteStorageMonitor ;
3131
3232 /// <summary>
33- /// Remote storaage path.
33+ /// Remote storage path.
3434 /// </summary>
3535 private readonly string RemoteStorageRootPath ;
3636
@@ -39,6 +39,12 @@ public class Commands
3939 /// </summary>
4040 private readonly ILog log ;
4141
42+ /// <summary>
43+ /// Initializes a new instance of the <see cref="Commands"/> class.
44+ /// </summary>
45+ /// <param name="engine">The engine instance.</param>
46+ /// <param name="remoteStorageRootPath">The remote storage root path.</param>
47+ /// <param name="log">The logger instance.</param>
4248 public Commands ( EngineWindows engine , string remoteStorageRootPath , ILog log )
4349 {
4450 this . Engine = engine ;
@@ -47,7 +53,7 @@ public Commands(EngineWindows engine, string remoteStorageRootPath, ILog log)
4753 }
4854
4955 /// <summary>
50- /// Start/ stop the Engine and all sync services.
56+ /// Start or stop the Engine and all sync services.
5157 /// </summary>
5258 public async Task StartStopEngineAsync ( )
5359 {
@@ -64,7 +70,7 @@ public async Task StartStopEngineAsync()
6470 }
6571
6672 /// <summary>
67- /// Start/ stop synchronization service.
73+ /// Start or stop the synchronization service.
6874 /// </summary>
6975 public async Task StartStopSynchronizationAsync ( )
7076 {
@@ -85,9 +91,12 @@ public async Task StartStopSynchronizationAsync()
8591 }
8692 }
8793
94+ /// <summary>
95+ /// Start or stop the remote storage monitor.
96+ /// </summary>
8897 public async Task StartStopRemoteStorageMonitorAsync ( )
8998 {
90- if ( RemoteStorageMonitor == null )
99+ if ( RemoteStorageMonitor == null )
91100 {
92101 Engine . Logger . LogError ( "Remote storage monitor is null." , Engine . Path ) ;
93102 return ;
@@ -98,7 +107,6 @@ public async Task StartStopRemoteStorageMonitorAsync()
98107 if ( Engine . State != EngineState . Running )
99108 {
100109 Engine . Logger . LogError ( "Failed to start. The Engine must be running." , Engine . Path ) ;
101- //Engine.RemoteStorageMonitor.Logger.LogError("Failed to start. The Engine must be running.");
102110 return ;
103111 }
104112 await RemoteStorageMonitor . StartAsync ( ) ;
@@ -110,37 +118,59 @@ public async Task StartStopRemoteStorageMonitorAsync()
110118 }
111119
112120 /// <summary>
113- /// Opens path with associated application.
121+ /// Opens the specified path with the associated application.
114122 /// </summary>
115- /// <param name="path">Path to the file or folder.</param>
123+ /// <param name="path">The path to the file or folder.</param>
116124 public static void Open ( string path )
117125 {
118- ProcessStartInfo startInfo = new ProcessStartInfo ( path ) ;
119- startInfo . UseShellExecute = true ; // Open window only if not opened already.
126+ ProcessStartInfo startInfo = new ProcessStartInfo ( path )
127+ {
128+ UseShellExecute = true // Open window only if not opened already.
129+ } ;
120130 using ( Process ufsWinFileManager = Process . Start ( startInfo ) )
121131 {
122-
123132 }
124133 }
125134
126135 /// <summary>
127- /// Open root user file system folder in Windows Explorer .
136+ /// Tries to open the specified path .
128137 /// </summary>
129- public async Task OpenRootFolderAsync ( )
138+ /// <param name="path">The path to the file or folder.</param>
139+ /// <returns>True if the path was opened successfully, otherwise false.</returns>
140+ public bool TryOpen ( string path )
130141 {
131- Open ( Engine . Path ) ;
142+ return TryOpen ( path , log ) ;
132143 }
133144
134145 /// <summary>
135- /// Open remote storage .
146+ /// Tries to open the specified path .
136147 /// </summary>
137- public async Task OpenRemoteStorageAsync ( )
148+ /// <param name="path">The path to the file or folder.</param>
149+ /// <returns>True if the path was opened successfully, otherwise false.</returns>
150+ public static bool TryOpen ( string path , ILog ? log = null )
138151 {
139- Open ( RemoteStorageRootPath ) ;
152+ try
153+ {
154+ if ( ! string . IsNullOrEmpty ( path ) && ( File . Exists ( path ) || Directory . Exists ( path ) ) )
155+ {
156+ Open ( path ) ;
157+ return true ;
158+ }
159+ else
160+ {
161+ log ? . Warn ( $ "The path { path } does not exist.") ;
162+ }
163+ }
164+ catch ( Exception ex )
165+ {
166+ log ? . Error ( $ "Failed to open { path } .", ex ) ;
167+ }
168+
169+ return false ;
140170 }
141171
142172 /// <summary>
143- /// Opens support portal.
173+ /// Opens the support portal.
144174 /// </summary>
145175 public static async Task OpenSupportPortalAsync ( )
146176 {
@@ -155,11 +185,11 @@ public async Task EngineExitAsync()
155185 await StopEngineAsync ( ) ;
156186 log . Info ( $ "\n \n { RemoteStorageRootPath } ") ;
157187 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 " ) ;
188+ log . Info ( "\n You can edit documents when the app is not running and then start the app to sync all changes to the remote storage.\n " ) ;
159189 }
160190
161191 /// <summary>
162- /// Stop the Engine and all sync services.
192+ /// Stops the Engine and all sync services.
163193 /// </summary>
164194 public async Task StopEngineAsync ( )
165195 {
@@ -173,31 +203,27 @@ public async Task StopEngineAsync()
173203 /// <summary>
174204 /// Opens Windows File Manager with both remote storage and user file system for testing.
175205 /// </summary>
176- /// <param name="openRemoteStorage">True if the Remote Storage must be opened. False - otherwise.</param>
206+ /// <param name="openRemoteStorage">True if the Remote Storage must be opened. False otherwise.</param>
177207 /// <param name="engineIndex">Index used to position Windows Explorer window to show this user file system.</param>
178- /// <param name="totalEngines">Total number of Engined that will be mounted by this app.</param>
208+ /// <param name="totalEngines">Total number of Engines that will be mounted by this app.</param>
209+ /// <param name="userFileSystemWindowName">Name of the user file system window.</param>
210+ /// <param name="cancellationToken">Cancellation token.</param>
179211 /// <remarks>This method is provided solely for the development and testing convenience.</remarks>
180212 public void ShowTestEnvironment ( string userFileSystemWindowName , bool openRemoteStorage = true , CancellationToken cancellationToken = default , int engineIndex = 0 , int totalEngines = 1 )
181213 {
182- int numWindowsPerEngine = 2 ; //openRemoteStorage ? 2 : 1; // Each engine shows 2 windows - remote storage and UFS.
183- int horizintalIndex = engineIndex * numWindowsPerEngine ;
214+ int numWindowsPerEngine = 2 ; // Each engine shows 2 windows - remote storage and UFS.
215+ int horizontalIndex = engineIndex * numWindowsPerEngine ;
184216 int totalWindows = totalEngines * numWindowsPerEngine ;
185217
186218 // Open remote storage.
187219 if ( openRemoteStorage )
188220 {
189- Commands . Open ( RemoteStorageRootPath ) ;
190- //string rsWindowName = Path.GetFileName(RemoteStorageRootPath.TrimEnd('\\'));
191- //IntPtr hWndRemoteStorage = WindowManager.FindWindow(rsWindowName, cancellationToken);
192- //WindowManager.PositionFileSystemWindow(hWndRemoteStorage, horizintalIndex, totalWindows);
221+ TryOpen ( RemoteStorageRootPath ) ;
193222 }
194223
195224 // Open Windows File Manager with user file system.
196- Commands . Open ( Engine . Path ) ;
197- //IntPtr hWndUserFileSystem = WindowManager.FindWindow(userFileSystemWindowName, cancellationToken);
198- //WindowManager.PositionFileSystemWindow(hWndUserFileSystem, horizintalIndex + 1, totalWindows);
225+ TryOpen ( Engine . Path ) ;
199226 }
200-
201227#endif
202228 }
203229}
0 commit comments