8fa8732cf1
- renaming in conf json - fix gestione classi post rename
79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using RestSharp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services
|
|
{
|
|
public class CalcRequestService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public CalcRequestService(IConfiguration config)
|
|
{
|
|
_config = config;
|
|
// verifico la url base
|
|
apiUrl = _config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "https://iis01.egalware.com/lux/srv/api";
|
|
routeBasePath = _config.GetValue<string>("ServerConf:RouteBaseUrl") ?? "window";
|
|
// fix opzioni base del RestClient
|
|
restOptStd = new RestClientOptions
|
|
{
|
|
Timeout = TimeSpan.FromSeconds(60),
|
|
BaseUrl = new Uri($"{apiUrl}/{routeBasePath}")
|
|
};
|
|
Log.Info("ImageCache Service Started");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Effettua una generica chiamata ApiRest
|
|
/// </summary>
|
|
/// <param name="ApiUrl">URL Api di base</param>
|
|
/// <param name="ApiRequest">Richiesta completa</param>
|
|
/// <param name="rawBody">Corpo Json trasmesso con richiesta</param>
|
|
/// <returns></returns>
|
|
public async Task<RestResponse> CallRestPost(string ApiUrl, string ApiRequest, object rawBody)
|
|
{
|
|
RestResponse response;
|
|
// cerco online
|
|
using (RestClient client = new RestClient(ApiUrl))
|
|
{
|
|
var request = new RestRequest(ApiRequest, Method.Post);
|
|
string rawData = JsonConvert.SerializeObject(rawBody);
|
|
request.AddJsonBody(rawData);
|
|
response = await client.ExecutePostAsync(request);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
#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
|
|
|
|
/// <summary>
|
|
/// Conf client RestSharp standard:
|
|
/// - base URI al sito
|
|
/// - timeout 1 min
|
|
/// </summary>
|
|
private RestClientOptions restOptStd { get; set; } = new RestClientOptions();
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |