-Aggiunta dei servizi di connessione REST base, di SAP e di Salesforce
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user