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;
        }
Пример #2
0
        private void RollContainers(
            Stack <ContainerHierarchyEntity> containersHierarchy,
            CancellationToken token)
        {
            IContentFileReader contentFileReader = new ContentFileReader();

            while (containersHierarchy.Count > 0)
            {
                var currentEntity = containersHierarchy.Pop();
                var parentEntity  = containersHierarchy.Count > 0 ? containersHierarchy.Peek() : null;

                ContainerWriterService.WriteFile(currentEntity.ContainerFile, token);
                if (parentEntity != null)
                {
                    var owner   = parentEntity.ContainerFile.GetContentFileByPath(currentEntity.OwnerPath);
                    var content = contentFileReader.Read(currentEntity.ContainerFile.Path);
                    owner.LoadOrginalContent(content); //Original or Custom?
                }
            }
        }
Пример #3
0
        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;
        }