Creation of ADO Connection
This commit is contained in:
@ -79,10 +79,12 @@ public class ProcessData : IProcessData
|
||||
workItems.Add(workItem);
|
||||
}
|
||||
List<char> spaces = new();
|
||||
bool keepRelations = false;
|
||||
List<string> lines = new();
|
||||
ReadOnlyCollection<Record> results;
|
||||
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(workItems);
|
||||
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(workItems, keepRelations);
|
||||
ReadOnlyCollection<Record> records = new(keyValuePairs.Values.ToArray());
|
||||
WriteFile(fileRead, destinationDirectory, fileInfoCollection, records, "records");
|
||||
ReadOnlyCollection<string> bugFeatureWorkItemTypes = new(new string[] { "Bug", "Feature" });
|
||||
ReadOnlyCollection<string> bugUserStoryWorkItemTypes = new(new string[] { "Bug", "User Story" });
|
||||
ReadOnlyCollection<string> bugUserStoryTaskWorkItemTypes = new(new string[] { "Bug", "User Story", "Task" });
|
||||
@ -179,16 +181,27 @@ public class ProcessData : IProcessData
|
||||
fileInfoCollection.Add(new(jsonFile));
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, Record> GetWorkItems(IEnumerable<WorkItem> workItems)
|
||||
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));
|
||||
results = GetKeyValuePairs(new(keyValuePairs), keepRelations);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void WriteFile(IFileRead fileRead, string destinationDirectory, List<FileInfo> fileInfoCollection, ReadOnlyCollection<Record> records, string fileName)
|
||||
{
|
||||
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 void WriteWithPartentsFile(IFileRead fileRead, string destinationDirectory, List<FileInfo> fileInfoCollection, ReadOnlyCollection<Record> records, ReadOnlyCollection<string> workItemTypes, string fileName)
|
||||
{
|
||||
List<Record> filtered = new();
|
||||
@ -197,7 +210,7 @@ public class ProcessData : IProcessData
|
||||
{
|
||||
if (r.WorkItem.State == "Removed" || !workItemTypes.Contains(r.WorkItem.WorkItemType))
|
||||
continue;
|
||||
record = new(r.WorkItem, r.Parent, Array.Empty<Record>());
|
||||
record = new(r.WorkItem, r.Parent, Array.Empty<Record>(), Array.Empty<Record>(), Array.Empty<Record>());
|
||||
filtered.Add(record);
|
||||
}
|
||||
string json = JsonSerializer.Serialize(filtered, new JsonSerializerOptions() { WriteIndented = true });
|
||||
@ -272,13 +285,15 @@ public class ProcessData : IProcessData
|
||||
spaces.RemoveAt(0);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs)
|
||||
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> records;
|
||||
ReadOnlyCollection<Record> childRecords;
|
||||
ReadOnlyCollection<Record> relatedRecords;
|
||||
ReadOnlyCollection<Record> successorRecords;
|
||||
foreach (KeyValuePair<int, WorkItem> keyValuePair in keyValuePairs)
|
||||
{
|
||||
nests.Clear();
|
||||
@ -288,12 +303,15 @@ public class ProcessData : IProcessData
|
||||
_ = keyValuePairs.TryGetValue(keyValuePair.Value.Parent.Value, out parentWorkItem);
|
||||
try
|
||||
{
|
||||
records = GetKeyValuePairs(keyValuePairs, keyValuePair.Value, nests);
|
||||
record = Record.Get(keyValuePair.Value, parentWorkItem, records);
|
||||
childRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Child", nests, keepRelations); // Forward
|
||||
// records = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Predecessor", nests, keepRelations); // Reverse
|
||||
relatedRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Related", nests, keepRelations); // Related
|
||||
successorRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Successor", nests, keepRelations); // Forward
|
||||
record = Record.Get(keyValuePair.Value, parentWorkItem, childRecords, relatedRecords, successorRecords, keepRelations);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
record = new(keyValuePair.Value, parentWorkItem, Array.Empty<Record>());
|
||||
record = new(keyValuePair.Value, parentWorkItem, Array.Empty<Record>(), Array.Empty<Record>(), Array.Empty<Record>());
|
||||
}
|
||||
results.Add(keyValuePair.Key, record);
|
||||
}
|
||||
@ -310,89 +328,9 @@ public class ProcessData : IProcessData
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, WorkItem workItem, List<bool> nests)
|
||||
{
|
||||
List<Record> results = new();
|
||||
int? childId;
|
||||
Record record;
|
||||
nests.Add(true);
|
||||
WorkItem? childWorkItem;
|
||||
WorkItem? parentWorkItem;
|
||||
List<WorkItem> collection = new();
|
||||
ReadOnlyCollection<Record> records;
|
||||
if (workItem.Relations is not null && workItem.Relations.Length > 0)
|
||||
{
|
||||
collection.Clear();
|
||||
foreach (Relation relation in workItem.Relations)
|
||||
{
|
||||
childId = GetIdFromUrlIfChild(relation);
|
||||
if (childId is not null && workItem.Parent is not null && relation?.URL is not null && relation.URL.Contains(workItem.Parent.Value.ToString()))
|
||||
continue;
|
||||
if (childId is null || !keyValuePairs.TryGetValue(childId.Value, out childWorkItem))
|
||||
continue;
|
||||
collection.Add(childWorkItem);
|
||||
}
|
||||
collection = (from l in collection orderby l.State != "Closed", l.Id select l).ToList();
|
||||
foreach (WorkItem w in collection)
|
||||
{
|
||||
if (nests.Count > 99)
|
||||
break;
|
||||
if (w.Parent is null)
|
||||
parentWorkItem = null;
|
||||
else
|
||||
_ = keyValuePairs.TryGetValue(w.Parent.Value, out parentWorkItem);
|
||||
records = GetKeyValuePairs(keyValuePairs, w, nests);
|
||||
record = Record.Get(w, parentWorkItem, records);
|
||||
results.Add(record);
|
||||
}
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static string GetClosed(WorkItem workItem) =>
|
||||
workItem.State != "Closed" ? "[ ]" : "[x]";
|
||||
|
||||
private static int? GetIdFromUrlIfChild(Relation relation)
|
||||
{
|
||||
int? result;
|
||||
string[] segments = relation?.Attributes is null || relation.Attributes.Name != "Child" ? Array.Empty<string>() : relation.URL.Split('/');
|
||||
if (segments.Length < 2)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
if (!int.TryParse(segments[segments.Length - 1], out int id))
|
||||
result = null;
|
||||
else
|
||||
result = id;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetChildrenDirectories(ReadOnlyDictionary<int, Record> keyValuePairs, List<bool> nests, string parentDirectory, Record record)
|
||||
{
|
||||
List<string> results = new();
|
||||
nests.Add(true);
|
||||
string directory;
|
||||
Record? childRecord;
|
||||
ReadOnlyCollection<string> childrenDirectories;
|
||||
foreach (Record r in record.Children)
|
||||
{
|
||||
// if (record.WorkItem.Id == 110730)
|
||||
// continue;
|
||||
// if (record.WorkItem.Id == 110732)
|
||||
// continue;
|
||||
directory = Path.Combine(parentDirectory, $"{r.WorkItem.WorkItemType.Substring(0, 1)}-{r.WorkItem.Id}-{r.WorkItem.Title.Trim().Substring(0, 1)}");
|
||||
results.Add(directory);
|
||||
if (!keyValuePairs.TryGetValue(r.WorkItem.Id, out childRecord))
|
||||
continue;
|
||||
if (nests.Count > 99)
|
||||
break;
|
||||
childrenDirectories = GetChildrenDirectories(keyValuePairs, nests, directory, childRecord);
|
||||
results.AddRange(childrenDirectories);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static void FilterChildren(ReadOnlyCollection<string> workItemTypes, Record record, List<Record> results)
|
||||
{
|
||||
foreach (Record r in record.Children)
|
||||
@ -462,7 +400,7 @@ public class ProcessData : IProcessData
|
||||
collection.Add($"- [ ] [{record.WorkItem.Id}]({url}{record.WorkItem.Id}) => {record.WorkItem.IterationPath} != {maxIterationPath}");
|
||||
collection.Add(string.Empty);
|
||||
lines.AddRange(collection);
|
||||
results.Add(WorkItem.Get(record, $"IterationPath:<a target='_blank' href='{url}{record.WorkItem.Id}'>{record.WorkItem.Id}</a>;{record.WorkItem.IterationPath} != {maxIterationPath}"));
|
||||
results.Add(Record.GetWithoutNesting(record, $"IterationPath:<a target='_blank' href='{url}{record.WorkItem.Id}'>{record.WorkItem.Id}</a>;{record.WorkItem.IterationPath} != {maxIterationPath}"));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -519,7 +457,7 @@ public class ProcessData : IProcessData
|
||||
violations.Add($"Tag:{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(WorkItem.Get(record, string.Join(" ", violations)));
|
||||
results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -574,7 +512,7 @@ public class ProcessData : IProcessData
|
||||
violations.Add($"Priority:{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(WorkItem.Get(record, string.Join(" ", violations)));
|
||||
results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -706,7 +644,7 @@ public class ProcessData : IProcessData
|
||||
violations.Add($"State:{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(WorkItem.Get(record, string.Join(" ", violations)));
|
||||
results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -744,7 +682,7 @@ public class ProcessData : IProcessData
|
||||
violations.Add($"State:{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(WorkItem.Get(record, string.Join(" ", violations)));
|
||||
results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -784,7 +722,7 @@ public class ProcessData : IProcessData
|
||||
violations.Add($"StartDate:{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(WorkItem.Get(record, string.Join(" ", violations)));
|
||||
results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations)));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
Reference in New Issue
Block a user