/// <summary> /// Standard Comparer delegate to sort resource relationships into a logical order for display. /// </summary> /// <param name="x">The first item to be compared.</param> /// <param name="y">The second item to be compared.</param> /// <returns>An integer indicating the comparison between x and y.</returns> public static int SortResourceRelationships(Tuple <ResourceRelationship, ResourceItem> x, Tuple <ResourceRelationship, ResourceItem> y) { _ = x ?? throw new ArgumentNullException(nameof(x)); _ = y ?? throw new ArgumentNullException(nameof(y)); if (x.Item1.ResourceRelationshipType == y.Item1.ResourceRelationshipType) { // Equal - sort on type var resourceTypeComparison = string.Compare(ResourceFormatter.GetResourceFriendlyName(x.Item2.Type), ResourceFormatter.GetResourceFriendlyName(y.Item2.Type), true, CultureInfo.CurrentCulture); if (resourceTypeComparison == 0) { // Equal - sort on name return(string.Compare(x.Item2.Name, y.Item2.Name, true, CultureInfo.CurrentCulture)); } else { return(resourceTypeComparison); } } ; if (x.Item1.ResourceRelationshipType < y.Item1.ResourceRelationshipType) { return(-1); } else { return(1); } }
/// <summary> /// This builds a new dropdown in the navbar so you can select resources. /// </summary> private void BuildSourceApplicationResourceSelector(ReportFile <ResourceContainer> source) { // Get a reference to the navbar <ul>. var container = source.ReportHtml.DocumentNode.SelectSingleNode(HtmlResources.NavbarListJQuery); // Create a new <li> within the navbar. var dropdownNode = HtmlNode.CreateNode(string.Format(CultureInfo.CurrentCulture, HtmlResources.SnippetNavbarDropdown, HtmlResources.NavbarResourcesHeading, HtmlResources.NavbarResourcesId)); container.AppendChild(dropdownNode); // Select the dropdown list as the current node. var dropdown = dropdownNode.SelectSingleNode(HtmlResources.NavbarResourcesDropdownJQuery); dropdown.RemoveAllChildren(); // Get a list of the resource types discovered var resourceTypes = from sourceResource in source.ReportData.FindAllResources() select new { sourceResource.Type, FriendlyName = ResourceFormatter.GetResourceFriendlyName(sourceResource.Type) }; foreach (var resourceType in resourceTypes.OrderBy(r => r.FriendlyName).Distinct()) { Logger.LogDebug(TraceMessages.ApplicationMenuBuildingItem, resourceType); var node = HtmlNode.CreateNode(string.Format(CultureInfo.CurrentCulture, HtmlResources.SnippetDropdownMenuItem, string.Concat("#", resourceType.Type), resourceType.FriendlyName)); dropdown.AppendChild(node); } }
/// <summary> /// Builds the source applications. /// </summary> private void BuildSourceApplications() { foreach (var source in _files.SourceApplications) { // Get a reference to the parent element for the menu items. var containerNode = source.ReportHtml.DocumentNode.SelectSingleNode(HtmlResources.ReportContentJQuery); var application = source.ReportData.FindResourcesByType(ModelConstants.ResourceApplication).FirstOrDefault(); Logger.LogDebug(TraceMessages.ApplicationSectionAddingItem, application.Name); var snippet = HtmlResources.SourceApplicationSectionSnippet; snippet = snippet.Replace("{refId}", application.RefId); snippet = snippet.Replace("{name}", application.Name); snippet = snippet.Replace("{description}", application.Description); var node = CreateNodeWithSnippetContent(snippet); containerNode.AppendChild(node); // Recursively build the resources by type at the next level down. var childNode = node.SelectSingleNode(string.Format(CultureInfo.CurrentCulture, HtmlResources.ApplicationSectionChildJQuery, application.RefId)); // Get a list of the resource types discovered var resourceTypes = from sourceResource in source.ReportData.FindAllResources() select new { sourceResource.Type, FriendlyName = ResourceFormatter.GetResourceFriendlyName(sourceResource.Type) }; foreach (var resourceType in resourceTypes.OrderBy(r => r.FriendlyName).Distinct()) { BuildSourceApplicationResources(childNode, source.ReportData.FindResourcesByType(resourceType.Type)); } // Create navigation for the resources. BuildSourceApplicationResourceSelector(source); } }
/// <summary> /// Sorts resources by their name. /// </summary> /// <param name="x">The first item to be compared.</param> /// <param name="y">The second item to be compared.</param> /// <returns>An integer indicating the comparison between x and y.</returns> public static int SortResourceItemsByTypeAndName(ResourceItem x, ResourceItem y) { _ = x ?? throw new ArgumentNullException(nameof(x)); _ = y ?? throw new ArgumentNullException(nameof(y)); if (x.Type == y.Type) { // Equal on type - sort on name return(string.Compare(x.Name, y.Name, true, CultureInfo.CurrentCulture)); } ; return(string.Compare(ResourceFormatter.GetResourceFriendlyName(x.Type), ResourceFormatter.GetResourceFriendlyName(y.Type), true, CultureInfo.CurrentCulture)); }
/// <summary> /// This builds a list of resource entries within the containing node. /// </summary> /// <param name="containerNode">The containing HTML node.</param> /// <param name="resourceItems">The resources.</param> private void BuildSourceApplicationResources(HtmlNode containerNode, IList <ResourceItem> resourceItems) { if (resourceItems.Count == 0) { return; } // Sort by name. var resources = resourceItems.ToList(); resources.Sort(Comparers.SortResourcesByName); // Create a header entry var sectionNode = HtmlNode.CreateNode(HtmlResources.SnippetEmptyDiv); sectionNode.InnerHtml = string.Format(CultureInfo.CurrentCulture, HtmlResources.ApplicationSubsectionHeading, resourceItems.First().Type, ResourceFormatter.GetResourceFriendlyName(resourceItems.First().Type)); containerNode.AppendChild(sectionNode); // Iterate through the resource definitions foreach (var resource in resources) { Logger.LogDebug(TraceMessages.ResourceAddingItem, resource.Name, resource.Type); var snippet = HtmlResources.SourceApplicationResourceSnippet; snippet = snippet.Replace("{icon}", ResourceFormatter.GetResourceIconFromType(resource.Type)); snippet = snippet.Replace("{refId}", resource.RefId); snippet = snippet.Replace("{name}", resource.Name); snippet = snippet.Replace("{description}", string.IsNullOrEmpty(resource.Description) ? HtmlResources.ResourceDefaultDescription : resource.Description); var node = CreateNodeWithSnippetContent(snippet); containerNode.AppendChild(node); // Build the analysis content for this resource. var childNode = node.SelectSingleNode(string.Format(CultureInfo.CurrentCulture, HtmlResources.ApplicationResourceChildJQuery, resource.RefId)); // Create the properties. childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetHeading, HtmlResources.AnalysisHeadingProperties))); foreach (var property in resource.Properties) { childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetProperty, property.Key, property.Value))); } if (resource.Properties.Count == 0) { // Add a placeholder if there are no relationships. childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetInformationMessage, HtmlResources.AnalysisMessageNoProperties))); } // Create the references. childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetHeading, HtmlResources.AnalysisHeadingReferences))); var rels = new List <Tuple <ResourceRelationship, ResourceItem> >(); // contains the resources for sorting. resource.ResourceRelationships.ToList().ForEach(r => rels.Add(new Tuple <ResourceRelationship, ResourceItem>(r, Model.FindResourceByRefId(r.ResourceRefId)))); // Adds the relationship plus the associated resource rels.Sort(Comparers.SortResourceRelationships); // Sort using a comparison delegate foreach (var reference in rels) { var parentApp = _files.SourceApplications.Where(s => s.ReportData.FindAllResources().Contains(reference.Item2)).FirstOrDefault(); var filename = parentApp == null ? string.Empty : parentApp.Filename; childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetLink, filename, reference.Item1.ResourceRefId, ResourceFormatter.GetResourceFriendlyName(reference.Item2.Type), reference.Item1.ResourceRelationshipType, reference.Item2.Name))); } if (resource.ResourceRelationships.Count == 0) { // Add a placeholder if there are no relationships. childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetInformationMessage, HtmlResources.AnalysisMessageNoReferenceLinks))); } // Create the analysis messages: childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetHeading, HtmlResources.AnalysisHeadingMessages))); foreach (var message in resource.ReportMessages) { if (message.Severity == MessageSeverity.Error) { childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetErrorMessage, message.Message))); } else if (message.Severity == MessageSeverity.Warning) { childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetWarningMessage, message.Message))); } else { childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetInformationMessage, message.Message))); } } if (resource.ReportMessages.Count == 0) { // Add a placeholder if there are no relationships. childNode.AppendChild(CreateNodeWithSnippetContent(string.Format(CultureInfo.CurrentCulture, HtmlResources.AnalysisSnippetInformationMessage, HtmlResources.AnalysisMessageNoMessages))); } } }