protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken token) { InitializeProgress(); String sourceFullPath = Path.Combine(context.InstallerTargetDirectory, Command.SourcePath); if (!File.Exists(sourceFullPath)) { throw new CmdExecutionFailedException("A file given by the sourcePath doesn't exist.", String.Format(Properties.Resources.CopyFileErrorParamMsg, Command.SourcePath)); } String targetFullPath = Path.Combine(context.InstallerTargetDirectory, Command.TargetPath); if (!PathUtilities.IsValidPath(targetFullPath)) { throw new CmdExecutionFailedException("A given targetPath is not a valid path.", String.Format(Properties.Resources.CopyFileErrorParamMsg, Command.SourcePath)); } PathUtilities.CreateDirectoryIfNotExist(Path.GetDirectoryName(targetFullPath)); FileUtilities.CopyFileEx(sourceFullPath, targetFullPath, token); SetMaxProgress(); }
protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken token) { InitializeProgress(); String sourceFullPath = Path.Combine(context.InstallerTargetDirectory, Command.SourcePath); if (!PathUtilities.IsValidPath(sourceFullPath)) { throw new CmdExecutionFailedException("A given sourcePath is not a valid path.", Properties.Resources.RestoreSourceErrorMsg); } var profileRootDir = ProfileLocator.TryGetProfileRootDirectory(); if (profileRootDir == null || !Directory.Exists(profileRootDir)) { throw new CmdExecutionFailedException("Invalid Profile Root directory.", Properties.Resources.RestoreTargetErrorMsg); } //Now Create all of the directories foreach (String dirPath in Directory.GetDirectories(sourceFullPath, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(sourceFullPath, profileRootDir)); } //Copy all the files & Replaces any files with the same name foreach (String filePath in Directory.GetFiles(sourceFullPath, "*.*", SearchOption.AllDirectories)) { File.Copy(filePath, filePath.Replace(sourceFullPath, profileRootDir), true); } SetMaxProgress(); }
public override void Execute(CmdExecutionContext context, CancellationToken token) { //Ta metoda bez bloków łapania wyjątków, w przypadku ewentualnego wyjątku pochodzącego z kodu z poza execute, spowoduje //wykrzaczenie się całej instalacji. Może trzeba zaimplementować IsCritical także dla CmdGroup... String targetfullPath = CommandGroup.TargetPath .GetAbsoluteOrPrependIfRelative(context.InstallerTargetDirectory); if (!File.Exists(targetfullPath)) { //Jeśli ten plik nie istnieje to szlag wszystkie komendy wewnętrzne. throw new CmdExecutionFailedException( String.Format("A specified target file: \"{0}\" doesn't exist", targetfullPath), String.Format(Properties.Resources.NotExistingFileOperationErrorParamMsg, targetfullPath)); } CurrentStep = 0; //should it be sorrounded with a try-catch? var containerFile = ContainerReaderService.ReadFile(targetfullPath, false); ContainerFileLoadManager loadManager = new ContainerFileLoadManager(); loadManager.MaxLoadReached += (sender, args) => { CurrentMessage = String.Format(Properties.Resources.RebuildingParametrizedMsg, CommandGroup.TargetPath); ContainerWriterService.WriteFile(containerFile, token); loadManager.FreeManagedFilesLoad(); }; var newExecutionContext = new SharedContainerCmdExecContext( context.InstallerSourceDirectory, context.InstallerTargetDirectory, containerFile); foreach (var executor in Executors) { var cmd = GetExecutorsAssociatedCommand(executor); var paths = GetPathsOfContentFiles(cmd); var contentFiles = GetContentFiles(containerFile, paths); loadManager.AddManagedFiles(contentFiles); LoadContentFiles(contentFiles); executor.Execute(newExecutionContext, token); } CurrentMessage = String.Format(Properties.Resources.RebuildingParametrizedMsg, CommandGroup.TargetPath); ContainerWriterService.WriteFile(containerFile, token); //Set max, completed CurrentStep = TotalSteps; }
public override void Execute(CmdExecutionContext context, CancellationToken token) { CurrentStep = 0; foreach (var executor in Executors) { executor.Execute(context, token); } CurrentStep = TotalSteps; }
protected EdataFile GetEdataFromContext(CmdExecutionContext context) { var sharedEdataContext = context as SharedEdataCmdExecutionContext; if (sharedEdataContext != null) { return(sharedEdataContext.EdataFile); } else { throw new InvalidOperationException("Cannot get an Edata file from the given context"); } }
protected bool CanGetEdataFromContext(CmdExecutionContext context) { var sharedEdataContext = context as SharedEdataCmdExecutionContext; if (sharedEdataContext != null) { return(sharedEdataContext.EdataFile != null); } else { return(false); } }
protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken token) { InitializeProgress(); token.ThrowIfCancellationRequested(); String sourceFullPath = Path.Combine(context.InstallerTargetDirectory, Command.SourcePath); if (PathUtilities.IsFile(sourceFullPath) && File.Exists(sourceFullPath)) { File.Delete(sourceFullPath); } else if (PathUtilities.IsDirectory(sourceFullPath) && Directory.Exists(sourceFullPath)) { Directory.Delete(sourceFullPath, true); } SetMaxProgress(); }
protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken token) { InitializeProgress(); var profileDirectories = ProfileLocator.GetProfileDirectories(); if (profileDirectories.Count() == 0) { throw new CmdExecutionFailedException("No profile directories found.", Properties.Resources.BackupSourceErrorMsg); } String targetFullPath = Path.Combine(context.InstallerTargetDirectory, Command.TargetPath); if (!PathUtilities.IsValidPath(targetFullPath)) { throw new CmdExecutionFailedException("A given targetPath is not a valid path.", Properties.Resources.BackupTargetErrorMsg); } foreach (var profileDir in profileDirectories) { var profileRootDir = ProfileLocator.TryGetProfileRootDirectory(); var profileSubPath = profileDir.Substring(profileRootDir.Length + 1); var destinationPath = Path.Combine(targetFullPath, profileSubPath); //Now Create all of the directories foreach (String dirPath in Directory.GetDirectories(profileDir, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(profileDir, destinationPath)); } //Copy all the files & Replaces any files with the same name foreach (String filePath in Directory.GetFiles(profileDir, "*.*", SearchOption.AllDirectories)) { File.Copy(filePath, filePath.Replace(profileDir, destinationPath), true); } } SetMaxProgress(); }
public override void Execute(CmdExecutionContext context, CancellationToken token) { //Ta metoda bez bloków łapania wyjątków, w przypadku ewentualnego wyjątku pochodzącego z kodu z poza execute, //spowoduje wykrzaczenie się całej instalacji. Może trzeba zaimplementować IsCritical także dla CmdGroup... String targetFullPath = CommandGroup.TargetPath .GetAbsoluteOrPrependIfRelative(context.InstallerTargetDirectory); if (!File.Exists(targetFullPath)) { //Jeśli ten plik nie istnieje to szlag wszystkie komendy wewnętrzne. throw new CmdExecutionFailedException( String.Format("A specified target file: \"{0}\" doesn't exist", targetFullPath), String.Format(Properties.Resources.NotExistingFileOperationErrorParamMsg, targetFullPath)); } String rootContentPath = CommandGroup.NestedTargetPath.Parts.FirstOrDefault(); if (rootContentPath == null) { throw new CmdExecutionFailedException( "Command's TargetContentPath doesn't contain any proper content path part."); } CurrentStep = 0; List <String> temporaryCreatedContainers = null; try { Stack <ContainerHierarchyEntity> containersHierarchy = null; //Tu wciąż brak komunikatu co się dzieje, tak więc wciąz jest wyświetlany poprzedni //czyli backup lub initialization jeśli ta komenda jest pierwszą. UnrollContainers(targetFullPath, out temporaryCreatedContainers, out containersHierarchy); var lastContainerFile = containersHierarchy.Peek().ContainerFile; //Interesuje nas tylko ostatni, bo to jego content bedzie ładowany, //reszta jest tylko rozwinieta na dysku ale nia ma załadowane wiecej jak jeden plik. ContainerFileLoadManager loadManager = new ContainerFileLoadManager(); loadManager.MaxLoadReached += (sender, args) => { CurrentMessage = String.Format(Properties.Resources.RebuildingParametrizedMsg, CommandGroup.TargetPath); ContainerWriterService.WriteFile(lastContainerFile, token); loadManager.FreeManagedFilesLoad(); }; var newExecutionContext = new SharedContainerCmdExecContext( context.InstallerSourceDirectory, context.InstallerTargetDirectory, lastContainerFile); foreach (var executor in Executors) { var cmd = GetExecutorsAssociatedCommand(executor); var paths = GetPathsOfContentFiles(cmd); var contentFiles = GetContentFiles(lastContainerFile, paths); loadManager.AddManagedFiles(contentFiles); LoadContentFiles(contentFiles); executor.Execute(newExecutionContext, token); } CurrentStep++; CurrentMessage = String.Format(Properties.Resources.RebuildingParametrizedMsg, CommandGroup.TargetPath); RollContainers(containersHierarchy, token); } finally { if (temporaryCreatedContainers != null) { temporaryCreatedContainers.ForEach(x => File.Delete(x)); } } //Set max, completed CurrentStep = TotalSteps; }
protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken?token = null) { CurrentStep = 0; CurrentMessage = Command.GetExecutionMessage(); //Cancel if requested; token.ThrowIfCanceledAndNotNull(); String sourceFullPath = Command.SourcePath.GetAbsoluteOrPrependIfRelative(context.InstallerSourceDirectory); if (!File.Exists(sourceFullPath)) { throw new CmdExecutionFailedException( String.Format("Command's source file \"{0}\" doesn't exist.", Command.SourcePath), String.Format(Properties.Resources.ReplaceImageErrorParametrizedMsg, Command.SourcePath)); } String targetfullPath = Command.TargetPath.GetAbsoluteOrPrependIfRelative(context.InstallerTargetDirectory); if (!File.Exists(targetfullPath)) { throw new CmdExecutionFailedException( String.Format("Command's target file \"{0}\" doesn't exist.", Command.TargetPath), String.Format(Properties.Resources.ReplaceImageErrorParametrizedMsg, Command.SourcePath)); } String contentPath = Command.NestedTargetPath.LastPart; if (contentPath == null) { throw new CmdExecutionFailedException( "Invalid command's TargetContentPath value.", String.Format(Properties.Resources.ReplaceImageErrorParametrizedMsg, Command.SourcePath)); } var edataFileReader = new EdataFileReader(); var contentOwningEdata = CanGetEdataFromContext(context) ? GetEdataFromContext(context) : edataFileReader.Read(targetfullPath, false); EdataContentFile contentFile = contentOwningEdata.GetContentFileByPath(contentPath); if (!contentFile.IsContentLoaded) { edataFileReader.LoadContent(contentFile); } if (contentFile.FileType != EdataContentFileType.Image) { throw new CmdExecutionFailedException( "Invalid command's TargetContentPath value. It doesn't point to an image content.", String.Format(Properties.Resources.ReplaceImageErrorParametrizedMsg, Command.SourcePath)); } CurrentStep++; var modifiedImageContent = ModifyImageContent(contentFile.Content, sourceFullPath); contentFile.Content = modifiedImageContent; if (!CanGetEdataFromContext(context)) { SaveEdataFile(contentOwningEdata, token); } CurrentStep = TotalSteps; }