@@ -30,6 +30,8 @@ namespace FileSplitter {
3030    /// </remarks> 
3131    public  class  FileSplitWorker  { 
3232
33+         #region Buffer and size constants
34+ 
3335        /// <summary> 
3436        /// Default buffer size 
3537        /// </summary> 
@@ -55,6 +57,8 @@ public class FileSplitWorker {
5557        /// </summary> 
5658        static   readonly  Int32  MINIMUM_PART_SIZE  =  BUFFER_SIZE ; 
5759
60+         #endregion
61+ 
5862        #region File System related limits
5963
6064        const  string  DriveFormat_FAT12  =  "FAT12" ; 
@@ -71,7 +75,9 @@ public class FileSplitWorker {
7175        const  string  DriveFormat_FAT32_FactorName  =  "Gb" ; 
7276
7377        #endregion
74-         
78+ 
79+         #region Delegates and events 
80+ 
7581        /// <summary> 
7682        /// Delegate for Split start 
7783        /// </summary> 
@@ -116,10 +122,44 @@ public class FileSplitWorker {
116122        /// </summary> 
117123        public  event  MessageHandler  message ; 
118124
125+         #endregion
126+ 
127+         #region Private variables 
128+ 
129+         /// <summary> 
130+         /// Stores the numbers of partes calculated if the partSize o unit is not changed 
131+         /// to reduce the number of recalculations 
132+         /// </summary> 
133+         private  Int32  partsCache ; 
134+ 
135+         /// <summary> 
136+         /// Size of the part (depending on the part unit) 
137+         /// </summary> 
138+         private  Int64  partSize ; 
139+ 
140+         /// <summary> 
141+         /// Operation mode to use 
142+         /// </summary> 
143+         private  SplitUnit  operationMode ; 
144+ 
145+         #endregion
146+ 
147+         #region Properties
148+ 
119149        /// <summary> 
120150        /// Getter for the part size in bytes 
121151        /// </summary> 
122-         public  Int64  PartSize  {  get ;  set ;  } 
152+         public  Int64  PartSize  { 
153+             get  { 
154+                 return  partSize ; 
155+             } 
156+             set  { 
157+                 if  ( value  !=  partSize )  { 
158+                     partsCache  =  0 ; 
159+                     partSize  =  value ; 
160+                 } 
161+             } 
162+         } 
123163
124164        /// <summary> 
125165        /// Filename to be split 
@@ -129,9 +169,17 @@ public class FileSplitWorker {
129169        /// <summary> 
130170        /// Operation Mode 
131171        /// </summary> 
132-         public  SplitUnit  OperationMode  {  get ;  set ;  } 
133- 
134-         private  Int32  partsCache ; 
172+         public  SplitUnit  OperationMode  { 
173+             get  { 
174+                 return  operationMode ; 
175+             } 
176+             set  { 
177+                 if  ( value  !=  operationMode )  { 
178+                     partsCache  =  0 ; 
179+                     operationMode  =  value ; 
180+                 } 
181+             } 
182+         } 
135183
136184        /// <summary> 
137185        /// Calculates number of parts, based on size of file a part size 
@@ -184,15 +232,9 @@ public Int32 Parts {
184232        /// </summary> 
185233        public  String  GenerationLogFile  {  get ;  set ;  } 
186234
187-         /// <summary> 
188-         /// Adds the file name to the log file 
189-         /// </summary> 
190-         /// <param name="fileName"></param> 
191-         private  void  registerCreatedFile ( String  fileName )  { 
192-             if  ( GenerationLogFile  !=  null )  { 
193-                 File . AppendAllText ( GenerationLogFile ,  fileName  +  Environment . NewLine ) ; 
194-             } 
195-         } 
235+         #endregion
236+ 
237+         #region event helper functions 
196238
197239        /// <summary> 
198240        /// Launch splitStart event 
@@ -236,6 +278,17 @@ private void onMessage(ExceptionMessage msg, params Object[] parameters) {
236278                message ( this ,  new  MessageArgs ( msg ,  parameters ) ) ; 
237279            } 
238280        } 
281+         #endregion 
282+ 
283+         /// <summary> 
284+         /// Adds the file name to the log file 
285+         /// </summary> 
286+         /// <param name="fileName"></param> 
287+         private  void  registerCreatedFile ( String  fileName )  { 
288+             if  ( GenerationLogFile  !=  null )  { 
289+                 File . AppendAllText ( GenerationLogFile ,  fileName  +  Environment . NewLine ) ; 
290+             } 
291+         } 
239292
240293        /// <summary> 
241294        /// Generates and registers next file name in the correct destination folder 
@@ -268,7 +321,6 @@ private Int64 getNumberOfLines(String inputFileName) {
268321            return  linesReaded ; 
269322        } 
270323
271- 
272324        /// <summary> 
273325        /// Split file by number of lines 
274326        /// </summary> 
@@ -277,7 +329,6 @@ private Int64 getNumberOfLines(String inputFileName) {
277329        /// <param name="sourceFileSize"></param> 
278330        private  void  splitByLines ( String  inputFileName ,  Int64  sourceFileSize )  { 
279331
280- 
281332            // File Pattern 
282333            Int64  actualFileNumber  =  1 ; 
283334            String  actualFileName  =  getNextFileName ( actualFileNumber ) ; 
@@ -418,7 +469,6 @@ private void splitBySize(String inputFileName, Int64 sourceFileSize) {
418469            } 
419470        } 
420471
421- 
422472        /// <summary> 
423473        /// Do split operation 
424474        /// </summary> 
@@ -476,6 +526,9 @@ public void doSplit() {
476526                    if  ( ! di . Exists )  { 
477527                        di . Create ( ) ; 
478528                    } 
529+                 }  else  { 
530+                     //If destination not set use original file path 
531+                     DestinationFolder  =  Path . GetDirectoryName ( this . FileName ) ; 
479532                } 
480533
481534                if  ( OperationMode  !=  SplitUnit . Lines )  { 
@@ -496,4 +549,4 @@ public void doSplit() {
496549            } 
497550        } 
498551    } 
499- } 
552+ } 
0 commit comments