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.Match, this.Replacement);
        }
        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));
        }
 public abstract void Apply(PackageContext packageContext);
        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;
        }
        public static void Apply(PackageContext packageContext, ManifestItem manifestItem, string match, string replacement)
        {
            Regex matchRegex = new Regex(match);

            Apply(packageContext, manifestItem, matchRegex, replacement);
        }
        private bool CreateProjectFromPackage()
        {
            PackageContext packageContext = null;
            List<InputResult> inputResults = new List<InputResult>();
            Project project = null;

            if (locationTextBox.Text.IsNullOrEmpty() || !Directory.Exists(locationTextBox.Text))
            {
                MessageBox.Show("Please enter or select a valid location to create your project.", null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            progressLabel.Text = "Initializing";
            progressBar.Value = 0;
            progressPanel.Visible = true;

            //Extract package inputs.
            inputResults = packageInputsFlowPanel.Controls.OfType<PackageInput>().Select(c => c.GetInputResult()).ToList();

            //Create the project.
            packageContext = new PackageContext(_selectedPackage, locationTextBox.Text, inputResults);

            try
            {
                ProjectFactory projectFactory = new ProjectFactory();

                projectFactory.ReportProgress += new Common.ReportProgressEventHandler(projectFactory_ReportProgress);
                project = projectFactory.CreateProject(packageContext);
                projectFactory.ReportProgress -= new Common.ReportProgressEventHandler(projectFactory_ReportProgress);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                progressPanel.Visible = false;
                return false;
            }

            ProjectContext.Initialize(project);

            return true;
        }