diff --git a/ocaml/sdk-gen/csharp/README.dist b/ocaml/sdk-gen/csharp/README.dist index 76e5e5cc72f..a35e923565d 100644 --- a/ocaml/sdk-gen/csharp/README.dist +++ b/ocaml/sdk-gen/csharp/README.dist @@ -38,7 +38,7 @@ https://discussions.citrix.com/forum/101-hypervisor-formerly-xenserver/ Prerequisites ------------- -This library requires .NET 4.5 or greater. +This library requires .NET Standard 2.0. Dependencies @@ -46,11 +46,6 @@ Dependencies XenServer.NET is dependent upon the following libraries: -- XML-RPC.NET by Charles Cook (see http://xml-rpc.net). - XML-RPC.NET is licensed under the MIT X11 license; see - LICENSE.CookComputing.XmlRpcV2.txt for details. A patched version of the library - (CookComputing.XmlRpcV2.dll) is shipped with XenServer.NET. - - Newtonsoft JSON.NET by James Newton-King (see https://www.newtonsoft.com/). JSON.NET is licensed under the MIT license; see LICENSE.Newtonsoft.Json.txt for details. A patched version of the library (Newtonsoft.Json.CH.dll) is @@ -72,24 +67,24 @@ Getting Started Extract the contents of this archive. A. To use the compiled binaries in your code: - 1. Copy XenServer.dll, CookComputing.XmlRpcV2.dll and Newtonsoft.Json.CH.dll + 1. Copy XenServer.dll and Newtonsoft.Json.CH.dll from the bin folder into your own workspace. 2. In Visual Studio, add references to all DLLs from your own program. Project > Add Reference > Browse. 3. You should now be ready to compile against XenServer.NET. B. To build the source code: - 1. Copy CookComputing.XmlRpcV2.dll and Newtonsoft.Json.CH.dll from the bin + 1. Copy Newtonsoft.Json.CH.dll from the bin folder into the source code folder at the same level as the project file XenServer.csproj 2. Open the project XenServer.csproj in Visual Studio. 3. You should now be ready to build the source code. C. To run the examples: - 1. Copy XenServer.dll, CookComputing.XmlRpcV2.dll and Newtonsoft.Json.CH.dll + 1. Copy XenServer.dll and Newtonsoft.Json.CH.dll from the bin folder into the samples folder at the same level as the project file XenSdkSample.csproj. - 2. Open XenSdkSample.sln inside Visual Studio (2013 or greater). + 2. Open XenSdkSample.sln inside Visual Studio (2019 or greater). 3. You should now be ready to compile the solution and run the examples. The solution project is a console application expecting the parameters to be passed to its Main method. diff --git a/ocaml/sdk-gen/csharp/autogen/samples/XenSdkSample.csproj b/ocaml/sdk-gen/csharp/autogen/samples/XenSdkSample.csproj index e6d7e09090e..8a8b965e9ef 100644 --- a/ocaml/sdk-gen/csharp/autogen/samples/XenSdkSample.csproj +++ b/ocaml/sdk-gen/csharp/autogen/samples/XenSdkSample.csproj @@ -53,10 +53,7 @@ false - - False - .\CookComputing.XmlRpcV2.dll - + False .\Newtonsoft.Json.CH.dll @@ -96,4 +93,4 @@ --> - + \ No newline at end of file diff --git a/ocaml/sdk-gen/csharp/autogen/src/Converters.cs b/ocaml/sdk-gen/csharp/autogen/src/Converters.cs index dbb8a218603..69836b2aac7 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/Converters.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/Converters.cs @@ -28,7 +28,6 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ - using System; using System.Collections.Generic; using System.Globalization; diff --git a/ocaml/sdk-gen/csharp/autogen/src/Event.cs b/ocaml/sdk-gen/csharp/autogen/src/Event.cs index 78c2fe2f7c4..8d7b2672aa7 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/Event.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/Event.cs @@ -30,10 +30,8 @@ using System; using System.Collections.Generic; -using CookComputing.XmlRpc; using Newtonsoft.Json; - namespace XenAPI { [JsonConverter(typeof(XenEventConverter))] @@ -86,66 +84,42 @@ public override string SaveChanges(Session session, string opaqueRef, Event serv public static Event get_record(Session session, string _event) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.event_get_record(session.opaque_ref, _event); - else - return new Event(session.XmlRpcProxy.event_get_record(session.opaque_ref, _event ?? "").parse()); + return session.JsonRpcClient.event_get_record(session.opaque_ref, _event); } public static string get_by_uuid(Session session, string _uuid) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.event_get_by_uuid(session.opaque_ref, _uuid); - else - return session.XmlRpcProxy.event_get_by_uuid(session.opaque_ref, _uuid ?? "").parse(); + return session.JsonRpcClient.event_get_by_uuid(session.opaque_ref, _uuid); } public static long get_id(Session session, string _event) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.event_get_id(session.opaque_ref, _event); - else - return long.Parse(session.XmlRpcProxy.event_get_id(session.opaque_ref, _event ?? "").parse()); + return session.JsonRpcClient.event_get_id(session.opaque_ref, _event); } public static void set_id(Session session, string _event, long _id) { - if (session.JsonRpcClient != null) - session.JsonRpcClient.event_set_id(session.opaque_ref, _event, _id); - else - session.XmlRpcProxy.event_set_id(session.opaque_ref, _event ?? "", _id.ToString()).parse(); + session.JsonRpcClient.event_set_id(session.opaque_ref, _event, _id); } public static void register(Session session, string[] _classes) { - if (session.JsonRpcClient != null) - session.JsonRpcClient.event_register(session.opaque_ref, _classes); - else - session.XmlRpcProxy.event_register(session.opaque_ref, _classes).parse(); + session.JsonRpcClient.event_register(session.opaque_ref, _classes); } public static void unregister(Session session, string[] _classes) { - if (session.JsonRpcClient != null) - session.JsonRpcClient.event_unregister(session.opaque_ref, _classes); - else - session.XmlRpcProxy.event_unregister(session.opaque_ref, _classes).parse(); + session.JsonRpcClient.event_unregister(session.opaque_ref, _classes); } public static Proxy_Event[] next(Session session) { - if (session.JsonRpcClient != null) - throw new NotImplementedException(); - else - return session.XmlRpcProxy.event_next(session.opaque_ref).parse(); + throw new NotImplementedException(); } public static IEventCollection from(Session session, string[] _classes, string _token, double _timeout) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.event_from(session.opaque_ref, _classes, _token, _timeout); - else - return session.XmlRpcProxy.event_from(session.opaque_ref, _classes, _token, _timeout).parse(); + return session.JsonRpcClient.event_from(session.opaque_ref, _classes, _token, _timeout); } private long _id; @@ -164,20 +138,16 @@ public long id public string timestamp; - [XmlRpcMember("class")] public string class_; public string operation; - [XmlRpcMember("ref")] public string opaqueRef; - [XmlRpcMember("snapshot")] public object snapshot; } - [XmlRpcMissingMapping(MappingAction.Ignore)] public class EventBatch : IEventCollection { public Event[] events; @@ -185,7 +155,6 @@ public class EventBatch : IEventCollection public string token; } - [XmlRpcMissingMapping(MappingAction.Ignore)] public class Events : IEventCollection { public Proxy_Event[] events; diff --git a/ocaml/sdk-gen/csharp/autogen/src/HTTP.cs b/ocaml/sdk-gen/csharp/autogen/src/HTTP.cs index 9b990f0a2ef..3dd388623b9 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/HTTP.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/HTTP.cs @@ -432,7 +432,6 @@ private static NetworkStream ConnectSocket(Uri uri, bool nodelay, int timeoutMs) Socket socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); socket.NoDelay = nodelay; - //socket.ReceiveBufferSize = 64 * 1024; socket.ReceiveTimeout = timeoutMs; socket.SendTimeout = timeoutMs; socket.Connect(uri.Host, uri.Port); diff --git a/ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs b/ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs index ae15831d640..bbd4ff01139 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs @@ -192,9 +192,9 @@ private void Rpc(string callName, JToken parameters, JsonSerializer serializer) private T Rpc(string callName, JToken parameters, JsonSerializer serializer) { - // Note that the following method handles an overflow condition by wrapping; - // if the _globalId reaches Int32.MaxValue, _globalId + 1 starts over from - // Int32.MinValue and no exception is thrown. + // Note that the following method handles an overflow condition by wrapping. + // If the _globalId reaches Int32.MaxValue, _globalId + 1 starts over from + // Int32.MinValue and no exception is thrown. var id = Interlocked.Increment(ref _globalId); JsonRequest request = JsonRequest.Create(JsonRpcVersion, id, callName, parameters); @@ -207,12 +207,12 @@ private T Rpc(string callName, JToken parameters, JsonSerializer serializer) webRequest.KeepAlive = KeepAlive; webRequest.UserAgent = UserAgent; webRequest.ConnectionGroupName = ConnectionGroupName; - webRequest.ProtocolVersion = ProtocolVersion; + webRequest.ProtocolVersion = ProtocolVersion ?? webRequest.ProtocolVersion; webRequest.ServicePoint.Expect100Continue = Expect100Continue; webRequest.AllowAutoRedirect = AllowAutoRedirect; webRequest.PreAuthenticate = PreAuthenticate; webRequest.AllowWriteStreamBuffering = true; - webRequest.CookieContainer = Cookies; + webRequest.CookieContainer = Cookies ?? webRequest.CookieContainer ?? new CookieContainer(); // for performance reasons it's preferable to deserialize directly // from the Stream rather than allocating strings inbetween @@ -261,7 +261,7 @@ private T Rpc(string callName, JToken parameters, JsonSerializer serializer) #endif if (res2.Error != null) { - var descr = new List {res2.Error.Message}; + var descr = new List { res2.Error.Message }; descr.AddRange(res2.Error.Data.ToObject()); throw new Failure(descr); } diff --git a/ocaml/sdk-gen/csharp/autogen/src/Response.cs b/ocaml/sdk-gen/csharp/autogen/src/Response.cs index ed3b86886e5..42d79f05ed1 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/Response.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/Response.cs @@ -1,38 +1,36 @@ -/* - * Copyright (c) Citrix Systems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1) Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2) Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * Copyright (c) Citrix Systems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; using System.Collections.Generic; -using CookComputing.XmlRpc; - namespace XenAPI { public static class ResponseTypes @@ -44,9 +42,9 @@ public static class ResponseTypes public struct Response { public string Status; - [XmlRpcMissingMapping(MappingAction.Ignore)] + public ValType Value; - [XmlRpcMissingMapping(MappingAction.Ignore)] + public string[] ErrorDescription; public Response(ValType Value) diff --git a/ocaml/sdk-gen/csharp/autogen/src/Session.cs b/ocaml/sdk-gen/csharp/autogen/src/Session.cs index 0d0b87930d1..a016ab58fa5 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/Session.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/Session.cs @@ -32,8 +32,6 @@ using System.Collections.Generic; using System.Linq; using System.Net; - -using CookComputing.XmlRpc; using Newtonsoft.Json; @@ -59,16 +57,20 @@ public partial class Session : XenObject private List roles = new List(); - /// - /// Applies only to API 2.6 (ely) or 2.8 (inverness) and above. - /// - public Action XmlRpcToJsonRpcInvoker = SwitchToJsonRpcBackend; - #region Constructors public Session(int timeout, string url) { - InitializeXmlRpcProxy(url, timeout); + JsonRpcClient = new JsonRpcClient(url) + { + ConnectionGroupName = ConnectionGroupName, + Timeout = timeout, + KeepAlive = true, + UserAgent = UserAgent, + WebProxy = Proxy, + JsonRpcVersion = JsonRpcVersion.v2, + AllowAutoRedirect = true + }; } public Session(string url) @@ -124,18 +126,6 @@ public Session(Session session, int timeout) Cookies = session.JsonRpcClient.Cookies }; } - else if (session.XmlRpcProxy != null) - { - XmlRpcProxy = XmlRpcProxyGen.Create(); - XmlRpcProxy.Url = session.Url; - XmlRpcProxy.Timeout = timeout; - XmlRpcProxy.NonStandard = session.XmlRpcProxy.NonStandard; - XmlRpcProxy.UseIndentation = session.XmlRpcProxy.UseIndentation; - XmlRpcProxy.UserAgent = session.XmlRpcProxy.UserAgent; - XmlRpcProxy.KeepAlive = session.XmlRpcProxy.KeepAlive; - XmlRpcProxy.Proxy = session.XmlRpcProxy.Proxy; - } - CopyADFromSession(session); } @@ -146,28 +136,12 @@ public static Session get_record(Session session, string _session) { Session newSession = new Session(session.Url) {opaque_ref = _session}; newSession.SetAPIVersion(); - if (newSession.XmlRpcToJsonRpcInvoker != null) - newSession.XmlRpcToJsonRpcInvoker(newSession); return newSession; } - private void InitializeXmlRpcProxy(string url, int timeout) - { - XmlRpcProxy = XmlRpcProxyGen.Create(); - XmlRpcProxy.Url = url; - XmlRpcProxy.NonStandard = XmlRpcNonStandard.All; - XmlRpcProxy.Timeout = timeout; - XmlRpcProxy.UseIndentation = false; - XmlRpcProxy.UserAgent = UserAgent; - XmlRpcProxy.KeepAlive = true; - XmlRpcProxy.Proxy = Proxy; - } - private void SetupSessionDetails() { SetAPIVersion(); - if (XmlRpcToJsonRpcInvoker != null) - XmlRpcToJsonRpcInvoker(this); SetADDetails(); SetRbacPermissions(); } @@ -254,18 +228,13 @@ public override string SaveChanges(Session session, string _serverOpaqueRef, Ses throw new Exception("The method or operation is not implemented."); } - public Proxy XmlRpcProxy { get; private set; } - public JsonRpcClient JsonRpcClient { get; private set; } public string Url { get { - if (JsonRpcClient != null) - return JsonRpcClient.Url; - else - return XmlRpcProxy.Url; + return JsonRpcClient.Url; } } @@ -273,17 +242,11 @@ public string ConnectionGroupName { get { - if (JsonRpcClient != null) - return JsonRpcClient.ConnectionGroupName; - else - return XmlRpcProxy.ConnectionGroupName; + return JsonRpcClient?.ConnectionGroupName; } set { - if (JsonRpcClient != null) - JsonRpcClient.ConnectionGroupName = value; - else - XmlRpcProxy.ConnectionGroupName = value; + JsonRpcClient.ConnectionGroupName = value; } } @@ -294,9 +257,6 @@ public ICredentials Credentials if (JsonRpcClient != null) return JsonRpcClient.WebProxy == null ? null : JsonRpcClient.WebProxy.Credentials; - if (XmlRpcProxy != null) - return XmlRpcProxy.Proxy == null ? null : XmlRpcProxy.Proxy.Credentials; - return null; } } @@ -339,11 +299,7 @@ public List Roles public void login_with_password(string username, string password) { - if (JsonRpcClient != null) - opaque_ref = JsonRpcClient.session_login_with_password(username, password); - else - opaque_ref = XmlRpcProxy.session_login_with_password(username, password).parse(); - + opaque_ref = JsonRpcClient.session_login_with_password(username, password); SetupSessionDetails(); } @@ -351,10 +307,7 @@ public void login_with_password(string username, string password, string version { try { - if (JsonRpcClient != null) - opaque_ref = JsonRpcClient.session_login_with_password(username, password, version); - else - opaque_ref = XmlRpcProxy.session_login_with_password(username, password, version).parse(); + opaque_ref = JsonRpcClient.session_login_with_password(username, password, version); SetupSessionDetails(); } @@ -376,10 +329,7 @@ public void login_with_password(string username, string password, string version { try { - if (JsonRpcClient != null) - opaque_ref = JsonRpcClient.session_login_with_password(username, password, version, originator); - else - opaque_ref = XmlRpcProxy.session_login_with_password(username, password, version, originator).parse(); + opaque_ref = JsonRpcClient.session_login_with_password(username, password, version, originator); SetupSessionDetails(); } @@ -414,44 +364,9 @@ private void SetAPIVersion() } } - /// - /// Applies only to API 2.6 (ely) or 2.8 (inverness) and above. - /// - private static void SwitchToJsonRpcBackend(Session session) - { - session.JsonRpcClient = null; - bool isELy = session.APIVersion == API_Version.API_2_6; - bool isInvernessOrAbove = session.APIVersion >= API_Version.API_2_8; - - if (isELy || isInvernessOrAbove) - { - session.JsonRpcClient = new JsonRpcClient(session.XmlRpcProxy.Url) - { - ConnectionGroupName = session.XmlRpcProxy.ConnectionGroupName, - Timeout = session.XmlRpcProxy.Timeout, - KeepAlive = session.XmlRpcProxy.KeepAlive, - UserAgent = session.XmlRpcProxy.UserAgent, - WebProxy = session.XmlRpcProxy.Proxy, - ProtocolVersion = session.XmlRpcProxy.ProtocolVersion, - Expect100Continue = session.XmlRpcProxy.Expect100Continue, - AllowAutoRedirect = session.XmlRpcProxy.AllowAutoRedirect, - PreAuthenticate = session.XmlRpcProxy.PreAuthenticate, - Cookies = session.XmlRpcProxy.CookieContainer - }; - - if (isInvernessOrAbove) - session.JsonRpcClient.JsonRpcVersion = JsonRpcVersion.v2; - - session.XmlRpcProxy = null; - } - } - public void slave_local_login_with_password(string username, string password) { - if (JsonRpcClient != null) - opaque_ref = JsonRpcClient.session_slave_local_login_with_password(username, password); - else - opaque_ref = XmlRpcProxy.session_slave_local_login_with_password(username, password).parse(); + opaque_ref = JsonRpcClient.session_slave_local_login_with_password(username, password); //assume the latest API APIVersion = API_Version.LATEST; } @@ -480,10 +395,7 @@ public void logout(string _self) if (_self == null) return; - if (JsonRpcClient != null) - JsonRpcClient.session_logout(_self); - else - XmlRpcProxy.session_logout(_self).parse(); + JsonRpcClient.session_logout(_self); } public void local_logout() @@ -502,10 +414,7 @@ public void local_logout(string opaqueRef) if (opaqueRef == null) return; - if (JsonRpcClient != null) - JsonRpcClient.session_local_logout(opaqueRef); - else - XmlRpcProxy.session_local_logout(opaqueRef).parse(); + JsonRpcClient.session_local_logout(opaqueRef); } public void change_password(string oldPassword, string newPassword) @@ -521,10 +430,7 @@ public void change_password(string oldPassword, string newPassword) /// public void change_password(Session session2, string oldPassword, string newPassword) { - if (JsonRpcClient != null) - JsonRpcClient.session_change_password(session2.opaque_ref, oldPassword, newPassword); - else - XmlRpcProxy.session_change_password(session2.opaque_ref, oldPassword, newPassword).parse(); + JsonRpcClient.session_change_password(session2.opaque_ref, oldPassword, newPassword); } public string get_this_host() @@ -534,10 +440,7 @@ public string get_this_host() public static string get_this_host(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_this_host(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_this_host(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_this_host(session.opaque_ref, _self ?? ""); } public string get_this_user() @@ -547,10 +450,7 @@ public string get_this_user() public static string get_this_user(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_this_user(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_this_user(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_this_user(session.opaque_ref, _self ?? ""); } public bool get_is_local_superuser() @@ -560,18 +460,12 @@ public bool get_is_local_superuser() public static bool get_is_local_superuser(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_is_local_superuser(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, _self ?? ""); } public static string[] get_rbac_permissions(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_rbac_permissions(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, _self ?? ""); } public DateTime get_last_active() @@ -581,10 +475,7 @@ public DateTime get_last_active() public static DateTime get_last_active(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_last_active(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_last_active(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_last_active(session.opaque_ref, _self ?? ""); } public bool get_pool() @@ -594,10 +485,7 @@ public bool get_pool() public static bool get_pool(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_pool(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_pool(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_pool(session.opaque_ref, _self ?? ""); } public XenRef get_subject() @@ -607,10 +495,7 @@ public XenRef get_subject() public static XenRef get_subject(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_subject(session.opaque_ref, _self ?? ""); - else - return new XenRef(session.XmlRpcProxy.session_get_subject(session.opaque_ref, _self ?? "").parse()); + return session.JsonRpcClient.session_get_subject(session.opaque_ref, _self ?? ""); } public string get_auth_user_sid() @@ -620,10 +505,7 @@ public string get_auth_user_sid() public static string get_auth_user_sid(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, _self ?? ""); - else - return session.XmlRpcProxy.session_get_auth_user_sid(session.opaque_ref, _self ?? "").parse(); + return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, _self ?? ""); } #region AD SID enumeration and bootout @@ -635,10 +517,7 @@ public string[] get_all_subject_identifiers() public static string[] get_all_subject_identifiers(Session session) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_all_subject_identifiers(session.opaque_ref); - else - return session.XmlRpcProxy.session_get_all_subject_identifiers(session.opaque_ref).parse(); + return session.JsonRpcClient.session_get_all_subject_identifiers(session.opaque_ref); } public XenRef async_get_all_subject_identifiers() @@ -648,10 +527,7 @@ public XenRef async_get_all_subject_identifiers() public static XenRef async_get_all_subject_identifiers(Session session) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.async_session_get_all_subject_identifiers(session.opaque_ref); - else - return XenRef.Create(session.XmlRpcProxy.async_session_get_all_subject_identifiers(session.opaque_ref).parse()); + return session.JsonRpcClient.async_session_get_all_subject_identifiers(session.opaque_ref); } public string logout_subject_identifier(string subject_identifier) @@ -661,13 +537,8 @@ public string logout_subject_identifier(string subject_identifier) public static string logout_subject_identifier(Session session, string subject_identifier) { - if (session.JsonRpcClient != null) - { - session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subject_identifier); - return string.Empty; - } - else - return session.XmlRpcProxy.session_logout_subject_identifier(session.opaque_ref, subject_identifier).parse(); + session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subject_identifier); + return string.Empty; } public XenRef async_logout_subject_identifier(string subject_identifier) @@ -677,10 +548,7 @@ public XenRef async_logout_subject_identifier(string subject_identifier) public static XenRef async_logout_subject_identifier(Session session, string subject_identifier) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier); - else - return XenRef.Create(session.XmlRpcProxy.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier).parse()); + return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier); } #endregion @@ -694,10 +562,7 @@ public Dictionary get_other_config() public static Dictionary get_other_config(Session session, string _self) { - if (session.JsonRpcClient != null) - return session.JsonRpcClient.session_get_other_config(session.opaque_ref, _self ?? ""); - else - return Maps.convert_from_proxy_string_string(session.XmlRpcProxy.session_get_other_config(session.opaque_ref, _self ?? "").parse()); + return session.JsonRpcClient.session_get_other_config(session.opaque_ref, _self ?? ""); } public void set_other_config(Dictionary _other_config) @@ -707,10 +572,7 @@ public void set_other_config(Dictionary _other_config) public static void set_other_config(Session session, string _self, Dictionary _other_config) { - if (session.JsonRpcClient != null) - session.JsonRpcClient.session_set_other_config(session.opaque_ref, _self ?? "", _other_config); - else - session.XmlRpcProxy.session_set_other_config(session.opaque_ref, _self ?? "", Maps.convert_to_proxy_string_string(_other_config)).parse(); + session.JsonRpcClient.session_set_other_config(session.opaque_ref, _self ?? "", _other_config); } public void add_to_other_config(string _key, string _value) @@ -720,10 +582,7 @@ public void add_to_other_config(string _key, string _value) public static void add_to_other_config(Session session, string _self, string _key, string _value) { - if (session.JsonRpcClient != null) - session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, _self ?? "", _key ?? "", _value ?? ""); - else - session.XmlRpcProxy.session_add_to_other_config(session.opaque_ref, _self ?? "", _key ?? "", _value ?? "").parse(); + session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, _self ?? "", _key ?? "", _value ?? ""); } public void remove_from_other_config(string _key) @@ -733,10 +592,7 @@ public void remove_from_other_config(string _key) public static void remove_from_other_config(Session session, string _self, string _key) { - if (session.JsonRpcClient != null) - session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, _self ?? "", _key ?? ""); - else - session.XmlRpcProxy.session_remove_from_other_config(session.opaque_ref, _self ?? "", _key ?? "").parse(); + session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, _self ?? "", _key ?? ""); } #endregion diff --git a/ocaml/sdk-gen/csharp/autogen/src/Subject2.cs b/ocaml/sdk-gen/csharp/autogen/src/Subject2.cs index ca10de88e71..a5de37096df 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/Subject2.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/Subject2.cs @@ -28,10 +28,6 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -using System; -using System.Collections.Generic; -using System.Text; - namespace XenAPI { public partial class Subject diff --git a/ocaml/sdk-gen/csharp/autogen/src/UserDetails.cs b/ocaml/sdk-gen/csharp/autogen/src/UserDetails.cs index 6e07d03f17c..b4ca1888584 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/UserDetails.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/UserDetails.cs @@ -30,7 +30,6 @@ using System; using System.Collections.Generic; -using System.Text; namespace XenAPI { diff --git a/ocaml/sdk-gen/csharp/autogen/src/XenObject.cs b/ocaml/sdk-gen/csharp/autogen/src/XenObject.cs index f9d8f66bf47..f5f2fb45e44 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/XenObject.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/XenObject.cs @@ -29,9 +29,7 @@ */ using System; -using System.Collections.Generic; using System.ComponentModel; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/ocaml/sdk-gen/csharp/autogen/src/XenRef.cs b/ocaml/sdk-gen/csharp/autogen/src/XenRef.cs index 58ca9ce76a3..7b02f287a6f 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/XenRef.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/XenRef.cs @@ -1,37 +1,36 @@ -/* - * Copyright (c) Citrix Systems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1) Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2) Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * Copyright (c) Citrix Systems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; using System.Collections; using System.Collections.Generic; -using System.Text; namespace XenAPI { diff --git a/ocaml/sdk-gen/csharp/gen_csharp_binding.ml b/ocaml/sdk-gen/csharp/gen_csharp_binding.ml index 27505968ed6..52fbf011c93 100644 --- a/ocaml/sdk-gen/csharp/gen_csharp_binding.ml +++ b/ocaml/sdk-gen/csharp/gen_csharp_binding.ml @@ -627,7 +627,6 @@ and gen_exposed_method cls msg curParams = let exposed_ret_type = exposed_type_opt msg.msg_result in let paramSignature = exposed_params msg classname curParams in let paramsDoc = get_params_doc msg classname curParams in - let callParams = exposed_call_params ~json:false msg classname curParams in let jsonCallParams = exposed_call_params ~json:true msg classname curParams in let publishInfo = get_published_info_message msg cls in let deprecatedInfo = get_deprecated_info_message msg in @@ -646,10 +645,7 @@ and gen_exposed_method cls msg curParams = \ /// %s%s\n\ \ public static %s %s(%s)\n\ \ {\n\ - \ if (session.JsonRpcClient != null)\n\ - \ %s;\n\ - \ else\n\ - \ %s;\n\ + \ %s;\n\ \ }\n" msg.msg_doc (if publishInfo = "" then "" else "\n /// " ^ publishInfo) @@ -659,10 +655,6 @@ and gen_exposed_method cls msg curParams = (sprintf "session.JsonRpcClient.%s(%s)" proxyMsgName jsonCallParams) msg.msg_result ) - (convert_from_proxy_opt - (sprintf "session.XmlRpcProxy.%s(%s).parse()" proxyMsgName callParams) - msg.msg_result - ) in let async = if msg.msg_async then @@ -673,16 +665,12 @@ and gen_exposed_method cls msg curParams = \ /// %s%s\n\ \ public static XenRef async_%s(%s)\n\ \ {\n\ - \ if (session.JsonRpcClient != null)\n\ - \ return session.JsonRpcClient.async_%s(%s);\n\ - \ else\n\ - \ return \ - XenRef.Create(session.XmlRpcProxy.async_%s(%s).parse());\n\ + \ return session.JsonRpcClient.async_%s(%s);\n\ \ }\n" msg.msg_doc (if publishInfo = "" then "" else "\n /// " ^ publishInfo) deprecatedInfoString paramsDoc deprecatedAttributeString msg.msg_name - paramSignature proxyMsgName jsonCallParams proxyMsgName callParams + paramSignature proxyMsgName jsonCallParams else "" in @@ -874,7 +862,7 @@ and gen_exposed_field out_chan cls content = (* ------------------- category: proxy classes *) and gen_proxy protocol = let all_methods = - classes |> List.map (gen_proxy_class_methods protocol) |> List.concat + classes |> List.map gen_proxy_class_methods |> List.concat in match protocol with | CommonFunctions.XmlRpc -> @@ -900,23 +888,18 @@ and gen_proxy protocol = ; ("proxy_class_fields", `A (List.map proxy_field all_fields)) ] in - let json_method x = `O [("proxy_method", `String x)] in - `O - [ - ("proxy_methods", `A (List.map json_method all_methods)) - ; ("proxy_classes", `A (List.map json_class classes)) - ] + `O [("proxy_classes", `A (List.map json_class classes))] | CommonFunctions.JsonRpc -> let json_method x = `O [("client_method", `String x)] in `O [("client_methods", `A (List.map json_method all_methods))] -and gen_proxy_class_methods protocol {name; messages; _} = - let gen_message_overloads protocol name message = - let generator params = gen_proxy_method protocol name message params in +and gen_proxy_class_methods {name; messages; _} = + let gen_message_overloads name message = + let generator params = gen_proxy_method name message params in gen_overloads generator message in let overloads = - messages |> List.map (gen_message_overloads protocol name) |> List.concat + messages |> List.map (gen_message_overloads name) |> List.concat in let records = if @@ -926,94 +909,67 @@ and gen_proxy_class_methods protocol {name; messages; _} = messages ) then - gen_proxy_method protocol name (get_all_records_method name) [] + gen_proxy_method name (get_all_records_method name) [] else "" in overloads @ [records] -and gen_proxy_method protocol classname message params = - let proxy_ret_type = proxy_type_opt message.msg_result in +and gen_proxy_method classname message params = let proxy_msg_name = proxy_msg_name classname message in - let proxyParams = - proxy_params ~with_types:true ~json:false message classname params - in let paramsJsonWithTypes = proxy_params ~with_types:true ~json:true message classname params in let paramsJsonNoTypes = proxy_params ~with_types:false ~json:true message classname params in - match protocol with - | CommonFunctions.XmlRpc -> - let sync = - sprintf - "\n\ - \ [XmlRpcMethod(\"%s.%s\")]\n\ - \ Response<%s>\n\ - \ %s(%s);" classname message.msg_name proxy_ret_type - proxy_msg_name proxyParams - in - let async = - if message.msg_async then - sprintf - "\n\n\ - \ [XmlRpcMethod(\"Async.%s.%s\")]\n\ - \ Response\n\ - \ async_%s(%s);" classname message.msg_name proxy_msg_name - proxyParams - else - "" - in - sync ^ async - | CommonFunctions.JsonRpc -> - let return_word = - match message.msg_result with Some (_, _) -> "return " | None -> "" - in - let param_converters = - List.map (fun x -> json_converter x.param_type) params - in - let converters = - json_converter_opt message.msg_result :: param_converters - |> List.filter (fun x -> x <> "") - in - let async_converters = - "new XenRefConverter()" :: param_converters - |> List.filter (fun x -> x <> "") - in - let sync = - sprintf - "\n\ - \ public %s %s(%s)\n\ - \ {\n\ - \ var converters = new List {%s};\n\ - \ var serializer = CreateSerializer(converters);\n\ - \ %sRpc%s(\"%s.%s\", new JArray(%s), serializer);\n\ - \ }" - (exposed_type_opt message.msg_result) - proxy_msg_name paramsJsonWithTypes - (String.concat ", " converters) - return_word - (json_deserialise_opt message.msg_result) - classname message.msg_name paramsJsonNoTypes - in - let async = - if message.msg_async then - sprintf - "\n\n\ - \ public XenRef async_%s(%s)\n\ - \ {\n\ - \ var converters = new List {%s};\n\ - \ var serializer = CreateSerializer(converters);\n\ - \ return Rpc>(\"Async.%s.%s\", new \ - JArray(%s), serializer);\n\ - \ }" proxy_msg_name paramsJsonWithTypes - (String.concat ", " async_converters) - classname message.msg_name paramsJsonNoTypes - else - "" - in - sync ^ async + let return_word = + match message.msg_result with Some (_, _) -> "return " | None -> "" + in + let param_converters = + List.map (fun x -> json_converter x.param_type) params + in + let converters = + json_converter_opt message.msg_result :: param_converters + |> List.filter (fun x -> x <> "") + in + let async_converters = + "new XenRefConverter()" :: param_converters + |> List.filter (fun x -> x <> "") + in + let sync = + sprintf + "\n\ + \ public %s %s(%s)\n\ + \ {\n\ + \ var converters = new List {%s};\n\ + \ var serializer = CreateSerializer(converters);\n\ + \ %sRpc%s(\"%s.%s\", new JArray(%s), serializer);\n\ + \ }" + (exposed_type_opt message.msg_result) + proxy_msg_name paramsJsonWithTypes + (String.concat ", " converters) + return_word + (json_deserialise_opt message.msg_result) + classname message.msg_name paramsJsonNoTypes + in + let async = + if message.msg_async then + sprintf + "\n\n\ + \ public XenRef async_%s(%s)\n\ + \ {\n\ + \ var converters = new List {%s};\n\ + \ var serializer = CreateSerializer(converters);\n\ + \ return Rpc>(\"Async.%s.%s\", new JArray(%s), \ + serializer);\n\ + \ }" proxy_msg_name paramsJsonWithTypes + (String.concat ", " async_converters) + classname message.msg_name paramsJsonNoTypes + else + "" + in + sync ^ async and proxy_params ~with_types ~json message classname params = let refParam = @@ -1103,9 +1059,8 @@ and gen_maps' out_chan = "%s\n\n\ using System;\n\ using System.Collections;\n\ - using System.Collections.Generic;\n\ - using CookComputing.XmlRpc;\n\n\n\ - namespace XenAPI\n\ + using System.Collections.Generic;\n\n\ + \ namespace XenAPI\n\ {\n\ \ internal class Maps\n\ \ {" Licence.bsd_two_clause ; @@ -1141,7 +1096,7 @@ and gen_map_conversion out_chan = function \ }\n\ \ catch\n\ \ {\n\ - \ continue;\n\ + \ // continue\n\ \ }\n\ \ }\n\ \ }\n\ @@ -1150,7 +1105,7 @@ and gen_map_conversion out_chan = function \ internal static Hashtable \ convert_to_proxy_%s_%s(Dictionary<%s, %s> table)\n\ \ {\n\ - \ var result = new XmlRpcStruct();\n\ + \ var result = new Hashtable();\n\ \ if (table != null)\n\ \ {\n\ \ foreach (%s key in table.Keys)\n\ @@ -1163,7 +1118,7 @@ and gen_map_conversion out_chan = function \ }\n\ \ catch\n\ \ {\n\ - \ continue;\n\ + \ // continue\n\ \ }\n\ \ }\n\ \ }\n\ @@ -1294,12 +1249,6 @@ and exposed_type_as_literal = function | x -> exposed_type x -and convert_from_proxy_opt thing = function - | Some (typ, _) -> - "return " ^ simple_convert_from_proxy thing typ - | None -> - thing - and convert_from_proxy_hashtable_value thing ty = match ty with | Int -> diff --git a/ocaml/sdk-gen/csharp/templates/Proxy.mustache b/ocaml/sdk-gen/csharp/templates/Proxy.mustache index a8bfe43bc61..a5726aaefa7 100644 --- a/ocaml/sdk-gen/csharp/templates/Proxy.mustache +++ b/ocaml/sdk-gen/csharp/templates/Proxy.mustache @@ -31,65 +31,20 @@ using System; using System.Collections; using System.Collections.Generic; -using CookComputing.XmlRpc; - namespace XenAPI { - public interface Proxy : IXmlRpcProxy - { - [XmlRpcMethod("event.get_record")] - Response - event_get_record(string session, string _event); - - [XmlRpcMethod("event.get_by_uuid")] - Response - event_get_by_uuid(string session, string _uuid); - - [XmlRpcMethod("event.get_id")] - Response - event_get_id(string session, string _event); - - [XmlRpcMethod("event.set_id")] - Response - event_set_id(string session, string _event, string _id); - - [XmlRpcMethod("event.register")] - Response - event_register(string session, string [] _classes); - - [XmlRpcMethod("event.unregister")] - Response - event_unregister(string session, string [] _classes); - - [XmlRpcMethod("event.next")] - Response - event_next(string session); - - [XmlRpcMethod("event.from")] - Response - event_from(string session, string [] _classes, string _token, double _timeout); -{{#proxy_methods}} -{{{proxy_method}}} -{{/proxy_methods}} - } - - [XmlRpcMissingMapping(MappingAction.Ignore)] public class Proxy_Event { public string id; public string timestamp; - [XmlRpcMember("class")] public string class_; public string operation; - [XmlRpcMember("ref")] public string opaqueRef; - [XmlRpcMember("snapshot")] public object snapshot; } {{#proxy_classes}} - [XmlRpcMissingMapping(MappingAction.Ignore)] public class Proxy_{{proxy_class_name}} { {{#proxy_class_fields}} diff --git a/ocaml/sdk-gen/csharp/templates/XenServer.csproj.mustache b/ocaml/sdk-gen/csharp/templates/XenServer.csproj.mustache index fa0ed70f896..53d0e23c374 100644 --- a/ocaml/sdk-gen/csharp/templates/XenServer.csproj.mustache +++ b/ocaml/sdk-gen/csharp/templates/XenServer.csproj.mustache @@ -1,96 +1,32 @@ - - + - Debug - AnyCPU - {83EAC000-F729-475D-AC1D-90DC0791DE8E} + netstandard2.0 Library - Properties XenAPI - XenServer - v4.5 + false - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 true - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - False - .\CookComputing.XmlRpcV2.dll - False .\Newtonsoft.Json.CH.dll - - - - -{{#api_members}} - -{{/api_members}} - - - - - - - - - - - - - - - - - - - - - - - - + True True FriendlyErrorNames.resx - + Designer ResXFileCodeGenerator XenAPI FriendlyErrorNames.Designer.cs - - diff --git a/ocaml/sdk-gen/powershell/README.dist b/ocaml/sdk-gen/powershell/README.dist index c1c900e10f2..a2c173addc1 100644 --- a/ocaml/sdk-gen/powershell/README.dist +++ b/ocaml/sdk-gen/powershell/README.dist @@ -38,7 +38,7 @@ https://discussions.citrix.com/forum/101-hypervisor-formerly-xenserver/ Prerequisites ------------- -This library requires .NET 4.5 and PowerShell 4.0. +This library requires .NET 6.0 and PowerShell 7.2. Dependencies @@ -46,12 +46,6 @@ Dependencies The Citrix Hypervisor PowerShell Module is dependent upon the following libraries: -- XML-RPC.NET by Charles Cook (see http://xml-rpc.net). - XML-RPC.NET is licensed under the MIT X11 license; see - LICENSE.CookComputing.XmlRpcV2.txt for details. A patched version of the library - (CookComputing.XmlRpcV2.dll) is shipped with the Citrix Hypervisor PowerShell - Module. - - Newtonsoft JSON.NET by James Newton-King (see https://www.newtonsoft.com/). JSON.NET is licensed under the MIT license; see LICENSE.Newtonsoft.Json.txt for details. A patched version of the library (Newtonsoft.Json.CH.dll) is @@ -147,9 +141,9 @@ Getting Started Building and Debugging the Source Code -------------------------------------- -1. Copy CookComputing.XmlRpcV2.dll, Newtonsoft.Json.CH.dll, and XenServer.dll from - the XenServerPSModule folder into the source code folder at the same level as - the project file XenServerPowerShell.csproj. +1. Copy Newtonsoft.Json.CH.dll and XenServer.dll from the XenServerPSModule + folder into the source code folder at the same level as the project + file XenServerPowerShell.csproj. 2. Open the project XenServerPowerShell.csproj in Visual Studio (2013 or greater). diff --git a/ocaml/sdk-gen/powershell/autogen/XenServerPSModule.psd1 b/ocaml/sdk-gen/powershell/autogen/XenServerPSModule.psd1 index b3c0bdfd8aa..62b3079b22a 100644 --- a/ocaml/sdk-gen/powershell/autogen/XenServerPSModule.psd1 +++ b/ocaml/sdk-gen/powershell/autogen/XenServerPSModule.psd1 @@ -41,29 +41,23 @@ CompanyName = 'Citrix Systems, Inc' Copyright = 'Copyright (c) Citrix Systems, Inc. All rights reserved.' # Requirements -PowerShellVersion = '4.0' +PowerShellVersion = '7.2' PowerShellHostName = '' PowerShellHostVersion = '' -DotNetFrameworkVersion = '4.5' -CLRVersion = '4.0.30319' ProcessorArchitecture = 'None' #Contents ModuleToProcess = 'XenServerPowerShell.dll' RequiredModules = @() NestedModules = @() -ModuleList = @('XenServerPowerShell.dll') -RequiredAssemblies = @('CookComputing.XmlRpcV2.dll', - 'Newtonsoft.Json.CH.dll', +RequiredAssemblies = @('Newtonsoft.Json.CH.dll', 'XenServer.dll') ScriptsToProcess = @('Initialize-Environment.ps1') TypesToProcess = @('XenServer.types.ps1xml') FormatsToProcess = @('XenServer.format.ps1xml') FileList = @('about_XenServer.help.txt', - 'CookComputing.XmlRpcV2.dll', 'Newtonsoft.Json.CH.dll', 'Initialize-Environment.ps1', - 'LICENSE.CookComputing.XmlRpcV2.txt', 'LICENSE.Newtonsoft.Json.txt', 'LICENSE.txt', 'README.txt', diff --git a/ocaml/sdk-gen/powershell/autogen/src/Connect-XenServer.cs b/ocaml/sdk-gen/powershell/autogen/src/Connect-XenServer.cs index c00e43be1ae..1615ac29ec5 100644 --- a/ocaml/sdk-gen/powershell/autogen/src/Connect-XenServer.cs +++ b/ocaml/sdk-gen/powershell/autogen/src/Connect-XenServer.cs @@ -37,7 +37,6 @@ using System.Security; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; - using XenAPI; namespace Citrix.XenServer.Commands @@ -45,8 +44,7 @@ namespace Citrix.XenServer.Commands [Cmdlet("Connect", "XenServer")] public class ConnectXenServerCommand : PSCmdlet { - private readonly string _apiVersionString = Helper.APIVersionString(API_Version.LATEST); - private string _originator = "XenServerPSModule/" + Helper.APIVersionString(API_Version.LATEST); + private readonly object _certificateValidationLock = new object(); public ConnectXenServerCommand() { @@ -81,7 +79,7 @@ public ConnectXenServerCommand() public string[] OpaqueRef { get; set; } [Parameter] - public string Originator { get { return _originator; } set { _originator = value; } } + public string Originator { get; set; } = "XenServerPSModule/" + Helper.APIVersionString(API_Version.LATEST); [Parameter] public SwitchParameter PassThru { get; set; } @@ -149,9 +147,7 @@ protected override void ProcessRecord() } else { - connUser = Creds.UserName.StartsWith("\\") - ? Creds.GetNetworkCredential().UserName - : Creds.UserName; + connUser = Creds.UserName.StartsWith("\\") ? Creds.GetNetworkCredential().UserName : Creds.UserName; IntPtr ptrPassword = Marshal.SecureStringToBSTR(Creds.Password); connPassword = Marshal.PtrToStringBSTR(ptrPassword); @@ -159,7 +155,7 @@ protected override void ProcessRecord() } } - ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); + ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; if (Url == null || Url.Length == 0) @@ -177,7 +173,7 @@ protected override void ProcessRecord() { if (OpaqueRef.Length != Url.Length) ThrowTerminatingError(new ErrorRecord( - new Exception("The number of opaque references provided should be the same as the number of xenservers."), + new Exception("The number of opaque references provided should be the same as the number of servers."), "", ErrorCategory.InvalidArgument, null)); @@ -194,7 +190,7 @@ protected override void ProcessRecord() session = new Session(Url[i]); try { - session.login_with_password(connUser, connPassword, _apiVersionString, Originator); + session.login_with_password(connUser, connPassword, Helper.APIVersionString(API_Version.LATEST), Originator); } catch (Failure f) { @@ -202,8 +198,7 @@ protected override void ProcessRecord() { ThrowTerminatingError(new ErrorRecord(f, "", ErrorCategory.InvalidArgument, Url[i]) { - ErrorDetails = new ErrorDetails(string.Format("The host you are trying to connect to is a slave. To make regular API calls, please connect to the master host (IP address: {0}).", - f.ErrorDescription[1])) + ErrorDetails = new ErrorDetails($"The host you are trying to connect to is a supporter. To make regular API calls, please connect to the pool coordinator (IP address: {f.ErrorDescription[1]}).") }); } else @@ -211,6 +206,25 @@ protected override void ProcessRecord() throw; } } + catch (WebException e) + { + if (e.InnerException?.InnerException is CertificateValidationException ex) + { + if (ShouldContinue(ex.Message, ex.Caption)) + { + AddCertificate(ex.Hostname, ex.Fingerprint); + i--; + continue; + } + + ThrowTerminatingError(new ErrorRecord(ex, "", ErrorCategory.AuthenticationError, Url[i]) + { + ErrorDetails = new ErrorDetails($"Certificate fingerprint rejected. ({ex.Fingerprint} - {ex.Hostname}).") + }); + } + + throw; + } } else { @@ -218,7 +232,6 @@ protected override void ProcessRecord() } session.Tag = Creds; - session.opaque_ref = session.opaque_ref; sessions[session.opaque_ref] = session; newSessions[session.opaque_ref] = session; @@ -239,67 +252,49 @@ protected override void ProcessRecord() WriteObject(newSessions.Values, true); } - #region Messages - - const string CERT_HAS_CHANGED_CAPTION = "Security Certificate Changed"; - - const string CERT_CHANGED = "The certificate fingerprint of the server you have connected to is:\n{0}\nBut was expected to be:\n{1}\n{2}\nDo you wish to continue?"; - - const string CERT_FOUND_CAPTION = "New Security Certificate"; - - const string CERT_FOUND = "The certificate fingerprint of the server you have connected to is :\n{0}\n{1}\nDo you wish to continue?"; - - const string CERT_TRUSTED = "The certificate on this server is trusted. It is recommended you re-issue this server's certificate."; - - const string CERT_NOT_TRUSTED = "The certificate on this server is not trusted."; - - #endregion - - private readonly object certificateValidationLock = new object(); + private void AddCertificate(string hostname, string fingerprint) + { + var certificates = CommonCmdletFunctions.LoadCertificates(); + certificates[hostname] = fingerprint; + CommonCmdletFunctions.SaveCertificates(certificates); + } - private bool ValidateServerCertificate( - object sender, - X509Certificate certificate, - X509Chain chain, - SslPolicyErrors sslPolicyErrors) + private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; - lock (certificateValidationLock) + lock (_certificateValidationLock) { - bool ignoreChanged = NoWarnCertificates || (bool)GetVariableValue("NoWarnCertificates", false); - bool ignoreNew = ignoreChanged || NoWarnNewCertificates || (bool)GetVariableValue("NoWarnNewCertificates", false); + bool ignoreChanged = Force || NoWarnCertificates || (bool)GetVariableValue("NoWarnCertificates", false); + bool ignoreNew = Force || NoWarnNewCertificates || (bool)GetVariableValue("NoWarnNewCertificates", false); HttpWebRequest webreq = (HttpWebRequest)sender; string hostname = webreq.Address.Host; string fingerprint = CommonCmdletFunctions.FingerprintPrettyString(certificate.GetCertHashString()); - string trusted = VerifyInAllStores(new X509Certificate2(certificate)) - ? CERT_TRUSTED : CERT_NOT_TRUSTED; + bool trusted = VerifyInAllStores(new X509Certificate2(certificate)); var certificates = CommonCmdletFunctions.LoadCertificates(); - bool ok; if (certificates.ContainsKey(hostname)) { - string fingerprint_old = certificates[hostname]; - if (fingerprint_old == fingerprint) + string fingerprintOld = certificates[hostname]; + if (fingerprintOld == fingerprint) return true; - ok = Force || ignoreChanged || ShouldContinue(string.Format(CERT_CHANGED, fingerprint, fingerprint_old, trusted), CERT_HAS_CHANGED_CAPTION); + if (!ignoreChanged) + throw new CertificateChangedException(fingerprint, fingerprintOld, trusted, hostname); } else { - ok = Force || ignoreNew || ShouldContinue(string.Format(CERT_FOUND, fingerprint, trusted), CERT_FOUND_CAPTION); + if (!ignoreNew) + throw new CertificateNotFoundException(fingerprint, trusted, hostname); } - if (ok) - { - certificates[hostname] = fingerprint; - CommonCmdletFunctions.SaveCertificates(certificates); - } - return ok; + certificates[hostname] = fingerprint; + CommonCmdletFunctions.SaveCertificates(certificates); + return true; } } @@ -316,4 +311,55 @@ private bool VerifyInAllStores(X509Certificate2 certificate2) } } } + + internal abstract class CertificateValidationException : Exception + { + protected const string CERT_TRUSTED = "The certificate on this server is trusted. It is recommended you re-issue this server's certificate."; + protected const string CERT_NOT_TRUSTED = "The certificate on this server is not trusted."; + + protected readonly bool Trusted; + public readonly string Fingerprint; + public readonly string Hostname; + + protected CertificateValidationException(string fingerprint, bool trusted, string hostname) + { + Fingerprint = fingerprint; + Trusted = trusted; + Hostname = hostname; + } + + public abstract string Caption { get; } + } + + internal class CertificateChangedException : CertificateValidationException + { + private readonly string _oldFingerprint; + + public CertificateChangedException(string fingerprint, string oldFingerprint, bool trusted, string hostname) + : base(fingerprint, trusted, hostname) + { + _oldFingerprint = oldFingerprint; + } + + public override string Caption => "Security Certificate Changed"; + + public override string Message => $"The certificate fingerprint of the server you have connected to is:\n{Fingerprint}\n" + + $"But was expected to be:\n{_oldFingerprint}\n" + + (Trusted ? CERT_TRUSTED : CERT_NOT_TRUSTED) + + "\nDo you wish to continue?"; + } + + internal class CertificateNotFoundException : CertificateValidationException + { + public CertificateNotFoundException(string fingerprint, bool trusted, string hostname) + : base(fingerprint, trusted, hostname) + { + } + + public override string Caption => "New Security Certificate"; + + public override string Message => $"The certificate fingerprint of the server you have connected to is :\n{Fingerprint}\n" + + (Trusted ? CERT_TRUSTED : CERT_NOT_TRUSTED) + + "\nDo you wish to continue?"; + } } diff --git a/ocaml/sdk-gen/powershell/autogen/src/Wait-XenTask.cs b/ocaml/sdk-gen/powershell/autogen/src/Wait-XenTask.cs index b9de7dd1202..9740de47c0d 100644 --- a/ocaml/sdk-gen/powershell/autogen/src/Wait-XenTask.cs +++ b/ocaml/sdk-gen/powershell/autogen/src/Wait-XenTask.cs @@ -1,30 +1,30 @@ /* - * Copyright (c) Citrix Systems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1) Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2) Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * Copyright (c) Citrix Systems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -32,8 +32,6 @@ using System.Collections.Generic; using System.Management.Automation; using System.Threading; -using System.Windows.Forms; - using XenAPI; namespace Citrix.XenServer.Commands @@ -46,7 +44,7 @@ public WaitXenServerTaskCommand() Min = 0; Max = 100; } - + #region Cmdlet Parameters [Parameter] @@ -55,7 +53,7 @@ public WaitXenServerTaskCommand() [Parameter(ParameterSetName = "XenObject", Mandatory = true, ValueFromPipeline = true, Position = 0)] public XenAPI.Task Task { get; set; } - [Parameter(ParameterSetName = "Ref", Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)] + [Parameter(ParameterSetName = "Ref", Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)] [Alias("opaque_ref")] public XenRef Ref { get; set; } @@ -69,9 +67,6 @@ public WaitXenServerTaskCommand() [Parameter] public SwitchParameter ShowProgress { get; set; } - [Parameter] - public ProgressBar Progressbar { get; set; } - [Parameter] public int Min { get; set; } @@ -85,7 +80,7 @@ public WaitXenServerTaskCommand() protected override void ProcessRecord() { GetSession(); - + string task = ParseTask(); RunApiCall(delegate() @@ -112,18 +107,14 @@ protected override void ProcessRecord() if (prog.PercentComplete == 100) prog.RecordType = ProgressRecordType.Completed; - if (Progressbar != null) - Progressbar.Value = (int)(Progressbar.Minimum + (prog.PercentComplete * ((Progressbar.Maximum - Progressbar.Minimum) / 100d))); - else if (ShowProgress) + if (ShowProgress) WriteProgress(prog); break; } else { - if (Progressbar != null) - Progressbar.Value = (int)(Progressbar.Minimum + (prog.PercentComplete * ((Progressbar.Maximum - Progressbar.Minimum) / 100d))); - else if (ShowProgress) + if (ShowProgress) WriteProgress(prog); } Thread.Sleep(500); @@ -133,7 +124,7 @@ protected override void ProcessRecord() { throw new Failure(XenAPI.Task.get_error_info(session, task)); } - + if (XenAPI.Task.get_status(session, task) == XenAPI.task_status_type.cancelled) { throw new Exception("User Cancelled"); @@ -142,7 +133,7 @@ protected override void ProcessRecord() if (PassThru) WriteObject(XenAPI.Task.get_result(session, task).Replace("", "").Replace("", ""), true); }); - + UpdateSessions(); } diff --git a/ocaml/sdk-gen/powershell/templates/XenServerPowerShell.csproj.mustache b/ocaml/sdk-gen/powershell/templates/XenServerPowerShell.csproj.mustache index 78a4a66da33..1646c9bb4a3 100644 --- a/ocaml/sdk-gen/powershell/templates/XenServerPowerShell.csproj.mustache +++ b/ocaml/sdk-gen/powershell/templates/XenServerPowerShell.csproj.mustache @@ -1,75 +1,22 @@ - - + - Debug - AnyCPU - {36FBEF99-707A-46EA-92F7-598BA9D77788} + net6.0 Library - Properties - XenServerPowerShell - XenServerPowerShell - v4.5 + false - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 + true - false Program - C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe + C:\Program Files\PowerShell\7\pwsh.exe -NoLogo -NoExit -Command "Import-Module '.\XenServerPowerShell.dll'" - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - False - $(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll - - - + + + False .\XenServer.dll - - - - - - - - - - - - -{{#cmdlets}} - -{{/cmdlets}} - - -