diff --git a/CartriX.Api/Controllers/Network/NetworkController.cs b/CartriX.Api/Controllers/Network/NetworkController.cs index 2b3ef31..5748823 100644 --- a/CartriX.Api/Controllers/Network/NetworkController.cs +++ b/CartriX.Api/Controllers/Network/NetworkController.cs @@ -36,9 +36,8 @@ namespace CartriX.Api.Controllers.Network /// Сделать ПИНГ к указанному хосту или IP Адресу /// [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] - [ProducesResponseType(typeof(bool), StatusCodes.Status404NotFound)] [HttpGet(nameof(Ping))] - public async Task Ping([FromQuery] string IpAddressOrHostname) => (await NetworkHelper.PingHostAsync(IpAddressOrHostname)) ? StatusCode(200, true) : StatusCode(404, false); + public async Task Ping([FromQuery] string IpAddressOrHostname) => StatusCode(200, await NetworkHelper.PingHostAsync(IpAddressOrHostname)); /// diff --git a/CartriX.Api/Controllers/Printer/PrinterController.cs b/CartriX.Api/Controllers/Printer/PrinterController.cs index 8852e9c..d7f4c8b 100644 --- a/CartriX.Api/Controllers/Printer/PrinterController.cs +++ b/CartriX.Api/Controllers/Printer/PrinterController.cs @@ -71,8 +71,9 @@ namespace CartriX.Api.Controllers.Printer /// Поменять статус принтера /// [ProducesResponseType(StatusCodes.Status200OK)] - [HttpPut(nameof(ChangeStatus))] - public async Task ChangeStatus([FromQuery] int PrinterId, [FromQuery] int StatusId) + [ProducesResponseType(StatusCodes.Status404NotFound)] + [HttpPatch(nameof(ChangeStatus))] + public async Task ChangeStatus([FromQuery] int PrinterId, [FromBody] int StatusId) { try { diff --git a/CartriX.Api/Controllers/Printer/PrinterMap.cs b/CartriX.Api/Controllers/Printer/PrinterMap.cs index 6ccfa46..44f6cd7 100644 --- a/CartriX.Api/Controllers/Printer/PrinterMap.cs +++ b/CartriX.Api/Controllers/Printer/PrinterMap.cs @@ -12,6 +12,7 @@ Model = printer.Model.ToItem(), StatusId = printer.StatusId, StatusName = printer.Status.Name, + ConnetctionTypeId = printer.PrinterConnetctionTypeId, ConnetctionTypeName = printer.PrinterConnetctionType.Name, InstalledCartridgeId = printer.InstalledCartridge.Id, LocationName = printer.Location.Name, diff --git a/CartriX.Api/Controllers/Printer/PrinterService.cs b/CartriX.Api/Controllers/Printer/PrinterService.cs index 4f08534..e47db8e 100644 --- a/CartriX.Api/Controllers/Printer/PrinterService.cs +++ b/CartriX.Api/Controllers/Printer/PrinterService.cs @@ -69,7 +69,11 @@ namespace CartriX.Api.Controllers.Cartridge var printer = await _context.Printers.FindAsync(PrinterId); if (printer is not null) { - if (await _context.PrinterStatuses.FindAsync(StatusId) is not null) printer.StatusId = StatusId; + if (await _context.PrinterStatuses.FindAsync(StatusId) is not null) + { + printer.StatusId = StatusId; + await _context.SaveChangesAsync(); + } else throw new NullReferenceException($"Нету статуса под идентификатором {StatusId}"); } else diff --git a/CartriX.Api/Service/CheckPrinterService.cs b/CartriX.Api/Service/CheckPrinterService.cs index 9a08ae2..eff3f8f 100644 --- a/CartriX.Api/Service/CheckPrinterService.cs +++ b/CartriX.Api/Service/CheckPrinterService.cs @@ -42,7 +42,7 @@ namespace CartriX.Api.Service await AnsiConsole.Status() .StartAsync("[bold cyan]Получение списка принтеров...[/]", async ctx => { - List printersList = await dbContext.Printers.Where(p => p.PrinterConnetctionTypeId == 1).AsTracking().ToListAsync(); + List printersList = await dbContext.Printers.Where(p => p.PrinterConnetctionTypeId == 1).Where(p => p.StatusId != 3).AsTracking().ToListAsync(); ctx.Status($"[green]✓[/] Получен список ({printersList.Count} устройств)"); await Task.Delay(500); diff --git a/CartriX.Api/db.db b/CartriX.Api/db.db index 2769ba6..d0fe14f 100644 Binary files a/CartriX.Api/db.db and b/CartriX.Api/db.db differ diff --git a/CartriX.Shared/Classes/ApiRoutes.cs b/CartriX.Shared/Classes/ApiRoutes.cs index 9e8a025..7e9da4d 100644 --- a/CartriX.Shared/Classes/ApiRoutes.cs +++ b/CartriX.Shared/Classes/ApiRoutes.cs @@ -34,8 +34,9 @@ namespace CartriX.Shared.Classes public static string ListConnectionType => $"api/{nameof(Printer)}/{nameof(ListConnectionType)}"; public static string ListPrintType => $"api/{nameof(Printer)}/{nameof(ListPrintType)}"; public static string GetAddressOIDs => $"api/{nameof(Printer)}/{nameof(GetAddressOIDs)}"; - } - public static class Location + public static string ChangeStatus(int PrinterId) => $"api/{nameof(Printer)}/{nameof(ChangeStatus)}?{nameof(PrinterId)}={PrinterId}"; + } + public static class Location { public static string List => $"api/{nameof(Location)}/{nameof(List)}"; public static string ListPrinters(int LocationId) => $"api/{nameof(Location)}/{nameof(ListPrinters)}?{nameof(LocationId)}={LocationId}"; diff --git a/CartriX.Shared/Models/Printer/PrinterItem.cs b/CartriX.Shared/Models/Printer/PrinterItem.cs index 9c97e20..372f436 100644 --- a/CartriX.Shared/Models/Printer/PrinterItem.cs +++ b/CartriX.Shared/Models/Printer/PrinterItem.cs @@ -41,6 +41,10 @@ /// public string StatusName { get; set; } = string.Empty; /// + /// Идентификатор типа подключения принтера + /// + public int ConnetctionTypeId { get; set; } + /// /// Название типа подключения принтера /// public string ConnetctionTypeName { get; set; } = string.Empty; diff --git a/CartriX.Web/Pages/PrinterPage.razor b/CartriX.Web/Pages/PrinterPage.razor index 6cc9b70..299e4c8 100644 --- a/CartriX.Web/Pages/PrinterPage.razor +++ b/CartriX.Web/Pages/PrinterPage.razor @@ -4,53 +4,114 @@ @inject IJSRuntime JS @using System.Net + -@if (printer.StatusId == 1) + + + + + + + +@if (dataIsLoading) +{ + +

Получаем информацию...

+
+} +else if (printer is null) { } else { - + if (pingIsActive) + { +

Пингуем...

+ } + else + { + + + + @if (printer.Model.PicturePath is null) + { + + } + else + { + + } + + + @printer.Model.Manufacturer.Name + + + + + + + + + + + + + + + + + } } - - - - - - - - - - - - - - @code { - //bool dataIsLoading; + bool dataIsLoading; + bool pingIsActive; [Parameter] public int PrinterId { get; set; } - private Models.Printer.PrinterItem printer = default!; + private Models.Printer.PrinterItem? printer = default!; protected async override Task OnInitializedAsync() { - // dataIsLoading = true; + dataIsLoading = true; await GetPrinterInfo(); - //dataIsLoading = false; + dataIsLoading = false; + StateHasChanged(); + await PingPrinter(); } - async Task GetPrinterInfo() { var responce = await http.GetAsync(ApiRoutes.Printer.Item(PrinterId)); var json = await responce.Content.ReadAsStringAsync(); printer = JsonConvert.DeserializeObject(json)!; } + async Task PingPrinter() + { + pingIsActive = true; + await InvokeAsync(StateHasChanged); + var responce = await http.GetFromJsonAsync(ApiRoutes.Network.Ping(printer!.IpAddressOrHostname!)); + Console.WriteLine(responce); + bool pingIsSuccessful = (bool)responce; + int SetStatusId = (pingIsSuccessful) ? 1 : 2; + await http.PatchAsJsonAsync(ApiRoutes.Printer.ChangeStatus(PrinterId), SetStatusId); + await GetPrinterInfo(); + pingIsActive = false; + await InvokeAsync(StateHasChanged); + } async Task ChangeCartridgeClick() { NavigationManager.NavigateTo($"/printer/{PrinterId}/cartridgereplace"); @@ -59,7 +120,7 @@ else { string features = "width=1280,height=720,resizable=no,scrollbars=yes"; - if (IPAddress.TryParse(printer.IpAddressOrHostname, out IPAddress? address)) + if (IPAddress.TryParse(printer!.IpAddressOrHostname, out IPAddress? address)) { await JS.InvokeVoidAsync("open", $"http://{address.ToString()}", "_blank", features); }