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; }
private void UnrollContainers( String targetPath, out List <String> tempContainers, out Stack <ContainerHierarchyEntity> containersHierarchy) { tempContainers = new List <String>(); containersHierarchy = new Stack <ContainerHierarchyEntity>(); IContentFileWriter contentWriter = new ContentFileWriter(); IContainerFile topContainer = ContainerReaderService.ReadFile(targetPath, false); containersHierarchy.Push(new ContainerHierarchyEntity(topContainer)); foreach (var containerPath in CommandGroup.NestedTargetPath.Parts) { var containerFile = containersHierarchy.Peek().ContainerFile; var contentFile = containerFile.GetContentFileByPath(containerPath); //if (contentFile.FileType == ContentFileType.Edata) //{ ContainerReaderService.LoadContent(contentFile); byte[] content = contentFile.Content; //Czytamy z pamięci żeby szybciej było, ale nie łądujemy zawartości żeby oszczedzić miejsce. var virtualContainer = ContainerReaderService.ReadRaw(content, false); //Tutaj mieć na uwadze, że ten sposób pozyskiwania ścieżki jest bardzo podatny na problemy, miejsce wolne itd. String lastPath = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileName(contentFile.Path)); contentWriter.Write(lastPath, content); virtualContainer.Path = lastPath; //Tutaj brakuje jakiejś możliwosci zmiany ścieżki dla kontenera //i zmiany stanu z wirtualnego do przechowywanego na dysku. containersHierarchy.Push(new ContainerHierarchyEntity(virtualContainer, containerPath)); tempContainers.Add(lastPath); //} } }