/// <summary> /// This method returns the Files Count /// </summary> public static FolderStatus GetFolderStatus(string folderPath, FolderStatus folderStatus) { // if the folderPath string exists and the folderStatus object exists if ((TextHelper.Exists(folderPath)) && (NullHelper.Exists(folderStatus))) { // get the files string[] filesArray = Directory.GetFiles(folderPath); List <string> files = filesArray.ToList(); // If the files collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(files)) { // Add the current files count folderStatus.FilesCount += files.Count; // Iterate the collection of string objects foreach (string file in files) { // Create a new instance of a 'FileInfo' object. FileInfo fileInfo = new FileInfo(file); // Add to the size folderStatus.Size += fileInfo.Length; } } // Now get any subdirectories string[] directories = Directory.GetDirectories(folderPath); List <string> folderList = directories.ToList(); // if there are any subFolders if (ListHelper.HasOneOrMoreItems(folderList)) { // Add to the FolderCount folderStatus.FolderCount += folderList.Count; // iterate the subFolders foreach (string subFolder in folderList) { // Get the files in the subFolders (recursively) folderStatus = GetFolderStatus(subFolder, folderStatus); } } } // return value return(folderStatus); }
/// <summary> /// This method Ships the solution and strips out all the garbage you do not want. /// </summary> public static SolutionStatus Ship(Shipment shipment, ProgressBar graph) { // initial value SolutionStatus status = new SolutionStatus(); // Finally: Let the shipping begin! if (NullHelper.Exists(shipment)) { // verify both folders exist if ((Directory.Exists(shipment.SourceFolderPath)) && (Directory.Exists(shipment.OutputFolderPath))) { // Create a folderStatus object FolderStatus sourceFolderStatus = new FolderStatus(); // SetupProgressBar sourceFolderStatus = GetFolderStatus(shipment.SourceFolderPath, sourceFolderStatus); // Set the SourceFolderStatus status.SourceFolderStatus = sourceFolderStatus; // If the graph object exists if (NullHelper.Exists(graph)) { // Set the maximum, reset to 0 and show the graph graph.Maximum = sourceFolderStatus.FilesCount; graph.Value = 0; graph.Visible = true; } // Create the folders shipment.SourceFolder = new Folder(); shipment.OutputFolder = new Folder(); // Set the Path shipment.SourceFolder.Path = shipment.SourceFolderPath; shipment.OutputFolder.Path = shipment.OutputFolderPath; // if a TimeStamp should be added before we start if (shipment.Options.AddTimestamp) { // Get the current timestamp string timeStamp = GetTimeStamp(); // Create the outputPath string outputPath = Path.Combine(shipment.OutputFolderPath, timeStamp); // Update the outputFolder (do not change the Shipment, that stays the same) shipment.OutputFolder.Path = outputPath; // Create the Directory Directory.CreateDirectory(outputPath); } // Create a DirectoryInfo DirectoryInfo directoryInfo = new DirectoryInfo(shipment.SourceFolderPath); // Now create the folder for the Solution string destinationFolder = Path.Combine(shipment.OutputFolder.Path, directoryInfo.Name); // Create the toplevel folder Directory.CreateDirectory(destinationFolder); // Begin Recursive Copy RecursiveCopy(shipment.SourceFolder.Path, destinationFolder, shipment, graph); // Create a folderStatus object FolderStatus outputFolderStatus = new FolderStatus(); // SetupProgressBar outputFolderStatus = GetFolderStatus(shipment.OutputFolder.Path, outputFolderStatus); // Set the OutputFolderStatus status.OutputFolderStatus = outputFolderStatus; // To Do: Display Stats // Show user a message import has finished MessageBoxHelper.ShowMessage("The solution has been shipped.", "Solution Shipped"); } else if (!Directory.Exists(shipment.SourceFolderPath)) { // Show the user a message MessageBoxHelper.ShowMessage("The 'Source Folder' path does not exist.", "Folder Not Found"); } else if (!Directory.Exists(shipment.OutputFolderPath)) { // Show the user a message MessageBoxHelper.ShowMessage("The 'Output Folder' path does not exist.", "Folder Not Found"); } } // return value return(status); }