/// <summary> /// /// </summary> /// <param name="fileAndDirectoryFullPaths">The full path to all the files and directorys to compress or archives to extract</param> /// <param name="archivefullPath">The path where to place the archive or the extracted files and directorys</param> /// <param name="format">The compression format(only for compression)</param> /// <param name="fastcompression">If you whan to compresss the files fast(only for compression)</param> /// <param name="password">(only for compression and if required)</param> /// <param name="compresstionlevel">How strong must the compression be (only for compression)</param> public ArchiveProcressScreen(IList<String> fileAndDirectoryFullPaths, string archivefullPath, ArchiveAction action, string archivename = null, OutArchiveFormat format = OutArchiveFormat.SevenZip, bool fastcompression = false, string password = null, CompressionLevel compresstionlevel = CompressionLevel.Normal) { SevenZipBase.SetLibraryPath(IntPtr.Size == 8 ? "7z64.dll" : "7z32.dll"); InitializeComponent(); _fileAndDirectoryFullPaths = fileAndDirectoryFullPaths; _archivePath = archivefullPath; _archivename = archivename; _action = action; _format = format; _compresstionlevel = compresstionlevel; _password = password; _fastcompression = fastcompression; _deltatotaal = pb_totaalfiles.Value += (int)(100 / fileAndDirectoryFullPaths.Count); tempPath = $"{Path.GetTempPath()}//7zip//"; pb_compression.Value = 0; pb_totaalfiles.Value = 0; }
/// <summary> /// /// </summary> /// <param name="fileAndDirectoryFullPaths">The full path to all the files and directorys to compress or archives to extract</param> /// <param name="archivefullPath">The path where to place the archive or the extracted files and directorys</param> /// <param name="format">The compression format(only for compression)</param> /// <param name="fastcompression">If you whan to compresss the files fast(only for compression)</param> /// <param name="password">(only for compression and if required)</param> /// <param name="compresstionlevel">How strong must the compression be (only for compression)</param> public ArchiveProcressScreen(IList <String> fileAndDirectoryFullPaths, string archivefullPath, ArchiveAction action, string archivename = null, OutArchiveFormat format = OutArchiveFormat.SevenZip, bool fastcompression = false, string password = null, CompressionLevel compresstionlevel = CompressionLevel.Normal) { SevenZipBase.SetLibraryPath(IntPtr.Size == 8? "7z64.dll" : "7z32.dll"); InitializeComponent(); _fileAndDirectoryFullPaths = fileAndDirectoryFullPaths; _archivePath = archivefullPath; _archivename = archivename; _action = action; _format = format; _compresstionlevel = compresstionlevel; _password = password; _fastcompression = fastcompression; _deltatotaal = pb_totaalfiles.Value += (int)(100 / fileAndDirectoryFullPaths.Count); tempPath = string.Format("{0}//7zip//", Path.GetTempPath()); pb_compression.Value = 0; pb_totaalfiles.Value = 0; }
/// <summary> /// Allows you to add files to an archive, whether the archive /// already exists or not /// </summary> /// <param name="archiveFullName"> /// The name of the archive to you want to add your files to /// </param> /// <param name="files"> /// A set of file names that are to be added /// </param> /// <param name="action"> /// Specifies how we are going to handle an existing archive /// </param> /// <param name="compression"> /// Specifies what type of compression to use - defaults to Optimal /// </param> public static void AddToArchive(string archiveFullName, List<string> files, ArchiveAction action = ArchiveAction.Replace, Overwrite fileOverwrite = Overwrite.IfNewer, CompressionLevel compression = CompressionLevel.Optimal) { //Identifies the mode we will be using - the default is Create ZipArchiveMode mode = ZipArchiveMode.Create; //Determines if the zip file even exists bool archiveExists = File.Exists(archiveFullName); //Figures out what to do based upon our specified overwrite method switch (action) { case ArchiveAction.Merge: //Sets the mode to update if the file exists, otherwise //the default of Create is fine if (archiveExists) { mode = ZipArchiveMode.Update; } break; case ArchiveAction.Replace: //Deletes the file if it exists. Either way, the default //mode of Create is fine if (archiveExists) { File.Delete(archiveFullName); } break; case ArchiveAction.Error: //Throws an error if the file exists if (archiveExists) { throw new IOException(String.Format("The zip file {0} already exists.", archiveFullName)); } break; case ArchiveAction.Ignore: //Closes the method silently and does nothing if (archiveExists) { return; } break; default: break; } //Opens the zip file in the mode we specified using (ZipArchive zipFile = ZipFile.Open(archiveFullName, mode)) { //This is a bit of a hack and should be refactored - I am //doing a similar foreach loop for both modes, but for Create //I am doing very little work while Update gets a lot of //code. This also does not handle any other mode (of //which there currently wouldn't be one since we don't //use Read here). if (mode == ZipArchiveMode.Create) { foreach (string file in files) { //Adds the file to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); } } else { foreach (string file in files) { var fileInZip = (from f in zipFile.Entries where f.Name == Path.GetFileName(file) select f).FirstOrDefault(); switch (fileOverwrite) { case Overwrite.Always: //Deletes the file if it is found if (fileInZip != null) { fileInZip.Delete(); } //Adds the file to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); break; case Overwrite.IfNewer: //This is a bit trickier - we only delete the file if it is //newer, but if it is newer or if the file isn't already in //the zip file, we will write it to the zip file if (fileInZip != null) { //Deletes the file only if it is older than our file. //Note that the file will be ignored if the existing file //in the archive is newer. if (fileInZip.LastWriteTime < File.GetLastWriteTime(file)) { fileInZip.Delete(); //Adds the file to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); } } else { //The file wasn't already in the zip file so add it to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); } break; case Overwrite.Never: //Don't do anything - this is a decision that you need to //consider, however, since this will mean that no file will //be writte. You could write a second copy to the zip with //the same name (not sure that is wise, however). break; default: break; } } } } }
public void When(ArchiveAction cmd) { ChangeAgg(cmd.Id, agg => agg.ArchiveAction(cmd.ActionId, _time)); }
protected override void InitializeAction() { Action = new ArchiveAction(ArticleService, FieldService, ProductService, CreateTransaction, NotificationService); }
/// <summary> /// Constructs the class. /// </summary> /// <param name="action">The processor action.</param> public ArchiveCommand(ArchiveAction action) { Action = action; }
/// <summary> /// Allows you to add files to an archive, whether the archive /// already exists or not /// </summary> /// <param name="archiveFullName"> /// The name of the archive to you want to add your files to /// </param> /// <param name="files"> /// A set of file names that are to be added /// </param> /// <param name="action"> /// Specifies how we are going to handle an existing archive /// </param> /// <param name="compression"> /// Specifies what type of compression to use - defaults to Optimal /// </param> public static void AddToArchive(string archiveFullName, List <string> files, ArchiveAction action = ArchiveAction.Replace, Overwrite fileOverwrite = Overwrite.IfNewer, CompressionLevel compression = CompressionLevel.Optimal) { //Identifies the mode we will be using - the default is Create ZipArchiveMode mode = ZipArchiveMode.Create; //Determines if the zip file even exists bool archiveExists = File.Exists(archiveFullName); //Figures out what to do based upon our specified overwrite method switch (action) { case ArchiveAction.Merge: //Sets the mode to update if the file exists, otherwise //the default of Create is fine if (archiveExists) { mode = ZipArchiveMode.Update; } break; case ArchiveAction.Replace: //Deletes the file if it exists. Either way, the default //mode of Create is fine if (archiveExists) { File.Delete(archiveFullName); } break; case ArchiveAction.Error: //Throws an error if the file exists if (archiveExists) { throw new IOException(String.Format("The zip file {0} already exists.", archiveFullName)); } break; case ArchiveAction.Ignore: //Closes the method silently and does nothing if (archiveExists) { return; } break; default: break; } //Opens the zip file in the mode we specified using (ZipArchive zipFile = ZipFile.Open(archiveFullName, mode)) { //This is a bit of a hack and should be refactored - I am //doing a similar foreach loop for both modes, but for Create //I am doing very little work while Update gets a lot of //code. This also does not handle any other mode (of //which there currently wouldn't be one since we don't //use Read here). if (mode == ZipArchiveMode.Create) { foreach (string file in files) { //Adds the file to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); } } else { foreach (string file in files) { var fileInZip = (from f in zipFile.Entries where f.Name == Path.GetFileName(file) select f).FirstOrDefault(); switch (fileOverwrite) { case Overwrite.Always: //Deletes the file if it is found if (fileInZip != null) { fileInZip.Delete(); } //Adds the file to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); break; case Overwrite.IfNewer: //This is a bit trickier - we only delete the file if it is //newer, but if it is newer or if the file isn't already in //the zip file, we will write it to the zip file if (fileInZip != null) { //Deletes the file only if it is older than our file. //Note that the file will be ignored if the existing file //in the archive is newer. if (fileInZip.LastWriteTime < File.GetLastWriteTime(file)) { fileInZip.Delete(); //Adds the file to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); } } else { //The file wasn't already in the zip file so add it to the archive zipFile.CreateEntryFromFile(file, Path.GetFileName(file), compression); } break; case Overwrite.Never: //Don't do anything - this is a decision that you need to //consider, however, since this will mean that no file will //be writte. You could write a second copy to the zip with //the same name (not sure that is wise, however). break; default: break; } } } } }
/// <summary> /// Intialize ImageCaster commands, parse arguments, /// and process the command the user input. /// /// This method also times the time taken to perform /// the command to help optimizations in development /// or user configurations. /// </summary> /// <param name="args">Command line arguments.</param> /// <returns>The exit code.</returns> public static async Task <int> Main(string[] args) { RootCommand command = new RootCommand("Perform aggregate tasks against a collection of images") { new Command("archive", "Archive collections of images or files into compressed archives") { Handler = CommandHandler.Create <FileInfo>((file) => { try { ImageCasterConfig config = ConfigurationFile.LoadFromFile(file.FullName); IAction action = new ArchiveAction(config); try { action.Execute(); } catch (ConfigurationException ex) { Logger.Error(ex.Message); return((int)ExitCode.MalformedConfigFields); } catch (FileNotFoundException ex) { Logger.Error(ex.Message); return((int)ExitCode.MalformedConfigFields); } catch (Exception ex) { return(OnInternalException(ex)); } } catch (JsonException ex) { return(OnJsonException(ex)); } return((int)ExitCode.Normal); }) }, new Command("build", "Export the output images from the source") { Handler = CommandHandler.Create <FileInfo>((file) => { try { ImageCasterConfig config = ConfigurationFile.LoadFromFile(file.FullName); IAction action = new BuildAction(config); try { action.Execute(); } catch (ConfigurationException ex) { Logger.Error(ex.Message); return((int)ExitCode.MalformedConfigFields); } catch (Exception ex) { return(OnInternalException(ex)); } return((int)ExitCode.Normal); } catch (JsonException ex) { return(OnJsonException(ex)); } }) }, new Command("check", "Validate that the project structure and standards are maintained") { Handler = CommandHandler.Create <FileInfo>((file) => { try { ImageCasterConfig config = ConfigurationFile.LoadFromFile(file.FullName); IAction action = new CheckAction(config.Checks); try { action.Execute(); } catch (ConfigurationException ex) { Logger.Error(ex.Message); return((int)ExitCode.MalformedConfigFields); } catch (ValidationException ex) { Logger.Error(ex.Message); return((int)ExitCode.CheckFailures); } catch (Exception ex) { return(OnInternalException(ex)); } } catch (JsonException ex) { return(OnJsonException(ex)); } return((int)ExitCode.Normal); }) }, new Command("montage", "Export a single image comprised of all matching output images") { Handler = CommandHandler.Create <FileInfo>((file) => { try { ImageCasterConfig config = ConfigurationFile.LoadFromFile(file.FullName); IAction action = new MontageAction(config); try { action.Execute(); } catch (ConfigurationException ex) { Logger.Error(ex.Message); return((int)ExitCode.MalformedConfigFields); } catch (Exception ex) { return(OnInternalException(ex)); } } catch (JsonException ex) { return(OnJsonException(ex)); } return((int)ExitCode.Normal); }) } }; command.Name = "imagecaster"; CommandLineBuilder commandLineBuilder = new CommandLineBuilder(command) { EnableDirectives = false }; // Default middlewares we want to add to our console application. commandLineBuilder.UseVersionOption().UseHelp().UseParseErrorReporting().CancelOnProcessTermination(); // These are our own defined middlewares. commandLineBuilder.UseLogger().UseTimer().UseLicense().UseImageCaster(); Parser parser = commandLineBuilder.Build(); return(await parser.InvokeAsync(args)); }
public void Archive([FromBody] ImageCasterConfig config) { ArchiveAction archive = new ArchiveAction(config); archive.Execute(); }