@using System.Net; @using System.Diagnostics; @using Hangfire; @using LANCommander.Server.Jobs.Background; @using Microsoft.EntityFrameworkCore; @inject HttpClient HttpClient @inject NavigationManager Navigator @inject ArchiveService ArchiveService @inject ModalService ModalService @inject IMessageService MessageService @inject IJSRuntime JS @inject ILogger Logger @ByteSizeLib.ByteSize.FromBytes(context.CompressedSize) @context.CreatedBy?.UserName
@code { [Parameter] public Guid GameId { get; set; } [Parameter] public Guid RedistributableId { get; set; } ICollection Archives { get; set; } ArchiveUploader Uploader; protected override async Task OnInitializedAsync() { await LoadData(); HttpClient.BaseAddress = new Uri(Navigator.BaseUri); } private async Task LoadData() { if (GameId != Guid.Empty) Archives = await ArchiveService.Get(a => a.GameId == GameId).ToListAsync(); else if (RedistributableId != Guid.Empty) Archives = await ArchiveService.Get(a => a.RedistributableId == RedistributableId).ToListAsync(); } private async Task Download(Archive archive) { string url = $"/Download/Game/{archive.Id}"; await JS.InvokeAsync("open", url, "_blank"); } private async Task UploadArchive() { await Uploader.Open(); } private async Task BrowseArchive(Archive archive) { var modalOptions = new ModalOptions() { Title = "Browse Archive", Maximizable = false, DefaultMaximized = true, Closable = true, WrapClassName = "file-picker-dialog", }; var modalRef = await ModalService.CreateModalAsync(modalOptions, archive.Id); } private async Task Update(Archive archive) { try { await ArchiveService.Update(archive); MessageService.Success("Archive updated!"); } catch (Exception ex) { MessageService.Error("Archive could not be updated."); Logger.LogError(ex, "Archive could not be updated."); } } private async Task Delete(Archive archive) { try { await ArchiveService.Delete(archive); await LoadData(); MessageService.Success("Archive deleted!"); } catch (Exception ex) { MessageService.Error("Archive could not be deleted."); Logger.LogError(ex, "Archive could not be deleted."); } } }