public void RegisterProperty(RuntimeAddin addin, string targetType, string name, string propertyType, bool isExternal, bool skipEmpty) { TypeRef tr; if (!pendingTypesByTypeName.TryGetValue(targetType, out tr)) { tr = new TypeRef(addin, targetType); pendingTypesByTypeName [targetType] = tr; } if (tr.DataType != null) { RegisterProperty(addin.GetType(targetType, true), name, addin.GetType(propertyType, true), isExternal, skipEmpty); return; } PropertyRef prop = new PropertyRef(addin, targetType, name, propertyType, isExternal, skipEmpty); if (tr.Properties == null) { tr.Properties = prop; } else { PropertyRef plink = tr.Properties; while (plink.Next != null) { plink = plink.Next; } plink.Next = prop; } }
public void UnregisterProperty(RuntimeAddin addin, string targetType, string name) { TypeRef tr; if (!pendingTypesByTypeName.TryGetValue(targetType, out tr)) { return; } if (tr.DataType != null) { Type t = addin.GetType(targetType, false); if (t != null) { UnregisterProperty(t, name); } return; } PropertyRef prop = tr.Properties; PropertyRef prev = null; while (prop != null) { if (prop.Name == name) { if (prev != null) { prev.Next = prop.Next; } else { tr.Properties = null; } break; } prev = prop; prop = prop.Next; } }
public SolutionEntityItem CreateItem(ProjectCreateInformation projectCreateInformation, string defaultLanguage) { Type type = addin.GetType(typeName, false); if (type == null) { MessageService.ShowError(GettextCatalog.GetString("Can't create project with type : {0}", typeName)); return(null); } SolutionEntityItem item = (SolutionEntityItem)Activator.CreateInstance(type); item.InitializeFromTemplate(template); string newProjectName = StringParserService.Parse(name, new string[, ] { { "ProjectName", projectCreateInformation.ProjectName } }); item.Name = newProjectName; item.FileName = Path.Combine(projectCreateInformation.ProjectBasePath, newProjectName); return(item); }
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); }
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); }
public WorkspaceItemCreatedInformation CreateEntry(ProjectCreateInformation projectCreateInformation, string defaultLanguage) { WorkspaceItem workspaceItem = null; if (string.IsNullOrEmpty(type)) { workspaceItem = new Solution(); } else { Type workspaceItemType = addin.GetType(type, false); if (workspaceItemType != null) { workspaceItem = Activator.CreateInstance(workspaceItemType) as WorkspaceItem; } if (workspaceItem == null) { MessageService.ShowError(GettextCatalog.GetString("Can't create solution with type: {0}", type)); return(null); } } var substitution = new string[, ] { { "ProjectName", projectCreateInformation.SolutionName } }; workspaceItem.Name = StringParserService.Parse(name, substitution); string newStartupProjectName = startupProject; if (newStartupProjectName != null) { newStartupProjectName = StringParserService.Parse(startupProject, substitution); } workspaceItem.SetLocation(projectCreateInformation.SolutionPath, workspaceItem.Name); ProjectCreateInformation localProjectCI; if (!string.IsNullOrEmpty(directory) && directory != ".") { localProjectCI = new ProjectCreateInformation(projectCreateInformation); localProjectCI.SolutionPath = Path.Combine(localProjectCI.SolutionPath, directory); localProjectCI.ProjectBasePath = Path.Combine(localProjectCI.ProjectBasePath, directory); if (!Directory.Exists(localProjectCI.SolutionPath)) { Directory.CreateDirectory(localProjectCI.SolutionPath); } if (!Directory.Exists(localProjectCI.ProjectBasePath)) { Directory.CreateDirectory(localProjectCI.ProjectBasePath); } } else { localProjectCI = projectCreateInformation; } var workspaceItemCreatedInfo = new WorkspaceItemCreatedInformation(workspaceItem); Solution solution = workspaceItem as Solution; if (solution != null) { for (int i = 0; i < entryDescriptors.Count; i++) { ProjectCreateInformation entryProjectCI; var entry = entryDescriptors[i] as ICustomProjectCIEntry; if (entry != null) { entryProjectCI = entry.CreateProjectCI(localProjectCI); } else { entryProjectCI = localProjectCI; } var solutionItemDesc = entryDescriptors[i]; SolutionEntityItem info = solutionItemDesc.CreateItem(entryProjectCI, defaultLanguage); if (info == null) { continue; } solutionItemDesc.InitializeItem(solution.RootFolder, entryProjectCI, defaultLanguage, info); IConfigurationTarget configurationTarget = info as IConfigurationTarget; if (configurationTarget != null) { foreach (ItemConfiguration configuration in configurationTarget.Configurations) { bool flag = false; foreach (SolutionConfiguration solutionCollection in solution.Configurations) { if (solutionCollection.Id == configuration.Id) { flag = true; } } if (!flag) { solution.AddConfiguration(configuration.Id, true); } } } if ((info is Project) && (solutionItemDesc is ProjectDescriptor)) { workspaceItemCreatedInfo.AddPackageReferenceForCreatedProject((Project)info, (ProjectDescriptor)solutionItemDesc); } solution.RootFolder.Items.Add(info); if (newStartupProjectName == info.Name) { solution.StartupItem = info; } } } if (!workspaceItem.FileFormat.CanWrite(workspaceItem)) { // The default format can't write solutions of this type. Find a compatible format. FileFormat f = IdeApp.Services.ProjectService.FileFormats.GetFileFormatsForObject(workspaceItem).First(); workspaceItem.ConvertToFormat(f, true); } return(workspaceItemCreatedInfo); }
public void AddMap(RuntimeAddin addin, string xmlMap, string fileId) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlMap); foreach (XmlElement elem in doc.DocumentElement.SelectNodes("DataItem")) { string tname = elem.GetAttribute("class"); Type type = addin.GetType(tname); if (type == null) { LoggingService.LogError("[SerializationMap " + fileId + "] Type not found: '" + tname + "'"); continue; } string cname = elem.GetAttribute("name"); string ftname = elem.GetAttribute("fallbackType"); SerializationMap map; if (!maps.TryGetValue(type, out map)) { map = new SerializationMap(type); maps [type] = map; map.FileId = fileId; if (cname.Length > 0 || ftname.Length > 0) { DataItemAttribute iat = new DataItemAttribute(); if (cname.Length > 0) { iat.Name = cname; } if (ftname.Length > 0) { iat.FallbackType = addin.GetType(ftname, true); } map.TypeAttributes.Add(iat); } } else { if (!string.IsNullOrEmpty(cname)) { throw new InvalidOperationException(string.Format("Type name for type '{0}' in map '{1}' already specified in another serialization map for the same type ({2}).", type, fileId, map.FileId)); } if (!string.IsNullOrEmpty(ftname)) { throw new InvalidOperationException(string.Format("Fallback type for type '{0}' in map '{1}' already specified in another serialization map for the same type ({2}).", type, fileId, map.FileId)); } } string customDataItem = elem.GetAttribute("customDataItem"); if (customDataItem.Length > 0) { ICustomDataItemHandler ch = (ICustomDataItemHandler)addin.CreateInstance(customDataItem, true); if (map.CustomHandler != null) { map.CustomHandler = new CustomDataItemHandlerChain(map.CustomHandler, ch); } else { map.CustomHandler = ch; } } ItemMember lastMember = null; int litc = 0; foreach (XmlElement att in elem.SelectNodes("ItemProperty|ExpandedCollection|LiteralProperty|ItemMember")) { string memberName = null; ItemMember prevMember = lastMember; lastMember = null; if (att.Name == "LiteralProperty") { ItemMember mem = new ItemMember(); memberName = mem.Name = "_literal_" + (++litc); mem.Type = typeof(string); mem.InitValue = att.GetAttribute("value"); mem.DeclaringType = map.Type; map.ExtendedMembers.Add(mem); ItemPropertyAttribute itemAtt = new ItemPropertyAttribute(); itemAtt.Name = att.GetAttribute("name"); map.AddMemberAttribute(mem, itemAtt); lastMember = mem; continue; } else if (att.Name == "ItemMember") { ItemMember mem = new ItemMember(); memberName = mem.Name = att.GetAttribute("name"); mem.Type = addin.GetType(att.GetAttribute("type"), true); mem.DeclaringType = map.Type; map.ExtendedMembers.Add(mem); lastMember = mem; continue; } else { memberName = att.GetAttribute("member"); Type mt; object mi; if (!FindMember(map, memberName, out mi, out mt)) { LoggingService.LogError("[SerializationMap " + fileId + "] Member '" + memberName + "' not found in type '" + tname + "'"); continue; } if (att.Name == "ItemProperty") { ItemPropertyAttribute itemAtt = new ItemPropertyAttribute(); string val = att.GetAttribute("name"); if (val.Length > 0) { itemAtt.Name = val; } val = att.GetAttribute("scope"); if (val.Length > 0) { itemAtt.Scope = val; } if (att.Attributes ["defaultValue"] != null) { if (mt.IsEnum) { itemAtt.DefaultValue = Enum.Parse(mt, att.GetAttribute("defaultValue")); } else { itemAtt.DefaultValue = Convert.ChangeType(att.GetAttribute("defaultValue"), mt); } } val = att.GetAttribute("serializationDataType"); if (val.Length > 0) { itemAtt.SerializationDataType = addin.GetType(val, true); } val = att.GetAttribute("valueType"); if (val.Length > 0) { itemAtt.ValueType = addin.GetType(val, true); } val = att.GetAttribute("readOnly"); if (val.Length > 0) { itemAtt.ReadOnly = bool.Parse(val); } val = att.GetAttribute("writeOnly"); if (val.Length > 0) { itemAtt.WriteOnly = bool.Parse(val); } val = att.GetAttribute("fallbackType"); if (val.Length > 0) { itemAtt.FallbackType = addin.GetType(val, true); } val = att.GetAttribute("isExternal"); if (val.Length > 0) { itemAtt.IsExternal = bool.Parse(val); } val = att.GetAttribute("skipEmpty"); if (val.Length > 0) { itemAtt.SkipEmpty = bool.Parse(val); } map.AddMemberAttribute(mi, itemAtt); } else if (att.Name == "ExpandedCollection") { ExpandedCollectionAttribute eat = new ExpandedCollectionAttribute(); map.AddMemberAttribute(mi, eat); } } if (prevMember != null) { prevMember.InsertBefore = memberName; } } } }
public WorkspaceItem CreateEntry(ProjectCreateInformation projectCreateInformation, string defaultLanguage) { WorkspaceItem workspaceItem = null; if (string.IsNullOrEmpty(type)) { workspaceItem = new Solution(); } else { Type workspaceItemType = addin.GetType(type, false); if (workspaceItemType != null) { workspaceItem = Activator.CreateInstance(workspaceItemType) as WorkspaceItem; } if (workspaceItem == null) { MessageService.ShowError(GettextCatalog.GetString("Can't create solution with type: {0}", type)); return(null); } } workspaceItem.Name = StringParserService.Parse(name, new string[, ] { { "ProjectName", projectCreateInformation.SolutionName } }); workspaceItem.SetLocation(projectCreateInformation.SolutionPath, workspaceItem.Name); ProjectCreateInformation localProjectCI; if (!string.IsNullOrEmpty(directory) && directory != ".") { localProjectCI = new ProjectCreateInformation(projectCreateInformation); localProjectCI.SolutionPath = Path.Combine(localProjectCI.SolutionPath, directory); localProjectCI.ProjectBasePath = Path.Combine(localProjectCI.ProjectBasePath, directory); if (!Directory.Exists(localProjectCI.SolutionPath)) { Directory.CreateDirectory(localProjectCI.SolutionPath); } if (!Directory.Exists(localProjectCI.ProjectBasePath)) { Directory.CreateDirectory(localProjectCI.ProjectBasePath); } } else { localProjectCI = projectCreateInformation; } Solution solution = workspaceItem as Solution; if (solution != null) { for (int i = 0; i < entryDescriptors.Count; i++) { ISolutionItemDescriptor solutionItem = entryDescriptors[i]; SolutionEntityItem info = solutionItem.CreateItem(localProjectCI, defaultLanguage); entryDescriptors[i].InitializeItem(solution.RootFolder, localProjectCI, defaultLanguage, info); IConfigurationTarget configurationTarget = info as IConfigurationTarget; if (configurationTarget != null) { foreach (ItemConfiguration configuration in configurationTarget.Configurations) { bool flag = false; foreach (SolutionConfiguration solutionCollection in solution.Configurations) { if (solutionCollection.Id == configuration.Id) { flag = true; } } if (!flag) { solution.AddConfiguration(configuration.Id, true); } } } solution.RootFolder.Items.Add(info); if (startupProject == info.Name) { solution.StartupItem = info; } } } return(workspaceItem); }