Exemple #1
0
        public void Removing_Solution_Folder_Removes_Children()
        {
            var solution = VisualStudioSolution.Create(@"c:\TestProject\Test.sln", "Test", false);

            solution.SaveEnabled = false;

            var startupProject = new TestProject("c:\\TestProject\\Project1\\Project.csproj");

            solution.AddItem(startupProject);

            solution.StartupProject = startupProject;

            var folder = solution.AddItem(SolutionFolder.Create("SubFolder"));

            solution.AddItem(new TestProject("c:\\TestProject\\Project1\\Project1.csproj"), folder);
            solution.AddItem(new TestProject("c:\\TestProject\\Project1\\Project2.csproj"), folder);

            Assert.Equal(3, solution.Projects.Count());
            Assert.Equal(4, solution.Model.Projects.Count);

            solution.RemoveItem(folder);
            Assert.Equal(1, solution.Projects.Count());
            Assert.Equal(1, solution.Model.Projects.Count);

            Assert.Equal(startupProject, solution.Projects.FirstOrDefault());
        }
Exemple #2
0
        public void Startup_Project_Property_is_Remove_From_Sln_When_Startup_Project_is_remove_from_Solution()
        {
            var solution = VisualStudioSolution.Create(@"c:\TestProject\Test.sln", "Test", false);

            solution.SaveEnabled = false;

            var startupProject = new TestProject("c:\\TestProject\\Project1\\Project.csproj");

            solution.AddItem(startupProject);

            solution.StartupProject = startupProject;

            solution.RemoveItem(startupProject);

            Assert.Null(solution.StartupProject);
        }
        public NewProjectDialogViewModel()
            : base("New Project", true, true)
        {
            _studio          = IoC.Get <IStudio>();
            _templateManager = IoC.Get <TemplateManager>();

            _allProjectTemplates = new Lazy <IDictionary <string, IEnumerable <ITemplate> > >(_templateManager.GetProjectTemplates);

            location = Platform.ProjectDirectory;

            SelectedLanguage = Languages.FirstOrDefault();
            SelectedTemplate = ProjectTemplates.FirstOrDefault();

            BrowseLocationCommand = ReactiveCommand.Create(async() =>
            {
                var ofd = new OpenFolderDialog
                {
                    InitialDirectory = location
                };

                var result = await ofd.ShowAsync();

                if (!string.IsNullOrEmpty(result))
                {
                    Location = result;
                }
            });

            OKCommand = ReactiveCommand.Create(async() =>
            {
                Close();

                bool loadNewSolution = false;

                if (_solutionFolder == null)
                {
                    IoC.Get <IStatusBar>().SetText("Creating new Solution...");
                    loadNewSolution = true;

                    var destination = Path.Combine(location, solutionName);
                    location        = destination;
                    _solutionFolder = VisualStudioSolution.Create(destination, solutionName, false, VisualStudioSolution.Extension);
                }
                else
                {
                    IoC.Get <IStatusBar>().SetText("Creating new project...");
                }

                var templateManager = IoC.Get <TemplateManager>();

                var templateDestination = Path.Combine(Location, name);

                if (await templateManager.CreateTemplate(selectedTemplate, templateDestination, ("name", name)) == CreationResult.Success)
                {
                    var projectFiles = GetProjectFiles(templateDestination);

                    bool defaultSet = _solutionFolder.Solution.StartupProject != null;

                    foreach (var projectFile in projectFiles)
                    {
                        var projectTypeGuid = ProjectUtils.GetProjectTypeGuidForProject(projectFile);

                        if (projectTypeGuid.HasValue)
                        {
                            var project = await ProjectUtils.LoadProjectFileAsync(
                                _solutionFolder.Solution, projectTypeGuid.Value, projectFile);

                            if (project != null)
                            {
                                _solutionFolder.Solution.AddItem(project, projectTypeGuid, _solutionFolder);
                            }

                            if (!defaultSet)
                            {
                                defaultSet = true;
                                _solutionFolder.Solution.StartupProject = project;
                            }

                            if (!loadNewSolution)
                            {
                                await project.LoadFilesAsync();

                                await project.ResolveReferencesAsync();
                            }
                        }
                        else
                        {
                            IoC.Get <Utils.IConsole>().WriteLine(
                                $"The project '{projectFile}' isn't supported by any installed project type!");
                        }
                    }
                }

                _solutionFolder.Solution.Save();

                if (loadNewSolution)
                {
                    await _studio.OpenSolutionAsync(_solutionFolder.Solution.Location);
                }
                else
                {
                    await _solutionFolder.Solution.RestoreSolutionAsync();
                }

                _solutionFolder = null;

                IoC.Get <IStatusBar>().ClearText();
            },
                                               this.WhenAny(x => x.Location, x => x.SolutionName, (location, solution) => solution.Value != null && !Directory.Exists(Path.Combine(location.Value, solution.Value))));

            UpdateTemplatesCommand = ReactiveCommand.Create(async() =>
            {
                var templateManager = IoC.Get <TemplateManager>();

                await Task.Run(() =>
                {
                    templateManager.UpdateDefaultTemplates();

                    _allProjectTemplates = new Lazy <IDictionary <string, IEnumerable <ITemplate> > >(_templateManager.GetProjectTemplates);

                    SelectedLanguage = SelectedLanguage;
                });
            });
        }
Exemple #4
0
        public NewProjectDialogViewModel() : base("New Project", true, true)
        {
            shell            = IoC.Get <IShell>();
            projectTemplates = new ObservableCollection <ITemplate>();
            Languages        = new List <ILanguageService>(shell.LanguageServices);

            location         = Platform.ProjectDirectory;
            SelectedLanguage = Languages.FirstOrDefault();
            SelectedTemplate = ProjectTemplates.FirstOrDefault();

            BrowseLocationCommand = ReactiveCommand.Create(async() =>
            {
                var ofd = new OpenFolderDialog
                {
                    InitialDirectory = location
                };

                var result = await ofd.ShowAsync();

                if (!string.IsNullOrEmpty(result))
                {
                    Location = result;
                }
            });

            OKCommand = ReactiveCommand.Create(async() =>
            {
                bool generateSolutionDirs = false;
                bool loadNewSolution      = false;

                if (_solutionFolder == null)
                {
                    loadNewSolution      = true;
                    generateSolutionDirs = true;

                    var destination = Path.Combine(location, solutionName);
                    _solutionFolder = VisualStudioSolution.Create(destination, solutionName, false, AvalonStudioSolution.Extension);
                }

                var templateManager = IoC.Get <TemplateManager>();

                var templateDestination = Path.Combine(_solutionFolder.Solution.CurrentDirectory, name);

                if (await templateManager.CreateTemplate(selectedTemplate, templateDestination, name) == CreationResult.Success)
                {
                    var projectFiles = GetProjectFiles(templateDestination);

                    bool defaultSet = _solutionFolder.Solution.StartupProject != null;

                    foreach (var projectFile in projectFiles)
                    {
                        var project = await Project.LoadProjectFileAsync(_solutionFolder.Solution, projectFile);
                        _solutionFolder.Solution.AddItem(project, _solutionFolder);

                        if (!defaultSet)
                        {
                            defaultSet = true;
                            _solutionFolder.Solution.StartupProject = project;
                        }
                    }
                }

                _solutionFolder.Solution.Save();

                if (loadNewSolution)
                {
                    await shell.OpenSolutionAsync(_solutionFolder.Solution.Location);
                }

                _solutionFolder = null;

                Close();
            },
                                               this.WhenAny(x => x.Location, x => x.SolutionName, (location, solution) => solution.Value != null && !Directory.Exists(Path.Combine(location.Value, solution.Value))));
        }