/// <summary> /// Recursively searches the specified directory tree for XML files which define UPF views and retrieves the XML elements which define those views. /// </summary> /// <param name="root">The root directory from which the recursive search began.</param> /// <param name="directory">The root of the directory tree to search.</param> /// <returns>A collection of <see cref="DataSourceDefinition"/> instances which represent UPF view definitions.</returns> private static IEnumerable <DataSourceDefinition> RecursivelySearchForViews(String root, String directory) { var result = new List <DataSourceDefinition>(); var files = Directory.GetFiles(directory, "*.xml"); foreach (var file in files) { try { var name = $"__Wrapper_{Path.GetFileNameWithoutExtension(file)}_{Guid.NewGuid():N}"; var definition = CreateDataSourceDefinitionFromFile(null, name, file); if (definition != null) { UvmlLoader.AddUvmlAnnotations( definition.Value.DataSourceWrapperName, definition.Value.Definition); result.Add(definition.Value); } } catch (XmlException) { continue; } } var subdirs = Directory.GetDirectories(directory); foreach (var subdir in subdirs) { result.AddRange(RecursivelySearchForViews(root, subdir)); } return(result); }
/// <summary> /// Loads the control's component root from the control's associated template. /// </summary> private void LoadComponentRoot() { if (componentRoot != null) { throw new InvalidOperationException(PresentationStrings.ComponentRootAlreadyLoaded); } this.ComponentRoot = UvmlLoader.LoadComponentTemplate(this); }
/// <summary> /// Gets a collection of <see cref="DataSourceDefinition"/> instances for any component templates which /// are currently registered with the Ultraviolet Presentation Foundation. /// </summary> /// <returns>A collection of <see cref="DataSourceDefinition"/> instances which represent UPF component template definitions.</returns> private static IEnumerable<DataSourceDefinition> RetrieveTemplateDefinitions(IExpressionCompilerState state) { if (state.ComponentTemplateManager == null) return Enumerable.Empty<DataSourceDefinition>(); var templateDefs = from template in state.ComponentTemplateManager select DataSourceDefinition.FromComponentTemplate(template.Key, template.Value.Root.Element("View")); var templateDefsList = templateDefs.ToList(); foreach (var templateDef in templateDefsList) UvmlLoader.AddUvmlAnnotations(templateDef.DataSourceWrapperName, templateDef.Definition); return templateDefsList; }
/// <summary> /// Loads the control's component root from the control's associated template. /// </summary> private void LoadComponentRoot() { if (componentRoot != null) { throw new InvalidOperationException(PresentationStrings.ComponentRootAlreadyLoaded); } var template = Ultraviolet.GetUI().GetPresentationFoundation().ComponentTemplates.Get(this); if (template == null) { return; } this.ComponentRoot = UvmlLoader.LoadComponentTemplate(this, template); }