Added new WPF client and accomodated folder structure
This commit is contained in:
@@ -1,265 +1,265 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Security;
|
||||
using WD7UVN_HFT_2023241.Models;
|
||||
|
||||
namespace WD7UVN_HFT_2023241.Client
|
||||
{
|
||||
class RestService
|
||||
{
|
||||
private static HttpClient client;
|
||||
|
||||
private static bool Ping(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
|
||||
|
||||
WebClient wc = new WebClient();
|
||||
wc.DownloadData(url);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger")
|
||||
{
|
||||
int tries = 0;
|
||||
bool isOk = false;
|
||||
do
|
||||
{
|
||||
isOk = Ping(baseurl + pingableEndpoint);
|
||||
tries++;
|
||||
} while (isOk == false && tries < 5);
|
||||
|
||||
if (isOk == false)
|
||||
{
|
||||
throw new EndpointNotAvailableException("Endpoint is not available!");
|
||||
}
|
||||
|
||||
HttpClientHandler handler = new HttpClientHandler();
|
||||
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
|
||||
handler.ServerCertificateCustomValidationCallback =
|
||||
(httpRequestMessage, cert, cetChain, policyErrors) =>
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
client = new HttpClient(handler);
|
||||
client.BaseAddress = new Uri(baseurl);
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue
|
||||
("application/json"));
|
||||
try
|
||||
{
|
||||
client.GetAsync("").GetAwaiter().GetResult();
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
throw new ArgumentException("Endpoint is not available!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<T> Get<T>(string endpoint)
|
||||
{
|
||||
List<T> items = new List<T>();
|
||||
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
items = response.Content.ReadAsAsync<List<T>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static T GetSingle<T>(string endpoint)
|
||||
{
|
||||
T item = default(T);
|
||||
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static T Get<T>(int id, string endpoint)
|
||||
{
|
||||
T item = default(T);
|
||||
HttpResponseMessage response = client.GetAsync(endpoint + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void Post<T>(T item, string endpoint)
|
||||
{
|
||||
HttpResponseMessage response =
|
||||
client.PostAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static void Delete(int id, string endpoint)
|
||||
{
|
||||
HttpResponseMessage response =
|
||||
client.DeleteAsync(endpoint + id.ToString()).GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static void Put<T>(T item, string endpoint)
|
||||
{
|
||||
HttpResponseMessage response =
|
||||
client.PutAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static List<Employee> WhoWorksInMaintainerTeam(int id)
|
||||
{
|
||||
var item = default(List<Employee>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoWorksInMaintainerTeam?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Employee>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Employee> GetSubordinates(int id)
|
||||
{
|
||||
var item = default(List<Employee>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/GetSubordinates?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Employee>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Customer> WhoUsesService(int id)
|
||||
{
|
||||
var item = default(List<Customer>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoUsesService?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Customer>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static Employee WhoIsResponsibleForService(int id)
|
||||
{
|
||||
Employee item = default(Employee);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoIsResponsibleForService?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<Employee>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Employee> WhoMaintainsService(int id)
|
||||
{
|
||||
var item = default(List<Employee>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoMaintainsService?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Employee>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public class RestExceptionInfo
|
||||
{
|
||||
public RestExceptionInfo()
|
||||
{
|
||||
|
||||
}
|
||||
public string Msg { get; set; }
|
||||
}
|
||||
|
||||
public class EndpointNotAvailableException : Exception
|
||||
{
|
||||
public EndpointNotAvailableException() : base("The client could not reach the API endpoint.")
|
||||
{
|
||||
}
|
||||
|
||||
public EndpointNotAvailableException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public EndpointNotAvailableException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Security;
|
||||
using WD7UVN_HFT_2023241.Models;
|
||||
|
||||
namespace WD7UVN_HFT_2023241.Client.Shared
|
||||
{
|
||||
public class RestService
|
||||
{
|
||||
private static HttpClient client;
|
||||
|
||||
private static bool Ping(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
|
||||
|
||||
WebClient wc = new WebClient();
|
||||
wc.DownloadData(url);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger")
|
||||
{
|
||||
int tries = 0;
|
||||
bool isOk = false;
|
||||
do
|
||||
{
|
||||
isOk = Ping(baseurl + pingableEndpoint);
|
||||
tries++;
|
||||
} while (isOk == false && tries < 5);
|
||||
|
||||
if (isOk == false)
|
||||
{
|
||||
throw new EndpointNotAvailableException("Endpoint is not available!");
|
||||
}
|
||||
|
||||
HttpClientHandler handler = new HttpClientHandler();
|
||||
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
|
||||
handler.ServerCertificateCustomValidationCallback =
|
||||
(httpRequestMessage, cert, cetChain, policyErrors) =>
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
client = new HttpClient(handler);
|
||||
client.BaseAddress = new Uri(baseurl);
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue
|
||||
("application/json"));
|
||||
try
|
||||
{
|
||||
client.GetAsync("").GetAwaiter().GetResult();
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
throw new ArgumentException("Endpoint is not available!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<T> Get<T>(string endpoint)
|
||||
{
|
||||
List<T> items = new List<T>();
|
||||
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
items = response.Content.ReadAsAsync<List<T>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static T GetSingle<T>(string endpoint)
|
||||
{
|
||||
T item = default(T);
|
||||
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static T Get<T>(int id, string endpoint)
|
||||
{
|
||||
T item = default(T);
|
||||
HttpResponseMessage response = client.GetAsync(endpoint + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void Post<T>(T item, string endpoint)
|
||||
{
|
||||
HttpResponseMessage response =
|
||||
client.PostAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static void Delete(int id, string endpoint)
|
||||
{
|
||||
HttpResponseMessage response =
|
||||
client.DeleteAsync(endpoint + id.ToString()).GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static void Put<T>(T item, string endpoint)
|
||||
{
|
||||
HttpResponseMessage response =
|
||||
client.PutAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static List<Employee> WhoWorksInMaintainerTeam(int id)
|
||||
{
|
||||
var item = default(List<Employee>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoWorksInMaintainerTeam?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Employee>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Employee> GetSubordinates(int id)
|
||||
{
|
||||
var item = default(List<Employee>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/GetSubordinates?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Employee>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Customer> WhoUsesService(int id)
|
||||
{
|
||||
var item = default(List<Customer>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoUsesService?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Customer>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static Employee WhoIsResponsibleForService(int id)
|
||||
{
|
||||
Employee item = default(Employee);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoIsResponsibleForService?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<Employee>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Employee> WhoMaintainsService(int id)
|
||||
{
|
||||
var item = default(List<Employee>);
|
||||
HttpResponseMessage response = client.GetAsync("/api/WhoMaintainsService?id=" + id.ToString()).GetAwaiter().GetResult();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
item = response.Content.ReadAsAsync<List<Employee>>().GetAwaiter().GetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||
throw new ArgumentException(error.Msg);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public class RestExceptionInfo
|
||||
{
|
||||
public RestExceptionInfo()
|
||||
{
|
||||
|
||||
}
|
||||
public string Msg { get; set; }
|
||||
}
|
||||
|
||||
public class EndpointNotAvailableException : Exception
|
||||
{
|
||||
public EndpointNotAvailableException() : base("The client could not reach the API endpoint.")
|
||||
{
|
||||
}
|
||||
|
||||
public EndpointNotAvailableException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public EndpointNotAvailableException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\WD7UVN_HFT_2023241.Models\WD7UVN_HFT_2023241.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,8 +4,9 @@ using System.Net.NetworkInformation;
|
||||
using System.Reflection;
|
||||
using ConsoleTools;
|
||||
using WD7UVN_HFT_2023241.Models;
|
||||
using WD7UVN_HFT_2023241.Client.Shared;
|
||||
|
||||
namespace WD7UVN_HFT_2023241.Client
|
||||
namespace WD7UVN_HFT_2023241.Client.TUI
|
||||
{
|
||||
public class CRUD
|
||||
{
|
||||
@@ -2,9 +2,10 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using ConsoleTools;
|
||||
using WD7UVN_HFT_2023241.Client.Shared;
|
||||
using WD7UVN_HFT_2023241.Models;
|
||||
|
||||
namespace WD7UVN_HFT_2023241.Client
|
||||
namespace WD7UVN_HFT_2023241.Client.TUI
|
||||
{
|
||||
public class NonCRUD
|
||||
{
|
||||
@@ -1,83 +1,84 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ConsoleTools;
|
||||
|
||||
namespace WD7UVN_HFT_2023241.Client
|
||||
{
|
||||
public enum CRUDActions
|
||||
{
|
||||
GetAll,
|
||||
GetById,
|
||||
Create,
|
||||
Update,
|
||||
Delete
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
RestService.Init();
|
||||
}
|
||||
catch (EndpointNotAvailableException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
// var commonConfig = new MenuConfig
|
||||
// {
|
||||
// Selector = "--> ",
|
||||
// EnableFilter = true,
|
||||
// EnableBreadcrumb = true,
|
||||
// WriteBreadcrumbAction = titles => Console.WriteLine(string.Join(" / ", titles)),
|
||||
// };
|
||||
|
||||
var nonCrudMenu = new ConsoleMenu(args, level: 2)
|
||||
.Add("Who maintains specified service?", () => NonCRUD.WhoMaintainsService())
|
||||
.Add("Get employee's subordinates", () => NonCRUD.GetSubordinates())
|
||||
.Add("Get clients using a specified service", () => NonCRUD.WhoUsesService())
|
||||
.Add("Get employees in specified maintainer team", () => NonCRUD.WhoWorksInMaintainerTeam())
|
||||
.Add("Get employee responsible for specified service", () => NonCRUD.WhoIsResponsibleForService())
|
||||
.Add("Back", ConsoleMenu.Close)
|
||||
.Add("Exit", () => Environment.Exit(0))
|
||||
//.Configure(commonConfig)
|
||||
.Configure(config =>
|
||||
{
|
||||
config.Title = "Non-CRUD Operations";
|
||||
});
|
||||
|
||||
var crudMenu = new ConsoleMenu(args, level: 1)
|
||||
.Add("Get all", () => CRUD.TypeSelectorMenu(CRUDActions.GetAll))
|
||||
.Add("Get by id", () => CRUD.TypeSelectorMenu(CRUDActions.GetById))
|
||||
.Add("Create", () => CRUD.TypeSelectorMenu(CRUDActions.Create))
|
||||
.Add("Update", () => CRUD.TypeSelectorMenu(CRUDActions.Update))
|
||||
.Add("Delete", () => CRUD.TypeSelectorMenu(CRUDActions.Delete))
|
||||
.Add("Back", ConsoleMenu.Close)
|
||||
.Add("Exit", () => Environment.Exit(0))
|
||||
//.Configure(commonConfig)
|
||||
.Configure(config =>
|
||||
{
|
||||
config.Title = "Tables";
|
||||
});
|
||||
|
||||
var menu = new ConsoleMenu(args, level: 0)
|
||||
.Add("CRUD", crudMenu.Show)
|
||||
.Add("Non-CRUD", nonCrudMenu.Show)
|
||||
.Add("Exit", () => Environment.Exit(0))
|
||||
//.Configure(commonConfig)
|
||||
.Configure(config =>
|
||||
{
|
||||
config.Title = "Main menu";
|
||||
config.EnableWriteTitle = true;
|
||||
config.EnableBreadcrumb = true;
|
||||
});
|
||||
|
||||
var token = new CancellationTokenSource().Token;
|
||||
await menu.ShowAsync(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ConsoleTools;
|
||||
using WD7UVN_HFT_2023241.Client.Shared;
|
||||
|
||||
namespace WD7UVN_HFT_2023241.Client.TUI
|
||||
{
|
||||
public enum CRUDActions
|
||||
{
|
||||
GetAll,
|
||||
GetById,
|
||||
Create,
|
||||
Update,
|
||||
Delete
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
RestService.Init();
|
||||
}
|
||||
catch (EndpointNotAvailableException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
// var commonConfig = new MenuConfig
|
||||
// {
|
||||
// Selector = "--> ",
|
||||
// EnableFilter = true,
|
||||
// EnableBreadcrumb = true,
|
||||
// WriteBreadcrumbAction = titles => Console.WriteLine(string.Join(" / ", titles)),
|
||||
// };
|
||||
|
||||
var nonCrudMenu = new ConsoleMenu(args, level: 2)
|
||||
.Add("Who maintains specified service?", () => NonCRUD.WhoMaintainsService())
|
||||
.Add("Get employee's subordinates", () => NonCRUD.GetSubordinates())
|
||||
.Add("Get clients using a specified service", () => NonCRUD.WhoUsesService())
|
||||
.Add("Get employees in specified maintainer team", () => NonCRUD.WhoWorksInMaintainerTeam())
|
||||
.Add("Get employee responsible for specified service", () => NonCRUD.WhoIsResponsibleForService())
|
||||
.Add("Back", ConsoleMenu.Close)
|
||||
.Add("Exit", () => Environment.Exit(0))
|
||||
//.Configure(commonConfig)
|
||||
.Configure(config =>
|
||||
{
|
||||
config.Title = "Non-CRUD Operations";
|
||||
});
|
||||
|
||||
var crudMenu = new ConsoleMenu(args, level: 1)
|
||||
.Add("Get all", () => CRUD.TypeSelectorMenu(CRUDActions.GetAll))
|
||||
.Add("Get by id", () => CRUD.TypeSelectorMenu(CRUDActions.GetById))
|
||||
.Add("Create", () => CRUD.TypeSelectorMenu(CRUDActions.Create))
|
||||
.Add("Update", () => CRUD.TypeSelectorMenu(CRUDActions.Update))
|
||||
.Add("Delete", () => CRUD.TypeSelectorMenu(CRUDActions.Delete))
|
||||
.Add("Back", ConsoleMenu.Close)
|
||||
.Add("Exit", () => Environment.Exit(0))
|
||||
//.Configure(commonConfig)
|
||||
.Configure(config =>
|
||||
{
|
||||
config.Title = "Tables";
|
||||
});
|
||||
|
||||
var menu = new ConsoleMenu(args, level: 0)
|
||||
.Add("CRUD", crudMenu.Show)
|
||||
.Add("Non-CRUD", nonCrudMenu.Show)
|
||||
.Add("Exit", () => Environment.Exit(0))
|
||||
//.Configure(commonConfig)
|
||||
.Configure(config =>
|
||||
{
|
||||
config.Title = "Main menu";
|
||||
config.EnableWriteTitle = true;
|
||||
config.EnableBreadcrumb = true;
|
||||
});
|
||||
|
||||
var token = new CancellationTokenSource().Token;
|
||||
await menu.ShowAsync(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WD7UVN_HFT_2023241.Models\WD7UVN_HFT_2023241.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\WD7UVN_HFT_2023241.Models\WD7UVN_HFT_2023241.Models.csproj" />
|
||||
<ProjectReference Include="..\Shared\WD7UVN_HFT_2023241.Client.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ConsoleMenu-simple" Version="2.6.1" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user