public async Task Create() { Runtime.AssertMainThread(); OnProjectCreating(); projectCreated = new TaskCompletionSource <bool> (); if (wizardProvider.HasWizard) { wizardProvider.BeforeProjectIsCreated(); } if (!await CreateProject()) { projectCreated.SetResult(false); OnProjectCreationFailed(); 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); OnProjectCreated(); } catch (Exception ex) { projectCreated.SetException(ex); throw; } }
public void Create() { if (wizardProvider.HasWizard) { wizardProvider.BeforeProjectIsCreated(); } if (!CreateProject()) { 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 SolutionEntityItem; if (eitem != null) { // Inherit the file format from the solution eitem.FileFormat = ParentFolder.ParentSolution.FileFormat; // 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(eitem); if (projectReferences.Any()) { eitem.Items.RemoveRange(projectReferences); } IdeApp.ProjectOperations.Save(eitem); if (projectReferences.Any()) { eitem.Items.AddRange(projectReferences); } } ParentFolder.AddItem(currentEntry, true); } } if (ParentFolder != null) { IdeApp.ProjectOperations.Save(ParentFolder.ParentSolution); } else { IdeApp.ProjectOperations.Save(processedTemplate.WorkspaceItems); } CreateVersionControlItems(); if (OpenSolution) { DisposeExistingNewItems(); TemplateWizard wizard = wizardProvider.CurrentWizard; var op = OpenCreatedSolution(processedTemplate); op.Completed += delegate { if (op.Success) { 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. disposeNewItem = false; RunTemplateActions(processedTemplate); if (wizardProvider.HasWizard) { wizardProvider.CurrentWizard.ItemsCreated(processedTemplate.WorkspaceItems); } if (ParentFolder != null) { InstallProjectTemplatePackages(ParentFolder.ParentSolution); } } IsNewItemCreated = true; UpdateDefaultSettings(); dialog.CloseDialog(); wizardProvider.Dispose(); imageProvider.Dispose(); }
public ParameterSource(TemplateWizard wizard) { this.wizard = wizard; }