143 lines
5.3 KiB
C#
143 lines
5.3 KiB
C#
namespace Lux.UI.Components.Compo.FileMan
|
|
{
|
|
public partial class BtlPreview
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string ApiUrl { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public string CalcTag { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public OfferRowModel CurrItem { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_OnClose { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<Dictionary<string, string>> EC_ReqSave { get; set; }
|
|
|
|
[Parameter]
|
|
public string GenericBasePath { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public string ImgBasePath { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IOfferRowService ORService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IImageCacheService ICService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void CloseEdit(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
|
|
{
|
|
// false --> NON salvo serializzato eprché ho già salvato l file x cui NON ricalcola la BOM
|
|
_ = EC_OnClose.InvokeAsync(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcolo URL immagine
|
|
/// </summary>
|
|
/// <param name="imgUid"></param>
|
|
/// <param name="env"></param>
|
|
/// <returns></returns>
|
|
private string imgUrl(string imgUid, string env)
|
|
{
|
|
// cast string su env..
|
|
EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
|
|
Enum.TryParse(env, out envir);
|
|
return ICService.ImageUrl($"{ApiUrl}/{ImgBasePath}", false, imgUid, envir);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue lettura file + invio richiesta specifica
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
/// <returns></returns>
|
|
|
|
private async Task UploadFile(InputFileChangeEventArgs e)
|
|
{
|
|
// init dizionari arg richiesta update
|
|
Dictionary<string, string> fileArgs = new Dictionary<string, string>();
|
|
Dictionary<string, string> bomArgs = new Dictionary<string, string>();
|
|
|
|
// leggo il contenuto del PRIMO (singolo) file
|
|
IBrowserFile file = e.File;
|
|
// limite file size (al momento 10 MB)
|
|
var maxAllowedSize = 10 * 1024 * 1024;
|
|
|
|
using var stream = file.OpenReadStream(maxAllowedSize);
|
|
using var reader = new StreamReader(stream);
|
|
string rawContent = await reader.ReadToEndAsync();
|
|
|
|
// se ho contenuto nel file...
|
|
if (!string.IsNullOrEmpty(rawContent))
|
|
{
|
|
// elimino vecchio file... richiedendo save senza parametri
|
|
Dictionary<string, string> dictSave = new Dictionary<string, string>();
|
|
await EC_ReqSave.InvokeAsync(dictSave);
|
|
|
|
// calcolo il nome del file trusted...
|
|
string trustedFileName = Path.GetRandomFileName();
|
|
CurrItem.FileResource = trustedFileName;
|
|
CurrItem.FileName = file.Name;
|
|
CurrItem.FileSize = rawContent.LongCount();
|
|
#if false
|
|
// aggiungo contenuto come SerStruct (in attesa di valutare FS save...)
|
|
CurrItem.SerStruct = rawContent;
|
|
#endif
|
|
|
|
// salvo sul DB i dati (nome, nome sicuro, size...)
|
|
await ORService.UpdateFileDataAsync(CurrItem);
|
|
|
|
// parametri richiesta
|
|
fileArgs.Add("FileName", $"{file.Name}");
|
|
fileArgs.Add("SerializedData", rawContent);
|
|
fileArgs.Add("Mode", $"{(int)Egw.Window.Data.Enums.QuestionModes.PREVIEW}");
|
|
fileArgs.Add("SubMode", "2");
|
|
fileArgs.Add("Height", "1200");
|
|
fileArgs.Add("Width", "1800");
|
|
// invio!
|
|
CalcRequestDTO calcRequestDTO = new CalcRequestDTO()
|
|
{
|
|
EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM,
|
|
DictExec = fileArgs
|
|
};
|
|
// richiesta PNG
|
|
await ICService.CallRestPost($"{ApiUrl}/{GenericBasePath}", $"{CalcTag}/{CurrItem.OfferRowUID}", calcRequestDTO);
|
|
|
|
// aggiungo info x BOM
|
|
bomArgs.Add("FileName", $"{file.Name}");
|
|
bomArgs.Add("SerializedData", rawContent);
|
|
bomArgs.Add("Mode", $"{(int)Egw.Window.Data.Enums.QuestionModes.BOM}");
|
|
// ...infine chiedo anche la BOM!
|
|
calcRequestDTO = new CalcRequestDTO()
|
|
{
|
|
EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM,
|
|
DictExec = bomArgs
|
|
};
|
|
// richiesta BOM
|
|
await ICService.CallRestPost($"{ApiUrl}/{GenericBasePath}", $"{CalcTag}/{CurrItem.OfferRowUID}", calcRequestDTO);
|
|
|
|
dictSave.Add("secureName", trustedFileName);
|
|
dictSave.Add("content", rawContent);
|
|
await EC_ReqSave.InvokeAsync(dictSave);
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |