Ready to beta test

This commit is contained in:
2022-08-26 15:40:05 -07:00
parent 121c0c4d0c
commit b3e643c221
90 changed files with 5023 additions and 20 deletions

31
classlib/AppSettings.cs Normal file
View File

@ -0,0 +1,31 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library;
public class AppSettings
{
public string Company { init; get; }
public Client Client { init; get; }
public Excel Excel { init; get; }
public string WorkingDirectoryName { init; get; }
public string URLs { init; get; }
[JsonConstructor]
public AppSettings(Client client, string company, Excel excel, string workingDirectoryName, string urls)
{
Client = client;
Company = company;
Excel = excel;
WorkingDirectoryName = workingDirectoryName;
URLs = urls;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -0,0 +1,59 @@
using Microsoft.Extensions.Configuration;
using System.Text.Json;
namespace Mesa_Backlog.Library.Binder;
public class AppSettings
{
#nullable disable
public Client Client { get; set; }
public string Company { get; set; }
public Excel Excel { get; set; }
public string WorkingDirectoryName { get; set; }
public string URLs { get; set; }
#nullable restore
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
private static Library.AppSettings Get(AppSettings appSettings)
{
Library.AppSettings result;
Library.Client client = new(
appSettings.Client.API,
appSettings.Client.BaseAddress,
appSettings.Client.BasePage,
appSettings.Client.PAT,
appSettings.Client.Project,
appSettings.Client.Query
);
Library.Excel excel = new(
appSettings.Excel.Sheet,
appSettings.Excel.SourceFile,
appSettings.Excel.TargetFile
);
result = new(
client,
appSettings.Company,
excel,
appSettings.WorkingDirectoryName,
appSettings.URLs
);
return result;
}
public static Library.AppSettings Get(IConfigurationRoot configurationRoot)
{
Library.AppSettings result;
AppSettings appSettings = configurationRoot.Get<AppSettings>();
result = Get(appSettings);
return result;
}
}

48
classlib/Binder/Client.cs Normal file
View File

@ -0,0 +1,48 @@
using Microsoft.Extensions.Configuration;
using System.Text.Json;
namespace Mesa_Backlog.Library.Binder;
public class Client
{
#nullable disable
public string API { get; set; }
public string BaseAddress { get; set; }
public string BasePage { get; set; }
public string PAT { get; set; }
public string Project { get; set; }
public string Query { get; set; }
#nullable restore
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
private static Library.Client Get(Client client)
{
Library.Client result;
result = new(
client.API,
client.BaseAddress,
client.BasePage,
client.PAT,
client.Project,
client.Query
);
return result;
}
public static Library.Client Get(IConfigurationRoot configurationRoot)
{
Library.Client result;
Client client = configurationRoot.Get<Client>();
result = Get(client);
return result;
}
}

42
classlib/Binder/Excel.cs Normal file
View File

@ -0,0 +1,42 @@
using Microsoft.Extensions.Configuration;
using System.Text.Json;
namespace Mesa_Backlog.Library.Binder;
public class Excel
{
#nullable disable
public string Sheet { get; set; }
public string SourceFile { get; set; }
public string TargetFile { get; set; }
#nullable restore
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
private static Library.Excel Get(Excel excel)
{
Library.Excel result;
result = new(
excel.Sheet,
excel.SourceFile,
excel.TargetFile
);
return result;
}
public static Library.Excel Get(IConfigurationRoot configurationRoot)
{
Library.Excel result;
Excel excel = configurationRoot.Get<Excel>();
result = Get(excel);
return result;
}
}

40
classlib/Client.cs Normal file
View File

@ -0,0 +1,40 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library;
public class Client
{
public string API { init; get; }
public string BaseAddress { init; get; }
public string BasePage { init; get; }
public string PAT { init; get; }
public string Project { init; get; }
public string Query { init; get; }
[JsonConstructor]
public Client(
string api,
string baseAddress,
string basePage,
string pat,
string project,
string query
)
{
API = api;
BaseAddress = baseAddress;
BasePage = basePage;
PAT = pat;
Project = project;
Query = query;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

31
classlib/Excel.cs Normal file
View File

@ -0,0 +1,31 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library;
public class Excel
{
public string Sheet { init; get; }
public string SourceFile { init; get; }
public string TargetFile { init; get; }
[JsonConstructor]
public Excel(
string sheet,
string sourceFile,
string targetFile
)
{
Sheet = sheet;
SourceFile = sourceFile;
TargetFile = targetFile;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

121
classlib/ExcelReader.cs Normal file
View File

@ -0,0 +1,121 @@
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.Text.Json;
namespace Mesa_Backlog.Library;
public class ExcelReader
{
/// <summary>
/// https://social.msdn.microsoft.com/Forums/en-US/2e030743-5d66-4e53-bbff-bb2eee0cbc9b/readingwriting-excel-without-excel?forum=Vsexpressvcs
/// </summary>
private static DataTable GetSheet(string fileName, string selectSql)
{
DataTable results = new();
#if Linux
()("Built on Linux!");
#elif OSX
()("Built on macOS!");
#elif Windows || !NETCORE
#pragma warning disable CA1416
for (int i = 0; i < int.MaxValue; i++)
{
try
{
OleDbConnectionStringBuilder connectionStringBuilder = new()
{
Provider = "Microsoft.ACE.OLEDB.12.0",
DataSource = fileName
};
connectionStringBuilder.Add("Extended Properties", "Excel 12.0 Xml;HDR=YES;IMEX=1;ReadOnly=1;");
using OleDbConnection connection = new(connectionStringBuilder.ConnectionString);
connection.Open();
using (OleDbDataAdapter adapter = new(selectSql, connection))
adapter.Fill(results);
connection.Close();
break;
}
catch (Exception)
{
if (i > 3) //2019-12-28 - 001
throw;
Thread.Sleep(1000);
}
#pragma warning restore CA1416
}
#else
()("Built in unknown!");
#endif
return results;
}
private static string DataTableToJSON(DataTable table)
{
string name;
string value;
object @object;
StringBuilder jsonString = new();
if (table.Rows.Count > 0)
{
_ = jsonString.Append('[');
for (int i = 0; i < table.Rows.Count; i++)
{
_ = jsonString.Append('{');
for (int j = 0; j < table.Columns.Count; j++)
{
@object = table.Rows[i][j];
if (@object is null)
value = string.Empty;
else
value = string.Concat(@object);
if (value.Contains('"'))
value = value.Replace("\"", "\\\"");
if (value.Contains('\n'))
value = value.Replace("\t", " ").Replace("\n", "<br />");
name = table.Columns[j].ColumnName.ToString();
if (name == ",")
name = "Title";
if (name.Contains('"'))
name = name.Replace("\"", "\\\"");
if (name.Contains('\n'))
name = name.Replace("\t", " ").Replace("\n", "<br />");
_ = jsonString.Append('"').Append(name).Append("\":").Append('"').Append(value).Append('"');
if (j < table.Columns.Count - 1)
_ = jsonString.Append(',');
}
_ = jsonString.Append('}');
if (i != table.Rows.Count - 1)
_ = jsonString.Append(',');
}
_ = jsonString.Append(']');
}
return jsonString.ToString();
}
public static string GetJson(string reportFullPath, string sheet)
{
string result;
string selectSql = string.Concat("SELECT * FROM [", sheet, "$]");
using (DataTable dataTable = GetSheet(reportFullPath, selectSql))
{
if (dataTable.Rows.Count == 0)
throw new Exception("No rows");
result = DataTableToJSON(dataTable);
}
return result;
}
public static FIBacklogMesa[] GetFIBacklogMesaCollection(string json)
{
FIBacklogMesa[]? results;
results = JsonSerializer.Deserialize<FIBacklogMesa[]>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
if (results is null || !results.Any())
throw new NullReferenceException();
return results;
}
public static string GetJson(FIBacklogMesa[]? fIBacklogMesaCollection) => JsonSerializer.Serialize(fIBacklogMesaCollection, new JsonSerializerOptions() { WriteIndented = true });
}

129
classlib/FIBacklogMesa.cs Normal file
View File

@ -0,0 +1,129 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library;
public class FIBacklogMesa
{
[JsonConstructor]
public FIBacklogMesa(string req,
string submitted,
string requestor,
string assignedTo,
string secondResource,
string title,
string epiLine,
string area,
string systemS,
string priSort,
string priority,
string status,
string definition,
string updates,
string estEffortDays,
string commitDate,
string reCommitDate,
string uATAsOf,
string cMPDate,
string f20,
string f21,
string f22,
string f23,
string f24,
string f25,
string f26,
string f27,
string f28,
string f29,
string f30,
string f31,
string f32,
string f33)
{
Req = req;
Submitted = submitted;
Requestor = requestor;
AssignedTo = assignedTo;
SecondResource = secondResource;
Title = title;
EpiLine = epiLine;
Area = area;
SystemS = systemS;
PriSort = priSort;
Priority = priority;
Status = status;
Definition = definition;
Updates = updates;
EstEffortDays = estEffortDays;
CommitDate = commitDate;
ReCommitDate = reCommitDate;
UATAsOf = uATAsOf;
CMPDate = cMPDate;
F20 = f20;
F21 = f21;
F22 = f22;
F23 = f23;
F24 = f24;
F25 = f25;
F26 = f26;
F27 = f27;
F28 = f28;
F29 = f29;
F30 = f30;
F31 = f31;
F32 = f32;
F33 = f33;
}
[JsonPropertyName("Req ")]
public string Req { get; set; } // { init; get; }
public string Submitted { get; set; } // { init; get; }
public string Requestor { get; set; } // { init; get; }
[JsonPropertyName("Assigned To ")]
public string AssignedTo { get; set; } // { init; get; }
[JsonPropertyName("Second Resource")]
public string SecondResource { get; set; } // { init; get; }
public string Title { get; set; } // { init; get; }
[JsonPropertyName("Epi Line")]
public string EpiLine { get; set; } // { init; get; }
public string Area { get; set; } // { init; get; }
[JsonPropertyName("System(s)")]
public string SystemS { get; set; } // { init; get; }
[JsonPropertyName("Pri Sort")]
public string PriSort { get; set; } // { init; get; }
public string Priority { get; set; } // { init; get; }
public string Status { get; set; } // { init; get; }
public string Definition { get; set; } // { init; get; }
public string Updates { get; set; } // { init; get; }
[JsonPropertyName("Est Effort _(days)")]
public string EstEffortDays { get; set; } // { init; get; }
[JsonPropertyName("Commit Date ")]
public string CommitDate { get; set; } // { init; get; }
[JsonPropertyName("Re-Commit Date ")]
public string ReCommitDate { get; set; } // { init; get; }
[JsonPropertyName("UAT as of ")]
public string UATAsOf { get; set; } // { init; get; }
public string CMPDate { get; set; } // { init; get; }
public string F20 { get; set; } // { init; get; }
public string F21 { get; set; } // { init; get; }
public string F22 { get; set; } // { init; get; }
public string F23 { get; set; } // { init; get; }
public string F24 { get; set; } // { init; get; }
public string F25 { get; set; } // { init; get; }
public string F26 { get; set; } // { init; get; }
public string F27 { get; set; } // { init; get; }
public string F28 { get; set; } // { init; get; }
public string F29 { get; set; } // { init; get; }
public string F30 { get; set; } // { init; get; }
public string F31 { get; set; } // { init; get; }
public string F32 { get; set; } // { init; get; }
public string F33 { get; set; } // { init; get; }
}

55
classlib/HttpClient.cs Normal file
View File

@ -0,0 +1,55 @@
using Mesa_Backlog.Library.WorkItems;
using System.Text.Json;
namespace Mesa_Backlog.Library;
public class HttpClient
{
public static Root GetWorkItem(System.Net.Http.HttpClient httpClient, string basePage, string api, int id)
{
Root result;
Task<HttpResponseMessage> httpResponseMessageTask = httpClient.GetAsync(string.Concat(basePage, api, "/workItems/", id));
httpResponseMessageTask.Wait();
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
throw new Exception(httpResponseMessageTask.Result.StatusCode.ToString());
Task<Stream> streamTask = httpResponseMessageTask.Result.Content.ReadAsStreamAsync();
streamTask.Wait();
if (!streamTask.Result.CanRead)
{
JsonElement? jsonElement = JsonSerializer.Deserialize<JsonElement>(streamTask.Result);
if (jsonElement is null)
throw new NullReferenceException(nameof(jsonElement));
}
Root? root = JsonSerializer.Deserialize<Root>(streamTask.Result, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
streamTask.Result.Dispose();
if (root is null || root.Fields is null)
throw new NullReferenceException(nameof(root));
result = root;
return result;
}
public static WIQL.WorkItem[] GetWorkItems(System.Net.Http.HttpClient httpClient, string basePage, string api, string query)
{
WIQL.WorkItem[] results;
Task<HttpResponseMessage> httpResponseMessageTask = httpClient.GetAsync(string.Concat(basePage, api, query));
httpResponseMessageTask.Wait();
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
throw new Exception(httpResponseMessageTask.Result.StatusCode.ToString());
Task<Stream> streamTask = httpResponseMessageTask.Result.Content.ReadAsStreamAsync();
streamTask.Wait();
if (!streamTask.Result.CanRead)
{
JsonElement? jsonElement = JsonSerializer.Deserialize<JsonElement>(streamTask.Result);
if (jsonElement is null)
throw new NullReferenceException(nameof(jsonElement));
}
WIQL.Root? root = JsonSerializer.Deserialize<WIQL.Root>(streamTask.Result, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
streamTask.Result.Dispose();
if (root is null || root.WorkItems is null)
throw new NullReferenceException(nameof(root));
results = root.WorkItems;
return results;
}
}

View File

@ -0,0 +1,8 @@
namespace Mesa_Backlog.Library;
public interface IWorkingDirectory
{
static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName) => WorkingDirectory.GetWorkingDirectory(executingAssemblyName, subDirectoryName);
}

167
classlib/IsEnvironment.cs Normal file
View File

@ -0,0 +1,167 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Mesa_Backlog.Library;
public class IsEnvironment
{
public enum Name
{
LinuxDevelopment,
LinuxProduction,
LinuxStaging,
OSXDevelopment,
OSXProduction,
OSXStaging,
WindowsDevelopment,
WindowsProduction,
WindowsStaging
}
public bool DebuggerWasAttachedDuringConstructor { get; private set; }
public bool Development { get; private set; }
public bool Linux { get; private set; }
public bool OSX { get; private set; }
public bool Production { get; private set; }
public bool Staging { get; private set; }
public bool Windows { get; private set; }
public string Profile { get; private set; }
public string AppSettingsFileName { get; private set; }
public string? ASPNetCoreEnvironment { get; private set; }
public IsEnvironment(string testCategory)
{
if (testCategory.EndsWith(".json"))
{
Production = testCategory == "appsettings.json";
Staging = testCategory.Contains(nameof(Staging));
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
Development = testCategory.Contains(nameof(Development));
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
}
else
{
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
OSX = !string.IsNullOrEmpty(testCategory) && testCategory.StartsWith(nameof(OSX));
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Linux = !string.IsNullOrEmpty(testCategory) && testCategory.StartsWith(nameof(Linux));
Staging = !string.IsNullOrEmpty(testCategory) && testCategory.EndsWith(nameof(Staging));
Windows = !string.IsNullOrEmpty(testCategory) && testCategory.StartsWith(nameof(Windows));
Production = !string.IsNullOrEmpty(testCategory) && testCategory.EndsWith(nameof(Production));
Development = !string.IsNullOrEmpty(testCategory) && testCategory.EndsWith(nameof(Development));
}
Profile = GetProfile();
AppSettingsFileName = GetAppSettingsFileName(processesCount: null);
}
public IsEnvironment(bool isDevelopment, bool isStaging, bool isProduction)
{
Staging = isStaging;
Production = isProduction;
Development = isDevelopment;
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Profile = GetProfile();
AppSettingsFileName = GetAppSettingsFileName(processesCount: null);
}
public IsEnvironment(int? processesCount, bool nullASPNetCoreEnvironmentIsDevelopment, bool nullASPNetCoreEnvironmentIsProduction)
{
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
ASPNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (nullASPNetCoreEnvironmentIsDevelopment && nullASPNetCoreEnvironmentIsProduction)
throw new Exception();
else if (string.IsNullOrEmpty(ASPNetCoreEnvironment) && nullASPNetCoreEnvironmentIsProduction)
Production = true;
else if (string.IsNullOrEmpty(ASPNetCoreEnvironment) && nullASPNetCoreEnvironmentIsDevelopment)
Development = true;
else if (string.IsNullOrEmpty(ASPNetCoreEnvironment) && !nullASPNetCoreEnvironmentIsDevelopment && !nullASPNetCoreEnvironmentIsProduction)
throw new Exception();
else
{
Staging = ASPNetCoreEnvironment is not null && ASPNetCoreEnvironment.EndsWith(nameof(Staging));
Production = ASPNetCoreEnvironment is not null && ASPNetCoreEnvironment.EndsWith(nameof(Production));
Development = ASPNetCoreEnvironment is not null && ASPNetCoreEnvironment.EndsWith(nameof(Development));
}
Profile = GetProfile();
AppSettingsFileName = GetAppSettingsFileName(processesCount);
}
private string GetProfile()
{
string result;
if (Windows && Production)
result = nameof(Production);
else if (Windows && Staging)
result = nameof(Staging);
else if (Windows && Development)
result = nameof(Development);
else if (Linux && Production)
result = nameof(Name.LinuxProduction);
else if (Linux && Staging)
result = nameof(Name.LinuxStaging);
else if (Linux && Development)
result = nameof(Name.LinuxDevelopment);
else if (OSX && Production)
result = nameof(Name.OSXProduction);
else if (OSX && Staging)
result = nameof(Name.OSXStaging);
else if (OSX && Development)
result = nameof(Name.OSXDevelopment);
else
throw new Exception();
return result;
}
private string GetAppSettingsFileName(int? processesCount)
{
string result;
if (Production)
{
if (processesCount is null)
result = "appsettings.json";
else
result = $"appsettings.{processesCount}.json";
}
else
{
string environment;
if (Staging)
environment = nameof(Staging);
else if (Development)
environment = nameof(Development);
else
throw new Exception();
if (processesCount is null)
result = $"appsettings.{environment}.json";
else
result = $"appsettings.{environment}.{processesCount}.json";
}
return result;
}
public static string GetEnvironmentName(IsEnvironment isEnvironment)
{
string result;
if (isEnvironment.Windows)
result = nameof(Windows);
else if (isEnvironment.Linux)
result = nameof(Linux);
else if (isEnvironment.OSX)
result = nameof(OSX);
else
throw new Exception();
return result;
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>6.0.303.1</Version>
<Company>Infineon Technologies Americas Corp.</Company>
<Authors>Mike Phares</Authors>
<PackageId>Infineon.Mesa.Library.Backlog</PackageId>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Data.OleDb" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.3" />
</ItemGroup>
</Project>

22
classlib/WIQL/Column.cs Normal file
View File

@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WIQL;
public class Column
{
[JsonConstructor]
public Column(
string referenceName,
string name,
string url
)
{
ReferenceName = referenceName;
Name = name;
Url = url;
}
public string ReferenceName { init; get; }
public string Name { init; get; }
public string Url { init; get; }
}

22
classlib/WIQL/Field.cs Normal file
View File

@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WIQL;
public class Field
{
[JsonConstructor]
public Field(
string referenceName,
string name,
string url
)
{
ReferenceName = referenceName;
Name = name;
Url = url;
}
public string ReferenceName { init; get; }
public string Name { init; get; }
public string Url { init; get; }
}

31
classlib/WIQL/Root.cs Normal file
View File

@ -0,0 +1,31 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WIQL;
public class Root
{
[JsonConstructor]
public Root(
string queryType,
string queryResultType,
DateTime asOf,
Column[] columns,
SortColumn[] sortColumns,
WorkItem[] workItems
)
{
QueryType = queryType;
QueryResultType = queryResultType;
AsOf = asOf;
Columns = columns;
SortColumns = sortColumns;
WorkItems = workItems;
}
public string QueryType { init; get; }
public string QueryResultType { init; get; }
public DateTime AsOf { init; get; }
public Column[] Columns { init; get; }
public SortColumn[] SortColumns { init; get; }
public WorkItem[] WorkItems { init; get; }
}

View File

@ -0,0 +1,19 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WIQL;
public class SortColumn
{
[JsonConstructor]
public SortColumn(
Field field,
bool descending
)
{
Field = field;
Descending = descending;
}
public Field Field { init; get; }
public bool Descending { init; get; }
}

19
classlib/WIQL/WorkItem.cs Normal file
View File

@ -0,0 +1,19 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WIQL;
public class WorkItem
{
[JsonConstructor]
public WorkItem(
int id,
string url
)
{
Id = id;
Url = url;
}
public int Id { init; get; }
public string Url { init; get; }
}

View File

@ -0,0 +1,91 @@
using System.Text;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.WebApi.Patch;
using Microsoft.VisualStudio.Services.WebApi.Patch.Json;
using WebApi = Microsoft.TeamFoundation.WorkItemTracking.WebApi;
namespace Mesa_Backlog.Library;
public class WorkItemTrackingHttpClient
{
private static void AddPatch(JsonPatchDocument document, string path, object value) => document.Add(new JsonPatchOperation { From = null, Operation = Operation.Add, Path = path, Value = value });
private static void ReplacePatch(JsonPatchDocument document, string path, object value) => document.Add(new JsonPatchOperation { From = null, Operation = Operation.Replace, Path = path, Value = value });
public static (string, JsonPatchDocument) GetCreate(bool development, FIBacklogMesa fIBacklogMesa)
{
JsonPatchDocument result = new();
string state = "New";
string iterationPath = $@"Mesa_FI\{fIBacklogMesa.Status}";
string systemAreaPath = $@"Mesa_FI\{fIBacklogMesa.SystemS}";
string title = fIBacklogMesa.Title.Length > 254 ? fIBacklogMesa.Title[..255] : fIBacklogMesa.Title;
string priority = fIBacklogMesa.Priority switch { "BugFix" => "1", "High" => "1", "Med" => "2", "Low" => "3", "TBD" => "4", _ => "4" };
string workItemType = fIBacklogMesa.Priority switch { "BugFix" => "Bug", "High" or "Med" or "Low" or "TBD" => "Feature", _ => "Feature" };
StringBuilder systemInfo = new();
_ = systemInfo.
Append("Req : ").Append(fIBacklogMesa.Req).Append("<br />").
Append("Requestor : ").Append(fIBacklogMesa.Requestor).Append("<br />").
Append("Submitted : ").Append(fIBacklogMesa.Submitted).Append("<br />").
Append("Assigned To : ").Append(fIBacklogMesa.AssignedTo).Append("<br />").
Append("Commit Date : ").Append(fIBacklogMesa.CommitDate).Append("<br />").
Append("Re-Commit Date : ").Append(fIBacklogMesa.ReCommitDate).Append("<br />").
Append("UAT as of : ").Append(fIBacklogMesa.UATAsOf).Append("<br />").
Append("CMP Date : ").Append(fIBacklogMesa.CMPDate);
string systemAssignedToDisplayName = fIBacklogMesa.Requestor switch
{
"Mike" => "Mike.Phares@infineon.com",
_ => string.Empty
};
AddPatch(result, "/fields/System.State", state);
AddPatch(result, "/fields/System.Title", title);
// AddPatch(result, "/fields/System.Comment", fIBacklogMesa.Updates);
AddPatch(result, "/fields/Microsoft.VSTS.Common.Priority", priority);
AddPatch(result, "/fields/Microsoft.VSTS.TCM.SystemInfo", systemInfo.ToString());
AddPatch(result, "/fields/System.Description", fIBacklogMesa.Definition);
if (!development)
AddPatch(result, "/fields/System.AreaPath", systemAreaPath);
if (!development)
AddPatch(result, "/fields/System.IterationPath", iterationPath);
if (!string.IsNullOrEmpty(fIBacklogMesa.AssignedTo))
AddPatch(result, "/fields/System.Tags", fIBacklogMesa.AssignedTo);
if (!string.IsNullOrEmpty(fIBacklogMesa.Submitted) && DateTime.TryParse(fIBacklogMesa.Submitted, out DateTime submitted))
AddPatch(result, "/fields/System.CreatedDate", submitted.ToString("MM/dd/yyyy hh:mm tt"));
if (!string.IsNullOrEmpty(systemAssignedToDisplayName))
AddPatch(result, "/fields/System.AssignedTo", systemAssignedToDisplayName);
// if (!string.IsNullOrEmpty(fIBacklogMesa.CMPDate) && DateTime.TryParse(fIBacklogMesa.CMPDate, out DateTime completedDate))
// AddPatch(result, "/fields/Microsoft.VSTS.Common.ClosedDate", completedDate);
// if (!string.IsNullOrEmpty(fIBacklogMesa.UATAsOf) && DateTime.TryParse(fIBacklogMesa.UATAsOf, out DateTime uatAsOfDate))
// AddPatch(result, "/fields/Microsoft.VSTS.Common.ResolvedDate", uatAsOfDate);
if (!string.IsNullOrEmpty(fIBacklogMesa.CommitDate) && DateTime.TryParse(fIBacklogMesa.CommitDate, out DateTime commitDate))
AddPatch(result, "/fields/Microsoft.VSTS.Scheduling.TargetDate", commitDate.ToString("MM/dd/yyyy hh:mm tt"));
if (!string.IsNullOrEmpty(fIBacklogMesa.EstEffortDays))
AddPatch(result, "/fields/Microsoft.VSTS.Scheduling.Effort", fIBacklogMesa.EstEffortDays);
return (workItemType, result);
}
public static Task<WorkItem> CreateWorkItem(bool development, WebApi.WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, FIBacklogMesa fIBacklogMesa)
{
Task<WorkItem> result;
(string workItemType, JsonPatchDocument document) = GetCreate(development, fIBacklogMesa);
result = workItemTrackingHttpClient.CreateWorkItemAsync(document, project, workItemType);
return result;
}
public static JsonPatchDocument GetUpdate(FIBacklogMesa fIBacklogMesa)
{
JsonPatchDocument result = new();
string title = fIBacklogMesa.Title.Length > 254 ? fIBacklogMesa.Title[..255] : fIBacklogMesa.Title;
ReplacePatch(result, "/fields/System.Title", title);
ReplacePatch(result, "/fields/System.Description", fIBacklogMesa.Definition);
return result;
}
public static Task<WorkItem> UpdateWorkItem(WebApi.WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, int id, FIBacklogMesa fIBacklogMesa)
{
Task<WorkItem> result;
JsonPatchDocument document = GetUpdate(fIBacklogMesa);
result = workItemTrackingHttpClient.UpdateWorkItemAsync(document, project, id);
return result;
}
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class Avatar
{
[JsonConstructor]
public Avatar(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,179 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class Fields
{
[JsonConstructor]
public Fields(string systemAreaPath,
string systemTeamProject,
string systemIterationPath,
string systemWorkItemType,
string systemState,
string systemReason,
User systemAssignedTo,
DateTime systemCreatedDate,
User systemCreatedBy,
DateTime systemChangedDate,
User systemChangedBy,
int systemCommentCount,
string systemTitle,
string systemBoardColumn,
bool systemBoardColumnDone,
DateTime microsoftVSTSCommonStateChangeDate,
DateTime microsoftVSTSCommonActivatedDate,
User microsoftVSTSCommonActivatedBy,
DateTime microsoftVSTSCommonResolvedDate,
User microsoftVSTSCommonResolvedBy,
DateTime microsoftVSTSCommonClosedDate,
User microsoftVSTSCommonClosedBy,
int microsoftVSTSCommonPriority,
double microsoftVSTSSchedulingEffort,
DateTime microsoftVSTSSchedulingTargetDate,
double microsoftVSTSCommonStackRank,
string microsoftVSTSCommonValueArea,
string microsoftVSTSTCMSystemInfo,
string wEF81590F0A22C04FEF834957660F5F0C58KanbanColumn,
bool wEF81590F0A22C04FEF834957660F5F0C58KanbanColumnDone,
string systemDescription,
string systemHistory,
string systemTags,
string href)
{
SystemAreaPath = systemAreaPath;
SystemTeamProject = systemTeamProject;
SystemIterationPath = systemIterationPath;
SystemWorkItemType = systemWorkItemType;
SystemState = systemState;
SystemReason = systemReason;
SystemAssignedTo = systemAssignedTo;
SystemCreatedDate = systemCreatedDate;
SystemCreatedBy = systemCreatedBy;
SystemChangedDate = systemChangedDate;
SystemChangedBy = systemChangedBy;
SystemCommentCount = systemCommentCount;
SystemTitle = systemTitle;
SystemBoardColumn = systemBoardColumn;
SystemBoardColumnDone = systemBoardColumnDone;
MicrosoftVSTSCommonStateChangeDate = microsoftVSTSCommonStateChangeDate;
MicrosoftVSTSCommonActivatedDate = microsoftVSTSCommonActivatedDate;
MicrosoftVSTSCommonActivatedBy = microsoftVSTSCommonActivatedBy;
MicrosoftVSTSCommonClosedBy = microsoftVSTSCommonClosedBy;
MicrosoftVSTSCommonClosedDate = microsoftVSTSCommonClosedDate;
MicrosoftVSTSCommonPriority = microsoftVSTSCommonPriority;
MicrosoftVSTSCommonResolvedBy = microsoftVSTSCommonResolvedBy;
MicrosoftVSTSCommonResolvedDate = microsoftVSTSCommonResolvedDate;
MicrosoftVSTSCommonStackRank = microsoftVSTSCommonStackRank;
MicrosoftVSTSCommonValueArea = microsoftVSTSCommonValueArea;
MicrosoftVSTSSchedulingEffort = microsoftVSTSSchedulingEffort;
MicrosoftVSTSSchedulingTargetDate = microsoftVSTSSchedulingTargetDate;
MicrosoftVSTSTCMSystemInfo = microsoftVSTSTCMSystemInfo;
WEF81590F0A22C04FEF834957660F5F0C58KanbanColumn = wEF81590F0A22C04FEF834957660F5F0C58KanbanColumn;
WEF81590F0A22C04FEF834957660F5F0C58KanbanColumnDone = wEF81590F0A22C04FEF834957660F5F0C58KanbanColumnDone;
SystemDescription = systemDescription;
SystemHistory = systemHistory;
SystemTags = systemTags;
Href = href;
}
[JsonPropertyName("System.AreaPath")]
public string SystemAreaPath { init; get; }
[JsonPropertyName("System.TeamProject")]
public string SystemTeamProject { init; get; }
[JsonPropertyName("System.IterationPath")]
public string SystemIterationPath { init; get; }
[JsonPropertyName("System.WorkItemType")]
public string SystemWorkItemType { init; get; }
[JsonPropertyName("System.State")]
public string SystemState { init; get; }
[JsonPropertyName("System.Reason")]
public string SystemReason { init; get; }
[JsonPropertyName("System.AssignedTo")]
public User SystemAssignedTo { init; get; }
[JsonPropertyName("System.CreatedDate")]
public DateTime SystemCreatedDate { init; get; }
[JsonPropertyName("System.CreatedBy")]
public User SystemCreatedBy { init; get; }
[JsonPropertyName("System.ChangedDate")]
public DateTime SystemChangedDate { init; get; }
[JsonPropertyName("System.ChangedBy")]
public User SystemChangedBy { init; get; }
[JsonPropertyName("System.CommentCount")]
public int SystemCommentCount { init; get; }
[JsonPropertyName("System.Title")]
public string SystemTitle { init; get; }
[JsonPropertyName("System.BoardColumn")]
public string SystemBoardColumn { init; get; }
[JsonPropertyName("System.BoardColumnDone")]
public bool SystemBoardColumnDone { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.StateChangeDate")]
public DateTime MicrosoftVSTSCommonStateChangeDate { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.ActivatedDate")]
public DateTime MicrosoftVSTSCommonActivatedDate { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.ActivatedBy")]
public User MicrosoftVSTSCommonActivatedBy { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.ResolvedDate")]
public DateTime MicrosoftVSTSCommonResolvedDate { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.ResolvedBy")]
public User MicrosoftVSTSCommonResolvedBy { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.ClosedDate")]
public DateTime MicrosoftVSTSCommonClosedDate { get; }
[JsonPropertyName("Microsoft.VSTS.Common.ClosedBy")]
public User MicrosoftVSTSCommonClosedBy { get; }
[JsonPropertyName("Microsoft.VSTS.Common.Priority")]
public int MicrosoftVSTSCommonPriority { init; get; }
[JsonPropertyName("Microsoft.VSTS.Scheduling.Effort")]
public double MicrosoftVSTSSchedulingEffort { init; get; }
[JsonPropertyName("Microsoft.VSTS.Scheduling.TargetDate")]
public DateTime MicrosoftVSTSSchedulingTargetDate { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.StackRank")]
public double MicrosoftVSTSCommonStackRank { init; get; }
[JsonPropertyName("Microsoft.VSTS.Common.ValueArea")]
public string MicrosoftVSTSCommonValueArea { init; get; }
[JsonPropertyName("Microsoft.VSTS.TCM.SystemInfo")]
public string MicrosoftVSTSTCMSystemInfo { init; get; }
[JsonPropertyName("WEF_81590F0A22C04FEF834957660F5F0C58_Kanban.Column")]
public string WEF81590F0A22C04FEF834957660F5F0C58KanbanColumn { init; get; }
[JsonPropertyName("WEF_81590F0A22C04FEF834957660F5F0C58_Kanban.Column.Done")]
public bool WEF81590F0A22C04FEF834957660F5F0C58KanbanColumnDone { init; get; }
[JsonPropertyName("System.Description")]
public string SystemDescription { init; get; }
[JsonPropertyName("System.History")]
public string SystemHistory { init; get; }
[JsonPropertyName("System.Tags")]
public string SystemTags { init; get; }
public string Href { init; get; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class Html
{
[JsonConstructor]
public Html(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,37 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class Links
{
[JsonConstructor]
public Links(
Avatar avatar,
Self self,
WorkItemUpdates workItemUpdates,
WorkItemRevisions workItemRevisions,
WorkItemComments workItemComments,
Html html,
WorkItemType workItemType,
Fields fields
)
{
Avatar = avatar;
Self = self;
WorkItemUpdates = workItemUpdates;
WorkItemRevisions = workItemRevisions;
WorkItemComments = workItemComments;
Html = html;
WorkItemType = workItemType;
Fields = fields;
}
public Avatar Avatar { init; get; }
public Self Self { init; get; }
public WorkItemUpdates WorkItemUpdates { init; get; }
public WorkItemRevisions WorkItemRevisions { init; get; }
public WorkItemComments WorkItemComments { init; get; }
public Html Html { init; get; }
public WorkItemType WorkItemType { init; get; }
public Fields Fields { init; get; }
}

View File

@ -0,0 +1,30 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class Root
{
[JsonConstructor]
public Root(
int id,
int rev,
Fields fields,
Links links,
string url
)
{
Id = id;
Rev = rev;
Fields = fields;
Links = links;
Url = url;
}
public int Id { init; get; }
public int Rev { init; get; }
public Fields Fields { init; get; }
[JsonPropertyName("_links")]
public Links Links { init; get; }
public string Url { init; get; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class Self
{
[JsonConstructor]
public Self(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,34 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class User
{
[JsonConstructor]
public User(
string displayName,
string url,
Links links,
string id,
string uniqueName,
string imageUrl,
string descriptor
)
{
DisplayName = displayName;
Url = url;
Links = links;
Id = id;
UniqueName = uniqueName;
ImageUrl = imageUrl;
Descriptor = descriptor;
}
public string DisplayName { init; get; }
public string Url { init; get; }
public Links Links { init; get; }
public string Id { init; get; }
public string UniqueName { init; get; }
public string ImageUrl { init; get; }
public string Descriptor { init; get; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class WorkItemComments
{
[JsonConstructor]
public WorkItemComments(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class WorkItemRevisions
{
[JsonConstructor]
public WorkItemRevisions(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class WorkItemType
{
[JsonConstructor]
public WorkItemType(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace Mesa_Backlog.Library.WorkItems;
public class WorkItemUpdates
{
[JsonConstructor]
public WorkItemUpdates(
string href
) => Href = href;
public string Href { init; get; }
}

View File

@ -0,0 +1,50 @@
namespace Mesa_Backlog.Library;
internal abstract class WorkingDirectory
{
internal static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName)
{
string result = string.Empty;
if (executingAssemblyName is null)
throw new Exception();
string traceFile;
List<string> directories = new();
Environment.SpecialFolder[] specialFolders = new Environment.SpecialFolder[]
{
Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolder.ApplicationData,
Environment.SpecialFolder.History,
Environment.SpecialFolder.CommonApplicationData,
Environment.SpecialFolder.InternetCache
};
foreach (Environment.SpecialFolder specialFolder in specialFolders)
directories.Add(Path.Combine(Environment.GetFolderPath(specialFolder), subDirectoryName, executingAssemblyName));
foreach (string directory in directories)
{
for (int i = 1; i < 3; i++)
{
if (i == 1)
result = directory;
else
result = string.Concat("D", directory[1..]);
try
{
if (!Directory.Exists(result))
_ = Directory.CreateDirectory(result);
traceFile = string.Concat(result, @"\", DateTime.Now.Ticks, ".txt");
File.WriteAllText(traceFile, traceFile);
File.Delete(traceFile);
break;
}
catch (Exception) { result = string.Empty; }
}
if (!string.IsNullOrEmpty(result))
break;
}
if (string.IsNullOrEmpty(result))
throw new Exception("Unable to set working directory!");
return result;
}
}