csharp_new_line_before_open_brace = none

This commit is contained in:
2025-07-27 12:33:54 -07:00
parent 341cc93a0a
commit e74a0ccdce
22 changed files with 908 additions and 653 deletions

View File

@ -7,8 +7,7 @@ using System.Text.Json.Serialization;
namespace File_Folder_Helper.ADO2024.PI4;
internal static partial class Helper20241108
{
internal static partial class Helper20241108 {
#if WorkItems
@ -49,13 +48,11 @@ internal static partial class Helper20241108
string Title,
string? Violation,
long? WeightedShortestJobFirst,
string WorkItemType)
{
string WorkItemType) {
public override string ToString() => $"{Id} - {WorkItemType} - {Title}";
public static WorkItem Get(WorkItem workItem, Relation[] relations)
{
public static WorkItem Get(WorkItem workItem, Relation[] relations) {
WorkItem result = new(workItem.ActivatedDate,
workItem.AreaPath,
workItem.AssignedTo,
@ -87,8 +84,7 @@ internal static partial class Helper20241108
return result;
}
public static WorkItem? GetWithOutRelations(WorkItem? workItem)
{
public static WorkItem? GetWithOutRelations(WorkItem? workItem) {
WorkItem? result = workItem is null ? null : new(workItem.ActivatedDate,
workItem.AreaPath,
workItem.AssignedTo,
@ -124,21 +120,17 @@ internal static partial class Helper20241108
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(WorkItem))]
private partial class WorkItemSourceGenerationContext : JsonSerializerContext
{
private partial class WorkItemSourceGenerationContext : JsonSerializerContext {
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(WorkItem[]))]
private partial class WorkItemCollectionSourceGenerationContext : JsonSerializerContext
{
private partial class WorkItemCollectionSourceGenerationContext : JsonSerializerContext {
}
private record Record(WorkItem WorkItem, WorkItem? Parent, Record[]? Children, Record[]? Related, Record[]? Successors)
{
private record Record(WorkItem WorkItem, WorkItem? Parent, Record[]? Children, Record[]? Related, Record[]? Successors) {
internal static Record GetWithoutNesting(Record record, string? violation)
{
internal static Record GetWithoutNesting(Record record, string? violation) {
Record result;
WorkItem workItem = new(record.WorkItem.ActivatedDate,
record.WorkItem.AreaPath,
@ -172,8 +164,7 @@ internal static partial class Helper20241108
return result;
}
private static Record Get(Record record, bool keepRelations)
{
private static Record Get(Record record, bool keepRelations) {
Record result;
Record[]? childRecords;
Record[]? relatedRecords;
@ -183,8 +174,7 @@ internal static partial class Helper20241108
WorkItem? workItem = keepRelations ? record.WorkItem : WorkItem.GetWithOutRelations(record.WorkItem) ?? throw new Exception();
if (record.Children is null)
childRecords = null;
else
{
else {
relationRecords = [];
foreach (Record r in record.Children)
relationRecords.Add(Get(r, keepRelations));
@ -192,8 +182,7 @@ internal static partial class Helper20241108
}
if (record.Related is null)
relatedRecords = null;
else
{
else {
relationRecords = [];
foreach (Record r in record.Related)
relationRecords.Add(Get(r, keepRelations));
@ -201,8 +190,7 @@ internal static partial class Helper20241108
}
if (record.Successors is null)
successorRecords = null;
else
{
else {
relationRecords = [];
foreach (Record r in record.Successors)
relationRecords.Add(Get(r, keepRelations));
@ -212,16 +200,14 @@ internal static partial class Helper20241108
return result;
}
internal static Record Get(WorkItem workItem, WorkItem? parent, ReadOnlyCollection<Record>? children, ReadOnlyCollection<Record>? related, ReadOnlyCollection<Record>? successors, bool keepRelations)
{
internal static Record Get(WorkItem workItem, WorkItem? parent, ReadOnlyCollection<Record>? children, ReadOnlyCollection<Record>? related, ReadOnlyCollection<Record>? successors, bool keepRelations) {
Record result;
Record record = new(workItem, parent, children?.ToArray(), related?.ToArray(), successors?.ToArray());
result = Get(record, keepRelations);
return result;
}
internal static ReadOnlyCollection<Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, WorkItem workItem, string relationName, List<bool> nests, bool keepRelations)
{
internal static ReadOnlyCollection<Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, WorkItem workItem, string relationName, List<bool> nests, bool keepRelations) {
List<Record> results = [];
Record record;
nests.Add(true);
@ -231,11 +217,9 @@ internal static partial class Helper20241108
ReadOnlyCollection<Record>? childRecords;
ReadOnlyCollection<Record>? relatedRecords;
ReadOnlyCollection<Record>? successorRecords;
if (workItem.Relations is not null && workItem.Relations.Length > 0)
{
if (workItem.Relations is not null && workItem.Relations.Length > 0) {
collection.Clear();
foreach (Relation relation in workItem.Relations)
{
foreach (Relation relation in workItem.Relations) {
if (relation.Attributes.Name != relationName)
continue;
if (workItem.Parent is not null && relation.Id == workItem.Parent.Value)
@ -245,8 +229,7 @@ internal static partial class Helper20241108
collection.Add(relationWorkItem);
}
collection = (from l in collection orderby l.State != "Closed", l.Id select l).ToList();
foreach (WorkItem w in collection)
{
foreach (WorkItem w in collection) {
if (nests.Count > 500)
break;
if (w.Parent is null)
@ -268,12 +251,10 @@ internal static partial class Helper20241108
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Record[]))]
private partial class RecordCollectionBCommonSourceGenerationContext : JsonSerializerContext
{
private partial class RecordCollectionBCommonSourceGenerationContext : JsonSerializerContext {
}
private static ReadOnlyDictionary<int, Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, bool keepRelations)
{
private static ReadOnlyDictionary<int, Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, bool keepRelations) {
Dictionary<int, Record> results = [];
Record record;
List<bool> nests = [];
@ -281,23 +262,19 @@ internal static partial class Helper20241108
ReadOnlyCollection<Record> childRecords;
ReadOnlyCollection<Record> relatedRecords;
ReadOnlyCollection<Record> successorRecords;
foreach (KeyValuePair<int, WorkItem> keyValuePair in keyValuePairs)
{
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
{
try {
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)
{
} catch (Exception) {
record = new(keyValuePair.Value, parentWorkItem, [], [], []);
}
results.Add(keyValuePair.Key, record);
@ -305,8 +282,7 @@ internal static partial class Helper20241108
return new(results);
}
private static ReadOnlyDictionary<int, Record> GetWorkItems(ReadOnlyCollection<WorkItem> workItems, bool keepRelations)
{
private static ReadOnlyDictionary<int, Record> GetWorkItems(ReadOnlyCollection<WorkItem> workItems, bool keepRelations) {
ReadOnlyDictionary<int, Record> results;
Dictionary<int, WorkItem> keyValuePairs = [];
foreach (WorkItem workItem in workItems)
@ -315,14 +291,12 @@ internal static partial class Helper20241108
return results;
}
private static ReadOnlyCollection<WorkItem>? GetWorkItems(string fileName, string sourceDirectory)
{
private static ReadOnlyCollection<WorkItem>? GetWorkItems(string fileName, string sourceDirectory) {
WorkItem[]? results;
string? checkFile = null;
string? checkDirectory = sourceDirectory;
string? pathRoot = Path.GetPathRoot(sourceDirectory);
for (int i = 0; i < int.MaxValue; i++)
{
for (int i = 0; i < int.MaxValue; i++) {
checkDirectory = Path.GetDirectoryName(checkDirectory);
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot)
break;
@ -333,16 +307,14 @@ internal static partial class Helper20241108
}
if (checkFile is null)
results = null;
else
{
else {
string json = File.ReadAllText(checkFile);
results = JsonSerializer.Deserialize(json, WorkItemCollectionSourceGenerationContext.Default.WorkItemArray);
}
return results is null ? null : new(results);
}
internal static void WriteMarkdown(ILogger<Worker> logger, List<string> args)
{
internal static void WriteMarkdown(ILogger<Worker> logger, List<string> args) {
// string url = args[5];
bool keepRelations = true;
string fileName = args[2];
@ -351,20 +323,17 @@ internal static partial class Helper20241108
string idCheck = sourceDirectoryName.Split('-', StringSplitOptions.None)[0];
if (!int.TryParse(idCheck, out int id))
logger.LogInformation("Not valid directory!");
else
{
else {
ReadOnlyCollection<WorkItem>? workItems = GetWorkItems(fileName, sourceDirectory);
if (workItems is null)
logger.LogInformation("No file found!");
else
{
else {
Record? record;
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(workItems, keepRelations);
logger.LogInformation("Found {keyValuePairs}", keyValuePairs.Count);
if (!keyValuePairs.TryGetValue(id, out record))
logger.LogInformation($"Id {id} not found!");
else
{
else {
logger.LogInformation($"Id {id} found with title {record.WorkItem.Title}!");
}
}
@ -373,8 +342,7 @@ internal static partial class Helper20241108
#else
internal static void WriteMarkdown(ILogger<Worker> logger, List<string> args)
{
internal static void WriteMarkdown(ILogger<Worker> logger, List<string> args) {
logger.LogError("WriteMarkdown is not available in WorkItems {args[0]}", args[0]);
logger.LogError("WriteMarkdown is not available in WorkItems {args[1]}", args[1]);
}