31
31
using System . Collections . Generic ;
32
32
using System . Linq ;
33
33
using System . Net ;
34
+ #if ( NET8_0_OR_GREATER )
35
+ using System . Net . Http ;
36
+ using System . Security . Cryptography . X509Certificates ;
37
+ #endif
34
38
using System . Net . Security ;
35
39
using Newtonsoft . Json ;
36
40
@@ -44,7 +48,7 @@ public partial class Session : XenObject<Session>
44
48
/// <summary>
45
49
/// This string is used as the HTTP UserAgent for each request.
46
50
/// </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 ) } " ;
48
52
49
53
/// <summary>
50
54
/// If null, no proxy is used, otherwise this proxy is used for each request.
@@ -55,8 +59,6 @@ public partial class Session : XenObject<Session>
55
59
56
60
public object Tag ;
57
61
58
- private List < Role > roles = new List < Role > ( ) ;
59
-
60
62
#region Constructors
61
63
62
64
public Session ( JsonRpcClient client )
@@ -124,7 +126,7 @@ public Session(Session session)
124
126
125
127
private static string GetUrl ( string hostname , int port )
126
128
{
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 } " ;
128
130
}
129
131
130
132
private void SetupSessionDetails ( )
@@ -159,7 +161,7 @@ private void CopyADFromSession(Session session)
159
161
IsLocalSuperuser = session . IsLocalSuperuser ;
160
162
SessionSubject = session . SessionSubject ;
161
163
UserSid = session . UserSid ;
162
- roles = session . Roles ;
164
+ Roles = session . Roles ;
163
165
Permissions = session . Permissions ;
164
166
}
165
167
@@ -208,7 +210,7 @@ private void SetRbacPermissions()
208
210
if ( r . subroles . Count > 0 && r . name_label == s )
209
211
{
210
212
r . opaque_ref = xr . opaque_ref ;
211
- roles . Add ( r ) ;
213
+ Roles . Add ( r ) ;
212
214
break ;
213
215
}
214
216
}
@@ -220,7 +222,8 @@ public override void UpdateFrom(Session update)
220
222
throw new Exception ( "The method or operation is not implemented." ) ;
221
223
}
222
224
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 )
224
227
{
225
228
throw new Exception ( "The method or operation is not implemented." ) ;
226
229
}
@@ -248,11 +251,19 @@ public int Timeout
248
251
set => JsonRpcClient . Timeout = value ;
249
252
}
250
253
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
251
261
public RemoteCertificateValidationCallback ServerCertificateValidationCallback
252
262
{
253
263
get => JsonRpcClient ? . ServerCertificateValidationCallback ;
254
264
set => JsonRpcClient . ServerCertificateValidationCallback = value ;
255
265
}
266
+ #endif
256
267
257
268
public ICredentials Credentials => JsonRpcClient ? . WebProxy ? . Credentials ;
258
269
@@ -306,7 +317,7 @@ public Dictionary<string, string> RequestHeaders
306
317
/// instead use Permissions. This list should only be used for UI purposes.
307
318
/// </summary>
308
319
[ JsonConverter ( typeof ( XenRefListConverter < Role > ) ) ]
309
- public List < Role > Roles => roles ;
320
+ public List < Role > Roles { get ; private set ; }
310
321
311
322
#endregion
312
323
@@ -315,9 +326,9 @@ public string[] GetSystemMethods()
315
326
return JsonRpcClient . system_list_methods ( ) ;
316
327
}
317
328
318
- public static Session get_record ( Session session , string _session )
329
+ public static Session get_record ( Session session , string sessionOpaqueRef )
319
330
{
320
- Session newSession = new Session ( session . Url ) { opaque_ref = _session } ;
331
+ Session newSession = new Session ( session . Url ) { opaque_ref = sessionOpaqueRef } ;
321
332
newSession . SetAPIVersion ( ) ;
322
333
return newSession ;
323
334
}
@@ -402,13 +413,13 @@ public void logout(Session session2)
402
413
/// <summary>
403
414
/// Log out of the session with the given reference, using this session for the connection.
404
415
/// </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 )
407
418
{
408
- if ( _self == null )
419
+ if ( self == null )
409
420
return ;
410
421
411
- JsonRpcClient . session_logout ( _self ) ;
422
+ JsonRpcClient . session_logout ( self ) ;
412
423
}
413
424
414
425
public void local_logout ( )
@@ -451,74 +462,74 @@ public string get_this_host()
451
462
return get_this_host ( this , opaque_ref ) ;
452
463
}
453
464
454
- public static string get_this_host ( Session session , string _self )
465
+ public static string get_this_host ( Session session , string self )
455
466
{
456
- return session . JsonRpcClient . session_get_this_host ( session . opaque_ref , _self ?? "" ) ;
467
+ return session . JsonRpcClient . session_get_this_host ( session . opaque_ref , self ?? "" ) ;
457
468
}
458
469
459
470
public string get_this_user ( )
460
471
{
461
472
return get_this_user ( this , opaque_ref ) ;
462
473
}
463
474
464
- public static string get_this_user ( Session session , string _self )
475
+ public static string get_this_user ( Session session , string self )
465
476
{
466
- return session . JsonRpcClient . session_get_this_user ( session . opaque_ref , _self ?? "" ) ;
477
+ return session . JsonRpcClient . session_get_this_user ( session . opaque_ref , self ?? "" ) ;
467
478
}
468
479
469
480
public bool get_is_local_superuser ( )
470
481
{
471
482
return get_is_local_superuser ( this , opaque_ref ) ;
472
483
}
473
484
474
- public static bool get_is_local_superuser ( Session session , string _self )
485
+ public static bool get_is_local_superuser ( Session session , string self )
475
486
{
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 ?? "" ) ;
477
488
}
478
489
479
- public static string [ ] get_rbac_permissions ( Session session , string _self )
490
+ public static string [ ] get_rbac_permissions ( Session session , string self )
480
491
{
481
- return session . JsonRpcClient . session_get_rbac_permissions ( session . opaque_ref , _self ?? "" ) ;
492
+ return session . JsonRpcClient . session_get_rbac_permissions ( session . opaque_ref , self ?? "" ) ;
482
493
}
483
494
484
495
public DateTime get_last_active ( )
485
496
{
486
497
return get_last_active ( this , opaque_ref ) ;
487
498
}
488
499
489
- public static DateTime get_last_active ( Session session , string _self )
500
+ public static DateTime get_last_active ( Session session , string self )
490
501
{
491
- return session . JsonRpcClient . session_get_last_active ( session . opaque_ref , _self ?? "" ) ;
502
+ return session . JsonRpcClient . session_get_last_active ( session . opaque_ref , self ?? "" ) ;
492
503
}
493
504
494
505
public bool get_pool ( )
495
506
{
496
507
return get_pool ( this , opaque_ref ) ;
497
508
}
498
509
499
- public static bool get_pool ( Session session , string _self )
510
+ public static bool get_pool ( Session session , string self )
500
511
{
501
- return session . JsonRpcClient . session_get_pool ( session . opaque_ref , _self ?? "" ) ;
512
+ return session . JsonRpcClient . session_get_pool ( session . opaque_ref , self ?? "" ) ;
502
513
}
503
514
504
515
public XenRef < Subject > get_subject ( )
505
516
{
506
517
return get_subject ( this , opaque_ref ) ;
507
518
}
508
519
509
- public static XenRef < Subject > get_subject ( Session session , string _self )
520
+ public static XenRef < Subject > get_subject ( Session session , string self )
510
521
{
511
- return session . JsonRpcClient . session_get_subject ( session . opaque_ref , _self ?? "" ) ;
522
+ return session . JsonRpcClient . session_get_subject ( session . opaque_ref , self ?? "" ) ;
512
523
}
513
524
514
525
public string get_auth_user_sid ( )
515
526
{
516
527
return get_auth_user_sid ( this , opaque_ref ) ;
517
528
}
518
529
519
- public static string get_auth_user_sid ( Session session , string _self )
530
+ public static string get_auth_user_sid ( Session session , string self )
520
531
{
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 ?? "" ) ;
522
533
}
523
534
524
535
#region AD SID enumeration and bootout
@@ -543,25 +554,25 @@ public static XenRef<Task> async_get_all_subject_identifiers(Session session)
543
554
return session . JsonRpcClient . async_session_get_all_subject_identifiers ( session . opaque_ref ) ;
544
555
}
545
556
546
- public string logout_subject_identifier ( string subject_identifier )
557
+ public string logout_subject_identifier ( string subjectIdentifier )
547
558
{
548
- return logout_subject_identifier ( this , subject_identifier ) ;
559
+ return logout_subject_identifier ( this , subjectIdentifier ) ;
549
560
}
550
561
551
- public static string logout_subject_identifier ( Session session , string subject_identifier )
562
+ public static string logout_subject_identifier ( Session session , string subjectIdentifier )
552
563
{
553
- session . JsonRpcClient . session_logout_subject_identifier ( session . opaque_ref , subject_identifier ) ;
564
+ session . JsonRpcClient . session_logout_subject_identifier ( session . opaque_ref , subjectIdentifier ) ;
554
565
return string . Empty ;
555
566
}
556
567
557
- public XenRef < Task > async_logout_subject_identifier ( string subject_identifier )
568
+ public XenRef < Task > async_logout_subject_identifier ( string subjectIdentifier )
558
569
{
559
- return async_logout_subject_identifier ( this , subject_identifier ) ;
570
+ return async_logout_subject_identifier ( this , subjectIdentifier ) ;
560
571
}
561
572
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 )
563
574
{
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 ) ;
565
576
}
566
577
567
578
#endregion
@@ -573,39 +584,39 @@ public Dictionary<string, string> get_other_config()
573
584
return get_other_config ( this , opaque_ref ) ;
574
585
}
575
586
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 )
577
588
{
578
- return session . JsonRpcClient . session_get_other_config ( session . opaque_ref , _self ?? "" ) ;
589
+ return session . JsonRpcClient . session_get_other_config ( session . opaque_ref , self ?? "" ) ;
579
590
}
580
591
581
- public void set_other_config ( Dictionary < string , string > _other_config )
592
+ public void set_other_config ( Dictionary < string , string > otherConfig )
582
593
{
583
- set_other_config ( this , opaque_ref , _other_config ) ;
594
+ set_other_config ( this , opaque_ref , otherConfig ) ;
584
595
}
585
596
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 )
587
598
{
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 ) ;
589
600
}
590
601
591
- public void add_to_other_config ( string _key , string _value )
602
+ public void add_to_other_config ( string key , string value )
592
603
{
593
- add_to_other_config ( this , opaque_ref , _key , _value ) ;
604
+ add_to_other_config ( this , opaque_ref , key , value ) ;
594
605
}
595
606
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 )
597
608
{
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 ?? "" ) ;
599
610
}
600
611
601
- public void remove_from_other_config ( string _key )
612
+ public void remove_from_other_config ( string key )
602
613
{
603
- remove_from_other_config ( this , opaque_ref , _key ) ;
614
+ remove_from_other_config ( this , opaque_ref , key ) ;
604
615
}
605
616
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 )
607
618
{
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 ?? "" ) ;
609
620
}
610
621
611
622
#endregion
0 commit comments