示例#1
0
        protected virtual async Task <bool> CreateFile(FileDescriptionTemplate newfile, SolutionFolderItem policyParent, Project project, SolutionFolder solutionFolder, string directory, string language, string name)
        {
            var tagModelProvider = (WorkspaceObject)project ?? (WorkspaceObject)solutionFolder;

            if (tagModelProvider != null)
            {
                var model = tagModelProvider.GetStringTagModel(new DefaultConfigurationSelector());
                newfile.SetProjectTagModel(model);
            }

            try {
                if (project != null)
                {
                    if (await newfile.AddToProjectAsync(policyParent, project, language, directory, name))
                    {
                        newfile.Show();
                        return(true);
                    }
                    return(false);
                }

                var singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    throw new InvalidOperationException("Single file template expected");
                }

                if (directory != null)
                {
                    string fileName = await singleFile.SaveFileAsync(policyParent, project, language, directory, name);

                    if (fileName != null)
                    {
                        if (solutionFolder != null)
                        {
                            if (solutionFolder.IsRoot)
                            {
                                // Don't allow adding files to the root folder. VS doesn't allow it
                                // If there is no existing folder, create one
                                solutionFolder = solutionFolder.ParentSolution.DefaultSolutionFolder;
                            }
                            solutionFolder.Files.Add(fileName);
                        }
                        IdeApp.Workbench.OpenDocument(fileName, project: null);
                        return(true);
                    }
                    return(false);
                }

                string unsavedFilename = singleFile.GetFileName(policyParent, project, language, directory, name);
                Stream stream          = singleFile.CreateFileContent(policyParent, project, language, unsavedFilename, name)
                                         ?? await singleFile.CreateFileContentAsync(policyParent, project, language, unsavedFilename, name);

                string mimeType = GuessMimeType(unsavedFilename);
                IdeApp.Workbench.NewDocument(unsavedFilename, mimeType, stream);
                return(true);
            } finally {
                newfile.SetProjectTagModel(null);
            }
        }
示例#2
0
        protected virtual async Task <bool> CreateFile(FileDescriptionTemplate newfile, SolutionFolderItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                var model = project.GetStringTagModel(new DefaultConfigurationSelector());
                newfile.SetProjectTagModel(model);
                try {
                    if (await newfile.AddToProjectAsync(policyParent, project, language, directory, name))
                    {
                        newfile.Show();
                        return(true);
                    }
                } finally {
                    newfile.SetProjectTagModel(null);
                }
            }
            else
            {
                var singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    throw new InvalidOperationException("Single file template expected");
                }

                if (directory != null)
                {
                    string fileName = await singleFile.SaveFileAsync(policyParent, project, language, directory, name);

                    if (fileName != null)
                    {
                        IdeApp.Workbench.OpenDocument(fileName, project);
                        return(true);
                    }
                }
                else
                {
                    string fileName = singleFile.GetFileName(policyParent, project, language, directory, name);
                    Stream stream   = singleFile.CreateFileContent(policyParent, project, language, fileName, name) ?? await singleFile.CreateFileContentAsync(policyParent, project, language, fileName, name);

                    string mimeType = GuessMimeType(fileName);
                    IdeApp.Workbench.NewDocument(fileName, mimeType, stream);
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
		protected virtual bool CreateFile (FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null) {
				var model = project.GetStringTagModel (new DefaultConfigurationSelector ());
				newfile.SetProjectTagModel (model);
				try {
	                if (newfile.AddToProject (policyParent, project, language, directory, name)) {
	                    newfile.Show ();
	                    return true;
					}
				} finally {
					newfile.SetProjectTagModel (null);
				}
			} else {
                SingleFileDescriptionTemplate singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                    throw new InvalidOperationException ("Single file template expected");

                if (directory != null) {
                    string fileName = singleFile.SaveFile (policyParent, project, language, directory, name);
                    if (fileName != null) {
						IdeApp.Workbench.OpenDocument (fileName, project);
                        return true;
                    }
				} else {
                    string fileName = singleFile.GetFileName (policyParent, project, language, directory, name);
                    Stream stream = singleFile.CreateFileContent (policyParent, project, language, fileName, name);

					string mimeType = GuessMimeType (fileName);
					IdeApp.Workbench.NewDocument (fileName, mimeType, stream);
					return true;
                }
            }
            return false;
        }