17c6366834
- da completare info BTL
122 lines
4.1 KiB
C#
122 lines
4.1 KiB
C#
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
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; }
|
|
|
|
[Parameter]
|
|
public EventCallback<Dictionary<string, string>> EC_DoUpdate { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_OnClose { get; set; }
|
|
|
|
[Parameter]
|
|
public string GenericBasePath { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public string ImgBasePath { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected ImageCacheService ICService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Calcolo URL immagine
|
|
/// </summary>
|
|
/// <param name="imgUid"></param>
|
|
/// <param name="env"></param>
|
|
/// <returns></returns>
|
|
protected 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);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
/// <summary>
|
|
/// Esegue lettura file + invio richiesta specifica
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
/// <returns></returns>
|
|
|
|
#region Private Methods
|
|
|
|
private async Task UploadFile(InputFileChangeEventArgs e)
|
|
{
|
|
// init dizionari arg richiesta update
|
|
Dictionary<string, string> fileArgs = 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();
|
|
|
|
// calcolo il nome del file trusted...
|
|
string trustedFileName = Path.GetRandomFileName();
|
|
CurrItem.FileResource = trustedFileName;
|
|
CurrItem.FileName = file.Name;
|
|
CurrItem.FileSize = rawContent.LongCount();
|
|
// salvo sul DB i dati (nome, nome sicuro, size...)
|
|
await DLService.OffertRowUpdateFileData(CurrItem);
|
|
|
|
// parametri richiesta
|
|
fileArgs.Add("Mode", $"{(int)Egw.Window.Data.Enums.QuestionModes.PREVIEW}");
|
|
fileArgs.Add("SubMode", "2");
|
|
fileArgs.Add("FileName", $"{file.Name}");
|
|
fileArgs.Add("Height", "1200");
|
|
fileArgs.Add("Width", "1800");
|
|
//fileArgs.Add("Btl", rawContent);
|
|
fileArgs.Add("SerializedData", rawContent);
|
|
// invio!
|
|
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
|
|
calcRequestDTO.EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM;
|
|
calcRequestDTO.DictExec = fileArgs;
|
|
await ICService.CallRestPost($"{ApiUrl}/{GenericBasePath}", $"{CalcTag}/{CurrItem.OfferRowUID}", calcRequestDTO);
|
|
|
|
// ora chiedo anche la BOM!
|
|
|
|
#if false
|
|
// salvo in locale il file: SISTEMARE PERMESSI
|
|
saveFileContent(EditFileRecord.OfferRowUID, trustedFileName, rawContent);
|
|
#endif
|
|
}
|
|
|
|
#endregion Private Methods
|
|
private void CloseEdit(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
|
|
{
|
|
_ = EC_OnClose.InvokeAsync(true);
|
|
}
|
|
}
|
|
} |