public static List <DataTemplateViewModel> GetDomainClassPropertyGridViewModelTemplates(BaseAttributeElementViewModel vm) { MetaModel metaModel = vm.Element.GetMetaModel(); DomainClass element = vm.Element as DomainClass; if (element == null) { return(null); } string examples = ""; bool bReferenceFound = false; foreach (DomainRole role in element.RolesPlayed) { if (role.Relationship is ReferenceRelationship && !bReferenceFound) { if (role.IsPropertyGenerator) { bReferenceFound = true; examples += " // EXAMLE: Custom values provider for role editor: " + "\r\n"; examples += " // HINT: Don't forget to set 'Generates Double Derived' to 'True' for " + element.Name + "\r\n"; examples += " protected override void CreateEditorViewModelFor" + role.PropertyName + "Role(System.Collections.Generic.List<PropertyGridEditorViewModel> collection)" + "\r\n"; examples += " {" + "\r\n"; examples += " /*" + "\r\n"; examples += " Copy and paste from the original method " + "\r\n"; examples += " */" + "\r\n\r\n"; examples += " // Change:" + "\r\n"; examples += " editor.DefaultValuesProvider = new LookupListEditorDefaultValuesProvider<object>(GetDefaultElements);" + "\r\n"; examples += " // End of original method:" + "\r\n"; examples += " collection.Add(editor);" + "\r\n" + "\r\n"; examples += " }" + "\r\n"; examples += " // This method returns the default values for a role view model" + "\r\n"; examples += " private List<object> GetDefaultElements(LookupListEditorViewModel viewModel)" + "\r\n"; examples += " {" + "\r\n"; examples += " " + element.Name + " element = this.Element as " + element.Name + ";\r\n"; examples += " // TODO" + "\r\n"; examples += " }" + "\r\n"; } } if (bReferenceFound) { break; } } List <DataTemplateViewModel> retVms = ParseFile(vm.ViewModelStore, "DomainClassPropertyGridTemplate.xml", new string[] { vm.Element.Name, // CustomString0 metaModel.Namespace, // CustomString1 examples, // CustomString2 }); DataTemplateViewModel specificVM = new DataTemplateViewModel(vm.ViewModelStore, "Specific ViewModel Properties", GetSpecificViewModelString(element, false)); retVms.Add(specificVM); specificVM.Description = "Properties and Roles generated for Specific ViewModels..."; return(retVms); }
private static List <DataTemplateViewModel> ParseFile(ViewModelStore store, string embeddedFileName, params string[] customStrings) { List <DataTemplateViewModel> viewModels = new List <DataTemplateViewModel>(); XmlDocument doc = GetFile(embeddedFileName); XmlNodeList list = doc.DocumentElement.GetElementsByTagName("DataTemplate"); foreach (XmlNode node in list) { string displayName = null; string description = null; string imageURI = null; string syntaxHighlighting = "C#"; string template = null; for (int i = 0; i < node.ChildNodes.Count; i++) { switch (node.ChildNodes[i].Name) { case "DisplayName": if (node.ChildNodes[i].HasChildNodes) { displayName = node.ChildNodes[i].ChildNodes[0].Value; } else { displayName = node.ChildNodes[i].Value; } break; case "Description": if (node.ChildNodes[i].HasChildNodes) { description = node.ChildNodes[i].ChildNodes[0].Value; } else { description = node.ChildNodes[i].Value; } break; case "ImageURI": if (node.ChildNodes[i].HasChildNodes) { imageURI = node.ChildNodes[i].ChildNodes[0].Value; } else { imageURI = node.ChildNodes[i].Value; } break; case "SyntaxHighlighting": if (node.ChildNodes[i].HasChildNodes) { syntaxHighlighting = node.ChildNodes[i].ChildNodes[0].Value; } else { syntaxHighlighting = node.ChildNodes[i].Value; } break; case "Template": if (node.ChildNodes[i].HasChildNodes) { if (node.ChildNodes[i].ChildNodes[0] is XmlCDataSection) { template = (node.ChildNodes[i].ChildNodes[0] as XmlCDataSection).Value; break; } } template = node.ChildNodes[i].Value; break; } } if (displayName != null && template != null) { // parse template template = ReplaceFields(template.Trim(), customStrings); // create vm DataTemplateViewModel vm = new DataTemplateViewModel(store, displayName, template); if (description != null) { vm.Description = description; } if (imageURI != null) { vm.ImageUri = imageURI; } if (syntaxHighlighting != null) { vm.SyntaxHighlighting = syntaxHighlighting; } viewModels.Add(vm); } } return(viewModels); }