Skip to content

Commit a248a71

Browse files
authored
Support for .NET8 and Tracing information (#6628)
The commit authored by Edwin is porting the changes from #5929.
2 parents f5eb08d + 47f1300 commit a248a71

File tree

10 files changed

+353
-183
lines changed

10 files changed

+353
-183
lines changed

.github/workflows/generate-and-build-sdks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jobs:
188188
- name: Build C# SDK
189189
shell: pwsh
190190
run: |
191-
dotnet build source/src `
191+
dotnet build source/src/XenServer.csproj `
192192
--disable-build-servers `
193193
--configuration Release `
194194
-p:Version=${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned `

ocaml/sdk-gen/csharp/autogen/src/Event.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public override void UpdateFrom(Event update)
4545
id = update.id;
4646
}
4747

48+
[Obsolete("Use the calls setting individual fields of the API object instead.")]
4849
public override string SaveChanges(Session session, string opaqueRef, Event serverObject)
4950
{
5051
if (opaqueRef == null)

ocaml/sdk-gen/csharp/autogen/src/Failure.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
using System.Collections.Generic;
3232
using System.Linq;
3333
using System.Resources;
34+
#if !(NET8_0_OR_GREATER)
3435
using System.Runtime.Serialization;
3536
using System.Text.RegularExpressions;
3637
using System.Xml;
38+
#endif
3739
using Newtonsoft.Json.Linq;
3840

3941

@@ -88,12 +90,14 @@ public Failure(string message, Exception exception)
8890
ParseExceptionMessage();
8991
}
9092

93+
#if !(NET8_0_OR_GREATER)
9194
protected Failure(SerializationInfo info, StreamingContext context)
9295
: base(info, context)
9396
{
9497
errorDescription = (List<string>)info.GetValue("errorDescription", typeof(List<string>));
9598
errorText = info.GetString("errorText");
9699
}
100+
#endif
97101

98102
#endregion
99103

@@ -174,7 +178,7 @@ public override string ToString()
174178
{
175179
return Message;
176180
}
177-
181+
#if !(NET8_0_OR_GREATER)
178182
public override void GetObjectData(SerializationInfo info, StreamingContext context)
179183
{
180184
if (info == null)
@@ -185,5 +189,6 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
185189

186190
base.GetObjectData(info, context);
187191
}
192+
#endif
188193
}
189194
}

ocaml/sdk-gen/csharp/autogen/src/HTTP.cs

Lines changed: 52 additions & 61 deletions
Large diffs are not rendered by default.

ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs

Lines changed: 223 additions & 54 deletions
Large diffs are not rendered by default.

ocaml/sdk-gen/csharp/autogen/src/Session.cs

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
using System.Collections.Generic;
3232
using System.Linq;
3333
using System.Net;
34+
#if (NET8_0_OR_GREATER)
35+
using System.Net.Http;
36+
using System.Security.Cryptography.X509Certificates;
37+
#endif
3438
using System.Net.Security;
3539
using Newtonsoft.Json;
3640

@@ -44,7 +48,7 @@ public partial class Session : XenObject<Session>
4448
/// <summary>
4549
/// This string is used as the HTTP UserAgent for each request.
4650
/// </summary>
47-
public static string UserAgent = string.Format("XenAPI/{0}", Helper.APIVersionString(API_Version.LATEST));
51+
public static string UserAgent = $"XenAPI/{Helper.APIVersionString(API_Version.LATEST)}";
4852

4953
/// <summary>
5054
/// If null, no proxy is used, otherwise this proxy is used for each request.
@@ -55,8 +59,6 @@ public partial class Session : XenObject<Session>
5559

5660
public object Tag;
5761

58-
private List<Role> roles = new List<Role>();
59-
6062
#region Constructors
6163

6264
public Session(JsonRpcClient client)
@@ -124,7 +126,7 @@ public Session(Session session)
124126

125127
private static string GetUrl(string hostname, int port)
126128
{
127-
return string.Format("{0}://{1}:{2}", port == 8080 || port == 80 ? "http" : "https", hostname, port);
129+
return $"{(port == 8080 || port == 80 ? "http" : "https")}://{hostname}:{port}";
128130
}
129131

130132
private void SetupSessionDetails()
@@ -159,7 +161,7 @@ private void CopyADFromSession(Session session)
159161
IsLocalSuperuser = session.IsLocalSuperuser;
160162
SessionSubject = session.SessionSubject;
161163
UserSid = session.UserSid;
162-
roles = session.Roles;
164+
Roles = session.Roles;
163165
Permissions = session.Permissions;
164166
}
165167

@@ -208,7 +210,7 @@ private void SetRbacPermissions()
208210
if (r.subroles.Count > 0 && r.name_label == s)
209211
{
210212
r.opaque_ref = xr.opaque_ref;
211-
roles.Add(r);
213+
Roles.Add(r);
212214
break;
213215
}
214216
}
@@ -220,7 +222,8 @@ public override void UpdateFrom(Session update)
220222
throw new Exception("The method or operation is not implemented.");
221223
}
222224

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

254+
#if (NET8_0_OR_GREATER)
255+
public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateValidationCallback
256+
{
257+
get => JsonRpcClient?.ServerCertificateValidationCallback;
258+
set => JsonRpcClient.ServerCertificateValidationCallback = value;
259+
}
260+
#else
251261
public RemoteCertificateValidationCallback ServerCertificateValidationCallback
252262
{
253263
get => JsonRpcClient?.ServerCertificateValidationCallback;
254264
set => JsonRpcClient.ServerCertificateValidationCallback = value;
255265
}
266+
#endif
256267

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

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

311322
#endregion
312323

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

318-
public static Session get_record(Session session, string _session)
329+
public static Session get_record(Session session, string sessionOpaqueRef)
319330
{
320-
Session newSession = new Session(session.Url) { opaque_ref = _session };
331+
Session newSession = new Session(session.Url) { opaque_ref = sessionOpaqueRef };
321332
newSession.SetAPIVersion();
322333
return newSession;
323334
}
@@ -402,13 +413,13 @@ public void logout(Session session2)
402413
/// <summary>
403414
/// Log out of the session with the given reference, using this session for the connection.
404415
/// </summary>
405-
/// <param name="_self">The session to log out</param>
406-
public void logout(string _self)
416+
/// <param name="self">The session to log out</param>
417+
public void logout(string self)
407418
{
408-
if (_self == null)
419+
if (self == null)
409420
return;
410421

411-
JsonRpcClient.session_logout(_self);
422+
JsonRpcClient.session_logout(self);
412423
}
413424

414425
public void local_logout()
@@ -451,74 +462,74 @@ public string get_this_host()
451462
return get_this_host(this, opaque_ref);
452463
}
453464

454-
public static string get_this_host(Session session, string _self)
465+
public static string get_this_host(Session session, string self)
455466
{
456-
return session.JsonRpcClient.session_get_this_host(session.opaque_ref, _self ?? "");
467+
return session.JsonRpcClient.session_get_this_host(session.opaque_ref, self ?? "");
457468
}
458469

459470
public string get_this_user()
460471
{
461472
return get_this_user(this, opaque_ref);
462473
}
463474

464-
public static string get_this_user(Session session, string _self)
475+
public static string get_this_user(Session session, string self)
465476
{
466-
return session.JsonRpcClient.session_get_this_user(session.opaque_ref, _self ?? "");
477+
return session.JsonRpcClient.session_get_this_user(session.opaque_ref, self ?? "");
467478
}
468479

469480
public bool get_is_local_superuser()
470481
{
471482
return get_is_local_superuser(this, opaque_ref);
472483
}
473484

474-
public static bool get_is_local_superuser(Session session, string _self)
485+
public static bool get_is_local_superuser(Session session, string self)
475486
{
476-
return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, _self ?? "");
487+
return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, self ?? "");
477488
}
478489

479-
public static string[] get_rbac_permissions(Session session, string _self)
490+
public static string[] get_rbac_permissions(Session session, string self)
480491
{
481-
return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, _self ?? "");
492+
return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, self ?? "");
482493
}
483494

484495
public DateTime get_last_active()
485496
{
486497
return get_last_active(this, opaque_ref);
487498
}
488499

489-
public static DateTime get_last_active(Session session, string _self)
500+
public static DateTime get_last_active(Session session, string self)
490501
{
491-
return session.JsonRpcClient.session_get_last_active(session.opaque_ref, _self ?? "");
502+
return session.JsonRpcClient.session_get_last_active(session.opaque_ref, self ?? "");
492503
}
493504

494505
public bool get_pool()
495506
{
496507
return get_pool(this, opaque_ref);
497508
}
498509

499-
public static bool get_pool(Session session, string _self)
510+
public static bool get_pool(Session session, string self)
500511
{
501-
return session.JsonRpcClient.session_get_pool(session.opaque_ref, _self ?? "");
512+
return session.JsonRpcClient.session_get_pool(session.opaque_ref, self ?? "");
502513
}
503514

504515
public XenRef<Subject> get_subject()
505516
{
506517
return get_subject(this, opaque_ref);
507518
}
508519

509-
public static XenRef<Subject> get_subject(Session session, string _self)
520+
public static XenRef<Subject> get_subject(Session session, string self)
510521
{
511-
return session.JsonRpcClient.session_get_subject(session.opaque_ref, _self ?? "");
522+
return session.JsonRpcClient.session_get_subject(session.opaque_ref, self ?? "");
512523
}
513524

514525
public string get_auth_user_sid()
515526
{
516527
return get_auth_user_sid(this, opaque_ref);
517528
}
518529

519-
public static string get_auth_user_sid(Session session, string _self)
530+
public static string get_auth_user_sid(Session session, string self)
520531
{
521-
return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, _self ?? "");
532+
return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, self ?? "");
522533
}
523534

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

546-
public string logout_subject_identifier(string subject_identifier)
557+
public string logout_subject_identifier(string subjectIdentifier)
547558
{
548-
return logout_subject_identifier(this, subject_identifier);
559+
return logout_subject_identifier(this, subjectIdentifier);
549560
}
550561

551-
public static string logout_subject_identifier(Session session, string subject_identifier)
562+
public static string logout_subject_identifier(Session session, string subjectIdentifier)
552563
{
553-
session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subject_identifier);
564+
session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subjectIdentifier);
554565
return string.Empty;
555566
}
556567

557-
public XenRef<Task> async_logout_subject_identifier(string subject_identifier)
568+
public XenRef<Task> async_logout_subject_identifier(string subjectIdentifier)
558569
{
559-
return async_logout_subject_identifier(this, subject_identifier);
570+
return async_logout_subject_identifier(this, subjectIdentifier);
560571
}
561572

562-
public static XenRef<Task> async_logout_subject_identifier(Session session, string subject_identifier)
573+
public static XenRef<Task> async_logout_subject_identifier(Session session, string subjectIdentifier)
563574
{
564-
return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier);
575+
return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subjectIdentifier);
565576
}
566577

567578
#endregion
@@ -573,39 +584,39 @@ public Dictionary<string, string> get_other_config()
573584
return get_other_config(this, opaque_ref);
574585
}
575586

576-
public static Dictionary<string, string> get_other_config(Session session, string _self)
587+
public static Dictionary<string, string> get_other_config(Session session, string self)
577588
{
578-
return session.JsonRpcClient.session_get_other_config(session.opaque_ref, _self ?? "");
589+
return session.JsonRpcClient.session_get_other_config(session.opaque_ref, self ?? "");
579590
}
580591

581-
public void set_other_config(Dictionary<string, string> _other_config)
592+
public void set_other_config(Dictionary<string, string> otherConfig)
582593
{
583-
set_other_config(this, opaque_ref, _other_config);
594+
set_other_config(this, opaque_ref, otherConfig);
584595
}
585596

586-
public static void set_other_config(Session session, string _self, Dictionary<string, string> _other_config)
597+
public static void set_other_config(Session session, string self, Dictionary<string, string> otherConfig)
587598
{
588-
session.JsonRpcClient.session_set_other_config(session.opaque_ref, _self ?? "", _other_config);
599+
session.JsonRpcClient.session_set_other_config(session.opaque_ref, self ?? "", otherConfig);
589600
}
590601

591-
public void add_to_other_config(string _key, string _value)
602+
public void add_to_other_config(string key, string value)
592603
{
593-
add_to_other_config(this, opaque_ref, _key, _value);
604+
add_to_other_config(this, opaque_ref, key, value);
594605
}
595606

596-
public static void add_to_other_config(Session session, string _self, string _key, string _value)
607+
public static void add_to_other_config(Session session, string self, string key, string value)
597608
{
598-
session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, _self ?? "", _key ?? "", _value ?? "");
609+
session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, self ?? "", key ?? "", value ?? "");
599610
}
600611

601-
public void remove_from_other_config(string _key)
612+
public void remove_from_other_config(string key)
602613
{
603-
remove_from_other_config(this, opaque_ref, _key);
614+
remove_from_other_config(this, opaque_ref, key);
604615
}
605616

606-
public static void remove_from_other_config(Session session, string _self, string _key)
617+
public static void remove_from_other_config(Session session, string self, string key)
607618
{
608-
session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, _self ?? "", _key ?? "");
619+
session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, self ?? "", key ?? "");
609620
}
610621

611622
#endregion

ocaml/sdk-gen/csharp/autogen/src/XenObject.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@ public abstract partial class XenObject<S> : IXenObject where S : XenObject<S>
4242
/// </summary>
4343
public abstract void UpdateFrom(S record);
4444

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

5648
public string opaque_ref { get; set; }

0 commit comments

Comments
 (0)