Skip to content

Commit

Permalink
Merge pull request #4782 from danilo-delbusso/private/danilod/sdk
Browse files Browse the repository at this point in the history
CP-40402: Move C# and Powershell SDK Generation to .NET Standard 2.0 / .NET 6.0
  • Loading branch information
robhoes authored Oct 10, 2022
2 parents 42d4de9 + 8dd60f4 commit 162efaa
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 711 deletions.
15 changes: 5 additions & 10 deletions ocaml/sdk-gen/csharp/README.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,14 @@ 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
------------

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
Expand All @@ -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
<host> <username> <password> to be passed to its Main method.
7 changes: 2 additions & 5 deletions ocaml/sdk-gen/csharp/autogen/samples/XenSdkSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="CookComputing.XmlRpcV2">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\CookComputing.XmlRpcV2.dll</HintPath>
</Reference>
<Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
<Reference Include="Newtonsoft.Json.CH">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\Newtonsoft.Json.CH.dll</HintPath>
Expand Down Expand Up @@ -96,4 +93,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
1 change: 0 additions & 1 deletion ocaml/sdk-gen/csharp/autogen/src/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/


using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down
47 changes: 8 additions & 39 deletions ocaml/sdk-gen/csharp/autogen/src/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@

using System;
using System.Collections.Generic;
using CookComputing.XmlRpc;
using Newtonsoft.Json;


namespace XenAPI
{
[JsonConverter(typeof(XenEventConverter))]
Expand Down Expand Up @@ -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;
Expand All @@ -164,28 +138,23 @@ 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;
public Dictionary<string, int> valid_ref_counts;
public string token;
}

[XmlRpcMissingMapping(MappingAction.Ignore)]
public class Events : IEventCollection
{
public Proxy_Event[] events;
Expand Down
1 change: 0 additions & 1 deletion ocaml/sdk-gen/csharp/autogen/src/HTTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ private void Rpc(string callName, JToken parameters, JsonSerializer serializer)

private T Rpc<T>(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);
Expand All @@ -207,12 +207,12 @@ private T Rpc<T>(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
Expand Down Expand Up @@ -261,7 +261,7 @@ private T Rpc<T>(string callName, JToken parameters, JsonSerializer serializer)
#endif
if (res2.Error != null)
{
var descr = new List<string> {res2.Error.Message};
var descr = new List<string> { res2.Error.Message };
descr.AddRange(res2.Error.Data.ToObject<string[]>());
throw new Failure(descr);
}
Expand Down
62 changes: 30 additions & 32 deletions ocaml/sdk-gen/csharp/autogen/src/Response.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -44,9 +42,9 @@ public static class ResponseTypes
public struct Response<ValType>
{
public string Status;
[XmlRpcMissingMapping(MappingAction.Ignore)]

public ValType Value;
[XmlRpcMissingMapping(MappingAction.Ignore)]

public string[] ErrorDescription;

public Response(ValType Value)
Expand Down
Loading

0 comments on commit 162efaa

Please sign in to comment.