Switch to Datagrid

This commit is contained in:
2024-10-07 19:27:14 -07:00
parent 3977727168
commit b4c91e3f2c
5 changed files with 129 additions and 74 deletions

View File

@ -246,7 +246,7 @@ public class FileRead : Shared.FileRead, IFileRead
}
}
private static void WriteFiles(string destinationDirectory, string fileName, ReadOnlyCollection<string> lines)
private static void WriteFiles(string destinationDirectory, string fileName, ReadOnlyCollection<string> lines, ReadOnlyCollection<WorkItem> workItems)
{
string text = string.Join(Environment.NewLine, lines);
string markdownFile = Path.Combine(destinationDirectory, $"{fileName}.md");
@ -258,6 +258,11 @@ public class FileRead : Shared.FileRead, IFileRead
string htmlOld = !File.Exists(htmlFile) ? string.Empty : File.ReadAllText(htmlFile);
if (html != htmlOld)
File.WriteAllText(htmlFile, html);
string json = JsonSerializer.Serialize(workItems.ToArray(), 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);
}
private static ReadOnlyCollection<WorkItem> FilterChildren(Record record, ReadOnlyCollection<string> workItemTypes)
@ -288,12 +293,13 @@ public class FileRead : Shared.FileRead, IFileRead
return result;
}
private static void FeatureCheckIterationPath(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
private static ReadOnlyCollection<WorkItem> FeatureCheckIterationPath122508(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
{
List<WorkItem> collection = new();
WorkItem workItem;
string? maxIterationPath;
List<string> results = new();
ReadOnlyCollection<WorkItem> workItems;
ReadOnlyCollection<WorkItem> childrenWorkItems;
foreach (KeyValuePair<int, Record> keyValuePair in workItemAndChildren)
{
workItem = keyValuePair.Value.WorkItem;
@ -302,8 +308,8 @@ public class FileRead : Shared.FileRead, IFileRead
results.Clear();
if (keyValuePair.Value.Children.Count == 0)
continue;
workItems = FilterChildren(keyValuePair.Value, workItemTypes);
maxIterationPath = GetMaxIterationPath(workItems);
childrenWorkItems = FilterChildren(keyValuePair.Value, workItemTypes);
maxIterationPath = GetMaxIterationPath(childrenWorkItems);
if (string.IsNullOrEmpty(maxIterationPath) || workItem.IterationPath == maxIterationPath)
continue;
results.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}");
@ -311,12 +317,15 @@ public class FileRead : Shared.FileRead, IFileRead
results.Add($"- [ ] [{workItem.Id}]({url}{workItem.Id}) => {workItem.IterationPath} != {maxIterationPath}");
results.Add(string.Empty);
lines.AddRange(results);
collection.Add(WorkItem.Get(workItem, $"IterationPath:{workItem.Id};{workItem.IterationPath} != {maxIterationPath}"));
collection.Add(workItem);
}
return new(collection);
}
private static ReadOnlyCollection<int> GetIdsNotMatching(string tags, ReadOnlyCollection<WorkItem> workItems)
private static ReadOnlyCollection<WorkItem> GetWorkItemsNotMatching(string tags, ReadOnlyCollection<WorkItem> workItems)
{
List<int> results = new();
List<WorkItem> results = new();
string[] segments;
string[] parentTags = tags.Split(';');
foreach (WorkItem workItem in workItems)
@ -324,81 +333,97 @@ public class FileRead : Shared.FileRead, IFileRead
segments = tags.Split(';');
if (segments.Length > 0 && parentTags.Any(l => segments.Contains(l)))
continue;
results.Add(workItem.Id);
results.Add(workItem);
}
return new(results);
}
private static void FeatureCheckTag(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
private static ReadOnlyCollection<WorkItem> FeatureCheckTag122514(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
{
List<WorkItem> collection = new();
WorkItem workItem;
List<string> results = new();
ReadOnlyCollection<int> idsNotMatching;
ReadOnlyCollection<WorkItem> workItems;
List<string> violations = new();
ReadOnlyCollection<WorkItem> childrenWorkItems;
ReadOnlyCollection<WorkItem> workItemsNotMatching;
foreach (KeyValuePair<int, Record> keyValuePair in workItemAndChildren)
{
workItem = keyValuePair.Value.WorkItem;
if (workItem.WorkItemType != workItemType)
continue;
results.Clear();
violations.Clear();
if (keyValuePair.Value.Children.Count == 0)
continue;
if (string.IsNullOrEmpty(workItem.Tags))
idsNotMatching = new(new int[] { workItem.Id });
workItemsNotMatching = new(new WorkItem[] { workItem });
else
{
workItems = FilterChildren(keyValuePair.Value, workItemTypes);
idsNotMatching = GetIdsNotMatching(workItem.Tags, workItems);
if (!string.IsNullOrEmpty(workItem.Tags) && idsNotMatching.Count == 0)
childrenWorkItems = FilterChildren(keyValuePair.Value, workItemTypes);
workItemsNotMatching = GetWorkItemsNotMatching(workItem.Tags, childrenWorkItems);
if (!string.IsNullOrEmpty(workItem.Tags) && workItemsNotMatching.Count == 0)
continue;
}
results.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}");
results.Add(string.Empty);
foreach (int id in idsNotMatching)
results.Add($"- [ ] [{id}]({url}{id}) {nameof(workItem.Tags)} != {workItem.Tags}");
foreach (WorkItem item in workItemsNotMatching)
results.Add($"- [ ] [{item}]({url}{item}) {nameof(workItem.Tags)} != {workItem.Tags}");
results.Add(string.Empty);
lines.AddRange(results);
violations.Add($"Tag:{workItem.Tags};");
foreach (WorkItem item in workItemsNotMatching)
violations.Add($"{item.Id}:{item.Tags};");
collection.Add(WorkItem.Get(workItem, string.Join(" ", violations)));
}
return new(collection);
}
private static ReadOnlyCollection<int> GetIdsNotMatching(int? priority, ReadOnlyCollection<WorkItem> workItems)
private static ReadOnlyCollection<WorkItem> GetWorkItemsNotMatching(int? priority, ReadOnlyCollection<WorkItem> workItems)
{
List<int> results = new();
List<WorkItem> results = new();
foreach (WorkItem workItem in workItems)
{
if (workItem.Priority == priority)
continue;
results.Add(workItem.Id);
results.Add(workItem);
}
return new(results);
}
private static void FeatureCheckPriority(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
private static ReadOnlyCollection<WorkItem> FeatureCheckPriority126169(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
{
List<WorkItem> collection = new();
WorkItem workItem;
List<string> results = new();
ReadOnlyCollection<int> idsNotMatching;
ReadOnlyCollection<WorkItem> workItems;
List<string> violations = new();
ReadOnlyCollection<WorkItem> childrenWorkItems;
ReadOnlyCollection<WorkItem> workItemsNotMatching;
foreach (KeyValuePair<int, Record> keyValuePair in workItemAndChildren)
{
workItem = keyValuePair.Value.WorkItem;
if (workItem.WorkItemType != workItemType)
continue;
results.Clear();
violations.Clear();
if (keyValuePair.Value.Children.Count == 0)
continue;
workItems = FilterChildren(keyValuePair.Value, workItemTypes);
idsNotMatching = GetIdsNotMatching(workItem.Priority, workItems);
if (idsNotMatching.Count == 0)
childrenWorkItems = FilterChildren(keyValuePair.Value, workItemTypes);
workItemsNotMatching = GetWorkItemsNotMatching(workItem.Priority, childrenWorkItems);
if (workItemsNotMatching.Count == 0)
continue;
results.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}");
results.Add(string.Empty);
results.Add($"- [{workItem.Id}]({url}{workItem.Id})");
foreach (int id in idsNotMatching)
results.Add($"- [ ] [{id}]({url}{id}) {nameof(workItem.Priority)} != {workItem.Priority}");
foreach (WorkItem item in workItemsNotMatching)
results.Add($"- [ ] [{item}]({url}{item}) {nameof(workItem.Priority)} != {workItem.Priority}");
results.Add(string.Empty);
lines.AddRange(results);
violations.Add($"Priority:{workItem.Priority};");
foreach (WorkItem item in workItemsNotMatching)
violations.Add($"{item.Id}:{item.Priority};");
collection.Add(WorkItem.Get(workItem, string.Join(" ", violations)));
}
return new(collection);
}
private static void WriteFiles(FileConnectorConfiguration fileConnectorConfiguration, string url, ReadOnlyCollection<string> workItemTypes, ReadOnlyCollection<WorkItem> workItems)
@ -406,15 +431,16 @@ public class FileRead : Shared.FileRead, IFileRead
string json;
List<char> spaces = new();
List<string> lines = new();
ReadOnlyDictionary<int, WorkItem> keyValuePairs = GetWorkItems(workItems);
ReadOnlyDictionary<int, Record> workItemAndChildren = GetWorkItemAndChildren(keyValuePairs);
ReadOnlyCollection<WorkItem> results;
ReadOnlyDictionary<int, WorkItem> collection = GetWorkItems(workItems);
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItemAndChildren(collection);
ReadOnlyCollection<string> bugUserStoryWorkItemTypes = new(new string[] { "Bug", "User Story" });
ReadOnlyCollection<string> bugUserStoryTaskWorkItemTypes = new(new string[] { "Bug", "User Story", "Task" });
if (!Directory.Exists(fileConnectorConfiguration.TargetFileLocation))
_ = Directory.CreateDirectory(fileConnectorConfiguration.TargetFileLocation);
if (workItemAndChildren.Count == -1)
if (keyValuePairs.Count == -1)
{
json = JsonSerializer.Serialize(workItemAndChildren, new JsonSerializerOptions() { WriteIndented = true });
json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions() { WriteIndented = true });
File.WriteAllText(Path.Combine(fileConnectorConfiguration.TargetFileLocation, ".json"), json);
}
foreach (string workItemType in workItemTypes)
@ -422,32 +448,33 @@ public class FileRead : Shared.FileRead, IFileRead
lines.Clear();
lines.Add($"# {workItemType}");
lines.Add(string.Empty);
AppendLines(url, spaces, lines, workItemAndChildren, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, workItemType, new(lines));
AppendLines(url, spaces, lines, keyValuePairs, workItemType);
results = new(Array.Empty<WorkItem>());
WriteFiles(fileConnectorConfiguration.TargetFileLocation, workItemType, new(lines), results);
}
{
lines.Clear();
string workItemType = "Feature";
lines.Add($"# {nameof(FeatureCheckIterationPath)}");
lines.Add($"# {nameof(FeatureCheckIterationPath122508)}");
lines.Add(string.Empty);
FeatureCheckIterationPath(url, lines, bugUserStoryTaskWorkItemTypes, workItemAndChildren, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, $"{nameof(FeatureCheckIterationPath)}", new(lines));
results = FeatureCheckIterationPath122508(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, "check-122508", new(lines), results);
}
{
lines.Clear();
string workItemType = "Feature";
lines.Add($"# {nameof(FeatureCheckTag)}");
lines.Add($"# {nameof(FeatureCheckTag122514)}");
lines.Add(string.Empty);
FeatureCheckTag(url, lines, bugUserStoryWorkItemTypes, workItemAndChildren, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, $"{nameof(FeatureCheckTag)}", new(lines));
results = FeatureCheckTag122514(url, lines, bugUserStoryWorkItemTypes, keyValuePairs, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, "check-122514", new(lines), results);
}
{
lines.Clear();
string workItemType = "Feature";
lines.Add($"# {nameof(FeatureCheckPriority)}");
lines.Add($"# {nameof(FeatureCheckPriority126169)}");
lines.Add(string.Empty);
FeatureCheckPriority(url, lines, bugUserStoryWorkItemTypes, workItemAndChildren, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, $"{nameof(FeatureCheckPriority)}", new(lines));
results = FeatureCheckPriority126169(url, lines, bugUserStoryWorkItemTypes, keyValuePairs, workItemType);
WriteFiles(fileConnectorConfiguration.TargetFileLocation, "check-126169", new(lines), results);
}
}
@ -457,10 +484,8 @@ public class FileRead : Shared.FileRead, IFileRead
{
string json = File.ReadAllText(reportFullPath);
WorkItem[]? workItems = JsonSerializer.Deserialize<WorkItem[]>(json);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(reportFullPath);
if (workItems is null)
throw new Exception(nameof(workItems));
string[] alternateTargetFolders = _FileConnectorConfiguration.AlternateTargetFolder.Split('|');
if (workItems.Length > 0)
WriteFiles(_FileConnectorConfiguration, _URL, _WorkItemTypes, new(workItems));
}