Example #1
0
        void OnProjectCreationFailed()
        {
            ProjectCreationFailed?.Invoke(this, EventArgs.Empty);

            if (IdeServices.DesktopService.AccessibilityInUse)
            {
                var announcement = GettextCatalog.GetString("{0} failed to create", SelectedTemplate.Name);
                IdeServices.DesktopService.MakeAccessibilityAnnouncement(announcement);
            }
        }
Example #2
0
        public async Task Create()
        {
            projectCreated = new TaskCompletionSource <bool> ();

            if (wizardProvider.HasWizard)
            {
                wizardProvider.BeforeProjectIsCreated();
            }

            if (!await CreateProject())
            {
                projectCreated.SetResult(false);
                ProjectCreationFailed?.Invoke(this, EventArgs.Empty);
                return;
            }

            Solution parentSolution = null;

            if (ParentFolder == null)
            {
                //NOTE: we can only create one solution, so if the first item is a solution, it's the only item
                parentSolution = processedTemplate.WorkspaceItems.FirstOrDefault() as Solution;
                if (parentSolution != null)
                {
                    if (parentSolution.RootFolder.Items.Count > 0)
                    {
                        currentEntries = new List <SolutionItem> (parentSolution.GetAllSolutionItems());
                    }
                    ParentFolder = parentSolution.RootFolder;
                }
            }
            else
            {
                parentSolution = ParentFolder.ParentSolution;
                currentEntries = processedTemplate.WorkspaceItems.OfType <SolutionItem> ().ToList();
            }

            // New combines (not added to parent combines) already have the project as child.
            if (!projectConfiguration.CreateSolution)
            {
                // Make sure the new item is saved before adding. In this way the
                // version control add-in will be able to put it under version control.
                foreach (SolutionItem currentEntry in currentEntries)
                {
                    var eitem = currentEntry as SolutionItem;
                    if (eitem != null)
                    {
                        // Inherit the file format from the solution
                        eitem.ConvertToFormat(ParentFolder.ParentSolution.FileFormat);

                        var project = eitem as Project;
                        if (project != null)
                        {
                            // Remove any references to other projects and add them back after the
                            // project is saved because a project reference cannot be resolved until
                            // the project has a parent solution.
                            List <ProjectReference> projectReferences = GetProjectReferences(project);
                            if (projectReferences.Any())
                            {
                                project.Items.RemoveRange(projectReferences);
                            }

                            await IdeApp.ProjectOperations.SaveAsync(eitem);

                            if (projectReferences.Any())
                            {
                                project.Items.AddRange(projectReferences);
                            }
                        }
                    }
                    ParentFolder.AddItem(currentEntry, true);
                }
            }
            else
            {
                string solutionFileName = Path.Combine(projectConfiguration.SolutionLocation, finalConfigurationPage.SolutionFileName);
                if (File.Exists(solutionFileName))
                {
                    if (!MessageService.Confirm(GettextCatalog.GetString("File {0} already exists. Overwrite?", solutionFileName), AlertButton.OverwriteFile))
                    {
                        ParentFolder = null;                        //Reset process of creating solution
                        projectCreated.SetResult(false);
                        return;
                    }
                    File.Delete(solutionFileName);
                }
            }

            dialog.CloseDialog();

            try {
                if (ParentFolder != null)
                {
                    await IdeApp.ProjectOperations.SaveAsync(ParentFolder.ParentSolution);
                }
                else
                {
                    await IdeApp.ProjectOperations.SaveAsync(processedTemplate.WorkspaceItems);
                }

                CreateVersionControlItems();

                if (OpenSolution)
                {
                    DisposeExistingNewItems();
                    TemplateWizard wizard = wizardProvider.CurrentWizard;
                    if (await OpenCreatedSolution(processedTemplate))
                    {
                        var sol = IdeApp.Workspace.GetAllSolutions().FirstOrDefault();
                        if (sol != null)
                        {
                            if (wizard != null)
                            {
                                wizard.ItemsCreated(new [] { sol });
                            }
                            InstallProjectTemplatePackages(sol);
                        }
                    }
                }
                else
                {
                    // The item is not a solution being opened, so it is going to be added to
                    // an existing item. In this case, it must not be disposed by the dialog.
                    RunTemplateActions(processedTemplate);
                    if (wizardProvider.HasWizard)
                    {
                        wizardProvider.CurrentWizard.ItemsCreated(processedTemplate.WorkspaceItems);
                    }
                    if (ParentFolder != null)
                    {
                        InstallProjectTemplatePackages(ParentFolder.ParentSolution);
                    }
                }

                wizardProvider.Dispose();
                IsNewItemCreated = true;
                UpdateDefaultSettings();

                projectCreated.SetResult(true);
                await Runtime.RunInMainThread(() => ProjectCreated?.Invoke(this, EventArgs.Empty));
            } catch (Exception ex) {
                projectCreated.SetException(ex);
                throw;
            }
        }