Skip to content

Support for .NET8 and Tracing information #6628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 22, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/generate-and-build-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
- name: Build C# SDK
shell: pwsh
run: |
dotnet build source/src `
dotnet build source/src/XenServer.csproj `
--disable-build-servers `
--configuration Release `
-p:Version=${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned `
Expand Down
1 change: 1 addition & 0 deletions ocaml/sdk-gen/csharp/autogen/src/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public override void UpdateFrom(Event update)
id = update.id;
}

[Obsolete("Use the calls setting individual fields of the API object instead.")]
public override string SaveChanges(Session session, string opaqueRef, Event serverObject)
{
if (opaqueRef == null)
Expand Down
7 changes: 6 additions & 1 deletion ocaml/sdk-gen/csharp/autogen/src/Failure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Resources;
#if !(NET8_0_OR_GREATER)
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Xml;
#endif
using Newtonsoft.Json.Linq;


Expand Down Expand Up @@ -88,12 +90,14 @@ public Failure(string message, Exception exception)
ParseExceptionMessage();
}

#if !(NET8_0_OR_GREATER)
protected Failure(SerializationInfo info, StreamingContext context)
: base(info, context)
{
errorDescription = (List<string>)info.GetValue("errorDescription", typeof(List<string>));
errorText = info.GetString("errorText");
}
#endif

#endregion

Expand Down Expand Up @@ -174,7 +178,7 @@ public override string ToString()
{
return Message;
}

#if !(NET8_0_OR_GREATER)
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
Expand All @@ -185,5 +189,6 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont

base.GetObjectData(info, context);
}
#endif
}
}
113 changes: 52 additions & 61 deletions ocaml/sdk-gen/csharp/autogen/src/HTTP.cs

Large diffs are not rendered by default.

277 changes: 223 additions & 54 deletions ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs

Large diffs are not rendered by default.

115 changes: 63 additions & 52 deletions ocaml/sdk-gen/csharp/autogen/src/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
#if (NET8_0_OR_GREATER)
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
#endif
using System.Net.Security;
using Newtonsoft.Json;

Expand All @@ -44,7 +48,7 @@ public partial class Session : XenObject<Session>
/// <summary>
/// This string is used as the HTTP UserAgent for each request.
/// </summary>
public static string UserAgent = string.Format("XenAPI/{0}", Helper.APIVersionString(API_Version.LATEST));
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.
Expand All @@ -55,8 +59,6 @@ public partial class Session : XenObject<Session>

public object Tag;

private List<Role> roles = new List<Role>();

#region Constructors

public Session(JsonRpcClient client)
Expand Down Expand Up @@ -124,7 +126,7 @@ public Session(Session session)

private static string GetUrl(string hostname, int port)
{
return string.Format("{0}://{1}:{2}", port == 8080 || port == 80 ? "http" : "https", hostname, port);
return $"{(port == 8080 || port == 80 ? "http" : "https")}://{hostname}:{port}";
}

private void SetupSessionDetails()
Expand Down Expand Up @@ -159,7 +161,7 @@ private void CopyADFromSession(Session session)
IsLocalSuperuser = session.IsLocalSuperuser;
SessionSubject = session.SessionSubject;
UserSid = session.UserSid;
roles = session.Roles;
Roles = session.Roles;
Permissions = session.Permissions;
}

Expand Down Expand Up @@ -208,7 +210,7 @@ private void SetRbacPermissions()
if (r.subroles.Count > 0 && r.name_label == s)
{
r.opaque_ref = xr.opaque_ref;
roles.Add(r);
Roles.Add(r);
break;
}
}
Expand All @@ -220,7 +222,8 @@ public override void UpdateFrom(Session update)
throw new Exception("The method or operation is not implemented.");
}

public override string SaveChanges(Session session, string _serverOpaqueRef, Session serverObject)
[Obsolete("Use the calls setting individual fields of the API object instead.")]
public override string SaveChanges(Session session, string serverOpaqueRef, Session serverObject)
{
throw new Exception("The method or operation is not implemented.");
}
Expand Down Expand Up @@ -248,11 +251,19 @@ public int Timeout
set => JsonRpcClient.Timeout = value;
}

#if (NET8_0_OR_GREATER)
public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateValidationCallback
{
get => JsonRpcClient?.ServerCertificateValidationCallback;
set => JsonRpcClient.ServerCertificateValidationCallback = value;
}
#else
public RemoteCertificateValidationCallback ServerCertificateValidationCallback
{
get => JsonRpcClient?.ServerCertificateValidationCallback;
set => JsonRpcClient.ServerCertificateValidationCallback = value;
}
#endif

public ICredentials Credentials => JsonRpcClient?.WebProxy?.Credentials;

Expand Down Expand Up @@ -306,7 +317,7 @@ public Dictionary<string, string> RequestHeaders
/// instead use Permissions. This list should only be used for UI purposes.
/// </summary>
[JsonConverter(typeof(XenRefListConverter<Role>))]
public List<Role> Roles => roles;
public List<Role> Roles { get; private set; }

#endregion

Expand All @@ -315,9 +326,9 @@ public string[] GetSystemMethods()
return JsonRpcClient.system_list_methods();
}

public static Session get_record(Session session, string _session)
public static Session get_record(Session session, string sessionOpaqueRef)
{
Session newSession = new Session(session.Url) { opaque_ref = _session };
Session newSession = new Session(session.Url) { opaque_ref = sessionOpaqueRef };
newSession.SetAPIVersion();
return newSession;
}
Expand Down Expand Up @@ -402,13 +413,13 @@ public void logout(Session session2)
/// <summary>
/// Log out of the session with the given reference, using this session for the connection.
/// </summary>
/// <param name="_self">The session to log out</param>
public void logout(string _self)
/// <param name="self">The session to log out</param>
public void logout(string self)
{
if (_self == null)
if (self == null)
return;

JsonRpcClient.session_logout(_self);
JsonRpcClient.session_logout(self);
}

public void local_logout()
Expand Down Expand Up @@ -451,74 +462,74 @@ public string get_this_host()
return get_this_host(this, opaque_ref);
}

public static string get_this_host(Session session, string _self)
public static string get_this_host(Session session, string self)
{
return session.JsonRpcClient.session_get_this_host(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_this_host(session.opaque_ref, self ?? "");
}

public string get_this_user()
{
return get_this_user(this, opaque_ref);
}

public static string get_this_user(Session session, string _self)
public static string get_this_user(Session session, string self)
{
return session.JsonRpcClient.session_get_this_user(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_this_user(session.opaque_ref, self ?? "");
}

public bool get_is_local_superuser()
{
return get_is_local_superuser(this, opaque_ref);
}

public static bool get_is_local_superuser(Session session, string _self)
public static bool get_is_local_superuser(Session session, string self)
{
return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, self ?? "");
}

public static string[] get_rbac_permissions(Session session, string _self)
public static string[] get_rbac_permissions(Session session, string self)
{
return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, self ?? "");
}

public DateTime get_last_active()
{
return get_last_active(this, opaque_ref);
}

public static DateTime get_last_active(Session session, string _self)
public static DateTime get_last_active(Session session, string self)
{
return session.JsonRpcClient.session_get_last_active(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_last_active(session.opaque_ref, self ?? "");
}

public bool get_pool()
{
return get_pool(this, opaque_ref);
}

public static bool get_pool(Session session, string _self)
public static bool get_pool(Session session, string self)
{
return session.JsonRpcClient.session_get_pool(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_pool(session.opaque_ref, self ?? "");
}

public XenRef<Subject> get_subject()
{
return get_subject(this, opaque_ref);
}

public static XenRef<Subject> get_subject(Session session, string _self)
public static XenRef<Subject> get_subject(Session session, string self)
{
return session.JsonRpcClient.session_get_subject(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_subject(session.opaque_ref, self ?? "");
}

public string get_auth_user_sid()
{
return get_auth_user_sid(this, opaque_ref);
}

public static string get_auth_user_sid(Session session, string _self)
public static string get_auth_user_sid(Session session, string self)
{
return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, self ?? "");
}

#region AD SID enumeration and bootout
Expand All @@ -543,25 +554,25 @@ public static XenRef<Task> async_get_all_subject_identifiers(Session session)
return session.JsonRpcClient.async_session_get_all_subject_identifiers(session.opaque_ref);
}

public string logout_subject_identifier(string subject_identifier)
public string logout_subject_identifier(string subjectIdentifier)
{
return logout_subject_identifier(this, subject_identifier);
return logout_subject_identifier(this, subjectIdentifier);
}

public static string logout_subject_identifier(Session session, string subject_identifier)
public static string logout_subject_identifier(Session session, string subjectIdentifier)
{
session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subject_identifier);
session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subjectIdentifier);
return string.Empty;
}

public XenRef<Task> async_logout_subject_identifier(string subject_identifier)
public XenRef<Task> async_logout_subject_identifier(string subjectIdentifier)
{
return async_logout_subject_identifier(this, subject_identifier);
return async_logout_subject_identifier(this, subjectIdentifier);
}

public static XenRef<Task> async_logout_subject_identifier(Session session, string subject_identifier)
public static XenRef<Task> async_logout_subject_identifier(Session session, string subjectIdentifier)
{
return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier);
return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subjectIdentifier);
}

#endregion
Expand All @@ -573,39 +584,39 @@ public Dictionary<string, string> get_other_config()
return get_other_config(this, opaque_ref);
}

public static Dictionary<string, string> get_other_config(Session session, string _self)
public static Dictionary<string, string> get_other_config(Session session, string self)
{
return session.JsonRpcClient.session_get_other_config(session.opaque_ref, _self ?? "");
return session.JsonRpcClient.session_get_other_config(session.opaque_ref, self ?? "");
}

public void set_other_config(Dictionary<string, string> _other_config)
public void set_other_config(Dictionary<string, string> otherConfig)
{
set_other_config(this, opaque_ref, _other_config);
set_other_config(this, opaque_ref, otherConfig);
}

public static void set_other_config(Session session, string _self, Dictionary<string, string> _other_config)
public static void set_other_config(Session session, string self, Dictionary<string, string> otherConfig)
{
session.JsonRpcClient.session_set_other_config(session.opaque_ref, _self ?? "", _other_config);
session.JsonRpcClient.session_set_other_config(session.opaque_ref, self ?? "", otherConfig);
}

public void add_to_other_config(string _key, string _value)
public void add_to_other_config(string key, string value)
{
add_to_other_config(this, opaque_ref, _key, _value);
add_to_other_config(this, opaque_ref, key, value);
}

public static void add_to_other_config(Session session, string _self, string _key, string _value)
public static void add_to_other_config(Session session, string self, string key, string value)
{
session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, _self ?? "", _key ?? "", _value ?? "");
session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, self ?? "", key ?? "", value ?? "");
}

public void remove_from_other_config(string _key)
public void remove_from_other_config(string key)
{
remove_from_other_config(this, opaque_ref, _key);
remove_from_other_config(this, opaque_ref, key);
}

public static void remove_from_other_config(Session session, string _self, string _key)
public static void remove_from_other_config(Session session, string self, string key)
{
session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, _self ?? "", _key ?? "");
session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, self ?? "", key ?? "");
}

#endregion
Expand Down
10 changes: 1 addition & 9 deletions ocaml/sdk-gen/csharp/autogen/src/XenObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ public abstract partial class XenObject<S> : IXenObject where S : XenObject<S>
/// </summary>
public abstract void UpdateFrom(S record);

/// <summary>
/// Save any changed fields to the server.
/// This method is usually invoked on a thread pool thread.
/// </summary>
/// <param name="session"></param>
/// <param name="serverOpaqueRef"/>
/// <param name="serverObject">Changes are sent to the server if the field in "this"
/// is different from serverObject. Can be the object in the cache, or another reference
/// object that we want to save changes to.</param>
[Obsolete("Use the calls setting individual fields of the API object instead.")]
public abstract string SaveChanges(Session session, string serverOpaqueRef, S serverObject);

public string opaque_ref { get; set; }
Expand Down
Loading
Loading