You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2017/01/04 18:41:18 UTC
[2/9] thrift git commit: THRIFT-3933 Microsoft .Net Core library port
and generator for this library Client: .NET Core Patch: Volodymyr Gotra
PR #1088,
with significant improvements by Jens Geyer PR #1149
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/ThriftTest/TestServer.cs
----------------------------------------------------------------------
diff --git a/test/netcore/ThriftTest/TestServer.cs b/test/netcore/ThriftTest/TestServer.cs
new file mode 100644
index 0000000..7976c5d
--- /dev/null
+++ b/test/netcore/ThriftTest/TestServer.cs
@@ -0,0 +1,556 @@
+\ufeff// 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.Security.Authentication;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
+using ThriftAsync.Test;
+using Thrift;
+using Thrift.Collections;
+using Thrift.Protocols;
+using Thrift.Server;
+using Thrift.Transports;
+using Thrift.Transports.Server;
+
+namespace Test
+{
+ internal class ServerParam
+ {
+ internal bool useBufferedSockets = false;
+ internal bool useFramed = false;
+ internal bool useEncryption = false;
+ internal bool compact = false;
+ internal bool json = false;
+ internal int port = 9090;
+ internal string pipe = null;
+
+ internal void Parse(List<string> args)
+ {
+ for (var i = 0; i < args.Count; i++)
+ {
+ if (args[i].StartsWith("--pipe="))
+ {
+ pipe = args[i].Substring(args[i].IndexOf("=") + 1);
+ }
+ else if (args[i].StartsWith("--port="))
+ {
+ port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
+ }
+ else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
+ {
+ useBufferedSockets = true;
+ }
+ else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
+ {
+ useFramed = true;
+ }
+ else if (args[i] == "--compact" || args[i] == "--protocol=compact")
+ {
+ compact = true;
+ }
+ else if (args[i] == "--json" || args[i] == "--protocol=json")
+ {
+ json = true;
+ }
+ else if (args[i] == "--threaded" || args[i] == "--server-type=threaded")
+ {
+ throw new NotImplementedException(args[i]);
+ }
+ else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool")
+ {
+ throw new NotImplementedException(args[i]);
+ }
+ else if (args[i] == "--prototype" || args[i] == "--processor=prototype")
+ {
+ throw new NotImplementedException(args[i]);
+ }
+ else if (args[i] == "--ssl")
+ {
+ useEncryption = true;
+ }
+ else
+ {
+ throw new ArgumentException(args[i]);
+ }
+ }
+
+ }
+ }
+
+ public class TestServer
+ {
+ public static int _clientID = -1;
+ public delegate void TestLogDelegate(string msg, params object[] values);
+
+ public class MyServerEventHandler : TServerEventHandler
+ {
+ public int callCount = 0;
+
+ public Task PreServeAsync(CancellationToken cancellationToken)
+ {
+ callCount++;
+ return Task.CompletedTask;
+ }
+
+ public Task<object> CreateContextAsync(TProtocol input, TProtocol output, CancellationToken cancellationToken)
+ {
+ callCount++;
+ return Task.FromResult<object>(null);
+ }
+
+ public Task DeleteContextAsync(object serverContext, TProtocol input, TProtocol output, CancellationToken cancellationToken)
+ {
+ callCount++;
+ return Task.CompletedTask;
+ }
+
+ public Task ProcessContextAsync(object serverContext, TClientTransport transport, CancellationToken cancellationToken)
+ {
+ callCount++;
+ return Task.CompletedTask;
+ }
+ };
+
+ public class TestHandlerAsync : ThriftAsync.Test.ThriftTest.IAsync
+ {
+ public TBaseServer server { get; set; }
+ private int handlerID;
+ private StringBuilder sb = new StringBuilder();
+ private TestLogDelegate logger;
+
+ public TestHandlerAsync()
+ {
+ handlerID = Interlocked.Increment(ref _clientID);
+ logger += testConsoleLogger;
+ logger.Invoke("New TestHandler instance created");
+ }
+
+ public void testConsoleLogger(string msg, params object[] values)
+ {
+ sb.Clear();
+ sb.AppendFormat("handler{0:D3}:", handlerID);
+ sb.AppendFormat(msg, values);
+ sb.AppendLine();
+ Console.Write(sb.ToString());
+ }
+
+ public Task testVoidAsync(CancellationToken cancellationToken)
+ {
+ logger.Invoke("testVoid()");
+ return Task.CompletedTask;
+ }
+
+ public Task<string> testStringAsync(string thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testString({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<bool> testBoolAsync(bool thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testBool({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<sbyte> testByteAsync(sbyte thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testByte({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<int> testI32Async(int thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testI32({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<long> testI64Async(long thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testI64({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<double> testDoubleAsync(double thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testDouble({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<byte[]> testBinaryAsync(byte[] thing, CancellationToken cancellationToken)
+ {
+ var hex = BitConverter.ToString(thing).Replace("-", string.Empty);
+ logger.Invoke("testBinary({0:X})", hex);
+ return Task.FromResult(thing);
+ }
+
+ public Task<Xtruct> testStructAsync(Xtruct thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing.String_thing, thing.Byte_thing, thing.I32_thing, thing.I64_thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<Xtruct2> testNestAsync(Xtruct2 nest, CancellationToken cancellationToken)
+ {
+ var thing = nest.Struct_thing;
+ logger.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
+ nest.Byte_thing,
+ thing.String_thing,
+ thing.Byte_thing,
+ thing.I32_thing,
+ thing.I64_thing,
+ nest.I32_thing);
+ return Task.FromResult(nest);
+ }
+
+ public Task<Dictionary<int, int>> testMapAsync(Dictionary<int, int> thing, CancellationToken cancellationToken)
+ {
+ sb.Clear();
+ sb.Append("testMap({{");
+ var first = true;
+ foreach (var key in thing.Keys)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ sb.Append(", ");
+ }
+ sb.AppendFormat("{0} => {1}", key, thing[key]);
+ }
+ sb.Append("}})");
+ logger.Invoke(sb.ToString());
+ return Task.FromResult(thing);
+ }
+
+ public Task<Dictionary<string, string>> testStringMapAsync(Dictionary<string, string> thing, CancellationToken cancellationToken)
+ {
+ sb.Clear();
+ sb.Append("testStringMap({{");
+ var first = true;
+ foreach (var key in thing.Keys)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ sb.Append(", ");
+ }
+ sb.AppendFormat("{0} => {1}", key, thing[key]);
+ }
+ sb.Append("}})");
+ logger.Invoke(sb.ToString());
+ return Task.FromResult(thing);
+ }
+
+ public Task<THashSet<int>> testSetAsync(THashSet<int> thing, CancellationToken cancellationToken)
+ {
+ sb.Clear();
+ sb.Append("testSet({{");
+ var first = true;
+ foreach (int elem in thing)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ sb.Append(", ");
+ }
+ sb.AppendFormat("{0}", elem);
+ }
+ sb.Append("}})");
+ logger.Invoke(sb.ToString());
+ return Task.FromResult(thing);
+ }
+
+ public Task<List<int>> testListAsync(List<int> thing, CancellationToken cancellationToken)
+ {
+ sb.Clear();
+ sb.Append("testList({{");
+ var first = true;
+ foreach (var elem in thing)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ sb.Append(", ");
+ }
+ sb.AppendFormat("{0}", elem);
+ }
+ sb.Append("}})");
+ logger.Invoke(sb.ToString());
+ return Task.FromResult(thing);
+ }
+
+ public Task<Numberz> testEnumAsync(Numberz thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testEnum({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<long> testTypedefAsync(long thing, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testTypedef({0})", thing);
+ return Task.FromResult(thing);
+ }
+
+ public Task<Dictionary<int, Dictionary<int, int>>> testMapMapAsync(int hello, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testMapMap({0})", hello);
+ var mapmap = new Dictionary<int, Dictionary<int, int>>();
+
+ var pos = new Dictionary<int, int>();
+ var neg = new Dictionary<int, int>();
+ for (var i = 1; i < 5; i++)
+ {
+ pos[i] = i;
+ neg[-i] = -i;
+ }
+
+ mapmap[4] = pos;
+ mapmap[-4] = neg;
+
+ return Task.FromResult(mapmap);
+ }
+
+ public Task<Dictionary<long, Dictionary<Numberz, Insanity>>> testInsanityAsync(Insanity argument, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testInsanity()");
+
+ /** from ThriftTest.thrift:
+ * So you think you've got this all worked, out eh?
+ *
+ * Creates a the returned map with these values and prints it out:
+ * { 1 => { 2 => argument,
+ * 3 => argument,
+ * },
+ * 2 => { 6 => <empty Insanity struct>, },
+ * }
+ * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
+ */
+
+ var first_map = new Dictionary<Numberz, Insanity>();
+ var second_map = new Dictionary<Numberz, Insanity>(); ;
+
+ first_map[Numberz.TWO] = argument;
+ first_map[Numberz.THREE] = argument;
+
+ second_map[Numberz.SIX] = new Insanity();
+
+ var insane = new Dictionary<long, Dictionary<Numberz, Insanity>>
+ {
+ [1] = first_map,
+ [2] = second_map
+ };
+
+ return Task.FromResult(insane);
+ }
+
+ public Task<Xtruct> testMultiAsync(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5,
+ CancellationToken cancellationToken)
+ {
+ logger.Invoke("testMulti()");
+
+ var hello = new Xtruct(); ;
+ hello.String_thing = "Hello2";
+ hello.Byte_thing = arg0;
+ hello.I32_thing = arg1;
+ hello.I64_thing = arg2;
+ return Task.FromResult(hello);
+ }
+
+ public Task testExceptionAsync(string arg, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testException({0})", arg);
+ if (arg == "Xception")
+ {
+ var x = new Xception
+ {
+ ErrorCode = 1001,
+ Message = arg
+ };
+ throw x;
+ }
+ if (arg == "TException")
+ {
+ throw new TException();
+ }
+ return Task.CompletedTask;
+ }
+
+ public Task<Xtruct> testMultiExceptionAsync(string arg0, string arg1, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testMultiException({0}, {1})", arg0, arg1);
+ if (arg0 == "Xception")
+ {
+ var x = new Xception
+ {
+ ErrorCode = 1001,
+ Message = "This is an Xception"
+ };
+ throw x;
+ }
+
+ if (arg0 == "Xception2")
+ {
+ var x = new Xception2
+ {
+ ErrorCode = 2002,
+ Struct_thing = new Xtruct { String_thing = "This is an Xception2" }
+ };
+ throw x;
+ }
+
+ var result = new Xtruct { String_thing = arg1 };
+ return Task.FromResult(result);
+ }
+
+ public Task testOnewayAsync(int secondsToSleep, CancellationToken cancellationToken)
+ {
+ logger.Invoke("testOneway({0}), sleeping...", secondsToSleep);
+ Thread.Sleep(secondsToSleep * 1000);
+ logger.Invoke("testOneway finished");
+
+ return Task.CompletedTask;
+ }
+ }
+
+
+ private enum ProcessorFactoryType
+ {
+ TSingletonProcessorFactory,
+ TPrototypeProcessorFactory,
+ }
+
+ internal static void PrintOptionsHelp()
+ {
+ Console.WriteLine("Server options:");
+ Console.WriteLine(" --pipe=<pipe name>");
+ Console.WriteLine(" --port=<port number>");
+ Console.WriteLine(" --transport=<transport name> one of buffered,framed (defaults to none)");
+ Console.WriteLine(" --protocol=<protocol name> one of compact,json (defaults to binary)");
+ Console.WriteLine(" --server-type=<type> one of threaded,threadpool (defaults to simple)");
+ Console.WriteLine(" --processor=<prototype>");
+ Console.WriteLine(" --ssl");
+ Console.WriteLine();
+ }
+
+ public static int Execute(List<string> args)
+ {
+ var logger = new LoggerFactory().CreateLogger("Test");
+
+ try
+ {
+ var param = new ServerParam();
+
+ try
+ {
+ param.Parse(args);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("*** FAILED ***");
+ Console.WriteLine("Error while parsing arguments");
+ Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
+ return 1;
+ }
+
+
+ // Transport
+ TServerTransport trans;
+ if (param.pipe != null)
+ {
+ trans = new TNamedPipeServerTransport(param.pipe);
+ }
+ else
+ {
+ if (param.useEncryption)
+ {
+ var certPath = "../keys/server.p12";
+ trans = new TTlsServerSocketTransport(param.port, param.useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls12);
+ }
+ else
+ {
+ trans = new TServerSocketTransport(param.port, 0, param.useBufferedSockets);
+ }
+ }
+
+ ITProtocolFactory proto;
+ if (param.compact)
+ proto = new TCompactProtocol.Factory();
+ else if (param.json)
+ proto = new TJsonProtocol.Factory();
+ else
+ proto = new TBinaryProtocol.Factory();
+
+ ITProcessorFactory processorFactory;
+
+ // Processor
+ var testHandler = new TestHandlerAsync();
+ var testProcessor = new ThriftAsync.Test.ThriftTest.AsyncProcessor(testHandler);
+ processorFactory = new SingletonTProcessorFactory(testProcessor);
+
+
+ TTransportFactory transFactory;
+ if (param.useFramed)
+ throw new NotImplementedException("framed"); // transFactory = new TFramedTransport.Factory();
+ else
+ transFactory = new TTransportFactory();
+
+ TBaseServer serverEngine = new AsyncBaseServer(processorFactory, trans, transFactory, transFactory, proto, proto, logger);
+
+ //Server event handler
+ var serverEvents = new MyServerEventHandler();
+ serverEngine.SetEventHandler(serverEvents);
+
+ // Run it
+ var where = (! string.IsNullOrEmpty(param.pipe)) ? "on pipe " + param.pipe : "on port " + param.port;
+ Console.WriteLine("Starting the AsyncBaseServer " + where +
+ " with processor TPrototypeProcessorFactory prototype factory " +
+ (param.useBufferedSockets ? " with buffered socket" : "") +
+ (param.useFramed ? " with framed transport" : "") +
+ (param.useEncryption ? " with encryption" : "") +
+ (param.compact ? " with compact protocol" : "") +
+ (param.json ? " with json protocol" : "") +
+ "...");
+ serverEngine.ServeAsync(CancellationToken.None).GetAwaiter().GetResult();
+ Console.ReadLine();
+ }
+ catch (Exception x)
+ {
+ Console.Error.Write(x);
+ return 1;
+ }
+ Console.WriteLine("done.");
+ return 0;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/ThriftTest/ThriftTest.sln
----------------------------------------------------------------------
diff --git a/test/netcore/ThriftTest/ThriftTest.sln b/test/netcore/ThriftTest/ThriftTest.sln
new file mode 100644
index 0000000..03b4f3d
--- /dev/null
+++ b/test/netcore/ThriftTest/ThriftTest.sln
@@ -0,0 +1,33 @@
+\ufeff
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ThriftTest", "ThriftTest.xproj", "{B0C13DA0-3117-4844-8AE8-B1775E46223D}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Thrift", "..\..\..\lib\netcore\Thrift\Thrift.xproj", "{6850CF46-5467-4C65-BD78-871581C539FC}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{839DBA0F-2D58-4266-A30D-3392BD710A59}"
+ ProjectSection(SolutionItems) = preProject
+ ..\global.json = ..\global.json
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B0C13DA0-3117-4844-8AE8-B1775E46223D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B0C13DA0-3117-4844-8AE8-B1775E46223D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B0C13DA0-3117-4844-8AE8-B1775E46223D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B0C13DA0-3117-4844-8AE8-B1775E46223D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/ThriftTest/ThriftTest.xproj
----------------------------------------------------------------------
diff --git a/test/netcore/ThriftTest/ThriftTest.xproj b/test/netcore/ThriftTest/ThriftTest.xproj
new file mode 100644
index 0000000..7746cc8
--- /dev/null
+++ b/test/netcore/ThriftTest/ThriftTest.xproj
@@ -0,0 +1,21 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>B0C13DA0-3117-4844-8AE8-B1775E46223D</ProjectGuid>
+ <RootNamespace>ThriftTest</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">bin\$(MSBuildProjectName)\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/ThriftTest/project.json
----------------------------------------------------------------------
diff --git a/test/netcore/ThriftTest/project.json b/test/netcore/ThriftTest/project.json
new file mode 100644
index 0000000..56d2777
--- /dev/null
+++ b/test/netcore/ThriftTest/project.json
@@ -0,0 +1,29 @@
+{
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "emitEntryPoint": true
+ },
+
+ "runtimes": {
+ "win10-x64": {},
+ "osx.10.11-x64": {},
+ "ubuntu.16.04-x64": {}
+ },
+
+ "dependencies": {
+ "System.Runtime.Serialization.Primitives": "4.1.1",
+ "System.ServiceModel.Primitives": "4.0.0"
+ },
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": "dnxcore50",
+ "dependencies": {
+ "Thrift": "1.0.0-*",
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0"
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/build.cmd
----------------------------------------------------------------------
diff --git a/test/netcore/build.cmd b/test/netcore/build.cmd
new file mode 100644
index 0000000..88ff20a
--- /dev/null
+++ b/test/netcore/build.cmd
@@ -0,0 +1,45 @@
+@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
+
+cd ThriftTest
+thrift -gen netcore:wcf -r ..\..\ThriftTest.thrift
+cd ..
+
+rem * Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline
+rem * For details see https://github.com/dotnet/cli/issues/3199 and related tickets
+rem * The problem does NOT affect Visual Studio builds.
+
+rem * workaround for "dotnet restore" issue
+xcopy ..\..\lib\netcore\Thrift .\Thrift /YSEI >NUL
+
+dotnet --info
+dotnet restore
+
+dotnet build **/*/project.json -r win10-x64
+dotnet build **/*/project.json -r osx.10.11-x64
+dotnet build **/*/project.json -r ubuntu.16.04-x64
+
+rem * workaround for "dotnet restore" issue
+del .\Thrift\* /Q /S >NUL
+rd .\Thrift /Q /S >NUL
+
+
+:eof
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/build.sh
----------------------------------------------------------------------
diff --git a/test/netcore/build.sh b/test/netcore/build.sh
new file mode 100644
index 0000000..3acd78a
--- /dev/null
+++ b/test/netcore/build.sh
@@ -0,0 +1,54 @@
+#!/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
+
+cd ThriftTest
+../../../compiler/cpp/thrift -gen netcore:wcf -r ../../ThriftTest.thrift
+cd ..
+
+
+# Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline
+# For details see https://github.com/dotnet/cli/issues/3199 and related tickets
+# The problem does NOT affect Visual Studio builds.
+
+# workaround for "dotnet restore" issue
+cp -u -p -r ..\..\lib\netcore\Thrift .\Thrift
+
+dotnet --info
+dotnet restore
+
+# dotnet test ./test/TEST_PROJECT_NAME -c Release -f netcoreapp1.0
+
+# Instead, run directly with mono for the full .net version
+dotnet build **/*/project.json -r win10-x64
+dotnet build **/*/project.json -r osx.10.11-x64
+dotnet build **/*/project.json -r ubuntu.16.04-x64
+
+#revision=${TRAVIS_JOB_ID:=1}
+#revision=$(printf "%04d" $revision)
+
+#dotnet pack ./src/PROJECT_NAME -c Release -o ./artifacts --version-suffix=$revision
+
+# workaround for "dotnet restore" issue
+rm -r .\Thrift
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/netcore/global.json
----------------------------------------------------------------------
diff --git a/test/netcore/global.json b/test/netcore/global.json
new file mode 100644
index 0000000..53f1811
--- /dev/null
+++ b/test/netcore/global.json
@@ -0,0 +1,3 @@
+{
+ "projects": [ "../../lib/netcore" ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index 2460b83..b101bfd 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -364,6 +364,34 @@
"workdir": "csharp"
},
{
+ "name": "netcore",
+ "transports": [
+ "buffered",
+ "framed"
+ ],
+ "sockets": [
+ "ip",
+ "ip-ssl"
+ ],
+ "protocols": [
+ "binary",
+ "compact",
+ "json"
+ ],
+ "server": {
+ "command": [
+ "dotnet restore && dotnet run server"
+ ]
+ },
+ "client": {
+ "timeout": 10,
+ "command": [
+ "dotnet run client"
+ ]
+ },
+ "workdir": "netcore/ThriftTest"
+ },
+ {
"name": "perl",
"transports": [
"buffered",
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/Makefile.am
----------------------------------------------------------------------
diff --git a/tutorial/Makefile.am b/tutorial/Makefile.am
index 5865c54..efa314a 100755
--- a/tutorial/Makefile.am
+++ b/tutorial/Makefile.am
@@ -58,6 +58,10 @@ if WITH_HAXE
SUBDIRS += haxe
endif
+if WITH_DOTNETCORE
+SUBDIRS += netcore
+endif
+
if WITH_GO
SUBDIRS += go
endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/.gitignore
----------------------------------------------------------------------
diff --git a/tutorial/netcore/.gitignore b/tutorial/netcore/.gitignore
new file mode 100644
index 0000000..9938bb2
--- /dev/null
+++ b/tutorial/netcore/.gitignore
@@ -0,0 +1 @@
+!**/*.pfx
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Client/Client.xproj
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Client/Client.xproj b/tutorial/netcore/Client/Client.xproj
new file mode 100644
index 0000000..8726182
--- /dev/null
+++ b/tutorial/netcore/Client/Client.xproj
@@ -0,0 +1,21 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>de78a01b-f7c6-49d1-97da-669d2ed37641</ProjectGuid>
+ <RootNamespace>Client</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Client/Program.cs
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Client/Program.cs b/tutorial/netcore/Client/Program.cs
new file mode 100644
index 0000000..5485e95
--- /dev/null
+++ b/tutorial/netcore/Client/Program.cs
@@ -0,0 +1,277 @@
+\ufeff// 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.Protocols;
+using Thrift.Transports;
+using Thrift.Transports.Client;
+using tutorial;
+using shared;
+
+namespace Client
+{
+ public class Program
+ {
+ private static readonly ILogger Logger = new LoggerFactory().CreateLogger(nameof(Client));
+
+ private static void DisplayHelp()
+ {
+ Console.WriteLine(@"
+Usage:
+ Client.exe -h
+ will diplay help information
+
+ Client.exe -t:<transport> -p:<protocol>
+ will run client with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+ -t (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)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+ Client.exe -t:tcp -p:binary
+");
+ }
+
+ public static void Main(string[] args)
+ {
+ args = args ?? new string[0];
+
+ if (args.Any(x => x.StartsWith("-h", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
+
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+ }
+ }
+
+ private static async Task RunAsync(string[] args, CancellationToken cancellationToken)
+ {
+ var clientTransport = GetTransport(args);
+
+ Logger.LogInformation($"Selected client transport: {clientTransport}");
+
+ var clientProtocol = GetProtocol(args, clientTransport);
+
+ Logger.LogInformation($"Selected client protocol: {clientProtocol}");
+
+ await RunClientAsync(clientProtocol, cancellationToken);
+ }
+
+ private static TClientTransport GetTransport(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-t"))?.Split(':')?[1];
+
+ Transport selectedTransport;
+ if (Enum.TryParse(transport, true, out selectedTransport))
+ {
+ switch (selectedTransport)
+ {
+ case Transport.Tcp:
+ return new TSocketClientTransport(IPAddress.Loopback, 9090);
+ case Transport.NamedPipe:
+ return new TNamedPipeClientTransport(".test");
+ case Transport.Http:
+ return new THttpClientTransport(new Uri("http://localhost:9090"), null);
+ case Transport.TcpBuffered:
+ return
+ new TBufferedClientTransport(
+ new TSocketClientTransport(IPAddress.Loopback, 9090));
+ case Transport.TcpTls:
+ return new TTlsSocketClientTransport(IPAddress.Loopback, 9090,
+ GetCertificate(), CertValidator, LocalCertificateSelectionCallback);
+ case Transport.Framed:
+ throw new NotSupportedException("Framed is not ready for samples");
+ }
+ }
+
+ return new TSocketClientTransport(IPAddress.Loopback, 9090);
+ }
+
+ 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 TProtocol GetProtocol(string[] args, TClientTransport transport)
+ {
+ var protocol = args.FirstOrDefault(x => x.StartsWith("-p"))?.Split(':')?[1];
+
+ Protocol selectedProtocol;
+ if (Enum.TryParse(protocol, true, out selectedProtocol))
+ {
+ switch (selectedProtocol)
+ {
+ case Protocol.Binary:
+ return new TBinaryProtocol(transport);
+ case Protocol.Compact:
+ return new TCompactProtocol(transport);
+ case Protocol.Json:
+ return new TJsonProtocol(transport);
+ }
+ }
+
+ return new TBinaryProtocol(transport);
+ }
+
+ private static async Task RunClientAsync(TProtocol protocol,
+ CancellationToken cancellationToken)
+ {
+ try
+ {
+ var client = new Calculator.Client(protocol);
+ await client.OpenTransportAsync(cancellationToken);
+
+ try
+ {
+ // Async version
+
+ Logger.LogInformation("PingAsync()");
+ await client.pingAsync(cancellationToken);
+
+ Logger.LogInformation("AddAsync(1,1)");
+ var sum = await client.addAsync(1, 1, cancellationToken);
+ Logger.LogInformation($"AddAsync(1,1)={sum}");
+
+ var work = new Work
+ {
+ Op = Operation.DIVIDE,
+ Num1 = 1,
+ Num2 = 0
+ };
+
+ try
+ {
+ Logger.LogInformation("CalculateAsync(1)");
+ await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation("Whoa we can divide by 0");
+ }
+ catch (InvalidOperation io)
+ {
+ Logger.LogInformation("Invalid operation: " + io);
+ }
+
+ work.Op = Operation.SUBTRACT;
+ work.Num1 = 15;
+ work.Num2 = 10;
+
+ try
+ {
+ Logger.LogInformation("CalculateAsync(1)");
+ var diff = await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation($"15-10={diff}");
+ }
+ catch (InvalidOperation io)
+ {
+ Logger.LogInformation("Invalid operation: " + io);
+ }
+
+ Logger.LogInformation("GetStructAsync(1)");
+ var log = await client.getStructAsync(1, cancellationToken);
+ Logger.LogInformation($"Check log: {log.Value}");
+
+ Logger.LogInformation("ZipAsync() with delay 100mc on server side");
+ await client.zipAsync(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex.ToString());
+ }
+ finally
+ {
+ protocol.Transport.Close();
+ }
+ }
+ catch (TApplicationException x)
+ {
+ Logger.LogError(x.ToString());
+ }
+ }
+
+ private enum Transport
+ {
+ Tcp,
+ NamedPipe,
+ Http,
+ TcpBuffered,
+ Framed,
+ TcpTls
+ }
+
+ private enum Protocol
+ {
+ Binary,
+ Compact,
+ Json,
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Client/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Client/Properties/AssemblyInfo.cs b/tutorial/netcore/Client/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..568382e
--- /dev/null
+++ b/tutorial/netcore/Client/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+\ufeff// 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
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Client/Properties/launchSettings.json
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Client/Properties/launchSettings.json b/tutorial/netcore/Client/Properties/launchSettings.json
new file mode 100644
index 0000000..f351eeb
--- /dev/null
+++ b/tutorial/netcore/Client/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "Client": {
+ "commandName": "Project",
+ "commandLineArgs": "-t:tcptls"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Client/ThriftTest.pfx
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Client/ThriftTest.pfx b/tutorial/netcore/Client/ThriftTest.pfx
new file mode 100644
index 0000000..f0ded28
Binary files /dev/null and b/tutorial/netcore/Client/ThriftTest.pfx differ
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Client/project.json
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Client/project.json b/tutorial/netcore/Client/project.json
new file mode 100644
index 0000000..c850e5d
--- /dev/null
+++ b/tutorial/netcore/Client/project.json
@@ -0,0 +1,28 @@
+{
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
+
+ "dependencies": {
+ "Interfaces": "1.0.0-*",
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0"
+ },
+ "Thrift": "1.0.0-*",
+ //"Thrift": "1.0.0-*"
+ },
+
+ "runtimes": {
+ "win10-x64": {},
+ "osx.10.11-x64": {},
+ "ubuntu.16.04-x64": {}
+ },
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": "dnxcore50"
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Interfaces/Interfaces.xproj
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Interfaces/Interfaces.xproj b/tutorial/netcore/Interfaces/Interfaces.xproj
new file mode 100644
index 0000000..d472ce6
--- /dev/null
+++ b/tutorial/netcore/Interfaces/Interfaces.xproj
@@ -0,0 +1,21 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>4d13163d-9067-4c9c-8af0-64e08451397d</ProjectGuid>
+ <RootNamespace>Interfaces</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs b/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..9126b17
--- /dev/null
+++ b/tutorial/netcore/Interfaces/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+\ufeff// 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
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Interfaces/project.json
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Interfaces/project.json b/tutorial/netcore/Interfaces/project.json
new file mode 100644
index 0000000..b5f7c98
--- /dev/null
+++ b/tutorial/netcore/Interfaces/project.json
@@ -0,0 +1,22 @@
+{
+ "version": "1.0.0-*",
+
+ "dependencies": {
+ "NETStandard.Library": "1.6.0",
+ "System.ServiceModel.Primitives": "4.0.0",
+ "Thrift": "1.0.0-*",
+ //"Thrift": "1.0.0-*"
+ },
+
+ "frameworks": {
+ "netstandard1.6": {
+ "imports": "dnxcore50"
+ }
+ },
+
+ "scripts": {
+ "precompile": [
+ //"%project:Directory%/../../thrift.exe -r -out %project:Directory% --gen netcore:wcf %project:Directory%/tutorial.thrift"
+ ]
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Makefile.am
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Makefile.am b/tutorial/netcore/Makefile.am
new file mode 100644
index 0000000..a3abaee
--- /dev/null
+++ b/tutorial/netcore/Makefile.am
@@ -0,0 +1,82 @@
+#
+# 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 = .
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+GENDIR = Interfaces/gen-netcore
+
+# Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline.
+# The problem does NOT affect Visual Studio builds, only cmdline.
+# - For details see https://github.com/dotnet/cli/issues/3199 and related tickets.
+# - Workaround is to temporarily copy the Thrift project into the solution
+COPYCMD = cp -u -p -r
+
+
+THRIFTCODE = \
+ Interfaces/Properties/AssemblyInfo.cs \
+ Client/Properties/AssemblyInfo.cs \
+ Client/Program.cs \
+ Server/Properties/AssemblyInfo.cs \
+ Server/Program.cs
+
+all-local: \
+ Client.exe
+
+Client.exe: $(THRIFTCODE)
+ $(MKDIR_P) $(GENDIR)
+ $(THRIFT) -gen netcore:wcf -r -out $(GENDIR) $(top_srcdir)/tutorial/tutorial.thrift
+ $(MKDIR_P) ./Thrift
+ $(COPYCMD) $(top_srcdir)/lib/netcore/Thrift/* ./Thrift
+ $(DOTNETCORE) --info
+ $(DOTNETCORE) restore
+ $(DOTNETCORE) build **/*/project.json -r win10-x64
+ $(DOTNETCORE) build **/*/project.json -r osx.10.11-x64
+ $(DOTNETCORE) build **/*/project.json -r ubuntu.16.04-x64
+
+clean-local:
+ $(RM) Client.exe
+ $(RM) Server.exe
+ $(RM) Interfaces.dll
+ $(RM) -r $(GENDIR)
+ $(RM) -r Client/bin
+ $(RM) -r Client/obj
+ $(RM) -r Server/bin
+ $(RM) -r Server/obj
+ $(RM) -r Interfaces/bin
+ $(RM) -r Interfaces/obj
+ $(RM) -r Thrift
+
+EXTRA_DIST = \
+ $(THRIFTCODE) \
+ global.json \
+ Tutorial.sln \
+ Interfaces/project.json \
+ Interfaces/Interfaces.xproj \
+ Server/project.json \
+ Server/Server.xproj \
+ Server/ThriftTest.pfx \
+ Client/project.json \
+ Client/Client.xproj \
+ Client/ThriftTest.pfx \
+ build.cmd \
+ build.sh \
+ README.md
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/README.md
----------------------------------------------------------------------
diff --git a/tutorial/netcore/README.md b/tutorial/netcore/README.md
new file mode 100644
index 0000000..18aac02
--- /dev/null
+++ b/tutorial/netcore/README.md
@@ -0,0 +1,253 @@
+# Building of samples for different platforms
+
+Details:
+
+- [https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index ](https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index "https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index ")
+- [https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog](https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog "https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog")
+
+# 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 -t:<transport> -p:<protocol>
+ will run server with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+
+ -t (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)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+
+ Server.exe -t: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 -t:<transport> -p:<protocol>
+ will run client with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+
+ -t (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)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+
+ Client.exe -t:tcp -p:binary
+
+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 netcore 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)
+```
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Server/Program.cs
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Server/Program.cs b/tutorial/netcore/Server/Program.cs
new file mode 100644
index 0000000..6041924
--- /dev/null
+++ b/tutorial/netcore/Server/Program.cs
@@ -0,0 +1,397 @@
+\ufeff// 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.Protocols;
+using Thrift.Server;
+using Thrift.Transports;
+using Thrift.Transports.Server;
+using tutorial;
+using shared;
+
+namespace Server
+{
+ public class Program
+ {
+ private static readonly ILogger Logger = new LoggerFactory().CreateLogger(nameof(Server));
+
+ public static void Main(string[] args)
+ {
+ args = args ?? new string[0];
+
+ if (args.Any(x => x.StartsWith("-h", 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();
+ }
+ }
+
+ private static void DisplayHelp()
+ {
+ Console.WriteLine(@"
+Usage:
+ Server.exe -h
+ will diplay help information
+
+ Server.exe -t:<transport> -p:<protocol>
+ will run server with specified arguments (tcp transport and binary protocol by default)
+
+Options:
+ -t (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)
+
+ -p (protocol):
+ binary - (default) binary protocol will be used
+ compact - compact protocol will be used
+ json - json protocol will be used
+
+Sample:
+ Server.exe -t: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("-p"))?.Split(':')?[1];
+ Protocol selectedProtocol;
+
+ Enum.TryParse(transport, true, out selectedProtocol);
+
+ return selectedProtocol;
+ }
+
+ private static Transport GetTransport(string[] args)
+ {
+ var transport = args.FirstOrDefault(x => x.StartsWith("-t"))?.Split(':')?[1];
+ Transport selectedTransport;
+
+ Enum.TryParse(transport, true, out selectedTransport);
+
+ return selectedTransport;
+ }
+
+ private static async Task RunSelectedConfigurationAsync(Transport transport,
+ Protocol protocol, CancellationToken cancellationToken)
+ {
+ var fabric = new LoggerFactory();
+ var handler = new CalculatorAsyncHandler();
+ var processor = new Calculator.AsyncProcessor(handler);
+
+ 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;
+ }
+
+ ITProtocolFactory inputProtocolFactory;
+ ITProtocolFactory outputProtocolFactory;
+
+ switch (protocol)
+ {
+ case Protocol.Binary:
+ {
+ inputProtocolFactory = new TBinaryProtocol.Factory();
+ outputProtocolFactory = new TBinaryProtocol.Factory();
+ }
+ break;
+ case Protocol.Compact:
+ {
+ inputProtocolFactory = new TCompactProtocol.Factory();
+ outputProtocolFactory = new TCompactProtocol.Factory();
+ }
+ break;
+ case Protocol.Json:
+ {
+ inputProtocolFactory = new TJsonProtocol.Factory();
+ outputProtocolFactory = new TJsonProtocol.Factory();
+ }
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null);
+ }
+
+ try
+ {
+ Logger.LogInformation(
+ $"Selected TAsyncServer with {serverTransport} transport and {inputProtocolFactory} protocol factories");
+
+ var server = new AsyncBaseServer(processor, serverTransport, inputProtocolFactory,
+ outputProtocolFactory, fabric);
+
+ Logger.LogInformation("Starting the server...");
+ await server.ServeAsync(cancellationToken);
+ }
+ catch (Exception x)
+ {
+ Logger.LogInformation(x.ToString());
+ }
+
+ Logger.LogInformation("Server stopped.");
+ }
+
+ 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
+ }
+
+ private enum Protocol
+ {
+ Binary,
+ Compact,
+ Json,
+ }
+
+ 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())
+ .UseIISIntegration()
+ .UseStartup<Startup>()
+ .Build();
+
+ host.Run(cancellationToken);
+ }
+
+ 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
+ {
+ Dictionary<int, SharedStruct> _log;
+
+ public CalculatorAsyncHandler()
+ {
+ _log = new Dictionary<int, SharedStruct>();
+ }
+
+ 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);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Server/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Server/Properties/AssemblyInfo.cs b/tutorial/netcore/Server/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..a044235
--- /dev/null
+++ b/tutorial/netcore/Server/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+\ufeff// 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
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Server/Properties/launchSettings.json
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Server/Properties/launchSettings.json b/tutorial/netcore/Server/Properties/launchSettings.json
new file mode 100644
index 0000000..e23253d
--- /dev/null
+++ b/tutorial/netcore/Server/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "Server": {
+ "commandName": "Project",
+ "commandLineArgs": "-t:tcptls"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Server/Server.xproj
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Server/Server.xproj b/tutorial/netcore/Server/Server.xproj
new file mode 100644
index 0000000..5cebad1
--- /dev/null
+++ b/tutorial/netcore/Server/Server.xproj
@@ -0,0 +1,21 @@
+\ufeff<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>e210fc10-5aff-4b04-ac21-58afc7b74b0c</ProjectGuid>
+ <RootNamespace>Server</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Server/ThriftTest.pfx
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Server/ThriftTest.pfx b/tutorial/netcore/Server/ThriftTest.pfx
new file mode 100644
index 0000000..f0ded28
Binary files /dev/null and b/tutorial/netcore/Server/ThriftTest.pfx differ
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Server/project.json
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Server/project.json b/tutorial/netcore/Server/project.json
new file mode 100644
index 0000000..7948c27
--- /dev/null
+++ b/tutorial/netcore/Server/project.json
@@ -0,0 +1,29 @@
+{
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
+
+ "dependencies": {
+ "Interfaces": "1.0.0-*",
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0"
+ },
+ "Microsoft.AspNetCore.Http": "1.0.0",
+ "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
+ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
+ "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
+ "Thrift": "1.0.0-*" },
+ "runtimes": {
+ "win10-x64": {},
+ "osx.10.11-x64": {},
+ "ubuntu.16.04-x64": {}
+ },
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": "dnxcore50"
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/Tutorial.sln
----------------------------------------------------------------------
diff --git a/tutorial/netcore/Tutorial.sln b/tutorial/netcore/Tutorial.sln
new file mode 100644
index 0000000..0368f21
--- /dev/null
+++ b/tutorial/netcore/Tutorial.sln
@@ -0,0 +1,45 @@
+\ufeff
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Server", "Server\Server.xproj", "{E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Interfaces", "Interfaces\Interfaces.xproj", "{4D13163D-9067-4C9C-8AF0-64E08451397D}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Client", "Client\Client.xproj", "{DE78A01B-F7C6-49D1-97DA-669D2ED37641}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Thrift", "..\..\lib\netcore\Thrift\Thrift.xproj", "{6850CF46-5467-4C65-BD78-871581C539FC}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49B45AE5-C6CB-4E11-AA74-6A5472FFAF8F}"
+ ProjectSection(SolutionItems) = preProject
+ global.json = global.json
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E210FC10-5AFF-4B04-AC21-58AFC7B74B0C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4D13163D-9067-4C9C-8AF0-64E08451397D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DE78A01B-F7C6-49D1-97DA-669D2ED37641}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6850CF46-5467-4C65-BD78-871581C539FC}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
http://git-wip-us.apache.org/repos/asf/thrift/blob/b587a12a/tutorial/netcore/build.cmd
----------------------------------------------------------------------
diff --git a/tutorial/netcore/build.cmd b/tutorial/netcore/build.cmd
new file mode 100644
index 0000000..2d20cbe
--- /dev/null
+++ b/tutorial/netcore/build.cmd
@@ -0,0 +1,45 @@
+@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
+
+cd Interfaces
+thrift -gen netcore:wcf -r ..\..\tutorial.thrift
+cd ..
+
+rem * Due to a known issue with "dotnet restore" the Thrift.dll dependency cannot be resolved from cmdline
+rem * For details see https://github.com/dotnet/cli/issues/3199 and related tickets
+rem * The problem does NOT affect Visual Studio builds.
+
+rem * workaround for "dotnet restore" issue
+xcopy ..\..\lib\netcore\Thrift .\Thrift /YSEI >NUL
+
+dotnet --info
+dotnet restore
+
+dotnet build **/*/project.json -r win10-x64
+dotnet build **/*/project.json -r osx.10.11-x64
+dotnet build **/*/project.json -r ubuntu.16.04-x64
+
+rem * workaround for "dotnet restore" issue
+del .\Thrift\* /Q /S >NUL
+rd .\Thrift /Q /S >NUL
+
+
+:eof