示例#1
0
		internal ProjectTemplateResult CreateAndOpenSolution(ProjectTemplateOptions options, string solutionDirectory, string solutionName)
		{
			FileName solutionFileName = FileName.Create(Path.Combine(solutionDirectory, solutionName + ".sln"));
			bool solutionOpened = false;
			ISolution createdSolution = SD.ProjectService.CreateEmptySolutionFile(solutionFileName);
			try {
				options.Solution = createdSolution;
				options.SolutionFolder = createdSolution;
				var result = CreateProjects(options);
				if (result == null) {
					return null;
				}
				createdSolution.Save(); // solution must be saved before it can be opened
				if (SD.ProjectService.OpenSolution(createdSolution)) {
					solutionOpened = true;
					SD.GetRequiredService<IProjectServiceRaiseEvents>().RaiseSolutionCreated(new SolutionEventArgs(createdSolution));
					return result;
				} else {
					return null;
				}
			} finally {
				if (!solutionOpened)
					createdSolution.Dispose();
			}
		}
        internal ProjectTemplateResult CreateAndOpenSolution(ProjectTemplateOptions options, string solutionDirectory, string solutionName)
        {
            FileName  solutionFileName = FileName.Create(Path.Combine(solutionDirectory, solutionName + ".sln"));
            bool      solutionOpened   = false;
            ISolution createdSolution  = SD.ProjectService.CreateEmptySolutionFile(solutionFileName);

            try {
                options.Solution       = createdSolution;
                options.SolutionFolder = createdSolution;
                var result = CreateProjects(options);
                if (result == null)
                {
                    return(null);
                }
                createdSolution.Save();                 // solution must be saved before it can be opened
                if (SD.ProjectService.OpenSolution(createdSolution))
                {
                    solutionOpened = true;
                    SD.GetRequiredService <IProjectServiceRaiseEvents>().RaiseSolutionCreated(new SolutionEventArgs(createdSolution));
                    return(result);
                }
                else
                {
                    return(null);
                }
            } finally {
                if (!solutionOpened)
                {
                    createdSolution.Dispose();
                }
            }
        }
示例#3
0
 public ProjectTemplateResult(ProjectTemplateOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     this.options = options;
 }
示例#4
0
        DirectoryName GetProjectBasePath(ProjectTemplateOptions projectCreateOptions)
        {
            if (String.IsNullOrEmpty(relativePath))
            {
                return(projectCreateOptions.ProjectBasePath);
            }
            string relativeBasePath = StringParser.Parse(relativePath, new StringTagPair("ProjectName", projectCreateOptions.ProjectName));

            return(projectCreateOptions.ProjectBasePath.CombineDirectory(relativeBasePath));
        }
        public override ProjectTemplateResult CreateProjects(ProjectTemplateOptions options)
        {
            var result = new ProjectTemplateResult(options);

            StandardHeader.SetHeaders();
            if (solutionDescriptor != null)
            {
                if (!solutionDescriptor.AddContents(options.SolutionFolder, result, languagename))
                {
                    return(null);
                }
            }
            if (projectDescriptor != null)
            {
                bool success = projectDescriptor.CreateProject(result, languagename, options.SolutionFolder);
                if (!success)
                {
                    return(null);
                }
            }
            return(result);
        }
示例#6
0
		public override ProjectTemplateResult CreateProjects(ProjectTemplateOptions options)
		{
			var result = new ProjectTemplateResult(options);
			StandardHeader.SetHeaders();
			if (solutionDescriptor != null) {
				if (!solutionDescriptor.AddContents(options.SolutionFolder, result, languagename))
					return null;
			}
			if (projectDescriptor != null) {
				IProject project = projectDescriptor.CreateProject(result, languagename);
				if (project != null) {
					options.SolutionFolder.Items.Add(project);
				} else {
					return null;
				}
			}
			return result;
		}
        void CreateProject()
        {
            if (categoryTreeView.SelectedNode != null) {
                PropertyService.Set("Dialogs.NewProjectDialog.LastSelectedCategory", TreeViewHelper.GetPath(categoryTreeView.SelectedNode));
                PropertyService.Set("Dialogs.NewProjectDialog.CategoryTreeState", TreeViewHelper.GetViewStateString(categoryTreeView));
                PropertyService.Set("Dialogs.NewProjectDialog.LargeImages", largeIconsRadioButton.Checked);
            }

            string solution = solutionNameTextBox.Text.Trim();
            string name     = nameTextBox.Text.Trim();
            string location = locationTextBox.Text.Trim();
            string projectNameError = CheckProjectName(solution, name, location);
            if (projectNameError != null) {
                MessageService.ShowError(projectNameError);
                return;
            }

            if (templateListView.SelectedItems.Count == 1 && locationTextBox.Text.Length > 0 && solutionNameTextBox.Text.Length > 0) {
                TemplateItem item = (TemplateItem)templateListView.SelectedItems[0];
                try {
                    System.IO.Directory.CreateDirectory(NewProjectDirectory);
                } catch (Exception) {
                    MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.CantCreateDirectoryError}");
                    return;
                }

                ProjectTemplateOptions cinfo = new ProjectTemplateOptions();

                if (item.Template.SupportedTargetFrameworks.Any()) {
                    cinfo.TargetFramework = (TargetFramework)targetFrameworkComboBox.SelectedItem;
                    PropertyService.Set("Dialogs.NewProjectDialog.TargetFramework", cinfo.TargetFramework.TargetFrameworkVersion);
                }

                cinfo.ProjectBasePath = DirectoryName.Create(NewProjectDirectory);
                cinfo.ProjectName     = name;

                if (createNewSolution) {
                    if (!SD.ProjectService.CloseSolution())
                        return;
                    result = item.Template.CreateAndOpenSolution(cinfo, NewSolutionDirectory, solution);
                } else {
                    cinfo.Solution = SolutionFolder.ParentSolution;
                    cinfo.SolutionFolder = SolutionFolder;
                    result = item.Template.CreateProjects(cinfo);
                    cinfo.Solution.Save();
                }

                if (result != null)
                    item.Template.RunOpenActions(result);

                ProjectBrowserPad.RefreshViewAsync();
                DialogResult = DialogResult.OK;
            }
        }
		public ProjectTemplateResult(ProjectTemplateOptions options)
		{
			if (options == null)
				throw new ArgumentNullException("options");
			this.options = options;
		}
示例#9
0
		/// <summary>
		/// Creates projects from the template; and adds them to the solution specified in the parameter object.
		/// </summary>
		/// <param name="options">Parameter object used to pass options for the template creation.</param>
		/// <returns>
		/// Returns a result object that describes the projects that were created;
		/// or null if the operation was aborted.
		/// </returns>
		/// <exception cref="IOException">Error writing the projects to disk</exception>
		/// <exception cref="ProjectLoadException">Error creating the projects (e.g. a separate download is required for projects of this type [like the F# compiler])</exception>
		public abstract ProjectTemplateResult CreateProjects(ProjectTemplateOptions options);
		public override ProjectTemplateResult CreateProjects(ProjectTemplateOptions options)
		{
			var result = new ProjectTemplateResult(options);
			StandardHeader.SetHeaders();
			if (solutionDescriptor != null) {
				if (!solutionDescriptor.AddContents(options.SolutionFolder, result, languagename))
					return null;
			}
			if (projectDescriptor != null) {
				bool success = projectDescriptor.CreateProject(result, languagename, options.SolutionFolder);
				if (!success) {
					return null;
				}
			}
			return result;
		}
 DirectoryName GetProjectBasePath(ProjectTemplateOptions projectCreateOptions)
 {
     if (String.IsNullOrEmpty(relativePath)) {
         return projectCreateOptions.ProjectBasePath;
     }
     string relativeBasePath = StringParser.Parse(relativePath, new StringTagPair("ProjectName", projectCreateOptions.ProjectName));
     return projectCreateOptions.ProjectBasePath.CombineDirectory(relativeBasePath);
 }
示例#12
0
 /// <summary>
 /// Creates projects from the template; and adds them to the solution specified in the parameter object.
 /// </summary>
 /// <param name="options">Parameter object used to pass options for the template creation.</param>
 /// <returns>
 /// Returns a result object that describes the projects that were created;
 /// or null if the operation was aborted.
 /// </returns>
 /// <exception cref="IOException">Error writing the projects to disk</exception>
 /// <exception cref="ProjectLoadException">Error creating the projects (e.g. a separate download is required for projects of this type [like the F# compiler])</exception>
 public abstract ProjectTemplateResult CreateProjects(ProjectTemplateOptions options);