Skip to content

Commit

Permalink
Merge pull request #72 from max-ieremenko/release/1.4.3
Browse files Browse the repository at this point in the history
release/1.4.3
  • Loading branch information
max-ieremenko authored Feb 5, 2022
2 parents a955d97 + 578bd68 commit ee20cb6
Show file tree
Hide file tree
Showing 45 changed files with 1,884 additions and 56 deletions.
26 changes: 26 additions & 0 deletions Build/sdk-test/interface-inheritance-ci-linux.ps1
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 }
}
}
27 changes: 27 additions & 0 deletions Build/sdk-test/interface-inheritance-locally.ps1
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"
}
17 changes: 17 additions & 0 deletions Examples/InterfaceInheritance/Client/Client.csproj
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>
80 changes: 80 additions & 0 deletions Examples/InterfaceInheritance/Client/ClientCalls.cs
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);
}
}
}
10 changes: 10 additions & 0 deletions Examples/InterfaceInheritance/Client/MyGrpcProxies.cs
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
{
}
}
12 changes: 12 additions & 0 deletions Examples/InterfaceInheritance/Contract/Contract.csproj
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 Examples/InterfaceInheritance/Contract/ICalculator{TValue}.cs
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 Examples/InterfaceInheritance/Contract/IDoubleCalculator.cs
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();
}
}
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();
}
}
13 changes: 13 additions & 0 deletions Examples/InterfaceInheritance/Contract/IRemoteService.cs
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();
}
}
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>
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>
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 Examples/InterfaceInheritance/Demo.ServerAspNetCore/Program.cs
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;
}
}
}
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 Examples/InterfaceInheritance/Demo.ServerAspNetCore/Startup.cs
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>();
});
}
}
}
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"
}
}
}
}
Loading

0 comments on commit ee20cb6

Please sign in to comment.