631 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			631 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Adaptation.FileHandlers.json.WorkItems;
 | |
| using Adaptation.Shared;
 | |
| using Adaptation.Shared.Duplicator;
 | |
| using Adaptation.Shared.Methods;
 | |
| using log4net;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Collections.ObjectModel;
 | |
| using System.IO;
 | |
| using System.Linq;
 | |
| using System.Text.Json;
 | |
| using System.Text.Json.Serialization;
 | |
| 
 | |
| namespace Adaptation.FileHandlers.Violation;
 | |
| 
 | |
| #nullable enable
 | |
| 
 | |
| public class ProcessData : IProcessData
 | |
| {
 | |
| 
 | |
|     private readonly List<object> _Details;
 | |
| 
 | |
|     List<object> Shared.Properties.IProcessData.Details => _Details;
 | |
| 
 | |
|     private readonly ILog _Log;
 | |
| 
 | |
|     string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) =>
 | |
|         throw new Exception(string.Concat("See ", nameof(WriteFiles)));
 | |
| 
 | |
|     Tuple<string, Test[], JsonElement[], List<FileInfo>> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection) =>
 | |
|         new(logistics.Logistics1[0], Array.Empty<Test>(), Array.Empty<JsonElement>(), fileInfoCollection);
 | |
| 
 | |
|     private static int GetState(WorkItem workItem) =>
 | |
|         workItem.State switch
 | |
|         {
 | |
|             "New" => 1,
 | |
|             "Active" => 2,
 | |
|             "Resolved" => 3,
 | |
|             "Closed" => 4,
 | |
|             "Removed" => 5,
 | |
|             _ => 8
 | |
|         };
 | |
| 
 | |
|     public ProcessData(IFileRead fileRead, Logistics logistics, string targetFileLocation, string url, ReadOnlyCollection<string> workItemTypes, List<FileInfo> fileInfoCollection)
 | |
|     {
 | |
|         if (fileRead.IsEAFHosted)
 | |
|         { }
 | |
|         _Details = new List<object>();
 | |
|         _Log = LogManager.GetLogger(typeof(ProcessData));
 | |
|         WriteFiles(fileRead, logistics, targetFileLocation, url, fileInfoCollection, workItemTypes);
 | |
|     }
 | |
| 
 | |
|     private void WriteFiles(IFileRead fileRead, Logistics logistics, string destinationDirectory, string url, List<FileInfo> fileInfoCollection, ReadOnlyCollection<string> __)
 | |
|     {
 | |
|         if (!Directory.Exists(destinationDirectory))
 | |
|             _ = Directory.CreateDirectory(destinationDirectory);
 | |
|         string json = File.ReadAllText(logistics.ReportFullPath);
 | |
|         // WorkItem[]? workItems = JsonSerializer.Deserialize<WorkItem[]>(json);
 | |
|         // if (workItems is null)
 | |
|         //     throw new Exception(nameof(workItems));
 | |
|         JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
 | |
|         if (jsonElements is null)
 | |
|             throw new Exception(nameof(jsonElements));
 | |
|         WorkItem? workItem;
 | |
|         List<WorkItem> workItems = new();
 | |
|         foreach (JsonElement jsonElement in jsonElements)
 | |
|         {
 | |
|             workItem = JsonSerializer.Deserialize<WorkItem>(jsonElement.ToString());
 | |
|             if (workItem is null)
 | |
|                 continue;
 | |
|             workItems.Add(workItem);
 | |
|         }
 | |
|         List<char> spaces = new();
 | |
|         bool keepRelations = false;
 | |
|         List<string> lines = new();
 | |
|         List<string> messages = new();
 | |
|         ReadOnlyCollection<Record> results;
 | |
|         ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(workItems, keepRelations);
 | |
|         ReadOnlyCollection<Record> records = new(keyValuePairs.Values.ToArray());
 | |
|         ReadOnlyCollection<string> bugUserStoryWorkItemTypes = new(new string[] { "Bug", "User Story" });
 | |
|         ReadOnlyCollection<string> bugUserStoryTaskWorkItemTypes = new(new string[] { "Bug", "User Story", "Task" });
 | |
|         {
 | |
|             lines.Clear();
 | |
|             string workItemType = "Feature";
 | |
|             lines.Add($"# {nameof(FeatureCheckIterationPath122508)}");
 | |
|             lines.Add(string.Empty);
 | |
|             results = FeatureCheckIterationPath122508(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType);
 | |
|             WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), workItemType, results, "check-122508");
 | |
|             _Details.Add(results);
 | |
|         }
 | |
|         {
 | |
|             lines.Clear();
 | |
|             string workItemType = "Feature";
 | |
|             lines.Add($"# {nameof(FeatureCheckTag122514)}");
 | |
|             lines.Add(string.Empty);
 | |
|             results = FeatureCheckTag122514(url, lines, bugUserStoryWorkItemTypes, keyValuePairs, workItemType);
 | |
|             WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), workItemType, results, "check-122514");
 | |
|             _Details.Add(results);
 | |
|         }
 | |
|         {
 | |
|             lines.Clear();
 | |
|             string workItemType = "Feature";
 | |
|             lines.Add($"# {nameof(FeatureCheckPriority126169)}");
 | |
|             lines.Add(string.Empty);
 | |
|             results = FeatureCheckPriority126169(url, lines, bugUserStoryWorkItemTypes, keyValuePairs, workItemType);
 | |
|             WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), workItemType, results, "check-126169");
 | |
|             _Details.Add(results);
 | |
|         }
 | |
|         {
 | |
|             lines.Clear();
 | |
|             string workItemType = "Feature";
 | |
|             lines.Add($"# {nameof(FeatureCheckState123066)}");
 | |
|             lines.Add(string.Empty);
 | |
|             results = FeatureCheckState123066(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType);
 | |
|             WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), workItemType, results, "check-123066");
 | |
|             _Details.Add(results);
 | |
|         }
 | |
|         {
 | |
|             lines.Clear();
 | |
|             string workItemType = "Feature";
 | |
|             lines.Add($"# {nameof(FeatureCheckState123067)}");
 | |
|             lines.Add(string.Empty);
 | |
|             results = FeatureCheckState123067(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType);
 | |
|             WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), workItemType, results, "check-123067");
 | |
|             _Details.Add(results);
 | |
|         }
 | |
|         {
 | |
|             lines.Clear();
 | |
|             string workItemType = "Feature";
 | |
|             lines.Add($"# {nameof(FeatureCheckStart122517)}");
 | |
|             lines.Add(string.Empty);
 | |
|             results = FeatureCheckStart122517(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType);
 | |
|             WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), workItemType, results, "check-122517");
 | |
|             _Details.Add(results);
 | |
|         }
 | |
|         if (messages.Count > 0)
 | |
|             throw new Exception($"{messages.Count}{Environment.NewLine}{string.Join(Environment.NewLine, messages)}");
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyDictionary<int, Record> GetWorkItems(IEnumerable<WorkItem> workItems, bool keepRelations)
 | |
|     {
 | |
|         ReadOnlyDictionary<int, Record> results;
 | |
|         Dictionary<int, WorkItem> keyValuePairs = new();
 | |
|         foreach (WorkItem workItem in workItems)
 | |
|             keyValuePairs.Add(workItem.Id, workItem);
 | |
|         results = GetKeyValuePairs(new(keyValuePairs), keepRelations);
 | |
|         return results;
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyDictionary<int, Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, bool keepRelations)
 | |
|     {
 | |
|         Dictionary<int, Record> results = new();
 | |
|         Record record;
 | |
|         List<bool> nests = new();
 | |
|         WorkItem? parentWorkItem;
 | |
|         ReadOnlyCollection<Record> childRecords;
 | |
|         ReadOnlyCollection<Record> relatedRecords;
 | |
|         ReadOnlyCollection<Record> successorRecords;
 | |
|         foreach (KeyValuePair<int, WorkItem> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             nests.Clear();
 | |
|             if (keyValuePair.Value.Parent is null)
 | |
|                 parentWorkItem = null;
 | |
|             else
 | |
|                 _ = keyValuePairs.TryGetValue(keyValuePair.Value.Parent.Value, out parentWorkItem);
 | |
|             try
 | |
|             {
 | |
|                 childRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Child", nests, keepRelations); // Forward
 | |
|                 relatedRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Related", nests, keepRelations); // Related
 | |
|                 successorRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Successor", nests, keepRelations); // Forward
 | |
|                 // predecessorRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Predecessor", nests, keepRelations); // Reverse
 | |
|                 record = Record.Get(keyValuePair.Value, parentWorkItem, childRecords, relatedRecords, successorRecords, keepRelations);
 | |
|             }
 | |
|             catch (Exception)
 | |
|             {
 | |
|                 Dictionary<string, string>? tag = null;
 | |
|                 record = new(keyValuePair.Value, parentWorkItem, Array.Empty<Record>(), Array.Empty<Record>(), Array.Empty<Record>(), tag);
 | |
|             }
 | |
|             results.Add(keyValuePair.Key, record);
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FeatureCheckIterationPath122508(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> keyValuePairs, string workItemType)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         Record record;
 | |
|         List<string> violations = new();
 | |
|         List<string> collection = new();
 | |
|         ReadOnlyCollection<Record> records;
 | |
|         ReadOnlyCollection<Record> maxIterationPaths;
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             record = keyValuePair.Value;
 | |
|             if (record.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (!record.WorkItem.IterationPath.Contains('\\'))
 | |
|                 continue;
 | |
|             if (record.WorkItem.WorkItemType != workItemType)
 | |
|                 continue;
 | |
|             collection.Clear();
 | |
|             violations.Clear();
 | |
|             if (record.Children is null || record.Children.Length == 0)
 | |
|                 continue;
 | |
|             records = FilterChildren(workItemTypes, record);
 | |
|             maxIterationPaths = GetMaxIterationPaths122508(records);
 | |
|             foreach (Record r in maxIterationPaths)
 | |
|             {
 | |
|                 if (string.IsNullOrEmpty(r.WorkItem.IterationPath) || record.WorkItem.IterationPath == r.WorkItem.IterationPath)
 | |
|                     continue;
 | |
|                 violations.Add($"<a target='_blank' href='{url}{r.WorkItem.Id}'>{r.WorkItem.Id}</a>:{r.WorkItem.IterationPath};");
 | |
|             }
 | |
|             if (violations.Count > 0)
 | |
|             {
 | |
|                 collection.Insert(0, string.Empty);
 | |
|                 collection.Insert(0, $"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}");
 | |
|                 lines.AddRange(collection);
 | |
|                 violations.Insert(0, $"<a target='_blank' href='{url}{record.WorkItem.Id}'>IterationPath</a>:{record.WorkItem.IterationPath};");
 | |
|                 results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
 | |
|             }
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> GetMaxIterationPaths122508(ReadOnlyCollection<Record> records)
 | |
|     {
 | |
|         List<Record> results;
 | |
|         List<Record>? collection;
 | |
|         Dictionary<string, List<Record>> keyValuePairs = new();
 | |
|         foreach (Record record in records)
 | |
|         {
 | |
|             if (!keyValuePairs.TryGetValue(record.WorkItem.IterationPath, out collection))
 | |
|             {
 | |
|                 keyValuePairs.Add(record.WorkItem.IterationPath, new());
 | |
|                 if (!keyValuePairs.TryGetValue(record.WorkItem.IterationPath, out collection))
 | |
|                     throw new Exception();
 | |
| 
 | |
|             }
 | |
|             collection.Add(record);
 | |
|         }
 | |
|         string? max = keyValuePairs.Keys.Max();
 | |
|         results = string.IsNullOrEmpty(max) ? new() : keyValuePairs[max];
 | |
|         return results.AsReadOnly();
 | |
|     }
 | |
| 
 | |
|     private static void WriteFiles(IFileRead fileRead, string destinationDirectory, List<FileInfo> fileInfoCollection, ReadOnlyCollection<string> lines, string _, ReadOnlyCollection<Record> records, string fileName)
 | |
|     {
 | |
|         string markdown = string.Join(Environment.NewLine, lines);
 | |
|         string markdownFile = Path.Combine(destinationDirectory, $"{fileName}.md");
 | |
|         string markdownOld = !File.Exists(markdownFile) ? string.Empty : File.ReadAllText(markdownFile);
 | |
|         if (markdown != markdownOld)
 | |
|             File.WriteAllText(markdownFile, markdown);
 | |
|         if (!fileRead.IsEAFHosted)
 | |
|             fileInfoCollection.Add(new(markdownFile));
 | |
|         string html = CommonMark.CommonMarkConverter.Convert(markdown).Replace("<a href", "<a target='_blank' href");
 | |
|         string htmlFile = Path.Combine(destinationDirectory, $"{fileName}.html");
 | |
|         string htmlOld = !File.Exists(htmlFile) ? string.Empty : File.ReadAllText(htmlFile);
 | |
|         if (html != htmlOld)
 | |
|             File.WriteAllText(htmlFile, html);
 | |
|         if (!fileRead.IsEAFHosted)
 | |
|             fileInfoCollection.Add(new(htmlFile));
 | |
|         string json = JsonSerializer.Serialize(records, new JsonSerializerOptions() { WriteIndented = true });
 | |
|         string jsonFile = Path.Combine(destinationDirectory, $"{fileName}.json");
 | |
|         string jsonOld = !File.Exists(jsonFile) ? string.Empty : File.ReadAllText(jsonFile);
 | |
|         if (json != jsonOld)
 | |
|             File.WriteAllText(jsonFile, json);
 | |
|         if (!fileRead.IsEAFHosted)
 | |
|             fileInfoCollection.Add(new(jsonFile));
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FeatureCheckTag122514(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> keyValuePairs, string workItemType)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         Record record;
 | |
|         List<string> collection = new();
 | |
|         List<string> violations = new();
 | |
|         ReadOnlyCollection<Record> records;
 | |
|         ReadOnlyCollection<Record> recordsNotMatching;
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             record = keyValuePair.Value;
 | |
|             if (record.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (record.WorkItem.WorkItemType != workItemType)
 | |
|                 continue;
 | |
|             collection.Clear();
 | |
|             violations.Clear();
 | |
|             if (record.Children is null || record.Children.Length == 0)
 | |
|                 continue;
 | |
|             if (string.IsNullOrEmpty(record.WorkItem.Tags))
 | |
|                 recordsNotMatching = new(new Record[] { record });
 | |
|             else
 | |
|             {
 | |
|                 records = FilterChildren(workItemTypes, record);
 | |
|                 recordsNotMatching = GetWorkItemsNotMatching122514(record, records);
 | |
|                 if (!string.IsNullOrEmpty(record.WorkItem.Tags) && recordsNotMatching.Count == 0)
 | |
|                     continue;
 | |
|             }
 | |
|             collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}");
 | |
|             collection.Add(string.Empty);
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 collection.Add($"- [ ] [{r.WorkItem}]({url}{r.WorkItem}) {nameof(record.WorkItem.Tags)} != {record.WorkItem.Tags}");
 | |
|             collection.Add(string.Empty);
 | |
|             lines.AddRange(collection);
 | |
|             violations.Add($"<a target='_blank' href='{url}{record.WorkItem.Id}'>Tag</a>:{record.WorkItem.Tags};");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 violations.Add($"<a target='_blank' href='{url}{r.WorkItem.Id}'>{r.WorkItem.Id}</a>:{r.WorkItem.Tags};");
 | |
|             results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FilterChildren(ReadOnlyCollection<string> workItemTypes, Record record)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         FilterChildren(workItemTypes, record, results);
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static void FilterChildren(ReadOnlyCollection<string> workItemTypes, Record record, List<Record> results)
 | |
|     {
 | |
|         if (record.Children is not null)
 | |
|         {
 | |
|             foreach (Record r in record.Children)
 | |
|             {
 | |
|                 if (!workItemTypes.Contains(r.WorkItem.WorkItemType))
 | |
|                     continue;
 | |
|                 results.Add(r);
 | |
|                 FilterChildren(workItemTypes, r, results);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> GetWorkItemsNotMatching122514(Record record, ReadOnlyCollection<Record> records)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         string[] segments;
 | |
|         string[] parentTags = record.WorkItem.Tags.Split(';').Select(l => l.Trim()).ToArray();
 | |
|         foreach (Record r in records)
 | |
|         {
 | |
|             segments = string.IsNullOrEmpty(r.WorkItem.Tags) ? Array.Empty<string>() : r.WorkItem.Tags.Split(';').Select(l => l.Trim()).ToArray();
 | |
|             if (segments.Length > 0 && parentTags.Any(l => segments.Contains(l)))
 | |
|                 continue;
 | |
|             results.Add(r);
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FeatureCheckPriority126169(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> keyValuePairs, string workItemType)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         Record record;
 | |
|         List<string> collection = new();
 | |
|         List<string> violations = new();
 | |
|         ReadOnlyCollection<Record> records;
 | |
|         ReadOnlyCollection<Record> recordsNotMatching;
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             record = keyValuePair.Value;
 | |
|             if (record.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (record.WorkItem.WorkItemType != workItemType)
 | |
|                 continue;
 | |
|             collection.Clear();
 | |
|             violations.Clear();
 | |
|             if (record.Children is null || record.Children.Length == 0)
 | |
|                 continue;
 | |
|             records = FilterChildren(workItemTypes, record);
 | |
|             recordsNotMatching = GetWorkItemsNotMatching126169(record, records);
 | |
|             if (recordsNotMatching.Count == 0)
 | |
|                 continue;
 | |
|             collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}");
 | |
|             collection.Add(string.Empty);
 | |
|             collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.Priority)} != {record.WorkItem.Priority}");
 | |
|             collection.Add(string.Empty);
 | |
|             lines.AddRange(collection);
 | |
|             violations.Add($"<a target='_blank' href='{url}{record.WorkItem.Id}'>Priority</a>:{record.WorkItem.Priority};");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 violations.Add($"<a target='_blank' href='{url}{r.WorkItem.Id}'>{r.WorkItem.Id}</a>:{r.WorkItem.Priority};");
 | |
|             results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> GetWorkItemsNotMatching126169(Record record, ReadOnlyCollection<Record> records)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         foreach (Record r in records)
 | |
|         {
 | |
|             if (record.WorkItem.Priority is null)
 | |
|             {
 | |
|                 results.Add(record);
 | |
|                 break;
 | |
|             }
 | |
|             if (r.WorkItem.Priority == record.WorkItem.Priority.Value)
 | |
|                 continue;
 | |
|             results.Add(r);
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FeatureCheckState123066(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> keyValuePairs, string workItemType)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         Record record;
 | |
|         List<string> collection = new();
 | |
|         List<string> violations = new();
 | |
|         ReadOnlyCollection<Record> records;
 | |
|         ReadOnlyCollection<Record> recordsNotMatching;
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             record = keyValuePair.Value;
 | |
|             if (record.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (record.WorkItem.WorkItemType != workItemType)
 | |
|                 continue;
 | |
|             collection.Clear();
 | |
|             violations.Clear();
 | |
|             if (record.Children is null || record.Children.Length == 0)
 | |
|                 continue;
 | |
|             records = FilterChildren(workItemTypes, record);
 | |
|             recordsNotMatching = GetWorkItemsNotMatching123066(record, records);
 | |
|             if (recordsNotMatching.Count == 0)
 | |
|                 continue;
 | |
|             collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}");
 | |
|             collection.Add(string.Empty);
 | |
|             collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.State)} != {record.WorkItem.State}");
 | |
|             collection.Add(string.Empty);
 | |
|             lines.AddRange(collection);
 | |
|             violations.Add($"<a target='_blank' href='{url}{record.WorkItem.Id}'>State</a>:{record.WorkItem.State};");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 violations.Add($"<a target='_blank' href='{url}{r.WorkItem.Id}'>{r.WorkItem.Id}</a>:{r.WorkItem.State};");
 | |
|             results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> GetWorkItemsNotMatching123066(Record record, ReadOnlyCollection<Record> records)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         int check;
 | |
|         int state = GetState(record.WorkItem);
 | |
|         List<KeyValuePair<int, Record>> collection = new();
 | |
|         foreach (Record r in records)
 | |
|         {
 | |
|             if (r.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             check = GetState(r.WorkItem);
 | |
|             if (check == state)
 | |
|                 continue;
 | |
|             collection.Add(new(check, r));
 | |
|         }
 | |
|         if (collection.Count > 0)
 | |
|         {
 | |
|             KeyValuePair<int, Record>[] notNewState = (from l in collection where l.Value.WorkItem.State != "New" select l).ToArray();
 | |
|             if (notNewState.Length == 0 && record.WorkItem.State is "New" or "Active")
 | |
|                 collection.Clear();
 | |
|             else if (notNewState.Length > 0)
 | |
|             {
 | |
|                 int minimum = notNewState.Min(l => l.Key);
 | |
|                 if (minimum == state)
 | |
|                     collection.Clear();
 | |
|                 else if (minimum == 1 && record.WorkItem.State == "New")
 | |
|                     collection.Clear();
 | |
|                 else if (notNewState.Length > 0 && record.WorkItem.State == "Active")
 | |
|                     collection.Clear();
 | |
|             }
 | |
|         }
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in collection.OrderByDescending(l => l.Key))
 | |
|             results.Add(keyValuePair.Value);
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FeatureCheckState123067(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> keyValuePairs, string workItemType)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         Record record;
 | |
|         List<string> collection = new();
 | |
|         List<string> violations = new();
 | |
|         ReadOnlyCollection<Record> records;
 | |
|         ReadOnlyCollection<Record> recordsNotMatching;
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             record = keyValuePair.Value;
 | |
|             if (record.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (record.WorkItem.WorkItemType != workItemType)
 | |
|                 continue;
 | |
|             collection.Clear();
 | |
|             violations.Clear();
 | |
|             if (record.Children is null || record.Children.Length == 0)
 | |
|                 continue;
 | |
|             records = FilterChildren(workItemTypes, record);
 | |
|             recordsNotMatching = GetWorkItemsNotMatching123067(record, records);
 | |
|             if (recordsNotMatching.Count == 0)
 | |
|                 continue;
 | |
|             collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}");
 | |
|             collection.Add(string.Empty);
 | |
|             collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.State)} != {record.WorkItem.State}");
 | |
|             collection.Add(string.Empty);
 | |
|             lines.AddRange(collection);
 | |
|             violations.Add($"<a target='_blank' href='{url}{record.WorkItem.Id}'>State</a>:{record.WorkItem.State};");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 violations.Add($"<a target='_blank' href='{url}{r.WorkItem.Id}'>{r.WorkItem.Id}</a>:{r.WorkItem.State};");
 | |
|             results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> GetWorkItemsNotMatching123067(Record record, ReadOnlyCollection<Record> records)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         int check;
 | |
|         int state = GetState(record.WorkItem);
 | |
|         List<KeyValuePair<int, Record>> collection = new();
 | |
|         foreach (Record r in records)
 | |
|         {
 | |
|             if (r.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             check = GetState(r.WorkItem);
 | |
|             if (check == state)
 | |
|                 continue;
 | |
|             collection.Add(new(check, r));
 | |
|         }
 | |
|         if (collection.Count > 0)
 | |
|         {
 | |
|             KeyValuePair<int, Record>[] notNewState = (from l in collection where l.Value.WorkItem.State != "New" select l).ToArray();
 | |
|             if (notNewState.Length == 0 && record.WorkItem.State is "New" or "Active")
 | |
|                 collection.Clear();
 | |
|             else if (notNewState.Length > 0)
 | |
|             {
 | |
|                 int minimum = notNewState.Min(l => l.Key);
 | |
|                 if (minimum == state)
 | |
|                     collection.Clear();
 | |
|                 else if (minimum == 1 && record.WorkItem.State == "New")
 | |
|                     collection.Clear();
 | |
|                 else if (notNewState.Length > 0 && record.WorkItem.State == "Active")
 | |
|                     collection.Clear();
 | |
|             }
 | |
|         }
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in collection.OrderByDescending(l => l.Key))
 | |
|             results.Add(keyValuePair.Value);
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> FeatureCheckStart122517(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> keyValuePairs, string workItemType)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         Record record;
 | |
|         List<string> collection = new();
 | |
|         List<string> violations = new();
 | |
|         ReadOnlyCollection<Record> records;
 | |
|         ReadOnlyCollection<Record> recordsNotMatching;
 | |
|         foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             record = keyValuePair.Value;
 | |
|             if (record.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (record.WorkItem.WorkItemType != workItemType)
 | |
|                 continue;
 | |
|             collection.Clear();
 | |
|             violations.Clear();
 | |
|             if (record.Children is null || record.Children.Length == 0)
 | |
|                 continue;
 | |
|             if (record.WorkItem.StartDate is null)
 | |
|                 continue;
 | |
|             records = FilterChildren(workItemTypes, record);
 | |
|             recordsNotMatching = GetWorkItemsNotMatching122517(record, records);
 | |
|             if (recordsNotMatching.Count == 0)
 | |
|                 continue;
 | |
|             collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}");
 | |
|             collection.Add(string.Empty);
 | |
|             collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.ActivatedDate)} != {record.WorkItem.ActivatedDate}");
 | |
|             collection.Add(string.Empty);
 | |
|             lines.AddRange(collection);
 | |
|             violations.Add($"<a target='_blank' href='{url}{record.WorkItem.Id}'>StartDate</a>:{record.WorkItem.StartDate};");
 | |
|             foreach (Record r in recordsNotMatching)
 | |
|                 violations.Add($"<a target='_blank' href='{url}{r.WorkItem.Id}'>{r.WorkItem.Id}</a>:{r.WorkItem.ActivatedDate};");
 | |
|             results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     private static ReadOnlyCollection<Record> GetWorkItemsNotMatching122517(Record record, ReadOnlyCollection<Record> records)
 | |
|     {
 | |
|         List<Record> results = new();
 | |
|         if (record.WorkItem.StartDate is null)
 | |
|             throw new Exception();
 | |
|         DateTime dateTime = record.WorkItem.StartDate.Value;
 | |
|         List<KeyValuePair<long, Record>> collection = new();
 | |
|         foreach (Record r in records)
 | |
|         {
 | |
|             if (r.WorkItem.State is "Removed")
 | |
|                 continue;
 | |
|             if (r.WorkItem.ActivatedDate is null)
 | |
|                 continue;
 | |
|             if (dateTime >= r.WorkItem.ActivatedDate.Value)
 | |
|                 continue;
 | |
|             collection.Add(new(r.WorkItem.ActivatedDate.Value.Ticks, r));
 | |
|         }
 | |
|         foreach (KeyValuePair<long, Record> keyValuePair in collection.OrderBy(l => l.Key))
 | |
|             results.Add(keyValuePair.Value);
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     internal static List<Description> GetDescriptions(JsonElement[] jsonElements)
 | |
|     {
 | |
|         List<Description> results = new();
 | |
|         Description? description;
 | |
|         JsonSerializerOptions jsonSerializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString };
 | |
|         foreach (JsonElement jsonElement in jsonElements)
 | |
|         {
 | |
|             if (jsonElement.ValueKind != JsonValueKind.Object)
 | |
|                 throw new Exception();
 | |
|             description = JsonSerializer.Deserialize<Description>(jsonElement.ToString(), jsonSerializerOptions);
 | |
|             if (description is null)
 | |
|                 continue;
 | |
|             results.Add(description);
 | |
|         }
 | |
|         return results;
 | |
|     }
 | |
| 
 | |
| } |