namespace EgwCoreLib.Lux.Data.Services.General { public class CalcRequestService : ICalcRequestService { #region Public Constructors public CalcRequestService(IConfiguration config) { _config = config; // verifico la url base apiUrl = _config.GetValue("ServerConf:Prog.ApiUrl") ?? "https://iis01.egalware.com/lux/srv/api"; routeBasePath = _config.GetValue("ServerConf:RouteBaseUrl") ?? "window"; // fix opzioni base del RestClient restOptStd = new RestClientOptions { Timeout = TimeSpan.FromSeconds(60), BaseUrl = new Uri($"{apiUrl}/{routeBasePath}") }; Log.Info("CalcRequest Service Started"); } #endregion Public Constructors #region Public Methods /// public async Task CallRestPost(string ApiUrl, string ApiRequest, object rawBody) { using var client = CreateClient(ApiUrl); var request = new RestRequest(ApiRequest, Method.Post); request.AddJsonBody(rawBody); return await client.ExecuteAsync(request); } #endregion Public Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); private readonly string apiUrl = ""; private readonly string routeBasePath = ""; private IConfiguration _config; #endregion Private Fields #region Private Properties /// /// Conf client RestSharp standard: /// - base URI al sito /// - timeout 1 min /// private RestClientOptions restOptStd { get; set; } = new RestClientOptions(); #endregion Private Properties #region Private Methods /// /// Helper creazione client Rest x RestSharp /// /// /// private RestClient CreateClient(string baseUrl) { var opt = new RestClientOptions { Timeout = restOptStd.Timeout, // eredita timeout BaseUrl = new Uri(baseUrl) // sovrascrive BaseUrl }; return new RestClient(opt); } #endregion Private Methods } }