C#

C# SDK

Official C# SDK for the Fluxum API service

WebSocket-based
End-to-end encryption
Async/await
.NET 6.0+

Quick Start

Get up and running with the Fluxum C# SDK in minutes

Using nuget

dotnet add package FluxumSDK

Real-time WebSocket

Connect to Fluxum's WebSocket gateway for instant job updates and real-time communication.

Client-side Encryption

Optional RSA key management for end-to-end encryption and maximum security.

Comprehensive Analytics

Track performance metrics, connection status, and job statistics with built-in analytics.

Event Handling

Handle real-time events with the SDK

// Connection events
sdk.Connected += (sender, e) => Console.WriteLine("Connected to Fluxum server");
sdk.Authenticated += (sender, e) => Console.WriteLine("Authentication successful");
sdk.Disconnected += (sender, e) => Console.WriteLine($"Disconnected: {e.Reason}");

// Job events
sdk.JobSubmitted += (sender, e) => Console.WriteLine($"Job submitted: {e.JobId}");
sdk.JobAccepted += (sender, e) => Console.WriteLine($"Job accepted: {e.JobId}");
sdk.JobUpdate += (sender, e) => Console.WriteLine($"Job update: {e.JobId}, {e.Status}");

// Error handling
sdk.Error += (sender, e) => Console.WriteLine($"Error: {e.Type}, {e.Message}");

// Rate limiting
sdk.RateLimitStatus += (sender, e) => Console.WriteLine($"Rate limit: {e.IsRateLimited}");

Job Submission Examples

Examples of different job types and configurations

Simple GET Request

var job = new JobPayload
{
    TargetUrl = "https://api.example.com/data",
    Method = "GET",
    Headers = new Dictionary<string, string>
    {
        { "Authorization", "Bearer your-token" }
    }
};

var jobId = await sdk.SubmitJob(job);

POST with JSON Body

var job = new JobPayload
{
    TargetUrl = "https://api.example.com/users",
    Method = "POST",
    Headers = new Dictionary<string, string>
    {
        { "Content-Type", "application/json" },
        { "Authorization", "Bearer your-token" }
    },
    Body = JsonSerializer.Serialize(new
    {
        name = "John Doe",
        email = "[email protected]"
    })
};

var jobId = await sdk.SubmitJob(job);

Form Data

var job = new JobPayload
{
    TargetUrl = "https://api.example.com/upload",
    Method = "POST",
    Headers = new Dictionary<string, string>
    {
        { "Content-Type", "multipart/form-data" }
    },
    Body = formData // FormData object
};

var jobId = await sdk.SubmitJob(job);

Advanced Features

Advanced configuration and features

Custom Encryption

var sdk = new FluxumSDK(new FluxumSDKOptions
{
    ApiKey = "your-api-key",
    EnableClientSideEncryption = true,
    EncryptionKey = "your-custom-encryption-key"
});

Connection Management

// Manual connection
await sdk.ConnectAsync();

// Disconnect
await sdk.DisconnectAsync();

// Check connection status
if (sdk.IsConnected)
{
    Console.WriteLine("Connected");
}

// Reconnect
await sdk.ReconnectAsync();

Analytics

// Get analytics data
var analytics = sdk.GetAnalytics();

Console.WriteLine($"Total jobs: {analytics.TotalJobs}");
Console.WriteLine($"Successful jobs: {analytics.SuccessfulJobs}");
Console.WriteLine($"Failed jobs: {analytics.FailedJobs}");
Console.WriteLine($"Average response time: {analytics.AverageResponseTime}");

// Reset analytics
sdk.ResetAnalytics();

Error Handling

Comprehensive error handling and recovery

// Global error handler
sdk.Error += (sender, e) =>
{
    switch (e.Type)
    {
        case ErrorType.Connection:
            Console.WriteLine($"Connection error: {e.Message}");
            break;
        case ErrorType.Authentication:
            Console.WriteLine($"Authentication error: {e.Message}");
            break;
        case ErrorType.Job:
            Console.WriteLine($"Job error: {e.Message}");
            break;
        case ErrorType.RateLimit:
            Console.WriteLine($"Rate limit exceeded: {e.Message}");
            break;
        default:
            Console.WriteLine($"Unknown error: {e.Message}");
            break;
    }
};

// Handle specific errors
sdk.ConnectionFailed += (sender, e) =>
{
    Console.WriteLine($"Failed to connect: {e.Message}");
    // Implement retry logic
};

sdk.AuthenticationFailed += (sender, e) =>
{
    Console.WriteLine($"Authentication failed: {e.Message}");
    // Handle invalid API key
};

Requirements

System requirements and dependencies

.NET Version

.NET 6.0 or higher

Dependencies

  • FluxumSDK NuGet package
  • SocketIOClient (WebSocket client)
  • Newtonsoft.Json (JSON serialization)
  • System.Security.Cryptography.Algorithms (encryption)

API Reference

Complete API documentation

Constructor

new FluxumSDK(FluxumSDKOptions options)

public class FluxumSDKOptions
{
    public string ApiKey { get; set; }
    public bool AutoConnect { get; set; } = true;
    public bool EnableClientSideEncryption { get; set; } = true;
    public bool EnableAnalytics { get; set; } = true;
    public int MaxReconnectAttempts { get; set; } = 5;
    public int ReconnectDelay { get; set; } = 1000;
    public int ConnectionTimeout { get; set; } = 30000;
    public LogLevel LogLevel { get; set; } = LogLevel.Info;
}

Methods

// Connection
await sdk.ConnectAsync();
await sdk.DisconnectAsync();
await sdk.ReconnectAsync();

// Status
sdk.isConnected() -> bool
sdk.isauthenticated() -> bool

// Jobs
fun submitJob(payload: JobPayload) -> str
fun cancelJob(jobId: str) -> None

// Analytics
fun get_analytics() -> AnalyticsData
fun reset_analytics() -> None

// Events
fun addEventListener(listener: SDKEventListener)
fun removeEventListener(listener: SDKEventListener)