/// <summary> /// Slims an AF SDK AFAttributeTemplate /// </summary> /// <param name="fat">The template to be slimmed</param> /// <param name="instance">Optional element instance to provide data reference information if not set on the template</param> /// <returns></returns> public static AFAttributeTemplateSlim ToSlim(this AFAttributeTemplate fat, AFAttribute instance = null) { AFAttributeTemplateSlim slim = new AFAttributeTemplateSlim() { Id = fat.ID, FullName = fat.GetPath(fat.ElementTemplate), Name = fat.Name, Description = fat.Description, IsTopLevel = fat.Parent == null, TypeName = fat.Type.Name, TypeQualifier = fat.TypeQualifier is IAFNamedObject ? ((IAFNamedObject)fat.TypeQualifier).Name : null, IsHidden = fat.IsHidden, //requires AF Client 2.7 or higher IsStatic = fat.DataReferencePlugIn == null && instance?.DataReferencePlugIn == null, HasChildren = fat.AttributeTemplates != null && fat.AttributeTemplates.Count > 0, CategoryNames = fat.Categories.Select(c => c.Name).ToList() }; return(slim); }
/// <summary> /// Slims an AF SDK AFAttributeTemplate /// </summary> /// <param name="attributeTemplate">The template to be slimmed</param> /// <param name="attributeInstance">Optional attribute instance to provide data reference information if not set on the template</param> /// <returns></returns> public static AFAttributeTemplateSlim ToSlim(this AFAttributeTemplateDTO attributeTemplate, AFAttributeDTO attributeInstance = null) { string pathRelativeToElement = attributeTemplate.GetPathRelativeToElement(); AFAttributeTemplateSlim slim = new AFAttributeTemplateSlim() { Id = attributeTemplate.Id, FullName = pathRelativeToElement, Name = attributeTemplate.Name, Description = attributeTemplate.Description, IsTopLevel = !pathRelativeToElement.Contains('|'), TypeName = attributeTemplate.Type, TypeQualifier = attributeTemplate.TypeQualifier, IsHidden = attributeTemplate.IsHidden, IsStatic = string.IsNullOrWhiteSpace(attributeTemplate.DataReferencePlugIn) && string.IsNullOrWhiteSpace(attributeInstance.DataReferencePlugIn), HasChildren = attributeTemplate.HasChildren, CategoryNames = attributeTemplate.CategoryNames }; return(slim); }
/// <summary> /// Creates a default display for a given Element Template and Element instance. /// </summary> /// <param name="elementTemplate">The element template on which the display will be based</param> /// <param name="initialContextElementPath">The element which will be the display's initial context</param> /// <param name="includedCategories">Optional list of categories to include. By default, all categories are included, as is the set of attributes not in a category. If specifying categories, the name @None will explicitly include uncategorized attributes.</param> /// <returns>A reference to the created display</returns> public Task <DisplayRevision> CreateDefaultDisplayAsync(AFElementTemplateSlim elementTemplate, string initialContextElementPath, ICollection <string> includedCategories = null) { //If the path is not escaped, do so here. TODO does this need to be URL encoded? if (!initialContextElementPath.Contains(@"\\\\")) { initialContextElementPath = initialContextElementPath.Replace(@"\", @"\\"); } string name = string.Format("{0} default display", elementTemplate.Name); //TODO check collisions CoresightDisplayBuilder displayBuilder = new CoresightDisplayBuilder(CoresightBaseUri, name); IEnumerable <AFAttributeTemplateSlim> includedAttributes = elementTemplate.AllAttributes.Where(a => !a.IsHidden && ValueTypeHelper.TypeIsSupported(a.TypeName)); Dictionary <string, IEnumerable <AFAttributeTemplateSlim> > attributesByCategory = AFAttributeTemplateSlim.GroupByCategory(includedAttributes, includedCategories); //If an explicit collection of included categories is specified, preserve its order bool explicitCategoriesSpecified = includedCategories != null && includedCategories.Count > 0; var attributesByCategoryOrdered = !explicitCategoriesSpecified? attributesByCategory.AsEnumerable() : includedCategories.Select(c => new KeyValuePair <string, IEnumerable <AFAttributeTemplateSlim> >(c, attributesByCategory[c])); foreach (var category in attributesByCategoryOrdered) { string titleText = AFAttributeTemplateSlim.NullCategory.Equals(category.Key, StringComparison.OrdinalIgnoreCase) ? "Uncategorized" : category.Key; titleText = attributesByCategory.Count < 2 ? null : titleText; AddAttributeGroup(displayBuilder, category.Value, initialContextElementPath, titleText); } return(displayBuilder.SaveAsync()); }
private static string GetAttributeInstancePath(string elementPath, AFAttributeTemplateSlim attributeTemplate, bool includeProtocol = true) { string protocol = includeProtocol ? "af:" : string.Empty; return(string.Concat(protocol, elementPath, "|", attributeTemplate.FullName)); }