GoCenter.SDK
0.2.0
See the version list below for details.
dotnet add package GoCenter.SDK --version 0.2.0
NuGet\Install-Package GoCenter.SDK -Version 0.2.0
<PackageReference Include="GoCenter.SDK" Version="0.2.0" />
<PackageVersion Include="GoCenter.SDK" Version="0.2.0" />
<PackageReference Include="GoCenter.SDK" />
paket add GoCenter.SDK --version 0.2.0
#r "nuget: GoCenter.SDK, 0.2.0"
#:package GoCenter.SDK@0.2.0
#addin nuget:?package=GoCenter.SDK&version=0.2.0
#tool nuget:?package=GoCenter.SDK&version=0.2.0
GoCenter SDK for C#
Official C# SDK for the GoCenter API, providing comprehensive hospital management and DICOM integration capabilities.
Features
- Multi-target Support: Compatible with .NET Framework 4.6.2, .NET Standard 2.0, and .NET 9.0
- Full CRUD Operations: Complete support for hospital management operations
- Dependency Injection: First-class support for ASP.NET Core DI with
IHttpClientFactoryandILoggerFactory - Resilient: Built-in retry mechanism using Polly with exponential backoff and jitter
- Type-Safe: Strongly-typed models and requests
- Async/Await: Modern async programming patterns with
CancellationTokensupport - Configurable: Flexible configuration options with validation
- Logging: Microsoft.Extensions.Logging integration
- Well-Documented: Comprehensive XML documentation and examples
- Tested: 103+ unit tests covering DI and non-DI scenarios
Installation
dotnet add package GoCenter.SDK
Or via Package Manager Console:
Install-Package GoCenter.SDK
Quick Start
Option 1: Direct Instantiation (Non-DI Scenarios)
using GoCenter.SDK.Client;
var config = new GoCenterClientConfig
{
ServerUrl = "https://your-gocenter-api-endpoint.com",
SecretKey = "your-secret-key",
Timeout = TimeSpan.FromSeconds(30),
RetryAttempts = 3
};
// HttpClient is managed internally via static pooling
using var client = new GoCenterClient(config);
Option 2: Dependency Injection (Recommended for ASP.NET Core)
using GoCenter.SDK.Extensions;
// In Program.cs or Startup.cs
builder.Services.AddGoCenterSDK(config =>
{
config.ServerUrl = "https://your-gocenter-api-endpoint.com";
config.SecretKey = "your-secret-key";
config.Timeout = TimeSpan.FromSeconds(30);
config.RetryAttempts = 3;
});
// Or use the simplified overload
builder.Services.AddGoCenterSDK(
"https://your-gocenter-api-endpoint.com",
"your-secret-key");
// Then inject in your services
public class HospitalService
{
private readonly IGoCenterClient _client;
private readonly ILogger<HospitalService> _logger;
public HospitalService(IGoCenterClient client, ILogger<HospitalService> logger)
{
_client = client;
_logger = logger;
}
}
Get All Hospitals
var hospitalList = await client.GetHospitalsAsync();
if (hospitalList.Status && hospitalList.Data != null)
{
foreach (var hospital in hospitalList.Data)
{
Console.WriteLine($"{hospital.HospitalName} - {hospital.HospitalCode}");
}
}
Get Hospitals by Code
var filteredList = await client.GetHospitalsAsync("HOSPITAL_CODE");
Get Single Hospital
var hospital = await client.GetHospitalAsync(hospitalId);
Console.WriteLine($"Hospital: {hospital.HospitalName}");
Console.WriteLine($"Server: {hospital.ServerAddress}");
Console.WriteLine($"Online: {hospital.OnLine}");
Create a Hospital
using GoCenter.SDK.Requests;
using GoCenter.SDK.Models;
var request = new CreateOrUpdateHospitalRequest
{
HospitalName = "Example Hospital",
HospitalCode = "EX001",
ServerAddress = "192.168.1.100:4242",
ServerMode = "DICOM",
Encryption = "TLS",
Standard = "v1",
AETitle = "EXAMPLE_AE",
ViewerMode = 0,
ViewerUrl = "https://viewer.example.com",
PreFetch = true,
Anonymous = false,
Proxy = 0,
S3Public = false,
SyncInstanceName = true,
PriorApis = new List<CreateOrUpdatePriorApi>
{
new CreateOrUpdatePriorApi
{
Type = PriorApiType.ImageServerPrior,
Endpoint = "https://imageserver.example.com/api",
Deleted = false
}
}
};
await client.AddHospitalAsync(request);
Update a Hospital
var request = new CreateOrUpdateHospitalRequest
{
Id = 123, // Required for updates
HospitalName = "Updated Hospital Name",
HospitalCode = "EX001",
// ... other properties
};
await client.UpdateHospitalAsync(request);
Delete a Hospital
await client.DeleteHospitalAsync(hospitalId);
Advanced Usage
Multiple Configurations with Named Clients
Support for multiple API endpoints in one application:
using GoCenter.SDK.Extensions;
using GoCenter.SDK.Services;
using GoCenter.SDK.Options;
using Microsoft.Extensions.Options;
// Register default configuration
builder.Services.AddGoCenterSDK(config =>
{
config.ServerUrl = "https://api-prod.example.com";
config.SecretKey = "prod-secret";
});
// Add additional named configurations
builder.Services.Configure<GoCenterOptions>(options =>
{
options.SetConfiguration("staging", new GoCenterClientConfig
{
ServerUrl = "https://api-staging.example.com",
SecretKey = "staging-secret",
Timeout = TimeSpan.FromSeconds(60)
});
});
// Use in your services
public class HospitalService
{
private readonly INamedClientManager _clientManager;
public HospitalService(INamedClientManager clientManager)
{
_clientManager = clientManager;
}
public async Task ProcessProduction()
{
// Get default client
var client = _clientManager.GetClient();
await client.GetHospitalsAsync();
}
public async Task ProcessStaging()
{
// Get named client
var client = _clientManager.GetClient("staging");
await client.GetHospitalsAsync();
}
}
Custom HttpClient Configuration
using System.Net.Http;
using GoCenter.SDK.Client;
// Create custom HttpClient
var httpClient = new HttpClient
{
Timeout = TimeSpan.FromMinutes(5)
};
// Add custom headers
httpClient.DefaultRequestHeaders.Add("X-Custom-Header", "CustomValue");
var config = new GoCenterClientConfig
{
ServerUrl = "https://api.example.com",
SecretKey = "secret"
};
// Client will use the provided HttpClient
using var client = new GoCenterClient(httpClient, config);
Logging Integration
The SDK integrates with Microsoft.Extensions.Logging:
// In DI scenarios, logging is automatic
builder.Services.AddGoCenterSDK(config =>
{
config.ServerUrl = "https://api.example.com";
config.SecretKey = "secret";
});
// Add logging configuration
builder.Services.AddLogging(logging =>
{
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Information);
});
// For non-DI scenarios, pass ILogger manually
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole().SetMinimumLevel(LogLevel.Debug);
});
var logger = loggerFactory.CreateLogger<GoCenterClient>();
var client = new GoCenterClient(config, logger);
Retry Configuration
The SDK uses Polly for resilient HTTP requests with exponential backoff:
var config = new GoCenterClientConfig
{
ServerUrl = "https://api.example.com",
SecretKey = "secret",
RetryAttempts = 3, // Number of retry attempts (default: 3)
Timeout = TimeSpan.FromSeconds(30)
};
// Retry behavior:
// - Retries on: HttpRequestException, TimeoutException, 5xx server errors
// - Does NOT retry: 4xx client errors, ArgumentException, etc.
// - Delay strategy: Exponential backoff with jitter (±25%)
// - Max delay: 30 seconds per retry
Route Configuration
Configure route prefix and suffix for API endpoints:
var config = new GoCenterClientConfig
{
ServerUrl = "https://api.example.com",
SecretKey = "secret",
RoutePrefix = "v1", // Adds /v1 before route
RouteSuffix = "json" // Adds /json after route
};
// Example: GET /v1/api/getHospitalList/json
Default Headers
Add custom headers to all requests:
var config = new GoCenterClientConfig
{
ServerUrl = "https://api.example.com",
SecretKey = "secret"
};
// Add headers via methods
config.AddHeader("X-API-Version", "1.0");
config.AddHeader("X-Client-Id", "my-app");
// Or directly
config.DefaultHeaders["X-Custom-Header"] = "CustomValue";
// Remove header
config.RemoveHeader("X-API-Version");
// Clear all headers
config.ClearHeaders();
HttpClient Management
The SDK provides two HttpClient management strategies:
Non-DI Mode: Uses HttpClientManager with static pooling
// Safe - HttpClient is reused from static pool
for (int i = 0; i < 1000; i++)
{
using var client = new GoCenterClient(config);
await client.GetHospitalAsync(i);
}
DI Mode: Uses IHttpClientFactory for optimal lifecycle management
// Registered in DI
builder.Services.AddGoCenterSDK(config => { /*...*/ });
// IHttpClientFactory manages HttpClient lifecycle
public class HospitalService
{
private readonly IGoCenterClient _client;
public HospitalService(IGoCenterClient client)
{
_client = client; // Managed by DI container
}
}
Error Handling
using GoCenter.SDK.Exceptions;
try
{
var hospital = await client.GetHospitalAsync(123);
}
catch (GoCenterApiException ex)
{
// API returned an error status code
Console.WriteLine($"API Error: {ex.StatusCode}");
Console.WriteLine($"Response: {ex.ResponseBody}");
}
catch (GoCenterException ex)
{
// SDK-level error (validation, serialization, etc.)
Console.WriteLine($"SDK Error: {ex.Message}");
}
catch (HttpRequestException ex)
{
// Network error
Console.WriteLine($"Network Error: {ex.Message}");
}
catch (OperationCanceledException)
{
// Request was cancelled
Console.WriteLine("Operation was cancelled");
}
Cancellation Token Support
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
try
{
var hospitals = await client.GetHospitalsAsync(
code: null,
cancellationToken: cts.Token);
}
catch (OperationCanceledException)
{
Console.WriteLine("Operation was cancelled");
}
API Reference
IGoCenterClient Interface
| Method | Description |
|---|---|
GetHospitalsAsync(code, ct) |
Retrieves a list of hospitals, optionally filtered by hospital code |
GetHospitalAsync(id, ct) |
Retrieves a single hospital by ID |
AddHospitalAsync(request, ct) |
Creates a new hospital |
UpdateHospitalAsync(request, ct) |
Updates an existing hospital |
DeleteHospitalAsync(id, ct) |
Deletes a hospital by ID |
Models
- Hospital: Complete hospital entity with all metadata
- HospitalList: Response containing a list of hospitals with status and message
- PriorApi: Prior API configuration for hospital integrations
- Tag: Hospital categorization tags
- CreateOrUpdateHospitalRequest: Request for creating or updating hospitals
- CreateOrUpdatePriorApi: Request for Prior API configuration
Enums
- PriorApiType:
Default,ImageServerPrior,GoQueryPrior
Configuration
GoCenterClientConfig Properties
| Property | Type | Default | Description |
|---|---|---|---|
ServerUrl |
string | Required | API endpoint URL (must be HTTP or HTTPS) |
SecretKey |
string | Required | Secret key for authentication |
Timeout |
TimeSpan | 30s | Request timeout |
RetryAttempts |
int | 3 | Number of retry attempts for failed requests |
RoutePrefix |
string | null | Optional prefix added to all routes |
RouteSuffix |
string | null | Optional suffix added to all routes |
DefaultHeaders |
Dictionary | Empty | Custom headers added to all requests |
UserAgent |
string | null | Custom User-Agent header |
Authentication
The SDK automatically handles authentication using a custom token-based approach:
- Generates a Unix timestamp
- Computes authentication token:
MD5(MD5(SecretKey) + MD5(Timestamp)) - Adds
X-Kayi-TimestampandX-Kayi-Tokenheaders to requests
You don't need to manually manage authentication - just provide your SecretKey in the configuration.
Exception Hierarchy
Exception
└── GoCenterException (Base SDK exception)
└── GoCenterApiException (HTTP status code errors)
- GoCenterException: Base exception for all SDK errors
- GoCenterApiException: API-specific errors with
StatusCodeandResponseBodyproperties
Requirements
- .NET Framework 4.6.2 or higher
- .NET Standard 2.0 or higher
- .NET 9.0 or higher (recommended for best performance)
Dependencies
The SDK uses central package management via Directory.Packages.props:
Core Dependencies
- Microsoft.Extensions.DependencyInjection.Abstractions >= 9.0.0
- Microsoft.Extensions.Http >= 9.0.0
- Microsoft.Extensions.Logging.Abstractions >= 9.0.0
- Microsoft.Extensions.Options >= 9.0.0
- Polly >= 8.5.0 (Resilience and transient fault handling)
- System.Text.Json >= 9.0.0
.NET Standard 2.0 / .NET Framework 4.6.2 Additional Dependencies
- Microsoft.Bcl.AsyncInterfaces >= 9.0.0
- System.Text.Json >= 9.0.0
.NET Framework 4.6.2 Specific Dependencies
- System.Net.Http >= 4.3.4
Development
Building
dotnet restore
dotnet build
Running Tests
# Run all tests (103+ unit tests)
dotnet test
# Run specific test project
dotnet test tests/GoCenter.SDK.Tests/GoCenter.SDK.Tests.csproj
# Run with coverage
dotnet test /p:CollectCoverage=true /p:CoverageReporter=html
Creating NuGet Package
dotnet pack -c Release -o ./artifacts
Project Structure
GoCenter.SDK/
├── src/GoCenter.SDK/
│ ├── Client/ # Client implementations
│ │ ├── GoCenterClient.cs # Main client implementation
│ │ ├── GoCenterClientConfig.cs
│ │ ├── GoCenterClientFactory.cs
│ │ ├── HttpClientManager.cs # Static HttpClient pooling
│ │ ├── IHttpClientProvider.cs # Abstraction for HttpClient management
│ │ └── ...
│ ├── Models/ # Data models
│ ├── Requests/ # Request DTOs
│ ├── Authentication/ # Request signing logic
│ ├── Exceptions/ # Custom exceptions
│ ├── Resilience/ # Polly retry policies
│ ├── Extensions/ # DI extensions
│ ├── Options/ # Configuration options
│ └── Services/ # Named client manager
├── tests/
│ ├── GoCenter.SDK.Tests/ # Unit tests (103+ tests)
│ └── GoCenter.SDK.IntegrationTests/
└── samples/ # Sample applications
Samples
Check the samples/GoCenter.SDK.Samples directory for complete working examples:
SimpleDIExample.cs- Dependency injection setup- Example CRUD operations
- Error handling patterns
- Retry mechanism demonstrations
dotnet run --project samples/GoCenter.SDK.Samples/GoCenter.SDK.Samples.csproj
Testing
The SDK includes comprehensive test coverage:
103+ Unit Tests
- Client instantiation (DI and non-DI modes)
- HTTP request/response handling
- Error handling and retries
- Configuration validation
- Service registration
- Polly resilience policies
Integration Tests
- Live API endpoint testing
- End-to-end CRUD operations
Contributing
Contributions are welcome! Please ensure:
- All tests pass (
dotnet test) - Code follows C# conventions
- XML documentation is provided for public APIs
- Changes are covered by unit tests
- Update relevant documentation
License
MIT License - see LICENSE file for details.
Support
For issues, questions, or contributions, please visit the repository or contact the maintainers.
Changelog
Version 1.1.0 (Current)
- ✨ Added Polly integration for resilient HTTP requests
- ✨ Added Microsoft.Extensions.Logging integration
- ✨ Implemented IHttpClientProvider abstraction
- ✨ Added support for custom HttpClient instances
- ✨ Added route prefix/suffix configuration
- ✨ Added default headers support
- ✨ Migrated to central package management
- ✨ Enhanced dependency injection support with ILoggerFactory
- ✨ Added comprehensive unit tests (103+ tests)
- 🐛 Fixed HttpClient disposal strategy
- 📚 Updated documentation
Version 1.0.0
- Initial release
- Full CRUD operations for hospitals
- .NET Standard 2.0 and .NET 9.0 support
- Comprehensive documentation and examples
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.10)
- Microsoft.Extensions.Configuration (>= 9.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Http (>= 9.0.10)
- Microsoft.Extensions.Logging (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Logging.Console (>= 9.0.10)
- Microsoft.Extensions.Options (>= 9.0.10)
- Polly (>= 8.6.4)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 9.0.10)
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.10)
- Microsoft.Extensions.Configuration (>= 9.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Http (>= 9.0.10)
- Microsoft.Extensions.Logging (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Logging.Console (>= 9.0.10)
- Microsoft.Extensions.Options (>= 9.0.10)
- Polly (>= 8.6.4)
- System.Text.Json (>= 9.0.10)
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Http (>= 9.0.10)
- Microsoft.Extensions.Logging (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Logging.Console (>= 9.0.10)
- Microsoft.Extensions.Options (>= 9.0.10)
- Polly (>= 8.6.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on GoCenter.SDK:
| Package | Downloads |
|---|---|
|
GoCenter.SDK.Samples
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.