Skip to content
Permalink
Browse files

Fix task-like UnaryResult

  • Loading branch information...
neuecc committed Apr 7, 2017
1 parent 8b1c7d8 commit fc8dac3e70f5204fad51be3efde1ed9b581ba82d
@@ -117,4 +117,5 @@ src/MagicOnion.Client.Unity/Temp/*

nuget/tools/*
nuget/*.nupkg
nuget/*.unitypackage
nuget/*.unitypackage
.vs/
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26228.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1987061F-8970-4018-8D58-6932961C9EB4}"
EndProject
@@ -35,6 +35,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedProjectLibrary", "san
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStandardShare", "sandbox\NetStandardShare\NetStandardShare.csproj", "{A9E28AFD-4FEC-416A-9F85-C64F05605B22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.ConsoleServer2", "sandbox\Sandbox.ConsoleServer2\Sandbox.ConsoleServer2.csproj", "{7CF23E57-381B-428D-B44A-D5328A71414B}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
sandbox\SharedProjectLibrary\SharedProjectLibrary.projitems*{5526fa31-4f38-4ff7-96ee-a73bf495e1ee}*SharedItemsImports = 13
@@ -77,6 +79,10 @@ Global
{A9E28AFD-4FEC-416A-9F85-C64F05605B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9E28AFD-4FEC-416A-9F85-C64F05605B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9E28AFD-4FEC-416A-9F85-C64F05605B22}.Release|Any CPU.Build.0 = Release|Any CPU
{7CF23E57-381B-428D-B44A-D5328A71414B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CF23E57-381B-428D-B44A-D5328A71414B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CF23E57-381B-428D-B44A-D5328A71414B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CF23E57-381B-428D-B44A-D5328A71414B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -91,5 +97,6 @@ Global
{FCE03661-803E-4629-944F-45DB6B444320} = {1987061F-8970-4018-8D58-6932961C9EB4}
{5526FA31-4F38-4FF7-96EE-A73BF495E1EE} = {7682EFFC-681C-4DCC-B5E7-D8449E42DAC9}
{A9E28AFD-4FEC-416A-9F85-C64F05605B22} = {7682EFFC-681C-4DCC-B5E7-D8449E42DAC9}
{7CF23E57-381B-428D-B44A-D5328A71414B} = {7682EFFC-681C-4DCC-B5E7-D8449E42DAC9}
EndGlobalSection
EndGlobal
@@ -36,6 +36,13 @@
"Sandbox.ConsoleServer": {},
"Sandbox.ConsoleClient": {}
}
},
"Server + Server2 + Client": {
"Projects": {
"Sandbox.ConsoleServer": {},
"Sandbox.ConsoleServer2": {},
"Sandbox.ConsoleClient": {}
}
}
}
}
@@ -36,26 +36,32 @@ static void Main(string[] args)

var channel = new Channel("localhost", 12345, ChannelCredentials.Insecure);
//channel.ConnectAsync().Wait();
var c = MagicOnionClient.Create<IMyFirstService>(channel);

c.SumAsync(10, 20).GetAwaiter().GetResult().ResponseAsync.GetAwaiter().GetResult();
var c = MagicOnionClient.Create<IStandard>(channel);

var c2 = MagicOnionClient.Create<IArgumentPattern>(channel);
var c3 = MagicOnionClient.Create<Sandbox.ConsoleServer.IChatRoomService>(channel);
var c4 = MagicOnionClient.Create<Sandbox.ConsoleServer.IStandard>(channel);
RunTest(c).GetAwaiter().GetResult();
return;

// TestHeartbeat(channel).GetAwaiter().GetResult();
UnaryRun(c).GetAwaiter().GetResult();
ClientStreamRun(c).GetAwaiter().GetResult();
DuplexStreamRun(c).GetAwaiter().GetResult();
ServerStreamRun(c).GetAwaiter().GetResult();

// many run
//UnaryLoadTest(c).GetAwaiter().GetResult();
//return;
////c.SumAsync(10, 20).GetAwaiter().GetResult().ResponseAsync.GetAwaiter().GetResult();

//var c2 = MagicOnionClient.Create<IArgumentPattern>(channel);
//var c3 = MagicOnionClient.Create<Sandbox.ConsoleServer.IChatRoomService>(channel);
//var c4 = MagicOnionClient.Create<Sandbox.ConsoleServer.IStandard>(channel);

//// TestHeartbeat(channel).GetAwaiter().GetResult();
//UnaryRun(c).GetAwaiter().GetResult();
//ClientStreamRun(c).GetAwaiter().GetResult();
//DuplexStreamRun(c).GetAwaiter().GetResult();
//ServerStreamRun(c).GetAwaiter().GetResult();

//// many run
////UnaryLoadTest(c).GetAwaiter().GetResult();

// HearbeatClient.Test(channel).GetAwaiter().GetResult();
Console.ReadLine();

//// HearbeatClient.Test(channel).GetAwaiter().GetResult();
//Console.ReadLine();

// ChatClient.Run(channel).GetAwaiter().GetResult();
//TestHeartbeat(channel).GetAwaiter().GetResult();
@@ -69,7 +75,12 @@ static void Main(string[] args)
}


static async Task RunTest(IStandard c)
{
var huga1 = await c.NullableCheck(false);
var huga2 = await c.NullableCheck(true);

}


// client, perfect!
@@ -13,6 +13,15 @@ namespace Sandbox.ConsoleServer.Services
{
public class Standard : ServiceBase<IStandard>, IStandard
{
public async UnaryResult<int?> NullableCheck(bool isNull)
{
await Task.Delay(TimeSpan.FromSeconds(5));

if (isNull) return null;
else return 100;
}


public async Task<ClientStreamingResult<int, string>> ClientStreaming1Async()
{
var stream = GetClientStreamingContext<int, string>();
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
@@ -0,0 +1,42 @@
using Grpc.Core;
using Grpc.Core.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sandbox.ConsoleServer2
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Server2:::");

////Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "DEBUG");
////Environment.SetEnvironmentVariable("GRPC_TRACE", "all");

//Environment.SetEnvironmentVariable("SETTINGS_MAX_HEADER_LIST_SIZE", "1000000");

//GrpcEnvironment.SetLogger(new ConsoleLogger());

//var service = MagicOnionEngine.BuildServerServiceDefinition(new MagicOnionOptions(true)
//{
// // MagicOnionLogger = new MagicOnionLogToGrpcLogger(),
// MagicOnionLogger = new MagicOnionLogToGrpcLoggerWithNamedDataDump(),
// GlobalFilters = new MagicOnionFilterAttribute[]
// {
// }
//});

//var server = new global::Grpc.Core.Server
//{
// Services = { service },
// Ports = { new ServerPort(Configuration.GrpcHost, 12346, ServerCredentials.Insecure) }
//};

//server.Start();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("Sandbox.ConsoleServer2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sandbox.ConsoleServer2")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
// その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]

// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
[assembly: Guid("7cf23e57-381b-428d-b44a-d5328a71414b")]

// アセンブリのバージョン情報は次の 4 つの値で構成されています:
//
// メジャー バージョン
// マイナー バージョン
// ビルド番号
// Revision
//
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7CF23E57-381B-428D-B44A-D5328A71414B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Sandbox.ConsoleServer2</RootNamespace>
<AssemblyName>Sandbox.ConsoleServer2</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL">
<HintPath>..\..\packages\Grpc.Core.1.2.2\lib\net45\Grpc.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MagicOnion\MagicOnion.csproj">
<Project>{c79ce0bf-ed4c-47be-822e-e82cf83fc68a}</Project>
<Name>MagicOnion</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Grpc.Core.1.2.2\build\net45\Grpc.Core.targets" Condition="Exists('..\..\packages\Grpc.Core.1.2.2\build\net45\Grpc.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Grpc.Core.1.2.2\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Grpc.Core.1.2.2\build\net45\Grpc.Core.targets'))" />
</Target>
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Grpc" version="1.2.2" targetFramework="net461" />
<package id="Grpc.Core" version="1.2.2" targetFramework="net461" />
<package id="System.Interactive.Async" version="3.1.1" targetFramework="net461" />
</packages>
@@ -6,6 +6,8 @@ namespace Sandbox.ConsoleServer
{
public interface IStandard : IService<IStandard>
{
UnaryResult<int?> NullableCheck(bool isNull);

UnaryResult<int> Unary1(int x, int y);
UnaryResult<int> Unary2(int x, int y);

@@ -55,7 +55,7 @@ public UnaryResult<T> Task
else
{
useBuilder = true;
return new UnaryResult<T>(methodBuilder.Task.Result);
return new UnaryResult<T>(methodBuilder.Task);
}
}
}
@@ -531,22 +531,25 @@ public bool Equals(MethodHandler other)

internal class MethodHandlerResultHelper
{
public static Task SerializeUnaryResult<T>(UnaryResult<T> result, ServiceContext context)
public static async Task SerializeUnaryResult<T>(UnaryResult<T> result, ServiceContext context)
{
if (result.hasRawValue)
{
var bytes = LZ4MessagePackSerializer.Serialize<T>(result.rawValue, context.FormatterResolver);
var value = (result.rawTaskValue != null) ? await result.rawTaskValue.ConfigureAwait(false) : result.rawValue;

var bytes = LZ4MessagePackSerializer.Serialize<T>(value, context.FormatterResolver);
context.Result = bytes;
}
return Task.CompletedTask;
}

public static async Task SerializeTaskUnaryResult<T>(Task<UnaryResult<T>> taskResult, ServiceContext context)
{
var result = await taskResult.ConfigureAwait(false);
if (result.hasRawValue)
{
var bytes = LZ4MessagePackSerializer.Serialize<T>(result.rawValue, context.FormatterResolver);
var value = (result.rawTaskValue != null) ? await result.rawTaskValue.ConfigureAwait(false) : result.rawValue;

var bytes = LZ4MessagePackSerializer.Serialize<T>(value, context.FormatterResolver);
context.Result = bytes;
}
}

0 comments on commit fc8dac3

Please sign in to comment.
You can’t perform that action at this time.