summaryrefslogtreecommitdiff
path: root/tutorial/netstd
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2019-01-28 23:27:45 +0100
committerJens Geyer <jensg@apache.org>2019-01-28 23:12:28 +0100
commitaa0c8b35d8f78812de1d7803d6277a37d2ed593a (patch)
treeb71ac06b6da5c135b11aea72bf12207e9cce0c2b /tutorial/netstd
parent1231930abd1d72b422deec967559caf3dc02dac7 (diff)
downloadthrift-aa0c8b35d8f78812de1d7803d6277a37d2ed593a.tar.gz
THRIFT-4723 Consolidate C#/netcore into new netstd language target
Client: netstd Patch: Jens Geyer This closes #1710
Diffstat (limited to 'tutorial/netstd')
-rw-r--r--tutorial/netstd/.gitignore1
-rw-r--r--tutorial/netstd/Client/Client.csproj37
-rw-r--r--tutorial/netstd/Client/Program.cs355
-rw-r--r--tutorial/netstd/Client/Properties/AssemblyInfo.cs40
-rw-r--r--tutorial/netstd/Client/Properties/launchSettings.json8
-rw-r--r--tutorial/netstd/Client/ThriftTest.pfxbin0 -> 2661 bytes
-rw-r--r--tutorial/netstd/Interfaces/.gitignore3
-rw-r--r--tutorial/netstd/Interfaces/Interfaces.csproj48
-rw-r--r--tutorial/netstd/Interfaces/Properties/AssemblyInfo.cs40
-rw-r--r--tutorial/netstd/Makefile.am42
-rw-r--r--tutorial/netstd/README.md278
-rw-r--r--tutorial/netstd/Server/Program.cs429
-rw-r--r--tutorial/netstd/Server/Properties/AssemblyInfo.cs40
-rw-r--r--tutorial/netstd/Server/Properties/launchSettings.json8
-rw-r--r--tutorial/netstd/Server/Server.csproj44
-rw-r--r--tutorial/netstd/Server/ThriftTest.pfxbin0 -> 2661 bytes
-rw-r--r--tutorial/netstd/Tutorial.sln78
-rw-r--r--tutorial/netstd/build.cmd25
-rw-r--r--tutorial/netstd/build.sh26
19 files changed, 1502 insertions, 0 deletions
diff --git a/tutorial/netstd/.gitignore b/tutorial/netstd/.gitignore
new file mode 100644
index 000000000..9938bb237
--- /dev/null
+++ b/tutorial/netstd/.gitignore
@@ -0,0 +1 @@
+!**/*.pfx \ No newline at end of file
diff --git a/tutorial/netstd/Client/Client.csproj b/tutorial/netstd/Client/Client.csproj
new file mode 100644
index 000000000..70eae1584
--- /dev/null
+++ b/tutorial/netstd/Client/Client.csproj
@@ -0,0 +1,37 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <!--
+ Licensed to the Apache Software Foundation(ASF) under one
+ or more contributor license agreements.See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp2.0</TargetFramework>
+ <AssemblyName>Client</AssemblyName>
+ <PackageId>Client</PackageId>
+ <OutputType>Exe</OutputType>
+ <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
+ <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
+ <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
+ <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Interfaces\Interfaces.csproj" />
+ <ProjectReference Include="..\..\..\lib\netstd\Thrift\Thrift.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/tutorial/netstd/Client/Program.cs b/tutorial/netstd/Client/Program.cs
new file mode 100644
index 000000000..bf35746e3
--- /dev/null
+++ b/tutorial/netstd/Client/Program.cs
@@ -0,0 +1,355 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
+using Thrift;
+using Thrift.Protocol;
+using Thrift.Transport;
+using Thrift.Transport.Client;
+using tutorial;
+using shared;
+
+namespace Client
+{
+ public class Program
+ {
+ private static readonly ILogger Logger = new LoggerFactory().AddConsole().AddDebug().CreateLogger(nameof(Client));
+
+ private static void DisplayHelp()
+ {
+ Logger.LogInformation(@"
+Usage:
+ Client.exe -help
+ will diplay help information
+
+ Client.exe -tr:<transport> -pr:<protocol> -mc:<numClients>
+ will run client with specified arguments (tcp transport and binary protocol by default) and with 1 client
+
+Options:
+ -tr (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - buffered transport over tcp will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (address - ""http://localhost:9090"")
+ tcptls - tcp tls transport will be used (host - ""localhost"", port - 9090)
+ framed - tcp framed transport will be used (host - ""localhost"", port - 9090)
+
+ -pr (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+ multiplexed - multiplexed protocol will be used
+
+ -mc (multiple clients):
+ <numClients> - number of multiple clients to connect to server (max 100, default 1)
+
+Sample:
+ Client.exe -tr:tcp -p:binary
+");
+ }
+
+ public static void Main(string[] args)
+ {
+ args = args ?? new string[0];
+
+ if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
+
+ Logger.LogInformation("Starting client...");
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+ }
+ }
+
+ private static async Task RunAsync(string[] args, CancellationToken cancellationToken)
+ {
+ var numClients = GetNumberOfClients(args);
+
+ Logger.LogInformation($"Selected # of clients: {numClients}");
+
+ var transports = new TTransport[numClients];
+ for (int i = 0; i < numClients; i++)
+ {
+ var t = GetTransport(args);
+ transports[i] = t;
+ }
+
+ Logger.LogInformation($"Selected client transport: {transports[0]}");
+
+ var protocols = new Tuple<Protocol, TProtocol>[numClients];
+ for (int i = 0; i < numClients; i++)
+ {
+ var p = GetProtocol(args, transports[i]);
+ protocols[i] = p;
+ }
+
+ Logger.LogInformation($"Selected client protocol: {protocols[0].Item1}");
+
+ var tasks = new Task[numClients];
+ for (int i = 0; i < numClients; i++)
+ {
+ var task = RunClientAsync(protocols[i], cancellationToken);
+ tasks[i] = task;
+ }
+
+ Task.WaitAll(tasks);
+
+ await Task.CompletedTask;
+ }
+
+ private static TTransport GetTransport(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-tr"))?.Split(':')?[1];
+
+ Transport selectedTransport;
+ if (Enum.TryParse(transport, true, out selectedTransport))
+ {
+ switch (selectedTransport)
+ {
+ case Transport.Tcp:
+ return new TSocketTransport(IPAddress.Loopback, 9090);
+ case Transport.NamedPipe:
+ return new TNamedPipeTransport(".test");
+ case Transport.Http:
+ return new THttpTransport(new Uri("http://localhost:9090"), null);
+ case Transport.TcpBuffered:
+ return new TBufferedTransport(new TSocketTransport(IPAddress.Loopback, 9090));
+ case Transport.TcpTls:
+ return new TTlsSocketTransport(IPAddress.Loopback, 9090, GetCertificate(), CertValidator, LocalCertificateSelectionCallback);
+ case Transport.Framed:
+ return new TFramedTransport(new TSocketTransport(IPAddress.Loopback, 9090));
+ }
+ }
+
+ return new TSocketTransport(IPAddress.Loopback, 9090);
+ }
+
+ private static int GetNumberOfClients(string[] args)
+ {
+ var numClients = args.FirstOrDefault(x => x.StartsWith("-mc"))?.Split(':')?[1];
+
+ Logger.LogInformation($"Selected # of clients: {numClients}");
+
+ int c;
+ if( int.TryParse(numClients, out c) && (0 < c) && (c <= 100))
+ return c;
+ else
+ return 1;
+ }
+
+ private static X509Certificate2 GetCertificate()
+ {
+ // due to files location in net core better to take certs from top folder
+ var certFile = GetCertPath(Directory.GetParent(Directory.GetCurrentDirectory()));
+ return new X509Certificate2(certFile, "ThriftTest");
+ }
+
+ private static string GetCertPath(DirectoryInfo di, int maxCount = 6)
+ {
+ var topDir = di;
+ var certFile =
+ topDir.EnumerateFiles("ThriftTest.pfx", SearchOption.AllDirectories)
+ .FirstOrDefault();
+ if (certFile == null)
+ {
+ if (maxCount == 0)
+ throw new FileNotFoundException("Cannot find file in directories");
+ return GetCertPath(di.Parent, maxCount - 1);
+ }
+
+ return certFile.FullName;
+ }
+
+ private static X509Certificate LocalCertificateSelectionCallback(object sender,
+ string targetHost, X509CertificateCollection localCertificates,
+ X509Certificate remoteCertificate, string[] acceptableIssuers)
+ {
+ return GetCertificate();
+ }
+
+ private static bool CertValidator(object sender, X509Certificate certificate,
+ X509Chain chain, SslPolicyErrors sslPolicyErrors)
+ {
+ return true;
+ }
+
+ private static Tuple<Protocol, TProtocol> GetProtocol(string[] args, TTransport transport)
+ {
+ var protocol = args.FirstOrDefault(x => x.StartsWith("-pr"))?.Split(':')?[1];
+
+ Protocol selectedProtocol;
+ if (Enum.TryParse(protocol, true, out selectedProtocol))
+ {
+ switch (selectedProtocol)
+ {
+ case Protocol.Binary:
+ return new Tuple<Protocol, TProtocol>(selectedProtocol, new TBinaryProtocol(transport));
+ case Protocol.Compact:
+ return new Tuple<Protocol, TProtocol>(selectedProtocol, new TCompactProtocol(transport));
+ case Protocol.Json:
+ return new Tuple<Protocol, TProtocol>(selectedProtocol, new TJsonProtocol(transport));
+ case Protocol.Multiplexed:
+ // it returns BinaryProtocol to avoid making wrapped protocol as public in TProtocolDecorator (in RunClientAsync it will be wrapped into Multiplexed protocol)
+ return new Tuple<Protocol, TProtocol>(selectedProtocol, new TBinaryProtocol(transport));
+ }
+ }
+
+ return new Tuple<Protocol, TProtocol>(selectedProtocol, new TBinaryProtocol(transport));
+ }
+
+ private static async Task RunClientAsync(Tuple<Protocol, TProtocol> protocolTuple, CancellationToken cancellationToken)
+ {
+ try
+ {
+ var protocol = protocolTuple.Item2;
+ var protocolType = protocolTuple.Item1;
+
+ TBaseClient client = null;
+
+ try
+ {
+ if (protocolType != Protocol.Multiplexed)
+ {
+
+ client = new Calculator.Client(protocol);
+ await ExecuteCalculatorClientOperations(cancellationToken, (Calculator.Client)client);
+ }
+ else
+ {
+ // it uses binary protocol there to create Multiplexed protocols
+ var multiplex = new TMultiplexedProtocol(protocol, nameof(Calculator));
+ client = new Calculator.Client(multiplex);
+ await ExecuteCalculatorClientOperations(cancellationToken, (Calculator.Client)client);
+
+ multiplex = new TMultiplexedProtocol(protocol, nameof(SharedService));
+ client = new SharedService.Client(multiplex);
+ await ExecuteSharedServiceClientOperations(cancellationToken, (SharedService.Client)client);
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError($"{client?.ClientId} " + ex);
+ }
+ finally
+ {
+ protocol.Transport.Close();
+ }
+ }
+ catch (TApplicationException x)
+ {
+ Logger.LogError(x.ToString());
+ }
+ }
+
+ private static async Task ExecuteCalculatorClientOperations(CancellationToken cancellationToken, Calculator.Client client)
+ {
+ await client.OpenTransportAsync(cancellationToken);
+
+ // Async version
+
+ Logger.LogInformation($"{client.ClientId} PingAsync()");
+ await client.pingAsync(cancellationToken);
+
+ Logger.LogInformation($"{client.ClientId} AddAsync(1,1)");
+ var sum = await client.addAsync(1, 1, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} AddAsync(1,1)={sum}");
+
+ var work = new Work
+ {
+ Op = Operation.DIVIDE,
+ Num1 = 1,
+ Num2 = 0
+ };
+
+ try
+ {
+ Logger.LogInformation($"{client.ClientId} CalculateAsync(1)");
+ await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Whoa we can divide by 0");
+ }
+ catch (InvalidOperation io)
+ {
+ Logger.LogInformation($"{client.ClientId} Invalid operation: " + io);
+ }
+
+ work.Op = Operation.SUBTRACT;
+ work.Num1 = 15;
+ work.Num2 = 10;
+
+ try
+ {
+ Logger.LogInformation($"{client.ClientId} CalculateAsync(1)");
+ var diff = await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} 15-10={diff}");
+ }
+ catch (InvalidOperation io)
+ {
+ Logger.LogInformation($"{client.ClientId} Invalid operation: " + io);
+ }
+
+ Logger.LogInformation($"{client.ClientId} GetStructAsync(1)");
+ var log = await client.getStructAsync(1, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Check log: {log.Value}");
+
+ Logger.LogInformation($"{client.ClientId} ZipAsync() with delay 100mc on server side");
+ await client.zipAsync(cancellationToken);
+ }
+ private static async Task ExecuteSharedServiceClientOperations(CancellationToken cancellationToken, SharedService.Client client)
+ {
+ await client.OpenTransportAsync(cancellationToken);
+
+ // Async version
+
+ Logger.LogInformation($"{client.ClientId} SharedService GetStructAsync(1)");
+ var log = await client.getStructAsync(1, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} SharedService Value: {log.Value}");
+ }
+
+
+ private enum Transport
+ {
+ Tcp,
+ NamedPipe,
+ Http,
+ TcpBuffered,
+ Framed,
+ TcpTls
+ }
+
+ private enum Protocol
+ {
+ Binary,
+ Compact,
+ Json,
+ Multiplexed
+ }
+ }
+}
diff --git a/tutorial/netstd/Client/Properties/AssemblyInfo.cs b/tutorial/netstd/Client/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..568382e66
--- /dev/null
+++ b/tutorial/netstd/Client/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Thrift")]
+[assembly: AssemblyCopyright("The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("de78a01b-f7c6-49d1-97da-669d2ed37641")] \ No newline at end of file
diff --git a/tutorial/netstd/Client/Properties/launchSettings.json b/tutorial/netstd/Client/Properties/launchSettings.json
new file mode 100644
index 000000000..6b7b60d78
--- /dev/null
+++ b/tutorial/netstd/Client/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "Client": {
+ "commandName": "Project",
+ "commandLineArgs": "-p:multiplexed"
+ }
+ }
+} \ No newline at end of file
diff --git a/tutorial/netstd/Client/ThriftTest.pfx b/tutorial/netstd/Client/ThriftTest.pfx
new file mode 100644
index 000000000..f0ded2817
--- /dev/null
+++ b/tutorial/netstd/Client/ThriftTest.pfx
Binary files differ
diff --git a/tutorial/netstd/Interfaces/.gitignore b/tutorial/netstd/Interfaces/.gitignore
new file mode 100644
index 000000000..2e7446e33
--- /dev/null
+++ b/tutorial/netstd/Interfaces/.gitignore
@@ -0,0 +1,3 @@
+# ignore for autogenerated files
+/shared
+/tutorial
diff --git a/tutorial/netstd/Interfaces/Interfaces.csproj b/tutorial/netstd/Interfaces/Interfaces.csproj
new file mode 100644
index 000000000..68d87476e
--- /dev/null
+++ b/tutorial/netstd/Interfaces/Interfaces.csproj
@@ -0,0 +1,48 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <!--
+ Licensed to the Apache Software Foundation(ASF) under one
+ or more contributor license agreements.See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ <AssemblyName>Interfaces</AssemblyName>
+ <PackageId>Interfaces</PackageId>
+ <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
+ <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
+ <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
+ <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="../../../lib/netstd/Thrift/Thrift.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="System.ServiceModel.Primitives" Version="[4.4,)" />
+ </ItemGroup>
+
+ <Target Name="PreBuild" BeforeTargets="_GenerateRestoreProjectSpec;Restore;Compile">
+ <Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
+ <Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
+ </Exec>
+ <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial -r ./../../tutorial.thrift" />
+ <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial -r ./../../tutorial.thrift" />
+ <Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial -r ./../../tutorial.thrift" />
+ </Target>
+
+</Project>
diff --git a/tutorial/netstd/Interfaces/Properties/AssemblyInfo.cs b/tutorial/netstd/Interfaces/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..9126b173e
--- /dev/null
+++ b/tutorial/netstd/Interfaces/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Thrift")]
+[assembly: AssemblyCopyright("The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("4d13163d-9067-4c9c-8af0-64e08451397d")] \ No newline at end of file
diff --git a/tutorial/netstd/Makefile.am b/tutorial/netstd/Makefile.am
new file mode 100644
index 000000000..e30555655
--- /dev/null
+++ b/tutorial/netstd/Makefile.am
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+SUBDIRS = .
+
+all-local:
+ $(DOTNETCORE) build
+
+clean-local:
+ $(RM) Interfaces.dll
+ $(RM) -r Client/bin
+ $(RM) -r Client/obj
+ $(RM) -r Server/bin
+ $(RM) -r Server/obj
+ $(RM) -r Interfaces/bin
+ $(RM) -r Interfaces/obj
+
+EXTRA_DIST = \
+ Client \
+ Interfaces \
+ README.md \
+ Server \
+ Tutorial.sln \
+ build.cmd \
+ build.sh
+
diff --git a/tutorial/netstd/README.md b/tutorial/netstd/README.md
new file mode 100644
index 000000000..8c8317a65
--- /dev/null
+++ b/tutorial/netstd/README.md
@@ -0,0 +1,278 @@
+# Building of samples for different platforms
+
+# Reused components
+- NET Core Standard 2.0
+- NET Core App 2.0
+
+# How to build
+- Download and install the latest .NET Core SDK for your platform https://www.microsoft.com/net/core#windowsvs2015 (archive for SDK 1.0.0-preview2-003121 located by: https://github.com/dotnet/core/blob/master/release-notes/download-archive.md)
+- Ensure that you have thrift.exe which supports netstd lib and it added to PATH
+- Go to current folder
+- Run **build.sh** or **build.cmd** from the root of cloned repository
+- Check tests in **src/Tests** folder
+- Continue with /tutorials/netstd
+
+# How to run
+
+Notes: dotnet run supports passing arguments to app after -- symbols (https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-run) - example: **dotnet run -- -h** will show help for app
+
+- build
+- go to folder (Client/Server)
+- run with specifying of correct parameters **dotnet run -tr:tcp -pr:multiplexed**, **dotnet run -help** (later, after migration to csproj and latest SDK will be possibility to use more usable form **dotnet run -- arguments**)
+
+#Notes
+- Possible adding additional platforms after stabilization of .NET Core (runtimes, platforms (Red Hat Linux, OpenSuse, etc.)
+
+#Known issues
+- In trace logging mode you can see some not important internal exceptions
+
+# Running of samples
+Please install Thrift C# .NET Core library or copy sources and build them to correcly build and run samples
+
+# NetCore Server
+
+Usage:
+
+ Server.exe -h
+ will diplay help information
+
+ Server.exe -tr:<transport> -pr:<protocol>
+ will run server with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+
+ -tr (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - tcp buffered transport will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (http address - ""localhost:9090"")
+ tcptls - tcp transport with tls will be used (host - ""localhost"", port - 9090)
+ framed - tcp framed transport will be used (host - ""localhost"", port - 9090)
+
+ -pr (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+
+ Server.exe -tr:tcp
+
+**Remarks**:
+
+ For TcpTls mode certificate's file ThriftTest.pfx should be in directory with binaries in case of command line usage (or at project level in case of debugging from IDE).
+ Password for certificate - "ThriftTest".
+
+
+
+# NetCore Client
+
+Usage:
+
+ Client.exe -h
+ will diplay help information
+
+ Client.exe -tr:<transport> -pr:<protocol> -mc:<numClients>
+ will run client with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+
+ -tr (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - buffered transport over tcp will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (address - ""http://localhost:9090"")
+ tcptls - tcp tls transport will be used (host - ""localhost"", port - 9090)
+ framed - tcp framed transport will be used (host - ""localhost"", port - 9090)
+
+ -pr (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+ -mc (multiple clients):
+ <numClients> - number of multiple clients to connect to server (max 100, default 1)
+
+Sample:
+
+ Client.exe -tr:tcp -pr:binary -mc:10
+
+Remarks:
+
+ For TcpTls mode certificate's file ThriftTest.pfx should be in directory
+ with binaries in case of command line usage (or at project level in case of debugging from IDE).
+ Password for certificate - "ThriftTest".
+
+# How to test communication between NetCore and Python
+
+* Generate code with the latest **thrift.exe** util
+* Ensure that **thrift.exe** util generated folder **gen-py** with generated code for Python
+* Create **client.py** and **server.py** from the code examples below and save them to the folder with previosly generated folder **gen-py**
+* Run netstd samples (client and server) and python samples (client and server)
+
+Remarks:
+
+Samples of client and server code below use correct methods (operations)
+and fields (properties) according to generated contracts from *.thrift files
+
+At Windows 10 add record **127.0.0.1 testserver** to **C:\Windows\System32\drivers\etc\hosts** file
+for correct work of python server
+
+
+**Python Client:**
+
+```python
+import sys
+import glob
+sys.path.append('gen-py')
+
+from tutorial import Calculator
+from tutorial.ttypes import InvalidOperation, Operation, Work
+
+from thrift import Thrift
+from thrift.transport import TSocket
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
+
+
+def main():
+ # Make socket
+ transport = TSocket.TSocket('127.0.0.1', 9090)
+
+ # Buffering is critical. Raw sockets are very slow
+ transport = TTransport.TBufferedTransport(transport)
+
+ # Wrap in a protocol
+ protocol = TBinaryProtocol.TBinaryProtocol(transport)
+
+ # Create a client to use the protocol encoder
+ client = Calculator.Client(protocol)
+
+ # Connect!
+ transport.open()
+
+ client.Ping()
+ print('ping()')
+
+ sum = client.Add(1, 1)
+ print(('1+1=%d' % (sum)))
+
+ work = Work()
+
+ work.Op = Operation.Divide
+ work.Num1 = 1
+ work.Num2 = 0
+
+ try:
+ quotient = client.Calculate(1, work)
+ print('Whoa? You know how to divide by zero?')
+ print('FYI the answer is %d' % quotient)
+ except InvalidOperation as e:
+ print(('InvalidOperation: %r' % e))
+
+ work.Op = Operation.Substract
+ work.Num1 = 15
+ work.Num2 = 10
+
+ diff = client.Calculate(1, work)
+ print(('15-10=%d' % (diff)))
+
+ log = client.GetStruct(1)
+ print(('Check log: %s' % (log.Value)))
+
+ client.Zip()
+ print('zip()')
+
+ # Close!
+ transport.close()
+
+if __name__ == '__main__':
+ try:
+ main()
+ except Thrift.TException as tx:
+ print('%s' % tx.message)
+```
+
+
+**Python Server:**
+
+
+```python
+import glob
+import sys
+sys.path.append('gen-py')
+
+from tutorial import Calculator
+from tutorial.ttypes import InvalidOperation, Operation
+
+from shared.ttypes import SharedStruct
+
+from thrift.transport import TSocket
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
+from thrift.server import TServer
+
+
+class CalculatorHandler:
+ def __init__(self):
+ self.log = {}
+
+ def Ping(self):
+ print('ping()')
+
+ def Add(self, n1, n2):
+ print('add(%d,%d)' % (n1, n2))
+ return n1 + n2
+
+ def Calculate(self, logid, work):
+ print('calculate(%d, %r)' % (logid, work))
+
+ if work.Op == Operation.Add:
+ val = work.Num1 + work.Num2
+ elif work.Op == Operation.Substract:
+ val = work.Num1 - work.Num2
+ elif work.Op == Operation.Multiply:
+ val = work.Num1 * work.Num2
+ elif work.Op == Operation.Divide:
+ if work.Num2 == 0:
+ x = InvalidOperation()
+ x.WhatOp = work.Op
+ x.Why = 'Cannot divide by 0'
+ raise x
+ val = work.Num1 / work.Num2
+ else:
+ x = InvalidOperation()
+ x.WhatOp = work.Op
+ x.Why = 'Invalid operation'
+ raise x
+
+ log = SharedStruct()
+ log.Key = logid
+ log.Value = '%d' % (val)
+ self.log[logid] = log
+
+ return val
+
+ def GetStruct(self, key):
+ print('getStruct(%d)' % (key))
+ return self.log[key]
+
+ def Zip(self):
+ print('zip()')
+
+if __name__ == '__main__':
+ handler = CalculatorHandler()
+ processor = Calculator.Processor(handler)
+ transport = TSocket.TServerSocket(host="testserver", port=9090)
+ tfactory = TTransport.TBufferedTransportFactory()
+ pfactory = TBinaryProtocol.TBinaryProtocolFactory()
+
+ server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
+ print('Starting the server...')
+ server.serve()
+ print('done.')
+
+ # You could do one of these for a multithreaded server
+ # server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
+ # server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
+```
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
new file mode 100644
index 000000000..9a650c5aa
--- /dev/null
+++ b/tutorial/netstd/Server/Program.cs
@@ -0,0 +1,429 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Thrift;
+using Thrift.Protocol;
+using Thrift.Server;
+using Thrift.Transport;
+using Thrift.Transport.Server;
+using tutorial;
+using shared;
+using Thrift.Processor;
+
+namespace Server
+{
+ public class Program
+ {
+ private static readonly ILogger Logger = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace).CreateLogger(nameof(Server));
+
+ public static void Main(string[] args)
+ {
+ args = args ?? new string[0];
+
+ if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+
+ Logger.LogInformation("Press any key to stop...");
+
+ Console.ReadLine();
+ source.Cancel();
+ }
+
+ Logger.LogInformation("Server stopped");
+ }
+
+ private static void DisplayHelp()
+ {
+ Logger.LogInformation(@"
+Usage:
+ Server.exe -help
+ will diplay help information
+
+ Server.exe -tr:<transport> -pr:<protocol>
+ will run server with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+ -tr (transport):
+ tcp - (default) tcp transport will be used (host - ""localhost"", port - 9090)
+ tcpbuffered - tcp buffered transport will be used (host - ""localhost"", port - 9090)
+ namedpipe - namedpipe transport will be used (pipe address - "".test"")
+ http - http transport will be used (http address - ""localhost:9090"")
+ tcptls - tcp transport with tls will be used (host - ""localhost"", port - 9090)
+ framed - tcp framed transport will be used (host - ""localhost"", port - 9090)
+
+ -pr (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+ multiplexed - multiplexed protocol will be used
+
+Sample:
+ Server.exe -tr:tcp
+");
+ }
+
+ private static async Task RunAsync(string[] args, CancellationToken cancellationToken)
+ {
+ var selectedTransport = GetTransport(args);
+ var selectedProtocol = GetProtocol(args);
+
+ if (selectedTransport == Transport.Http)
+ {
+ new HttpServerSample().Run(cancellationToken);
+ }
+ else
+ {
+ await RunSelectedConfigurationAsync(selectedTransport, selectedProtocol, cancellationToken);
+ }
+ }
+
+ private static Protocol GetProtocol(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-pr"))?.Split(':')?[1];
+
+ Enum.TryParse(transport, true, out Protocol selectedProtocol);
+
+ return selectedProtocol;
+ }
+
+ private static Transport GetTransport(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-tr"))?.Split(':')?[1];
+
+ Enum.TryParse(transport, true, out Transport selectedTransport);
+
+ return selectedTransport;
+ }
+
+ private static async Task RunSelectedConfigurationAsync(Transport transport, Protocol protocol, CancellationToken cancellationToken)
+ {
+ var fabric = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace);
+ var handler = new CalculatorAsyncHandler();
+ ITAsyncProcessor processor = null;
+
+ TServerTransport serverTransport = null;
+
+ switch (transport)
+ {
+ case Transport.Tcp:
+ serverTransport = new TServerSocketTransport(9090);
+ break;
+ case Transport.TcpBuffered:
+ serverTransport = new TServerSocketTransport(port: 9090, clientTimeout: 10000, useBufferedSockets: true);
+ break;
+ case Transport.NamedPipe:
+ serverTransport = new TNamedPipeServerTransport(".test");
+ break;
+ case Transport.TcpTls:
+ serverTransport = new TTlsServerSocketTransport(9090, false, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback);
+ break;
+ case Transport.Framed:
+ serverTransport = new TServerFramedTransport(9090);
+ break;
+ }
+
+ ITProtocolFactory inputProtocolFactory;
+ ITProtocolFactory outputProtocolFactory;
+
+ switch (protocol)
+ {
+ case Protocol.Binary:
+ {
+ inputProtocolFactory = new TBinaryProtocol.Factory();
+ outputProtocolFactory = new TBinaryProtocol.Factory();
+ processor = new Calculator.AsyncProcessor(handler);
+ }
+ break;
+ case Protocol.Compact:
+ {
+ inputProtocolFactory = new TCompactProtocol.Factory();
+ outputProtocolFactory = new TCompactProtocol.Factory();
+ processor = new Calculator.AsyncProcessor(handler);
+ }
+ break;
+ case Protocol.Json:
+ {
+ inputProtocolFactory = new TJsonProtocol.Factory();
+ outputProtocolFactory = new TJsonProtocol.Factory();
+ processor = new Calculator.AsyncProcessor(handler);
+ }
+ break;
+ case Protocol.Multiplexed:
+ {
+ inputProtocolFactory = new TBinaryProtocol.Factory();
+ outputProtocolFactory = new TBinaryProtocol.Factory();
+
+ var calcHandler = new CalculatorAsyncHandler();
+ var calcProcessor = new Calculator.AsyncProcessor(calcHandler);
+
+ var sharedServiceHandler = new SharedServiceAsyncHandler();
+ var sharedServiceProcessor = new SharedService.AsyncProcessor(sharedServiceHandler);
+
+ var multiplexedProcessor = new TMultiplexedProcessor();
+ multiplexedProcessor.RegisterProcessor(nameof(Calculator), calcProcessor);
+ multiplexedProcessor.RegisterProcessor(nameof(SharedService), sharedServiceProcessor);
+
+ processor = multiplexedProcessor;
+ }
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null);
+ }
+
+ try
+ {
+ Logger.LogInformation(
+ $"Selected TAsyncServer with {serverTransport} transport, {processor} processor and {inputProtocolFactory} protocol factories");
+
+ var server = new TSimpleAsyncServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, fabric);
+
+ Logger.LogInformation("Starting the server...");
+ await server.ServeAsync(cancellationToken);
+ }
+ catch (Exception x)
+ {
+ Logger.LogInformation(x.ToString());
+ }
+ }
+
+ private static X509Certificate2 GetCertificate()
+ {
+ // due to files location in net core better to take certs from top folder
+ var certFile = GetCertPath(Directory.GetParent(Directory.GetCurrentDirectory()));
+ return new X509Certificate2(certFile, "ThriftTest");
+ }
+
+ private static string GetCertPath(DirectoryInfo di, int maxCount = 6)
+ {
+ var topDir = di;
+ var certFile =
+ topDir.EnumerateFiles("ThriftTest.pfx", SearchOption.AllDirectories)
+ .FirstOrDefault();
+ if (certFile == null)
+ {
+ if (maxCount == 0)
+ throw new FileNotFoundException("Cannot find file in directories");
+ return GetCertPath(di.Parent, maxCount - 1);
+ }
+
+ return certFile.FullName;
+ }
+
+ private static X509Certificate LocalCertificateSelectionCallback(object sender,
+ string targetHost, X509CertificateCollection localCertificates,
+ X509Certificate remoteCertificate, string[] acceptableIssuers)
+ {
+ return GetCertificate();
+ }
+
+ private static bool ClientCertValidator(object sender, X509Certificate certificate,
+ X509Chain chain, SslPolicyErrors sslPolicyErrors)
+ {
+ return true;
+ }
+
+ private enum Transport
+ {
+ Tcp,
+ TcpBuffered,
+ NamedPipe,
+ Http,
+ TcpTls,
+ Framed
+ }
+
+ private enum Protocol
+ {
+ Binary,
+ Compact,
+ Json,
+ Multiplexed
+ }
+
+ public class HttpServerSample
+ {
+ public void Run(CancellationToken cancellationToken)
+ {
+ var config = new ConfigurationBuilder()
+ .AddEnvironmentVariables(prefix: "ASPNETCORE_")
+ .Build();
+
+ var host = new WebHostBuilder()
+ .UseConfiguration(config)
+ .UseKestrel()
+ .UseUrls("http://localhost:9090")
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .UseStartup<Startup>()
+ .Build();
+
+ host.RunAsync(cancellationToken).GetAwaiter().GetResult();
+ }
+
+ public class Startup
+ {
+ public Startup(IHostingEnvironment env)
+ {
+ var builder = new ConfigurationBuilder()
+ .SetBasePath(env.ContentRootPath)
+ .AddEnvironmentVariables();
+
+ Configuration = builder.Build();
+ }
+
+ public IConfigurationRoot Configuration { get; }
+
+ // This method gets called by the runtime. Use this method to add services to the container.
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddTransient<Calculator.IAsync, CalculatorAsyncHandler>();
+ services.AddTransient<ITAsyncProcessor, Calculator.AsyncProcessor>();
+ services.AddTransient<THttpServerTransport, THttpServerTransport>();
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env,
+ ILoggerFactory loggerFactory)
+ {
+ app.UseMiddleware<THttpServerTransport>();
+ }
+ }
+ }
+
+ public class CalculatorAsyncHandler : Calculator.IAsync
+ {
+ private readonly Dictionary<int, SharedStruct> _log = new Dictionary<int, SharedStruct>();
+
+ public CalculatorAsyncHandler()
+ {
+ }
+
+ public async Task<SharedStruct> getStructAsync(int key,
+ CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("GetStructAsync({0})", key);
+ return await Task.FromResult(_log[key]);
+ }
+
+ public async Task pingAsync(CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("PingAsync()");
+ await Task.CompletedTask;
+ }
+
+ public async Task<int> addAsync(int num1, int num2, CancellationToken cancellationToken)
+ {
+ Logger.LogInformation($"AddAsync({num1},{num2})");
+ return await Task.FromResult(num1 + num2);
+ }
+
+ public async Task<int> calculateAsync(int logid, Work w, CancellationToken cancellationToken)
+ {
+ Logger.LogInformation($"CalculateAsync({logid}, [{w.Op},{w.Num1},{w.Num2}])");
+
+ var val = 0;
+ switch (w.Op)
+ {
+ case Operation.ADD:
+ val = w.Num1 + w.Num2;
+ break;
+
+ case Operation.SUBTRACT:
+ val = w.Num1 - w.Num2;
+ break;
+
+ case Operation.MULTIPLY:
+ val = w.Num1 * w.Num2;
+ break;
+
+ case Operation.DIVIDE:
+ if (w.Num2 == 0)
+ {
+ var io = new InvalidOperation
+ {
+ WhatOp = (int) w.Op,
+ Why = "Cannot divide by 0"
+ };
+
+ throw io;
+ }
+ val = w.Num1 / w.Num2;
+ break;
+
+ default:
+ {
+ var io = new InvalidOperation
+ {
+ WhatOp = (int) w.Op,
+ Why = "Unknown operation"
+ };
+
+ throw io;
+ }
+ }
+
+ var entry = new SharedStruct
+ {
+ Key = logid,
+ Value = val.ToString()
+ };
+
+ _log[logid] = entry;
+
+ return await Task.FromResult(val);
+ }
+
+ public async Task zipAsync(CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("ZipAsync() with delay 100mc");
+ await Task.Delay(100, CancellationToken.None);
+ }
+ }
+
+ public class SharedServiceAsyncHandler : SharedService.IAsync
+ {
+ public async Task<SharedStruct> getStructAsync(int key, CancellationToken cancellationToken)
+ {
+ Logger.LogInformation("GetStructAsync({0})", key);
+ return await Task.FromResult(new SharedStruct()
+ {
+ Key = key,
+ Value = "GetStructAsync"
+ });
+ }
+ }
+ }
+}
diff --git a/tutorial/netstd/Server/Properties/AssemblyInfo.cs b/tutorial/netstd/Server/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..a0442350b
--- /dev/null
+++ b/tutorial/netstd/Server/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Thrift")]
+[assembly: AssemblyCopyright("The Apache Software Foundation")]
+[assembly: AssemblyTrademark("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("e210fc10-5aff-4b04-ac21-58afc7b74b0c")] \ No newline at end of file
diff --git a/tutorial/netstd/Server/Properties/launchSettings.json b/tutorial/netstd/Server/Properties/launchSettings.json
new file mode 100644
index 000000000..78076ff7c
--- /dev/null
+++ b/tutorial/netstd/Server/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "Server": {
+ "commandName": "Project",
+ "commandLineArgs": "-p:multiplexed"
+ }
+ }
+} \ No newline at end of file
diff --git a/tutorial/netstd/Server/Server.csproj b/tutorial/netstd/Server/Server.csproj
new file mode 100644
index 000000000..4b20a3b05
--- /dev/null
+++ b/tutorial/netstd/Server/Server.csproj
@@ -0,0 +1,44 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+ <!--
+ Licensed to the Apache Software Foundation(ASF) under one
+ or more contributor license agreements.See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp2.0</TargetFramework>
+ <AssemblyName>Server</AssemblyName>
+ <PackageId>Server</PackageId>
+ <OutputType>Exe</OutputType>
+ <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
+ <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
+ <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
+ <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="../Interfaces/Interfaces.csproj" />
+ <ProjectReference Include="../../../lib/netstd/Thrift/Thrift.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore" Version="[2.0,)" />
+ <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="[2.0,)" />
+ <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="[2.0,)" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="[2.0,)" />
+ </ItemGroup>
+
+</Project>
diff --git a/tutorial/netstd/Server/ThriftTest.pfx b/tutorial/netstd/Server/ThriftTest.pfx
new file mode 100644
index 000000000..f0ded2817
--- /dev/null
+++ b/tutorial/netstd/Server/ThriftTest.pfx
Binary files differ
diff --git a/tutorial/netstd/Tutorial.sln b/tutorial/netstd/Tutorial.sln
new file mode 100644
index 000000000..84b257902
--- /dev/null
+++ b/tutorial/netstd/Tutorial.sln
@@ -0,0 +1,78 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26114.2
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Thrift", "..\..\lib\netstd\Thrift\Thrift.csproj", "{C20EA2A9-7660-47DE-9A49-D1EF12FB2895}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Interfaces", "Interfaces\Interfaces.csproj", "{B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{E08F5B84-2B4A-4E09-82D1-E0715775CE5E}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Debug|x64.Build.0 = Debug|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Debug|x86.Build.0 = Debug|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Release|x64.ActiveCfg = Release|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Release|x64.Build.0 = Release|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Release|x86.ActiveCfg = Release|Any CPU
+ {C20EA2A9-7660-47DE-9A49-D1EF12FB2895}.Release|x86.Build.0 = Release|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Debug|x64.Build.0 = Debug|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Debug|x86.Build.0 = Debug|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Release|x64.ActiveCfg = Release|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Release|x64.Build.0 = Release|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Release|x86.ActiveCfg = Release|Any CPU
+ {B9E24D84-2712-4158-8F1A-DDE44CD1BB0A}.Release|x86.Build.0 = Release|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Debug|x64.Build.0 = Debug|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Debug|x86.Build.0 = Debug|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Release|x64.ActiveCfg = Release|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Release|x64.Build.0 = Release|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Release|x86.ActiveCfg = Release|Any CPU
+ {E4CA1EF0-B181-4A5D-A02C-DB0750A59CDF}.Release|x86.Build.0 = Release|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Debug|x64.Build.0 = Debug|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Debug|x86.Build.0 = Debug|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Release|x64.ActiveCfg = Release|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Release|x64.Build.0 = Release|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Release|x86.ActiveCfg = Release|Any CPU
+ {E08F5B84-2B4A-4E09-82D1-E0715775CE5E}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {070A5D1D-B29D-4603-999D-693DB444AD0D}
+ EndGlobalSection
+EndGlobal
diff --git a/tutorial/netstd/build.cmd b/tutorial/netstd/build.cmd
new file mode 100644
index 000000000..9b84ef276
--- /dev/null
+++ b/tutorial/netstd/build.cmd
@@ -0,0 +1,25 @@
+@echo off
+rem /*
+rem * Licensed to the Apache Software Foundation (ASF) under one
+rem * or more contributor license agreements. See the NOTICE file
+rem * distributed with this work for additional information
+rem * regarding copyright ownership. The ASF licenses this file
+rem * to you under the Apache License, Version 2.0 (the
+rem * "License"); you may not use this file except in compliance
+rem * with the License. You may obtain a copy of the License at
+rem *
+rem * http://www.apache.org/licenses/LICENSE-2.0
+rem *
+rem * Unless required by applicable law or agreed to in writing,
+rem * software distributed under the License is distributed on an
+rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+rem * KIND, either express or implied. See the License for the
+rem * specific language governing permissions and limitations
+rem * under the License.
+rem */
+setlocal
+
+dotnet --info
+dotnet build
+
+:eof
diff --git a/tutorial/netstd/build.sh b/tutorial/netstd/build.sh
new file mode 100644
index 000000000..c97e310f0
--- /dev/null
+++ b/tutorial/netstd/build.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+#exit if any command fails
+set -e
+
+dotnet --info
+dotnet build