@@ -65,6 +65,11 @@ public partial class Session : XenObject<Session>
6565 private string [ ] permissions = null ;
6666 private List < Role > roles = new List < Role > ( ) ;
6767
68+ /// <summary>
69+ /// Applies only to API 2.6 (ely) or 2.8 (inverness) and above.
70+ /// </summary>
71+ public Action < Session > XmlRpcToJsonRpcInvoker = SwitchToJsonRpcBackend ;
72+
6873 #region Constructors
6974
7075 public Session ( int timeout , string url )
@@ -99,7 +104,8 @@ public Session(string url, string opaqueRef)
99104 {
100105 opaque_ref = opaqueRef ;
101106 SetAPIVersion ( ) ;
102- SwapRpcBackend ( ) ;
107+ if ( XmlRpcToJsonRpcInvoker != null )
108+ XmlRpcToJsonRpcInvoker ( this ) ;
103109 SetADDetails ( ) ;
104110 SetRbacPermissions ( ) ;
105111 }
@@ -129,7 +135,8 @@ public static Session get_record(Session session, string _session)
129135 Session newSession = new Session ( session . proxy . Url ) ;
130136 newSession . opaque_ref = _session ;
131137 newSession . SetAPIVersion ( ) ;
132- newSession . SwapRpcBackend ( ) ;
138+ if ( newSession . XmlRpcToJsonRpcInvoker != null )
139+ newSession . XmlRpcToJsonRpcInvoker ( newSession ) ;
133140 return newSession ;
134141 }
135142
@@ -296,7 +303,8 @@ public void login_with_password(string username, string password)
296303 opaque_ref = proxy . session_login_with_password ( username , password ) . parse ( ) ;
297304
298305 SetAPIVersion ( ) ;
299- SwapRpcBackend ( ) ;
306+ if ( XmlRpcToJsonRpcInvoker != null )
307+ XmlRpcToJsonRpcInvoker ( this ) ;
300308 }
301309
302310 public void login_with_password ( string username , string password , string version )
@@ -309,7 +317,8 @@ public void login_with_password(string username, string password, string version
309317 opaque_ref = proxy . session_login_with_password ( username , password , version ) . parse ( ) ;
310318
311319 SetAPIVersion ( ) ;
312- SwapRpcBackend ( ) ;
320+ if ( XmlRpcToJsonRpcInvoker != null )
321+ XmlRpcToJsonRpcInvoker ( this ) ;
313322 SetADDetails ( ) ;
314323 SetRbacPermissions ( ) ;
315324 }
@@ -337,7 +346,8 @@ public void login_with_password(string username, string password, string version
337346 opaque_ref = proxy . session_login_with_password ( username , password , version , originator ) . parse ( ) ;
338347
339348 SetAPIVersion ( ) ;
340- SwapRpcBackend ( ) ;
349+ if ( XmlRpcToJsonRpcInvoker != null )
350+ XmlRpcToJsonRpcInvoker ( this ) ;
341351 SetADDetails ( ) ;
342352 SetRbacPermissions ( ) ;
343353 }
@@ -374,27 +384,27 @@ private void SetAPIVersion()
374384 /// <summary>
375385 /// Applies only to API 2.6 (ely) or 2.8 (inverness) and above.
376386 /// </summary>
377- private void SwapRpcBackend ( )
387+ private static void SwitchToJsonRpcBackend ( Session session )
378388 {
379- JsonRpcClient = null ;
380- bool isELy = APIVersion == API_Version . API_2_6 ;
381- bool isInvernessOrAbove = APIVersion >= API_Version . API_2_8 ;
389+ session . JsonRpcClient = null ;
390+ bool isELy = session . APIVersion == API_Version . API_2_6 ;
391+ bool isInvernessOrAbove = session . APIVersion >= API_Version . API_2_8 ;
382392
383393 if ( isELy || isInvernessOrAbove )
384394 {
385- JsonRpcClient = new JsonRpcClient ( proxy . Url )
395+ session . JsonRpcClient = new JsonRpcClient ( session . proxy . Url )
386396 {
387- ConnectionGroupName = proxy . ConnectionGroupName ,
388- Timeout = proxy . Timeout ,
389- KeepAlive = proxy . KeepAlive ,
390- UserAgent = proxy . UserAgent ,
391- WebProxy = proxy . Proxy
397+ ConnectionGroupName = session . proxy . ConnectionGroupName ,
398+ Timeout = session . proxy . Timeout ,
399+ KeepAlive = session . proxy . KeepAlive ,
400+ UserAgent = session . proxy . UserAgent ,
401+ WebProxy = session . proxy . Proxy
392402 } ;
393403
394404 if ( isInvernessOrAbove )
395- JsonRpcClient . JsonRpcVersion = JsonRpcVersion . v2 ;
405+ session . JsonRpcClient . JsonRpcVersion = JsonRpcVersion . v2 ;
396406
397- proxy = null ;
407+ session . proxy = null ;
398408 }
399409 }
400410
0 commit comments