Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-40402: Move C# and Powershell SDK Generation to .NET Standard 2.0 / .NET 6.0 #4782

Merged
merged 21 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a3e5112
CP-40402: Remove use of WinForms in PowerShell SDK
danilo-delbusso Aug 31, 2022
09d8e90
CP-40402: Target .NET Standard 2.0 in C# SDK
danilo-delbusso Aug 31, 2022
2ab2bf1
CP-40402: Remove XML RPC mentions in C# SDK source
danilo-delbusso Aug 31, 2022
fce1f17
CP-40402: Remove XML RPC from C# SDK generation
danilo-delbusso Aug 31, 2022
2f99c47
CP-40402: Remove XML RPC from C# SDK README
danilo-delbusso Aug 31, 2022
50157d3
CP-40402: Target .NET 6.0 in PowerShell SDK
danilo-delbusso Aug 31, 2022
13db78a
CP-40402: Update PowerShell module definition for use with .NET 6.0
danilo-delbusso Aug 31, 2022
f29ae0f
CP-40402: Remove XML RPC from PowerShell SDK README
danilo-delbusso Aug 31, 2022
05dcaa2
CP-40402: Update references in the C# SDK samples
danilo-delbusso Aug 31, 2022
a3781bc
Run `ShouldContinue` on the main thread in `Connect-Xenserver.cs`
danilo-delbusso Sep 5, 2022
e40bd1e
Format `gen_csharp_binding.ml` with `make format`
danilo-delbusso Sep 5, 2022
4bb64b2
CP-40402: Add missing newline to `XenServer.csproj.mustache`
danilo-delbusso Sep 12, 2022
6be3515
CP-40402: Revert regressions introduced in `Session.cs`
danilo-delbusso Sep 30, 2022
dae86ef
CP-40402: Improve web request property initialisation
danilo-delbusso Sep 30, 2022
7a75d53
Remove `Newtonsoft.Json.CH.dll` reference from PS SDK
danilo-delbusso Oct 4, 2022
200837e
Use NuGet for `System.Management.Automation`
danilo-delbusso Oct 4, 2022
779ca2a
Remove redundant or useless properties in PS module manifest
danilo-delbusso Oct 4, 2022
d283aa8
Some refactoring.
kc284 Oct 4, 2022
6136002
Update powershell executable path in project debug configuration
danilo-delbusso Oct 5, 2022
fba2bc7
Set default value for `AllowAutoRedirect` in `Session.cs`
danilo-delbusso Oct 5, 2022
8dd60f4
Set OS condition for Powershell SDK debug configuration
danilo-delbusso Oct 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
danilo-delbusso marked this conversation as resolved.
Show resolved Hide resolved
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