SHA256
feat StayExport - Refactor Export Services.
- Created new service: IStayExportService" for common export operations. - Updated older services to be "IStayExportFormatProvider". This services will only implement the export format. - Renamed "IStayExportServiceFactory" to "IStayExportFormatProviderFactory" as this factory now is used to get the format providers for the given format.
This commit is contained in:
1 parent
058352b7f3
commit
6fe5a5e5a3
11 files changed
+157
-91
No files matched your search
@@ -1,12 +1,9 @@
|
||||
@attribute [Route($"{GuestConsts.Page_StayExport_List}")]
|
||||
|
||||
@using FluentStorage;
|
||||
@using FluentStorage.Storage;
|
||||
@using System.Text.Json;
|
||||
@using Microsoft.Extensions.Options;
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Models.Configuration;
|
||||
@using Somnia.GuestLog.Services;
|
||||
@using Somnia.GuestLog.Services.StayExport;
|
||||
|
||||
@inject IStayExportFileEntityService stayExportEntityService
|
||||
@inject NavigationManager Navigation
|
||||
@@ -15,7 +12,7 @@
|
||||
@inject IDataListService dataListService;
|
||||
@inject ILocalizerService Localizer;
|
||||
|
||||
@inject IOptions<StayExportConfig> exportConfig
|
||||
@inject IStayExportService ExportService;
|
||||
@inject IJSRuntime JS
|
||||
|
||||
|
||||
@@ -126,7 +123,7 @@
|
||||
|
||||
private async Task BtnDownloadFile(StayExportFileDTO item)
|
||||
{
|
||||
if(item.ExportResult == Enums.Models.StayExportFileResult.NoData)
|
||||
if (item.ExportResult == Enums.Models.StayExportFileResult.NoData)
|
||||
{
|
||||
userMessage.ShowMessage("A Export without data can't be downloaded!", MessageKind.Warning);
|
||||
return;
|
||||
@@ -138,10 +135,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
IStore store = StorageFactory.FromConnectionString(exportConfig.Value.ExportStorageConnectionString);
|
||||
|
||||
using Stream objectStream = new MemoryStream();
|
||||
await store.GetObject(item.ExportedPath, objectStream);
|
||||
Result loadResult = await ExportService.GetExportedFileAsync(item, objectStream);
|
||||
if (!loadResult.IsSuccess)
|
||||
{
|
||||
userMessage.ShowResultWithMessage(loadResult, "Exported File can't be downloaded");
|
||||
return;
|
||||
}
|
||||
|
||||
objectStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
using var streamRef = new DotNetStreamReference(stream: objectStream);
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
@attribute [Route($"{GuestConsts.Page_StayExport_New}")]
|
||||
|
||||
@using FluentValidation;
|
||||
@using FluentStorage;
|
||||
@using FluentStorage.Storage;
|
||||
@using Microsoft.Extensions.Options;
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Models.Configuration;
|
||||
@using Somnia.GuestLog.Enums.Models;
|
||||
@using Somnia.GuestLog.Services;
|
||||
@using Somnia.GuestLog.Validators;
|
||||
@@ -17,9 +13,8 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject IValidator<StayExportParamsDTO> ExportParamsValidator;
|
||||
@inject ILocalizerService Localizer;
|
||||
@inject IStayExportServiceFactory ExportServiceFactory;
|
||||
@inject IStayExportService ExportService;
|
||||
|
||||
@inject IOptions<StayExportConfig> exportConfig
|
||||
@inject IJSRuntime JS
|
||||
|
||||
|
||||
@@ -121,9 +116,7 @@
|
||||
|
||||
var loadingDialog = await DialogService.ShowAsync<LoadingDialog>();
|
||||
|
||||
var exportService = ExportServiceFactory.GetService(exportFormat.Value);
|
||||
var exportResult = await exportService.ExportStaysByParams(exportParams);
|
||||
|
||||
var exportResult = await ExportService.ExportStaysByParamsAsync(exportFormat.Value, exportParams);
|
||||
exportedFile = exportResult.Value;
|
||||
loadingDialog.Close();
|
||||
|
||||
@@ -141,7 +134,6 @@
|
||||
private async Task BtnDownloadExportedFile()
|
||||
{
|
||||
Debug.Assert(exportedFile != null);
|
||||
Debug.Assert(exportConfig.Value.ExportStorageConnectionString != null);
|
||||
|
||||
if (string.IsNullOrEmpty(exportedFile.ExportedPath))
|
||||
{
|
||||
@@ -149,16 +141,19 @@
|
||||
return;
|
||||
}
|
||||
|
||||
IStore store = StorageFactory.FromConnectionString(exportConfig.Value.ExportStorageConnectionString);
|
||||
using Stream dataStream = new MemoryStream();
|
||||
|
||||
using Stream objectStream = new MemoryStream();
|
||||
await store.GetObject(exportedFile.ExportedPath, objectStream);
|
||||
objectStream.Seek(0, SeekOrigin.Begin);
|
||||
Result loadResult = await ExportService.GetExportedFileAsync(exportedFile, dataStream);
|
||||
if (!loadResult.IsSuccess)
|
||||
{
|
||||
userMessage.ShowResultWithMessage(loadResult, "Exported File can't be downloaded");
|
||||
return;
|
||||
}
|
||||
|
||||
dataStream.Seek(0, SeekOrigin.Begin);
|
||||
using var streamRef = new DotNetStreamReference(stream: dataStream);
|
||||
|
||||
var fileName = Path.GetFileName(exportedFile.ExportedPath);
|
||||
|
||||
using var streamRef = new DotNetStreamReference(stream: objectStream);
|
||||
|
||||
await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
|
||||
|
||||
userMessage.ShowMessage("Exported File downloaded!", MessageKind.Success);
|
||||
|
||||
Reference in new issue
Block a user