@@ -72,41 +72,57 @@ public string[] Path
7272 [ Parameter ( Mandatory = false ) ]
7373 public bool Force { get ; set ; }
7474
75+ /// <summary>
76+ /// Resume flag, if 'true' then it will keep track of command status
77+ /// if command is unsuccessful due to disconnection then it will prompt user next time to complete it first
78+ /// </summary>
79+ [ Parameter ( ) ]
80+ [ Alias ( "ResumeFlag" ) ]
81+ public SwitchParameter Resume { get ; set ; }
82+
7583 protected override void ProcessRecord ( )
7684 {
7785 ResumeSupport = new Resume . ResumeSupport ( ) ;
7886 FileSupport = new FileSupport ( MarkFileStatus ) ;
79-
80- if ( ResumeSupport . IsPending )
81- {
82- Logger . Instance . Info ( "Last command wasn't successful due to discconnection." ) ;
8387
84- Console . Write ( "Last command wasn't successful due to discconnection, enter 'y' to complete or any other key to ignore: " ) ;
85- Collection < PSObject > result = InvokeCommand . InvokeScript ( "Read-Host" ) ;
86- string userOption = result != null && result . Count > 0 ? result [ 0 ] . ToString ( ) : string . Empty ;
87-
88- if ( userOption . ToLower ( ) . Equals ( "y" ) )
88+ if ( Resume )
89+ {
90+ if ( ResumeSupport . IsPending )
8991 {
90- Logger . Instance . Info ( "Copying those files which were missed due to discconnection with following parameters. Source Path:{0} Destination:{1} Forced:{2} Details:{3}" ,
91- String . Join ( "," , ResumeSupport . GetPath ) , ResumeSupport . GetDestination , ResumeSupport . GetForce , ResumeSupport . GetDetails ) ;
92+ Logger . Instance . Info ( "Last command wasn't successful due to discconnection." ) ;
9293
93- StartCopying ( ResumeSupport . GetPath , ResumeSupport . GetDestination , ResumeSupport . GetForce , ResumeSupport . GetDetails ) ;
94+ WriteObject ( "Last command wasn't successful due to discconnection, enter 'y' to complete or any other key to ignore: " ) ;
95+ Collection < PSObject > result = InvokeCommand . InvokeScript ( "Read-Host" ) ;
96+ string userOption = result != null && result . Count > 0 ? result [ 0 ] . ToString ( ) : string . Empty ;
9497
95- Logger . Instance . Info ( "Copying operation completed for missing files" ) ;
96- ResumeSupport . End ( ) ;
97- WriteObject ( "Last command completed, starting current operation" ) ;
98+ if ( userOption . ToLower ( ) . Equals ( "y" ) )
99+ {
100+ Logger . Instance . Info ( "Copying those files which were missed due to discconnection with following parameters. Source Path:{0} Destination:{1} Forced:{2} Details:{3}" ,
101+ String . Join ( "," , ResumeSupport . GetPath ) , ResumeSupport . GetDestination , ResumeSupport . GetForce , ResumeSupport . GetDetails ) ;
102+
103+ StartCopying ( ResumeSupport . GetPath , ResumeSupport . GetDestination , ResumeSupport . GetForce , ResumeSupport . GetDetails ) ;
104+
105+ Logger . Instance . Info ( "Copying operation completed for missing files" ) ;
106+ ResumeSupport . End ( ) ;
107+ WriteObject ( "Last command completed, starting current operation" ) ;
108+ }
98109 }
99110 }
111+ else
112+ {
113+ ResumeSupport . UnmarkResumeFlag ( ) ;
114+ }
100115
101- Logger . Instance . Info ( String . Format ( "Starting Copy Operation with following parameters. Source Path:{0} Destination:{1} Forced:{2} Details:{3}" ,
116+ Logger . Instance . Info ( String . Format ( "Starting Copy Operation with following parameters. Source Path:{0} Destination:{1} Forced:{2} Details:{3}" ,
102117 String . Join ( "," , Path ) , Destination , Force , Details ) ) ;
103- ResumeSupport . Start ( Path , Destination , Force , Details ) ;
104118
119+ if ( Resume ) ResumeSupport . Start ( Path , Destination , Force , Details ) ;
120+
105121 StartCopying ( Path , Destination . Trim ( ) , Force , Details ) ;
106122 Thread . Sleep ( 100 ) ;
107123
108- ResumeSupport . End ( ) ;
109- Logger . Instance . Info ( "Command executed successfully" ) ;
124+ if ( Resume ) ResumeSupport . End ( ) ;
125+
110126 WriteObject ( "Files copied successfully" ) ;
111127 }
112128
@@ -233,7 +249,7 @@ private void RecursiveUpload(ShareFileClient client, int uploadId, FileSystemInf
233249 {
234250 var newFolder = new Models . Folder ( ) { Name = source . Name } ;
235251 newFolder = client . Items . CreateFolder ( target . url , newFolder , Force || ResumeSupport . IsPending , false ) . Execute ( ) ;
236-
252+
237253 ActionManager actionManager = new ActionManager ( this , source . Name ) ;
238254 ActionType actionType = Force ? ActionType . Force : ActionType . None ;
239255
@@ -252,7 +268,7 @@ private void RecursiveUpload(ShareFileClient client, int uploadId, FileSystemInf
252268 }
253269 }
254270 }
255-
271+
256272 actionManager . Execute ( ) ;
257273 }
258274 else if ( source is FileInfo )
@@ -316,7 +332,10 @@ private void RecursiveDownload(ShareFileClient client, int downloadId, Models.It
316332
317333 private void MarkFileStatus ( String fileName )
318334 {
319- ResumeSupport . MarkFileStatus ( fileName ) ;
335+ if ( Resume )
336+ {
337+ ResumeSupport . MarkFileStatus ( fileName ) ;
338+ }
320339 }
321340
322341 #region Previous Implementations (commented) > Upload/Download
@@ -410,7 +429,7 @@ private void MarkFileStatus(String fileName)
410429 // }
411430 // }
412431 //}
413-
432+
414433 #endregion
415434
416435 protected void RecursiveCopy ( FileSystemInfo source , DirectoryInfo target )
0 commit comments