-Aggiunta dei servizi di connessione REST base, di SAP e di Salesforce

This commit is contained in:
Alessio Dal Santo
2025-06-16 17:42:55 +02:00
parent 7346db3b63
commit 53058e16a6
6 changed files with 858 additions and 1 deletions
@@ -1,10 +1,12 @@
using DataConnection.REST.Configuration;
using DataConnection.REST.Interfaces;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@@ -98,6 +100,35 @@ namespace DataConnection.REST.Implementations
}
}
public virtual async Task<Dictionary<string, object>?> CreateEntityAsync(string entityName, Dictionary<string, object> entityData, CancellationToken cancellationToken = default)
{
// Default implementation - derived classes should override this for service-specific logic
try
{
var response = await _httpClient.PostAsJsonAsync($"/{entityName}", entityData, cancellationToken);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);
if (string.IsNullOrEmpty(responseContent))
return entityData; // Return original data if no response content
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
return JsonSerializer.Deserialize<Dictionary<string, object>>(responseContent, options);
}
catch (HttpRequestException ex)
{
Console.WriteLine($"HTTP Request Error during entity creation: {ex.Message}");
throw;
}
catch (Exception ex)
{
Console.WriteLine($"Error during entity creation: {ex.Message}");
throw;
}
}
// Implement other methods (PUT, DELETE, etc.) similarly
public void Dispose()