Try Catch on Serialize
Better Relation Data
This commit is contained in:
@ -11,7 +11,9 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace Adaptation.FileHandlers.json;
|
||||
@ -111,14 +113,54 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
|
||||
#nullable enable
|
||||
|
||||
private static ReadOnlyCollection<WorkItem> GetWorkItems(ReadOnlyCollection<Value> valueWithReqCollection)
|
||||
private static string GetParamCase(string value)
|
||||
{
|
||||
List<WorkItem> results = new();
|
||||
string result;
|
||||
StringBuilder stringBuilder = new(value);
|
||||
List<Match> matches = new();
|
||||
MatchCollection matchCollection = Regex.Matches(value, "([A-Z]+(.))");
|
||||
foreach (object? item in matchCollection)
|
||||
{
|
||||
if (item is not Match match)
|
||||
continue;
|
||||
matches.Add(match);
|
||||
}
|
||||
for (int i = matches.Count - 1; i > -1; i--)
|
||||
_ = stringBuilder.Insert(matches[i].Index, '-');
|
||||
string[] segments = Regex.Split(stringBuilder.ToString().ToLower(), "[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+");
|
||||
result = string.Join("-", segments).Trim('-');
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, WorkItem> GetKeyValuePairs(ReadOnlyCollection<Value> valueWithReqCollection)
|
||||
{
|
||||
Dictionary<int, WorkItem> results = new();
|
||||
Fields fields;
|
||||
WorkItem workItem;
|
||||
Relation relation;
|
||||
string[] segments;
|
||||
List<Relation> relations;
|
||||
WorkItems.Attribute attributes;
|
||||
foreach (Value value in valueWithReqCollection)
|
||||
{
|
||||
relations = new();
|
||||
fields = value.Fields;
|
||||
if (value.Relations is not null)
|
||||
{
|
||||
foreach (WIQL.Relation r in value.Relations)
|
||||
{
|
||||
segments = r?.Attributes is null ? Array.Empty<string>() : r.URL.Split('/');
|
||||
if (segments.Length < 2)
|
||||
continue;
|
||||
if (r?.Attributes is null)
|
||||
continue;
|
||||
if (!int.TryParse(segments[segments.Length - 1], out int id))
|
||||
continue;
|
||||
attributes = new(r.Attributes.IsLocked, r.Attributes.Name, null, null, null);
|
||||
relation = new(attributes, id, r.Rel);
|
||||
relations.Add(relation);
|
||||
}
|
||||
}
|
||||
workItem = new(fields.MicrosoftVSTSCommonActivatedDate == DateTime.MinValue ? null : fields.MicrosoftVSTSCommonActivatedDate,
|
||||
fields.SystemAreaPath,
|
||||
fields.SystemAssignedTo?.DisplayName,
|
||||
@ -133,7 +175,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
fields.SystemIterationPath,
|
||||
fields.SystemParent == 0 ? null : fields.SystemParent,
|
||||
fields.MicrosoftVSTSCommonPriority == 0 ? null : fields.MicrosoftVSTSCommonPriority,
|
||||
value.Relations,
|
||||
relations.ToArray(),
|
||||
fields.CustomRequester?.DisplayName,
|
||||
fields.MicrosoftVSTSCommonResolvedDate == DateTime.MinValue ? null : fields.MicrosoftVSTSCommonResolvedDate,
|
||||
value.Rev,
|
||||
@ -143,10 +185,41 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
fields.SystemTags,
|
||||
fields.MicrosoftVSTSSchedulingTargetDate == DateTime.MinValue ? null : fields.MicrosoftVSTSSchedulingTargetDate,
|
||||
fields.MicrosoftVSTSCommonTimeCriticality is null or 0 ? null : (long)fields.MicrosoftVSTSCommonTimeCriticality,
|
||||
fields.SystemTitle,
|
||||
fields.SystemTitle.Trim(),
|
||||
null,
|
||||
fields.CustomWSJF is null or 0 ? null : (long)fields.CustomWSJF,
|
||||
fields.SystemWorkItemType);
|
||||
results.Add(workItem.Id, workItem);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<WorkItem> GetWorkItems(ReadOnlyCollection<Value> valueWithReqCollection)
|
||||
{
|
||||
List<WorkItem> results = new();
|
||||
WorkItem workItem;
|
||||
Relation relation;
|
||||
string parameterTitle;
|
||||
List<Relation> relations;
|
||||
WorkItem? relationWorkItem;
|
||||
WorkItems.Attribute attributes;
|
||||
ReadOnlyDictionary<int, WorkItem> keyValuePairs = GetKeyValuePairs(valueWithReqCollection);
|
||||
foreach (KeyValuePair<int, WorkItem> keyValuePair in keyValuePairs)
|
||||
{
|
||||
relations = new();
|
||||
if (keyValuePair.Value.Relations is not null)
|
||||
{
|
||||
foreach (Relation r in keyValuePair.Value.Relations)
|
||||
{
|
||||
if (!keyValuePairs.TryGetValue(r.Id, out relationWorkItem))
|
||||
continue;
|
||||
parameterTitle = GetParamCase(relationWorkItem.Title);
|
||||
attributes = new(r.Attributes.IsLocked, r.Attributes.Name, parameterTitle, relationWorkItem.State, relationWorkItem.WorkItemType);
|
||||
relation = new(attributes, r.Id, r.Rel);
|
||||
relations.Add(relation);
|
||||
}
|
||||
}
|
||||
workItem = WorkItem.Get(keyValuePair.Value, relations.ToArray());
|
||||
results.Add(workItem);
|
||||
}
|
||||
return new(results);
|
||||
@ -237,7 +310,10 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
{
|
||||
_SMTP.SendHighPriorityEmailMessage(subject, body);
|
||||
File.WriteAllText(".email", body);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
try
|
||||
@ -252,7 +328,10 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
{
|
||||
_SMTP.SendHighPriorityEmailMessage(subject, body);
|
||||
File.WriteAllText(".email", body);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user