public override void Apply(PackageContext packageContext)
        {
            if (packageContext.Package.Manifest.Automatic)
            {
                foreach (string filePath in Directory.GetFiles(packageContext.OutputPath, "*", SearchOption.AllDirectories))
                {
                    ManifestItem manifestItem = new ManifestItem(null, ManifestItemType.File, filePath.Substring(packageContext.OutputPath.Length + 1), false);

                    foreach (InputResult inputResult in packageContext.InputResults)
                    {
                        ApplyInputReplacementsAction.Apply(packageContext, manifestItem, inputResult);
                    }
                }
            }
            else
            {
                foreach (ManifestItem item in packageContext.Package.Manifest.Items)
                {
                    foreach (InputResult inputResult in packageContext.InputResults)
                    {
                        ApplyInputReplacementsAction.Apply(packageContext, item, inputResult);
                    }
                }
            }
        }
        public static void Apply(PackageContext packageContext, ManifestItem manifestItem, InputResult inputResult)
        {
            if (inputResult == null)
            {
                throw new ArgumentNullException("inputResult");
            }

            ReplaceTextAction.Apply(packageContext, manifestItem, @"\{{{0}\}}".FormatString(inputResult.Input.ID), inputResult.Value);
        }
예제 #3
0
        public override void Apply(PackageContext packageContext)
        {
            ManifestItem manifestItem = packageContext.Package.GetManifestItemByID(this.ManifestItemID);

            if (manifestItem == null)
            {
                throw new ApplicationException("Could not locate manifest item with ID \"{0}\".".FormatString(this.ManifestItemID));
            }

            Apply(packageContext, manifestItem, this.NewName);
        }
예제 #4
0
        public override void Apply(PackageContext packageContext)
        {
            ManifestItem manifestItem = packageContext.Package.GetManifestItemByID(this.ManifestItemID);

            if (manifestItem == null)
            {
                throw new ApplicationException("Could not locate manifest item with ID \"{0}\".".FormatString(this.ManifestItemID));
            }

            Apply(packageContext, manifestItem, packageContext.GetAbsoluteOutputPath(this.RelativePath), !this.SkipIfExists);
        }
예제 #5
0
        public static void Apply(PackageContext packageContext, ManifestItem manifestItem, string newName)
        {
            string manifestItemPath        = null;
            string newNameWithReplacements = null;

            if (manifestItem == null)
            {
                throw new ArgumentNullException("manifestItem");
            }

            manifestItemPath = packageContext.GetAbsoluteOutputPath(manifestItem.RelativePath);

            //Apply input replacements to the new file/folder name.
            newNameWithReplacements = ApplyAllInputReplacementsAction.Apply(packageContext, newName);

            //Remove any invalid characters.
            foreach (char character in Path.GetInvalidPathChars())
            {
                newNameWithReplacements = newNameWithReplacements.Replace(character.ToString(), string.Empty);
            }

            if (manifestItem.Type == ManifestItemType.File)
            {
                FileInfo fileInfo = new FileInfo(manifestItemPath);
                string   newPath  = Path.Combine(Path.GetDirectoryName(fileInfo.FullName), newNameWithReplacements);

                if (!fileInfo.Exists)
                {
                    throw new ApplicationException("Manifest item not found at path \"{0}\".".FormatString(manifestItemPath));
                }

                if (File.Exists(newPath))
                {
                    File.Delete(newPath);
                }

                fileInfo.MoveTo(newPath);
            }
            else if (manifestItem.Type == ManifestItemType.Folder)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(manifestItemPath);

                if (!directoryInfo.Exists)
                {
                    throw new ApplicationException("Manifest item not found at path \"{0}\".".FormatString(manifestItemPath));
                }

                directoryInfo.MoveTo(Path.Combine(Path.GetDirectoryName(directoryInfo.Parent.FullName), newNameWithReplacements));
            }
        }
        public override void Apply(PackageContext packageContext)
        {
            ManifestItem manifestItem = packageContext.Package.GetManifestItemByID(this.ManifestItemID);
            InputResult  inputResult  = packageContext.GetInputResultByID(this.InputID);

            if (manifestItem == null)
            {
                throw new ApplicationException("Could not locate manifest item with ID \"{0}\".".FormatString(this.ManifestItemID));
            }

            if (inputResult == null)
            {
                throw new ApplicationException("Could not locate input with ID \"{0}\".".FormatString(this.InputID));
            }

            Apply(packageContext, manifestItem, inputResult);
        }
예제 #7
0
        public static void Apply(PackageContext packageContext, ManifestItem manifestItem, string destinationPath, bool overwrite)
        {
            if (manifestItem == null)
            {
                throw new ArgumentNullException("manifestItem");
            }

            if (!File.Exists(destinationPath) || overwrite)
            {
                using (Stream inputStream = File.OpenRead(packageContext.Package.Path))
                {
                    using (Stream outputStream = File.OpenWrite(destinationPath))
                    {
                        SimpleZip.UnzipFile(inputStream, outputStream, manifestItem.RelativePath, null);
                    }
                }
            }
        }
예제 #8
0
        public static void Apply(PackageContext packageContext, ManifestItem manifestItem, Regex matchRegex, string replacement)
        {
            string manifestItemPath = null;

            if (manifestItem == null)
            {
                throw new ArgumentNullException("manifestItem");
            }

            if (manifestItem.Type != ManifestItemType.File)
            {
                throw new ApplicationException("Can not replace text in a manifest item which is not a file.");
            }

            manifestItemPath = packageContext.GetAbsoluteOutputPath(manifestItem.RelativePath);

            if (!File.Exists(manifestItemPath))
            {
                throw new ApplicationException("Manifest item not found at path \"{0}\".".FormatString(manifestItemPath));
            }

            File.WriteAllText(manifestItemPath, Apply(File.ReadAllText(manifestItemPath), matchRegex, replacement));
        }
예제 #9
0
        public Project CreateProject(PackageContext packageContext)
        {
            ManifestItem projectFileManifestItem = null;
            string       projectFilePath         = null;
            Project      project       = null;
            long         actionCount   = 0;
            long         currentAction = 0;

            this.ReportProgress("Initializing", null, null);
            actionCount += packageContext.InputResults.CountOrDefault();
            actionCount += packageContext.Package.PackageReferences.SumOrDefault(o => o.Package.Actions.CountOrDefault());
            actionCount += packageContext.Package.Actions.CountOrDefault();

            //Create the output path.
            this.ReportProgress("Validating Path", null, null);

            if (!Directory.Exists(packageContext.OutputPath))
            {
                Directory.CreateDirectory(packageContext.OutputPath);
            }

            //Validate the inputs.
            this.ReportProgress("Validating Inputs", null, null);

            if (!packageContext.InputResults.IsNullOrEmpty())
            {
                packageContext.InputResults.ForEach(o =>
                {
                    o.Validate();
                    this.OnReportProgress("Validating Inputs", currentAction++, actionCount);
                });
            }

            //Execute the actions.
            this.ReportProgress("Executing Actions", null, null);

            if (!packageContext.Package.PackageReferences.IsNullOrEmpty())
            {
                packageContext.Package.PackageReferences.ForEach(pr => pr.Package.Actions.ForEach(a =>
                {
                    a.Apply(packageContext);
                    this.OnReportProgress("Executing Actions", currentAction++, actionCount);
                }));
            }

            packageContext.Package.Actions.ForEach(a =>
            {
                a.Apply(packageContext);
                this.OnReportProgress("Executing Actions", currentAction++, actionCount);
            });

            this.ReportProgress("Opening Project", null, null);

            //Find the project file manifest item.
            projectFileManifestItem = packageContext.Package.GetManifestItemByID(packageContext.Package.Manifest.ProjectFileManifestItemID);

            if (projectFileManifestItem == null)
            {
                throw new ApplicationException("Could not locate manifest item with ID \"{0}\".".FormatString(projectFileManifestItem.ID));
            }

            //Check if the project file was renamed.
            foreach (RenameAction action in packageContext.Package.Actions.OfType <RenameAction>().Where(o => string.Equals(o.ManifestItemID, projectFileManifestItem.ID)))
            {
                projectFilePath = ApplyAllInputReplacementsAction.Apply(packageContext, action.NewName);
            }

            //Open the project.
            projectFilePath = Path.Combine(packageContext.GetAbsoluteOutputPath(Path.GetDirectoryName(projectFileManifestItem.RelativePath)), projectFilePath);
            project         = Project.Open(projectFilePath);

            return(project);
        }
예제 #10
0
        public static void Apply(PackageContext packageContext, ManifestItem manifestItem, string match, string replacement)
        {
            Regex matchRegex = new Regex(match);

            Apply(packageContext, manifestItem, matchRegex, replacement);
        }