Esempio n. 1
0
        public virtual bool CanCreateUnsavedFiles(FileDescriptionTemplate newfile, SolutionFolderItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                return(true);
            }
            else
            {
                var singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    return(false);
                }

                if (directory != null)
                {
                    return(true);
                }
                else
                {
                    string fileName = singleFile.GetFileName(policyParent, project, language, directory, name);
                    string mimeType = GuessMimeType(fileName);
                    return(DisplayBindingService.GetDefaultViewBinding(null, mimeType, null) != null);
                }
            }
        }
Esempio n. 2
0
        public virtual bool CanCreateUnsavedFiles(FileDescriptionTemplate newfile, SolutionFolderItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                return(true);
            }
            else
            {
                var singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    return(false);
                }

                if (directory != null)
                {
                    return(true);
                }
                else
                {
                    string fileName       = singleFile.GetFileName(policyParent, project, language, directory, name);
                    string mimeType       = GuessMimeType(fileName);
                    var    fileDescriptor = new FileDescriptor(fileName, mimeType, project);
                    return(IdeServices.DocumentControllerService.GetSupportedControllers(fileDescriptor).Result.Any(c => c.CanUseAsDefault));
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        protected virtual bool CreateFile(FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                if (newfile.AddToProject(policyParent, project, language, directory, name))
                {
                    newfile.Show();
                    return(true);
                }
            }
            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);
                        return(true);
                    }
                }
                else
                {
                    string fileName = singleFile.GetFileName(policyParent, project, language, directory, name);
                    Stream stream   = singleFile.CreateFileContent(policyParent, project, language, fileName, name);

                    // Guess the mime type of the new file
                    string fn  = Path.GetTempFileName();
                    string ext = Path.GetExtension(fileName);
                    int    n   = 0;
                    while (File.Exists(fn + n + ext))
                    {
                        n++;
                    }
                    FileService.MoveFile(fn, fn + n + ext);
                    string mimeType = DesktopService.GetMimeTypeForUri(fn + n + ext);
                    FileService.DeleteFile(fn + n + ext);
                    if (mimeType == null || mimeType == "")
                    {
                        mimeType = "text";
                    }

                    IdeApp.Workbench.NewDocument(fileName, mimeType, stream);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public static FileDescriptionTemplate CreateTemplate(XmlElement element, FilePath baseDirectory)
        {
            if (templates == null)
            {
                templates = new List <FileTemplateTypeCodon> ();
                AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/FileTemplateTypes", OnExtensionChanged);
            }

            foreach (FileTemplateTypeCodon template in templates)
            {
                if (template.ElementName == element.Name)
                {
                    FileDescriptionTemplate t = (FileDescriptionTemplate)template.CreateInstance(typeof(FileDescriptionTemplate));
                    t.Load(element, baseDirectory);
                    return(t);
                }
            }
            throw new InvalidOperationException("Unknown file template type: " + element.Name);
        }
Esempio n. 7
0
        protected virtual bool CreateFile(FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                if (newfile.AddToProject(policyParent, project, language, directory, name))
                {
                    newfile.Show();
                    return(true);
                }
            }
            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);
                        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);
        }
        public override void Load(XmlElement filenode, FilePath baseDirectory)
        {
            dirName = filenode.GetAttribute("name");
            if (string.IsNullOrEmpty(dirName) || !FileService.IsValidFileName(dirName))
            {
                throw new InvalidOperationException("Invalid name in directory template");
            }

            foreach (XmlNode node in filenode)
            {
                if (!(node is XmlElement))
                {
                    continue;
                }

                FileDescriptionTemplate t = FileDescriptionTemplate.CreateTemplate((XmlElement)node, baseDirectory);
                if (t == null)
                {
                    throw new InvalidOperationException("Invalid file template in directory template");
                }

                templates.Add(t);
            }
        }
Esempio n. 9
0
        public static ProjectDescriptor CreateProjectDescriptor(XmlElement xmlElement, FilePath baseDirectory)
        {
            ProjectDescriptor projectDescriptor = new ProjectDescriptor();

            projectDescriptor.name            = xmlElement.GetAttribute("name");
            projectDescriptor.directory       = xmlElement.GetAttribute("directory");
            projectDescriptor.createCondition = xmlElement.GetAttribute("if");

            projectDescriptor.type = xmlElement.GetAttribute("type");

            if (xmlElement ["Files"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Files"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        projectDescriptor.files.Add(
                            FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory));
                    }
                }
            }

            if (xmlElement ["Resources"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Resources"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var fileTemplate = FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory);
                        if (fileTemplate is SingleFileDescriptionTemplate)
                        {
                            projectDescriptor.resources.Add((SingleFileDescriptionTemplate)fileTemplate);
                        }
                        else
                        {
                            MessageService.ShowError(GettextCatalog.GetString("Only single-file templates allowed to generate resource files"));
                        }
                    }
                }
            }

            if (xmlElement ["References"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["References"].ChildNodes)
                {
                    projectDescriptor.references.Add(new ProjectReferenceDescription((XmlElement)xmlNode));
                }
            }

            projectDescriptor.projectOptions = xmlElement ["Options"];
            if (projectDescriptor.projectOptions == null)
            {
                projectDescriptor.projectOptions = xmlElement.OwnerDocument.CreateElement("Options");
            }

            if (xmlElement ["Packages"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Packages"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var packageReference = ProjectTemplatePackageReference.Create((XmlElement)xmlNode, baseDirectory);
                        projectDescriptor.packageReferences.Add(packageReference);
                    }
                }
            }

            return(projectDescriptor);
        }
Esempio n. 10
0
        internal static FileTemplate LoadFileTemplate(RuntimeAddin addin, XmlDocument xmlDocument, FilePath baseDirectory = new FilePath(), string templateId = "")
        {
            //Configuration
            XmlElement xmlNodeConfig = xmlDocument.DocumentElement ["TemplateConfiguration"];

            FileTemplate fileTemplate;

            if (xmlNodeConfig ["Type"] != null)
            {
                Type configType = addin.GetType(xmlNodeConfig ["Type"].InnerText);

                if (typeof(FileTemplate).IsAssignableFrom(configType))
                {
                    fileTemplate = (FileTemplate)Activator.CreateInstance(configType);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("The file template class '{0}' must be a subclass of MonoDevelop.Ide.Templates.FileTemplate", xmlNodeConfig ["Type"].InnerText));
                }
            }
            else
            {
                fileTemplate = new FileTemplate();
            }

            fileTemplate.Originator   = xmlDocument.DocumentElement.GetAttribute("Originator");
            fileTemplate.Created      = xmlDocument.DocumentElement.GetAttribute("Created");
            fileTemplate.LastModified = xmlDocument.DocumentElement.GetAttribute("LastModified");

            if (xmlNodeConfig ["_Name"] != null)
            {
                fileTemplate.Name = xmlNodeConfig ["_Name"].InnerText;
            }
            else
            {
                throw new InvalidOperationException(string.Format("Missing element '_Name' in file template: {0}", templateId));
            }

            if (xmlNodeConfig ["LanguageName"] != null)
            {
                fileTemplate.LanguageName = xmlNodeConfig ["LanguageName"].InnerText;
            }

            if (xmlNodeConfig ["ProjectType"] != null)
            {
                var projectTypeList = new List <string> ();
                foreach (var item in xmlNodeConfig["ProjectType"].InnerText.Split(','))
                {
                    projectTypeList.Add(item.Trim());
                }
                fileTemplate.ProjectTypes = projectTypeList;
            }

            fileTemplate.Categories = new Dictionary <string, string> ();
            if (xmlNodeConfig ["_Category"] != null)
            {
                foreach (XmlNode xmlNode in xmlNodeConfig.GetElementsByTagName("_Category"))
                {
                    if (xmlNode is XmlElement)
                    {
                        string projectType = "";
                        if (xmlNode.Attributes ["projectType"] != null)
                        {
                            projectType = xmlNode.Attributes ["projectType"].Value;
                        }

                        if (!string.IsNullOrEmpty(projectType) && fileTemplate.ProjectTypes.Contains(projectType))
                        {
                            fileTemplate.Categories.Add(projectType, xmlNode.InnerText);
                        }
                        else if (!fileTemplate.Categories.ContainsKey(DefaultCategoryKey))
                        {
                            fileTemplate.Categories.Add(DefaultCategoryKey, xmlNode.InnerText);
                        }
                    }
                }
            }
            else
            {
                throw new InvalidOperationException(string.Format("Missing element '_Category' in file template: {0}", templateId));
            }

            if (xmlNodeConfig ["_Description"] != null)
            {
                fileTemplate.Description = xmlNodeConfig ["_Description"].InnerText;
            }

            if (xmlNodeConfig ["Icon"] != null)
            {
                fileTemplate.Icon = ImageService.GetStockId(addin, xmlNodeConfig ["Icon"].InnerText, IconSize.Dnd);
            }

            if (xmlNodeConfig ["Wizard"] != null)
            {
                fileTemplate.Icon = xmlNodeConfig ["Wizard"].Attributes ["path"].InnerText;
            }

            if (xmlNodeConfig ["DefaultFilename"] != null)
            {
                fileTemplate.DefaultFilename = xmlNodeConfig ["DefaultFilename"].InnerText;
                string isFixed = xmlNodeConfig ["DefaultFilename"].GetAttribute("IsFixed");
                if (isFixed.Length > 0)
                {
                    bool bFixed;
                    if (bool.TryParse(isFixed, out bFixed))
                    {
                        fileTemplate.IsFixedFilename = bFixed;
                    }
                    else
                    {
                        throw new InvalidOperationException("Invalid value for IsFixed in template.");
                    }
                }
            }

            //Template files
            XmlNode xmlNodeTemplates = xmlDocument.DocumentElement ["TemplateFiles"];

            if (xmlNodeTemplates != null)
            {
                foreach (XmlNode xmlNode in xmlNodeTemplates.ChildNodes)
                {
                    var xmlElement = xmlNode as XmlElement;
                    if (xmlElement != null)
                    {
                        fileTemplate.Files.Add(
                            FileDescriptionTemplate.CreateTemplate(xmlElement, baseDirectory));
                    }
                }
            }

            //Conditions
            XmlNode xmlNodeConditions = xmlDocument.DocumentElement ["Conditions"];

            if (xmlNodeConditions != null)
            {
                foreach (XmlNode xmlNode in xmlNodeConditions.ChildNodes)
                {
                    var xmlElement = xmlNode as XmlElement;
                    if (xmlElement != null)
                    {
                        fileTemplate.Conditions.Add(FileTemplateCondition.CreateCondition(xmlElement));
                    }
                }
            }

            return(fileTemplate);
        }
Esempio n. 11
0
        private static FileTemplate LoadFileTemplate(RuntimeAddin addin, ProjectTemplateCodon codon)
        {
            XmlDocument xmlDocument   = codon.GetTemplate();
            FilePath    baseDirectory = codon.BaseDirectory;

            //Configuration
            XmlElement xmlNodeConfig = xmlDocument.DocumentElement["TemplateConfiguration"];

            FileTemplate fileTemplate = null;

            if (xmlNodeConfig["Type"] != null)
            {
                Type configType = addin.GetType(xmlNodeConfig["Type"].InnerText);

                if (typeof(FileTemplate).IsAssignableFrom(configType))
                {
                    fileTemplate = (FileTemplate)Activator.CreateInstance(configType);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("The file template class '{0}' must be a subclass of MonoDevelop.Ide.Templates.FileTemplate", xmlNodeConfig["Type"].InnerText));
                }
            }
            else
            {
                fileTemplate = new FileTemplate();
            }

            fileTemplate.originator   = xmlDocument.DocumentElement.GetAttribute("Originator");
            fileTemplate.created      = xmlDocument.DocumentElement.GetAttribute("Created");
            fileTemplate.lastModified = xmlDocument.DocumentElement.GetAttribute("LastModified");

            if (xmlNodeConfig["_Name"] != null)
            {
                fileTemplate.name = xmlNodeConfig["_Name"].InnerText;
            }
            else
            {
                throw new InvalidOperationException(string.Format("Missing element '_Name' in file template: {0}", codon.Id));
            }

            if (xmlNodeConfig["_Category"] != null)
            {
                fileTemplate.category = xmlNodeConfig["_Category"].InnerText;
            }
            else
            {
                throw new InvalidOperationException(string.Format("Missing element '_Category' in file template: {0}", codon.Id));
            }

            if (xmlNodeConfig["LanguageName"] != null)
            {
                fileTemplate.languageName = xmlNodeConfig["LanguageName"].InnerText;
            }

            if (xmlNodeConfig["ProjectType"] != null)
            {
                fileTemplate.projecttype = xmlNodeConfig["ProjectType"].InnerText;
            }

            if (xmlNodeConfig["_Description"] != null)
            {
                fileTemplate.description = xmlNodeConfig["_Description"].InnerText;
            }

            if (xmlNodeConfig["Icon"] != null)
            {
                fileTemplate.icon = ImageService.GetStockId(addin, xmlNodeConfig["Icon"].InnerText, IconSize.Dnd);  //xmlNodeConfig["_Description"].InnerText;
            }

            if (xmlNodeConfig["Wizard"] != null)
            {
                fileTemplate.icon = xmlNodeConfig["Wizard"].Attributes["path"].InnerText;
            }

            if (xmlNodeConfig["DefaultFilename"] != null)
            {
                fileTemplate.defaultFilename = xmlNodeConfig["DefaultFilename"].InnerText;
                string isFixed = xmlNodeConfig["DefaultFilename"].GetAttribute("IsFixed");
                if (isFixed.Length > 0)
                {
                    bool bFixed;
                    if (bool.TryParse(isFixed, out bFixed))
                    {
                        fileTemplate.isFixedFilename = bFixed;
                    }
                    else
                    {
                        throw new InvalidOperationException("Invalid value for IsFixed in template.");
                    }
                }
            }

            //Template files
            XmlNode xmlNodeTemplates = xmlDocument.DocumentElement["TemplateFiles"];

            if (xmlNodeTemplates != null)
            {
                foreach (XmlNode xmlNode in xmlNodeTemplates.ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        fileTemplate.files.Add(
                            FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory));
                    }
                }
            }

            //Conditions
            XmlNode xmlNodeConditions = xmlDocument.DocumentElement["Conditions"];

            if (xmlNodeConditions != null)
            {
                foreach (XmlNode xmlNode in xmlNodeConditions.ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        fileTemplate.conditions.Add(FileTemplateCondition.CreateCondition((XmlElement)xmlNode));
                    }
                }
            }

            return(fileTemplate);
        }
Esempio n. 12
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;
        }
Esempio n. 13
0
		public virtual bool CanCreateUnsavedFiles (FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
		{
			if (project != null) {
				return true;
			} else {
				SingleFileDescriptionTemplate singleFile = newfile as SingleFileDescriptionTemplate;
				if (singleFile == null)
					return false;

				if (directory != null) {
					return true;
				} else {
					string fileName = singleFile.GetFileName (policyParent, project, language, directory, name);
					string mimeType = GuessMimeType (fileName);
					return DisplayBindingService.GetDefaultViewBinding (null, mimeType, null) != null;
				}
			}
		}
Esempio n. 14
0
        public static ProjectDescriptor CreateProjectDescriptor(XmlElement xmlElement, FilePath baseDirectory)
        {
            ProjectDescriptor projectDescriptor = new ProjectDescriptor();

            projectDescriptor.name = xmlElement.GetAttribute("name");

            projectDescriptor.type = xmlElement.GetAttribute("type");
            if (String.IsNullOrEmpty(projectDescriptor.type))
            {
                projectDescriptor.type = "DotNet";
            }

            if (xmlElement["Files"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Files"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        projectDescriptor.files.Add(
                            FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory));
                    }
                }
            }

            if (xmlElement["Resources"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Resources"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var fileTemplate = FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory);
                        if (fileTemplate is SingleFileDescriptionTemplate)
                        {
                            projectDescriptor.resources.Add((SingleFileDescriptionTemplate)fileTemplate);
                        }
                        else
                        {
                            MessageService.ShowError(GettextCatalog.GetString("Only single-file templates allowed to generate resource files"));
                        }
                    }
                }
            }

            if (xmlElement["References"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["References"].ChildNodes)
                {
                    XmlElement       elem             = (XmlElement)xmlNode;
                    var              refType          = elem.GetAttribute("type");
                    ProjectReference projectReference = new ProjectReference((ReferenceType)Enum.Parse(typeof(ReferenceType), refType), elem.GetAttribute("refto"));
                    string           specificVersion  = elem.GetAttribute("SpecificVersion");
                    if (!string.IsNullOrEmpty(specificVersion))
                    {
                        projectReference.SpecificVersion = bool.Parse(specificVersion);
                    }
                    projectDescriptor.references.Add(projectReference);
                }
            }

            projectDescriptor.projectOptions = xmlElement["Options"];
            if (projectDescriptor.projectOptions == null)
            {
                projectDescriptor.projectOptions = xmlElement.OwnerDocument.CreateElement("Options");
            }

            return(projectDescriptor);
        }
Esempio n. 15
0
		protected virtual bool CreateFile (FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null) {
                if (newfile.AddToProject (policyParent, project, language, directory, name)) {
                    newfile.Show ();
                    return true;
                }
			} 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);
                        return true;
                    }
				} else {
                    string fileName = singleFile.GetFileName (policyParent, project, language, directory, name);
                    Stream stream = singleFile.CreateFileContent (policyParent, project, language, fileName, name);

                    // Guess the mime type of the new file
                    string fn = Path.GetTempFileName ();
                    string ext = Path.GetExtension (fileName);
					int n=0;
                    while (File.Exists (fn + n + ext))
                        n++;
                    FileService.MoveFile (fn, fn + n + ext);
					string mimeType = DesktopService.GetMimeTypeForUri (fn + n + ext);
                    FileService.DeleteFile (fn + n + ext);
                    if (mimeType == null || mimeType == "")
                        mimeType = "text";

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