public static void Main(string[] args) { Console.WriteLine("Create an example Coresight display"); Console.WriteLine("Paste in your PI WebAPI URL:"); Uri webApiBaseUri = new Uri(Console.ReadLine().TrimEnd('/') + "/"); Console.WriteLine("Paste in your Coresight URL:"); string coresightUri = Console.ReadLine(); Console.WriteLine("Paste in the path to an AF Element whose template will form the default display"); string elementPath = Console.ReadLine(); Console.WriteLine("Optionally, provide a semicolon-delimited list of attribute categories to be included. By default, all are included."); string attributeCategoryList = Console.ReadLine(); List <string> includedCategories = attributeCategoryList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); PIWebAPIClient piWebApiClient = new PIWebAPIClient(webApiBaseUri); AFElementDTO elementDTO = piWebApiClient.GetElementDTOByPathAsync(elementPath).GetAwaiter().GetResult(); AFElementTemplateSlim elementTemplate = piWebApiClient.GetElementTemplateSlimAsync(elementDTO).GetAwaiter().GetResult(); CoresightDefaultDisplayFactory displayFactory = new CoresightDefaultDisplayFactory(coresightUri); DisplayRevision defaultDisplay = displayFactory.CreateDefaultDisplayAsync(elementTemplate, elementPath, includedCategories).GetAwaiter().GetResult(); Uri displayUri = defaultDisplay.GetUri(displayFactory.CoresightBaseUri); Console.WriteLine("New display created at {0}", displayUri); Console.ReadKey(); Console.ReadKey(); }
private async Task <List <AFAttributeDTO> > GetTopLevelAttributeDTOsAsync(AFElementDTO elementDTO) { List <AFAttributeTemplateDTO> allTopLevelAttributes = new List <AFAttributeTemplateDTO>(); string requestUri = string.Format("elements/{0}/attributes?showExcluded=true", elementDTO.WebId); return(await GetObjectAsync <ItemCollectionDTO <AFAttributeDTO> >(requestUri)); }
public Task <AFElementTemplateSlim> GetElementTemplateSlimAsync(AFElementDTO forElement, string alternateTemplateName = null) { string templateName = string.IsNullOrWhiteSpace(alternateTemplateName) ? forElement.TemplateName : alternateTemplateName; string[] pathTokens = forElement.Path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); string serverName = pathTokens[0]; string databaseName = pathTokens[1]; string templatePath = string.Format("\\\\{0}\\{1}\\ElementTemplates[{2}]", serverName, databaseName, templateName); return(GetElementTemplateSlimAsync(templatePath, forElement)); }
private async Task <List <AFAttributeDTO> > GetAllAttributeDTOsAsync(AFElementDTO elementDTO) { List <AFAttributeDTO> topLevelAttributes = await GetTopLevelAttributeDTOsAsync(elementDTO).ConfigureAwait(false); List <Task <List <AFAttributeDTO> > > attributeQueryTasks = new List <Task <List <AFAttributeDTO> > >(); foreach (AFAttributeDTO topLevelAttribute in topLevelAttributes) { Task <List <AFAttributeDTO> > attributeQueryTask = GetAllAttributeDTOsAsync(topLevelAttribute); attributeQueryTasks.Add(attributeQueryTask); } IEnumerable <List <AFAttributeDTO> > attributeQueryTaskResults = await Task.WhenAll <List <AFAttributeDTO> >(attributeQueryTasks).ConfigureAwait(false); return(attributeQueryTaskResults.SelectMany(aq => aq).ToList()); }
public async Task <AFElementTemplateSlim> GetElementTemplateSlimAsync(string templateAbsolutePath, AFElementDTO elementDTO) { AFElementTemplateDTO elementTemplateDTO = await GetElementTemplateDTOAsync(templateAbsolutePath); return(await GetElementTemplateSlimAsync(elementTemplateDTO, elementDTO).ConfigureAwait(false)); }
public async Task <AFElementTemplateSlim> GetElementTemplateSlimAsync(AFElementTemplateDTO elementTemplateDTO, AFElementDTO elementDTO) { List <AFAttributeTemplateDTO> attributeTemplates = await GetAllAttributeTemplateDTOsAsync(elementTemplateDTO); List <AFAttributeDTO> attributeInstances = await GetAllAttributeDTOsAsync(elementDTO); return(elementTemplateDTO.ToSlim(attributeTemplates, attributeInstances)); }