Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public override string ToString()
public partial class JsonRpcClient
{
private int _globalId;
private string _userAgent;

#if (NET8_0_OR_GREATER)
private static readonly Type ClassType = typeof(JsonRpcClient);
Expand Down Expand Up @@ -205,6 +206,10 @@ public JsonRpcClient(string baseUrl)
Url = baseUrl;
JsonRpcUrl = new Uri(new Uri(baseUrl), "/jsonrpc").ToString();
JsonRpcVersion = JsonRpcVersion.v1;
Timeout = Session.STANDARD_TIMEOUT;
UserAgent = Session.DefaultUserAgent;
KeepAlive = true;
AllowAutoRedirect = true;
}

/// <summary>
Expand All @@ -215,7 +220,11 @@ public JsonRpcClient(string baseUrl)
public event Action<string> RequestEvent;

public JsonRpcVersion JsonRpcVersion { get; set; }
public string UserAgent { get; set; }
public string UserAgent
{
get => _userAgent;
set => _userAgent = string.IsNullOrEmpty(value) ? Session.DefaultUserAgent : value;
}
public bool KeepAlive { get; set; }
public IWebProxy WebProxy { get; set; }
public int Timeout { get; set; }
Expand Down
47 changes: 28 additions & 19 deletions ocaml/sdk-gen/csharp/autogen/src/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,16 @@ public partial class Session : XenObject<Session>
public const int STANDARD_TIMEOUT = 24 * 60 * 60 * 1000;

/// <summary>
/// This string is used as the HTTP UserAgent for each request.
/// The default HTTP UserAgent for each request.
/// </summary>
public static string UserAgent = $"XenAPI/{Helper.APIVersionString(API_Version.LATEST)}";

/// <summary>
/// If null, no proxy is used, otherwise this proxy is used for each request.
/// </summary>
public static IWebProxy Proxy = null;

public API_Version APIVersion = API_Version.UNKNOWN;

public object Tag;
public static readonly string DefaultUserAgent = $"XenAPI/{Helper.APIVersionString(API_Version.LATEST)}";

#region Constructors

/// <exception cref="ArgumentNullException">Thrown if 'client' is null</exception>
public Session(JsonRpcClient client)
{
client.Timeout = STANDARD_TIMEOUT;
client.KeepAlive = true;
client.UserAgent = UserAgent;
client.WebProxy = Proxy;
client.AllowAutoRedirect = true;
JsonRpcClient = client;
JsonRpcClient = client ?? throw new ArgumentNullException(nameof(client));
}

public Session(string url) :
Expand Down Expand Up @@ -230,6 +217,19 @@ public override string SaveChanges(Session session, string serverOpaqueRef, Sess

#region Properties

/// <summary>
/// The WebProxy to use for each HTTP request.
/// </summary>
public IWebProxy Proxy
{
get => JsonRpcClient.WebProxy;
set => JsonRpcClient.WebProxy = value;
}

public API_Version APIVersion { get; private set; } = API_Version.UNKNOWN;

public object Tag { get; set; }

/// <summary>
/// Retrieves the current users details from the UserDetails map. These values are only updated when a new session is created.
/// </summary>
Expand All @@ -239,15 +239,24 @@ public override string SaveChanges(Session session, string serverOpaqueRef, Sess

public string Url => JsonRpcClient.Url;

/// <summary>
/// The UserAgent to use for each HTTP request. If set to null or empty the DefaultUserAgent will be used.
/// </summary>
public string UserAgent
{
get => JsonRpcClient.UserAgent;
set => JsonRpcClient.UserAgent = value;
}

public string ConnectionGroupName
{
get => JsonRpcClient?.ConnectionGroupName;
get => JsonRpcClient.ConnectionGroupName;
set => JsonRpcClient.ConnectionGroupName = value;
}

public int Timeout
{
get => JsonRpcClient?.Timeout ?? STANDARD_TIMEOUT;
get => JsonRpcClient.Timeout;
set => JsonRpcClient.Timeout = value;
}

Expand Down
Loading