Example #1
0
        private void RemoveCondition(Microsoft.Build.Evaluation.Project buildProject, SolutionDataViewModel solutionData)
        {
            var allGroups = buildProject.Xml.PropertyGroups;

            var toRemove = new List<ProjectPropertyGroupElement>();

            if (!solutionData.CreateFakes)
            {
                toRemove.AddRange(allGroups.Where(x => x.Condition.Contains("Fake")));
            }

            if (!solutionData.CreateFakes)
            {
                toRemove.AddRange(allGroups.Where(x => x.Condition.Contains("Tests")));
            }

            if (toRemove.Count > 0)
            {
                foreach (var pg in toRemove.Distinct())
                {
                    buildProject.Xml.RemoveChild(pg);
                }

                buildProject.Save();
            }
        }
Example #2
0
        private void RemoveSamples(Microsoft.Build.Evaluation.Project buildProject, SolutionDataViewModel solutionData)
        {
            var items = buildProject.Items.ToArray();
            var toRemove = new List<ProjectItem>();
            foreach (var item in items)
            {
                var name = item.EvaluatedInclude;
                var index = name.IndexOf(Path.DirectorySeparatorChar);
                if (index < 0)
                {
                    continue;
                }
                var folder = name.Substring(0, index);

                switch (folder)
                {
                    case "Views":
                    case "ViewModels":
                    case "Resources":
                        var itemName = Path.GetFileNameWithoutExtension(name);
                        if (itemName == "ShellViewModel")
                        {
                            var body = CreateEmptyShell(buildProject);
                            var itemFileName = Path.GetDirectoryName(item.Xml.IncludeLocation.File);
                            itemFileName = Path.Combine(itemFileName, name);
                            File.WriteAllText(itemFileName, body);
                            continue;
                        }
                        toRemove.Add(item);
                        break;
                }
            }

            if (toRemove.Count > 0)
            {
                buildProject.RemoveItems(toRemove);
                buildProject.Save();
            }
        }
Example #3
0
        private void ModifyProject(string projectFilePath, SolutionDataViewModel solutionData)
        {
            if (!string.Equals(Path.GetExtension(projectFilePath), ".csproj"))
            {
                return;
            }

            var buildProject = new Microsoft.Build.Evaluation.Project(projectFilePath);

            if (solutionData.MustRemoveConditions)
            {
                RemoveCondition(buildProject, solutionData);
            }

            if (!solutionData.CreateSamples && Path.GetFileNameWithoutExtension(projectFilePath).EndsWith("Shell"))
            {
                RemoveSamples(buildProject, solutionData);
            }

            ProjectCollection.GlobalProjectCollection.UnloadProject(buildProject);
            //System.Threading.Thread.Sleep(500);
        }
Example #4
0
        private void CreateSolutionFolder(
            SolutionFolder solutionFolder,
            SolutionFolderData solutionFolderData,
            Action<double> progressAction,
            SolutionDataViewModel solutionData,
            CancellationToken ct)
        {
            if (!solutionData.CreateTests &&
                solutionFolder == null &&
                solutionFolderData.Name == "Tests")
            {
                return;
            }

            if (!solutionData.CreateFakes &&
                solutionFolderData.Name == "Fake")
            {
                return;
            }

            var addedProject = solutionFolder == null
                ? GetSolution().AddSolutionFolder(solutionFolderData.Name)
                : solutionFolder.AddSolutionFolder(solutionFolderData.Name);

            if (solutionFolderData.Items.Length == 0)
            {
                return;
            }

            SolutionFolder subFolder = addedProject.Object as SolutionFolder;
            var k = 1.0/solutionFolderData.Items.Length;
            for (int i = 0; i < solutionFolderData.Items.Length; ++i)
            {
                var pr = k*i;
                progressAction(pr);
                int j = i;
                CreateSolutionItem(
                    subFolder,
                    solutionFolderData.Items[i], progress =>
                    {
                        pr = k*j + progress*k;
                        progressAction(pr);
                    },
                    solutionData,
                    ct);
                ct.ThrowIfCancellationRequested();
            }
        }
Example #5
0
        private void CreateSolutionItem(
            SolutionFolder solutionFolder,
            SolutionItemData solutionItemData,
            Action<double> progressAction,
            SolutionDataViewModel solutionData,
            CancellationToken ct)
        {
            var solutionFolderData = solutionItemData as SolutionFolderData;
            if (solutionFolderData != null)
            {
                CreateSolutionFolder(
                    solutionFolder,
                    solutionFolderData,
                    progressAction,
                    solutionData,
                    ct);
                return;
            }

            var projectData = solutionItemData as ProjectData;
            if (projectData != null)
            {
                CreateProject(
                    solutionFolder,
                    projectData,
                    progressAction,
                    ct);
                return;
            }

            throw new ArgumentException("Unknown solution item type");
        }
Example #6
0
        private void CreateSolution(SolutionVariantData solutionVariantData, SolutionDataViewModel solutionData)
        {
            var solution = GetSolution();

            var waitViewModel = new WaitViewModel();
            var window = WpfServices.CreateWindow<WaitView>(waitViewModel);
            WpfServices.SetWindowOwner(window, solution.DTE.MainWindow);
            waitViewModel.Completed += async (s, a) =>
            {
                await window.Dispatcher.InvokeAsync(() =>
                {
                    window.DialogResult = !a.Cancelled && a.Error == null;
                });
            };
            waitViewModel.Caption = "Creating solution...";
            waitViewModel.Run((p, ct) =>
            {
                int count = solutionVariantData.Items.Length;
                double k = 1.0/count;
                for (int i = 0; i < count; ++i)
                {
                    var pr = k*i;
                    p.Report(pr);
                    int j = i;
                    CreateSolutionItem(
                        null,
                        solutionVariantData.Items[i], progress =>
                        {
                            pr = k*j + progress*k;
                            p.Report(pr);
                        },
                        solutionData,
                        ct);
                    ct.ThrowIfCancellationRequested();
                }
            });
            var retVal = window.ShowDialog() ?? false;

            if (!retVal)
            {
                throw new WizardCancelledException();
            }
        }
Example #7
0
        private void AddSolutionFolder(SolutionFolder parent, SolutionFolderTemplate solutionFolder,
            IList<Project> projects, SolutionDataViewModel solutionData)
        {
            if (!solutionData.CreateTests &&
                parent == null &&
                solutionFolder.Name == "Tests")
            {
                return;
            }

            if (!solutionData.CreateFakes &&
                solutionFolder.Name == "Fake")
            {
                return;
            }

            var addedProject = parent == null
                ? GetSolution().AddSolutionFolder(solutionFolder.Name)
                : parent.AddSolutionFolder(solutionFolder.Name);

            foreach (var item in solutionFolder.Items)
            {
                AddProjectToSolution(addedProject.Object as SolutionFolder, item, projects, solutionData);
            }
        }
Example #8
0
 private void AddProjectToSolution(SolutionFolder parent, SolutionItemTemplate project, IList<Project> projects,
     SolutionDataViewModel solutionData)
 {
     if (project is SolutionFolderTemplate)
     {
         AddSolutionFolder(parent, (SolutionFolderTemplate) project, projects, solutionData);
     }
     else
     {
         AddProject(parent, (ProjectTemplate) project, projects);
     }
 }