-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from max-ieremenko/release/1.4.3
release/1.4.3
- Loading branch information
Showing
45 changed files
with
1,884 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
$Settings | ||
) | ||
|
||
Enter-Build { | ||
$exampleDir = Join-Path $Settings.examples "InterfaceInheritance" | ||
} | ||
|
||
task Default Build, Run | ||
|
||
task Build { | ||
exec { dotnet restore $exampleDir } | ||
exec { dotnet build --configuration Release $exampleDir } | ||
} | ||
|
||
task Run { | ||
$apps = @("Demo.ServerAspNetCore", "Demo.ServerSelfHost") | ||
foreach ($app in $apps) { | ||
Write-Output "=== exec $app ===" | ||
|
||
$entryPoint = Join-Path $exampleDir "$app/bin/Release/net6.0/$app.dll" | ||
exec { dotnet $entryPoint } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
$Settings | ||
) | ||
|
||
task Default Clean, Build, Run | ||
|
||
task Clean { | ||
Remove-DirectoryRecurse -Path (Join-Path $settings.examples "InterfaceInheritance") -Filters "bin", "obj" | ||
} | ||
|
||
task Build { | ||
Build-ExampleInContainer ` | ||
-Sources $settings.sources ` | ||
-Examples $settings.examples ` | ||
-Packages $settings.buildOut ` | ||
-ExampleName "InterfaceInheritance" ` | ||
-DotNet "net6.0" | ||
} | ||
|
||
task Run { | ||
Invoke-ExampleInContainer ` | ||
-Example (Join-Path $settings.examples "InterfaceInheritance") ` | ||
-DotNet "net6.0" ` | ||
-Apps "Demo.ServerAspNetCore", "Demo.ServerSelfHost" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Grpc.Core" Version="$(GrpcCoreVersion)" /> | ||
<PackageReference Include="ServiceModel.Grpc" Version="$(ServiceModelGrpcVersion)" /> | ||
<PackageReference Include="ServiceModel.Grpc.DesignTime" Version="$(ServiceModelGrpcVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Contract\Contract.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Contract; | ||
using Grpc.Core; | ||
using ServiceModel.Grpc.Client; | ||
|
||
namespace Client | ||
{ | ||
public sealed class ClientCalls | ||
{ | ||
private readonly IClientFactory _clientFactory; | ||
private readonly Channel _channel; | ||
|
||
public ClientCalls(int serverPort) | ||
{ | ||
_clientFactory = new ClientFactory(); | ||
|
||
// register generated IGenericCalculator<int> proxy, see MyGrpcProxies | ||
_clientFactory.AddGenericCalculatorInt32Client(); | ||
|
||
_channel = new Channel("localhost", serverPort, ChannelCredentials.Insecure); | ||
} | ||
|
||
public async Task InvokeGenericCalculator() | ||
{ | ||
// create instance of GenericCalculatorInt32Client, see MyGrpcProxies | ||
var proxy = _clientFactory.CreateClient<IGenericCalculator<int>>(_channel); | ||
|
||
// POST /IGenericCalculator-Int32/Touch | ||
Console.WriteLine("Invoke Touch"); | ||
var touchResponse = proxy.Touch(); | ||
Console.WriteLine(" {0}", touchResponse); | ||
|
||
// POST /IGenericCalculator-Int32/GetRandomValue | ||
Console.WriteLine("Invoke GetRandomValue"); | ||
var x = await proxy.GetRandomValue(); | ||
var y = await proxy.GetRandomValue(); | ||
Console.WriteLine(" X = {0}", x); | ||
Console.WriteLine(" Y = {0}", y); | ||
|
||
// POST /IGenericCalculator-Int32/Sum | ||
Console.WriteLine("Invoke Sum"); | ||
var sumResponse = await proxy.Sum(x, y); | ||
Console.WriteLine(" {0} + {1} = {2}", x, y, sumResponse); | ||
|
||
// POST /IGenericCalculator-Int32/Multiply | ||
Console.WriteLine("Invoke Multiply"); | ||
var multiplyResponse = await proxy.Multiply(x, y); | ||
Console.WriteLine(" {0} * {1} = {2}", x, y, multiplyResponse); | ||
} | ||
|
||
public async Task InvokeDoubleCalculator() | ||
{ | ||
// proxy will be generated on-fly | ||
var proxy = _clientFactory.CreateClient<IDoubleCalculator>(_channel); | ||
|
||
// POST /IDoubleCalculator/Touch | ||
Console.WriteLine("Invoke Touch"); | ||
var touchResponse = proxy.Touch(); | ||
Console.WriteLine(" {0}", touchResponse); | ||
|
||
// POST /IDoubleCalculator/GetRandomValue | ||
Console.WriteLine("Invoke GetRandomValue"); | ||
var x = await proxy.GetRandomValue(); | ||
var y = await proxy.GetRandomValue(); | ||
Console.WriteLine(" X = {0}", x); | ||
Console.WriteLine(" Y = {0}", y); | ||
|
||
// POST /IDoubleCalculator/Sum | ||
Console.WriteLine("Invoke Sum"); | ||
var sumResponse = await proxy.Sum(x, y); | ||
Console.WriteLine(" {0} + {1} = {2}", x, y, sumResponse); | ||
|
||
// POST /IDoubleCalculator/Multiply | ||
Console.WriteLine("Invoke Multiply"); | ||
var multiplyResponse = await proxy.Multiply(x, y); | ||
Console.WriteLine(" {0} * {1} = {2}", x, y, multiplyResponse); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Contract; | ||
using ServiceModel.Grpc.DesignTime; | ||
|
||
namespace Client | ||
{ | ||
[ImportGrpcService(typeof(IGenericCalculator<int>))] // configure ServiceModel.Grpc.DesignTime to generate a source code for IGenericCalculator<int> client proxy | ||
internal static partial class MyGrpcProxies | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" /> | ||
<PackageReference Include="ServiceModel.Grpc" Version="$(ServiceModelGrpcVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
17 changes: 17 additions & 0 deletions
17
Examples/InterfaceInheritance/Contract/ICalculator{TValue}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.ServiceModel; | ||
using System.Threading.Tasks; | ||
|
||
// ReSharper disable OperationContractWithoutServiceContract | ||
|
||
namespace Contract | ||
{ | ||
// remove [ServiceContract] | ||
public interface ICalculator<TValue> : IRemoteService | ||
{ | ||
[OperationContract] | ||
Task<TValue> Sum(TValue x, TValue y); | ||
|
||
[OperationContract] | ||
ValueTask<TValue> Multiply(TValue x, TValue y); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Examples/InterfaceInheritance/Contract/IDoubleCalculator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ServiceModel; | ||
using System.Threading.Tasks; | ||
|
||
namespace Contract | ||
{ | ||
[ServiceContract] | ||
public interface IDoubleCalculator : ICalculator<double> | ||
{ | ||
[OperationContract] | ||
ValueTask<double> GetRandomValue(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Examples/InterfaceInheritance/Contract/IGenericCalculator{TValue}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ServiceModel; | ||
using System.Threading.Tasks; | ||
|
||
namespace Contract | ||
{ | ||
[ServiceContract] | ||
public interface IGenericCalculator<TValue> : ICalculator<TValue> | ||
{ | ||
[OperationContract] | ||
ValueTask<TValue> GetRandomValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ReSharper disable OperationContractWithoutServiceContract | ||
|
||
using System.ServiceModel; | ||
|
||
namespace Contract | ||
{ | ||
// remove [ServiceContract] | ||
public interface IRemoteService | ||
{ | ||
[OperationContract] | ||
string Touch(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Examples/InterfaceInheritance/Demo.ServerAspNetCore/Demo.ServerAspNetCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ServiceModel.Grpc.AspNetCore" Version="$(ServiceModelGrpcVersion)" /> | ||
<PackageReference Include="ServiceModel.Grpc.DesignTime" Version="$(ServiceModelGrpcVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Client\Client.csproj" /> | ||
<ProjectReference Include="..\Service\Service.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
9 changes: 9 additions & 0 deletions
9
Examples/InterfaceInheritance/Demo.ServerAspNetCore/Demo.ServerAspNetCore.csproj.user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ActiveDebugProfile>ServerAspNetCore</ActiveDebugProfile> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
</Project> |
10 changes: 10 additions & 0 deletions
10
Examples/InterfaceInheritance/Demo.ServerAspNetCore/MyGrpcServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Service; | ||
using ServiceModel.Grpc.DesignTime; | ||
|
||
namespace Demo.ServerAspNetCore | ||
{ | ||
[ExportGrpcService(typeof(GenericCalculator<int>), GenerateAspNetExtensions = true)] // configure ServiceModel.Grpc.DesignTime to generate a source code for IGenericCalculator<int> endpoint | ||
internal static partial class MyGrpcServices | ||
{ | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Examples/InterfaceInheritance/Demo.ServerAspNetCore/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Client; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Demo.ServerAspNetCore | ||
{ | ||
public static class Program | ||
{ | ||
public static async Task Main() | ||
{ | ||
using (var host = await StartWebHost()) | ||
{ | ||
var calls = new ClientCalls(5000); | ||
|
||
await calls.InvokeGenericCalculator(); | ||
await calls.InvokeDoubleCalculator(); | ||
|
||
if (Debugger.IsAttached) | ||
{ | ||
Console.WriteLine("..."); | ||
Console.ReadLine(); | ||
} | ||
|
||
await host.StopAsync(); | ||
} | ||
} | ||
|
||
private static async Task<IHost> StartWebHost() | ||
{ | ||
var host = Host | ||
.CreateDefaultBuilder() | ||
.ConfigureAppConfiguration(builder => | ||
{ | ||
builder.AddJsonFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"), false, false); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}) | ||
.Build(); | ||
|
||
await host.StartAsync(); | ||
return host; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Examples/InterfaceInheritance/Demo.ServerAspNetCore/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"profiles": { | ||
"ServerAspNetCore": { | ||
"commandName": "Project", | ||
"launchBrowser": false, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Examples/InterfaceInheritance/Demo.ServerAspNetCore/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Service; | ||
|
||
namespace Demo.ServerAspNetCore | ||
{ | ||
internal sealed class Startup | ||
{ | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddServiceModelGrpc(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
// register generated GenericCalculatorInt32Endpoint, see MyGrpcServices | ||
endpoints.MapGenericCalculatorInt32(); | ||
|
||
// endpoint will be generated on-fly | ||
endpoints.MapGrpcService<DoubleCalculator>(); | ||
}); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Examples/InterfaceInheritance/Demo.ServerAspNetCore/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Kestrel": { | ||
"Endpoints": { | ||
"Http2": { | ||
"Url": "http://*:5000", | ||
"Protocols": "Http2" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.