GoCenter.SDK 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GoCenter.SDK --version 0.1.0
                    
NuGet\Install-Package GoCenter.SDK -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GoCenter.SDK" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GoCenter.SDK" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GoCenter.SDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GoCenter.SDK --version 0.1.0
                    
#r "nuget: GoCenter.SDK, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GoCenter.SDK@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GoCenter.SDK&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GoCenter.SDK&version=0.1.0
                    
Install as a Cake Tool

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 IHttpClientFactory and ILoggerFactory
  • 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 CancellationToken support
  • 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);
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:

  1. Generates a Unix timestamp
  2. Computes authentication token: MD5(MD5(SecretKey) + MD5(Timestamp))
  3. Adds X-Kayi-Timestamp and X-Kayi-Token headers 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 StatusCode and ResponseBody properties

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:

  1. All tests pass (dotnet test)
  2. Code follows C# conventions
  3. XML documentation is provided for public APIs
  4. Changes are covered by unit tests
  5. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
0.4.0 389 11/12/2025
0.2.0 251 11/4/2025
0.1.0 269 11/4/2025