Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// Copyright (c) ZeroC, Inc.

using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Compressor.Examples;

public static class CompressorInterceptorExamples
{
public static async Task UseCompressor()
{
#region UseCompressor
// Create a connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA));

// Create an invocation pipeline and install the compressor interceptor.
Pipeline pipeline = new Pipeline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@

using GreeterExample;
using IceRpc.Slice;
using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Telemetry.Examples;
namespace IceRpc.Compressor.Examples;

public static class CompressorMiddlewareExamples
{
public static async Task UseCompressor()
{
#region UseCompressor
// Create a connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));

// Add the compressor middleware to the dispatch pipeline.
Router router = new Router()
.UseCompressor(CompressionFormat.Brotli)
.Map(new Chatbot());

await using var server = new Server(router);
// The default transport (QUIC) requires a server certificate. CreateServerAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable);

await using var server = new Server(
router,
serverAuthenticationOptions: CreateServerAuthenticationOptions(serverCertificate));
server.Listen();
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="../Chatbot.cs" />
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<SliceFile Include="../Greeter.slice" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="IceRpc" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright (c) ZeroC, Inc.

using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Deadline.Examples;

// This class provides code snippets used by the doc-comments of the deadline interceptor.
Expand All @@ -8,7 +11,13 @@ public static class DeadlineInterceptorExamples
public static async Task UseDeadline()
{
#region UseDeadline
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA));

// Create an invocation pipeline, that uses the deadline interceptor.
Pipeline pipeline = new Pipeline()
Expand All @@ -20,7 +29,13 @@ public static async Task UseDeadline()
public static async Task UseDeadlineWithDefaultTimeout()
{
#region UseDeadlineWithDefaultTimeout
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA));

// Create an invocation pipeline, that uses the deadline interceptor and has a default
// timeout of 500 ms.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) ZeroC, Inc.

using GreeterExample;
using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Deadline.Examples;

Expand All @@ -15,7 +17,16 @@ public static async Task UseDeadline()
.UseDeadline()
.Map(new Chatbot());

await using var server = new Server(router);
// The default transport (QUIC) requires a server certificate. CreateServerAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable);

await using var server = new Server(
router,
serverAuthenticationOptions: CreateServerAuthenticationOptions(serverCertificate));
server.Listen();
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="../Chatbot.cs" />
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<SliceFile Include="../Greeter.slice" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="IceRpc" />
Expand Down
1 change: 1 addition & 0 deletions docfx/examples/IceRpc.Examples/IceRpc.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<OutputDir>generated/protoc</OutputDir>
</ProtoFile>
<Compile Include="../Chatbot.cs" />
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="IceRpc" />
Expand Down
11 changes: 9 additions & 2 deletions docfx/examples/IceRpc.Examples/PipelineExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

using GreeterExample;
using Microsoft.Extensions.Logging;
using System.Security.Cryptography.X509Certificates;
using VisitorCenter;
using static Program;

namespace IceRpc.Examples;

Expand All @@ -17,8 +19,13 @@ public static async Task CreatingAndUsingThePipeline()
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Information));

// Create a client connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA));

// Create an invocation pipeline and install the logger interceptor.
Pipeline pipeline = new Pipeline()
Expand Down
24 changes: 22 additions & 2 deletions docfx/examples/IceRpc.Examples/RouterExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using GreeterExample;
using IceRpc.Slice;
using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Examples;

Expand All @@ -16,8 +18,17 @@ public static async Task CreatingAndUsingTheRouterWithMiddleware()
.UseCompressor(CompressionFormat.Brotli)
.Map(new Chatbot());

// The default transport (QUIC) requires a server certificate. CreateServerAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable);

// Create a server that uses the router as its dispatch pipeline.
await using var server = new Server(router);
await using var server = new Server(
router,
serverAuthenticationOptions: CreateServerAuthenticationOptions(serverCertificate));
server.Listen();
#endregion
}
Expand All @@ -38,8 +49,17 @@ public static async Task CreatingAndUsingTheRouterWithAnInlineDispatcher()
}))
.Map(new Chatbot());

// The default transport (QUIC) requires a server certificate. CreateServerAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable);

// Create a server that uses the router as its dispatcher.
await using var server = new Server(router);
await using var server = new Server(
router,
serverAuthenticationOptions: CreateServerAuthenticationOptions(serverCertificate));
server.Listen();
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="../Chatbot.cs" />
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<SliceFile Include="../Greeter.slice" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) ZeroC, Inc.

using Microsoft.Extensions.Logging;
using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Logger.Examples;

Expand All @@ -16,9 +18,14 @@ public static async Task UseLogger()
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Debug));

// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

// Create a client connection that logs messages to a logger with category IceRpc.ClientConnection.
await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA),
logger: loggerFactory.CreateLogger<ClientConnection>());

// Create an invocation pipeline and install the logger interceptor. This interceptor logs invocations using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="../Chatbot.cs" />
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<SliceFile Include="../Greeter.slice" />
<PackageReference Include="IceRpc" />
<PackageReference Include="IceRpc.Slice" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright (c) ZeroC, Inc.

using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Metrics.Examples;

// This class provides code snippets used by the doc-comments of the metrics interceptor.
Expand All @@ -8,8 +11,13 @@ public static class MetricsInterceptorExamples
public static async Task UseMetrics()
{
#region UseMetrics
// Create a client connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA));

// Create an invocation pipeline and install the metrics interceptor.
Pipeline pipeline = new Pipeline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using GreeterExample;
using IceRpc.Slice;
using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.Metrics.Examples;

Expand All @@ -16,7 +18,16 @@ public static async Task UseMetrics()
.UseMetrics()
.Map(new Chatbot());

await using var server = new Server(router);
// The default transport (QUIC) requires a server certificate. CreateServerAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable);

await using var server = new Server(
router,
serverAuthenticationOptions: CreateServerAuthenticationOptions(serverCertificate));
server.Listen();
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<SliceFile Include="../Greeter.slice">
<OutputDir>generated/slicec</OutputDir>
</SliceFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using GreeterExample;
using IceRpc.Features;
using System.Collections.Immutable;
using System.Security.Cryptography.X509Certificates;
using VisitorCenter;
using static Program;

namespace IceRpc.RequestContext.Examples;

Expand All @@ -13,8 +15,13 @@ public static class RequestContextInterceptorExamples
public static async Task UseRequestContext()
{
#region UseRequestContext
// Create a client connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// The server uses a test certificate, so we trust its root CA. CreateClientAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: CreateClientAuthenticationOptions(rootCA));

// Add the request context interceptor to the invocation pipeline.
Pipeline pipeline = new Pipeline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

using GreeterExample;
using IceRpc.Slice;
using System.Security.Cryptography.X509Certificates;
using static Program;

namespace IceRpc.RequestContext.Examples;

// This class provides code snippets used by the doc-comments of the request context middleware.
public static class MetricsMiddlewareExamples
public static class RequestContextMiddlewareExamples
{
public static async Task UseRequestContext()
{
Expand All @@ -16,7 +18,16 @@ public static async Task UseRequestContext()
.UseRequestContext()
.Map(new Chatbot());

await using var server = new Server(router);
// The default transport (QUIC) requires a server certificate. CreateServerAuthenticationOptions
// is a helper from examples/common/Program.Authentication.cs in the icerpc-csharp repo.
using var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable);

await using var server = new Server(
router,
serverAuthenticationOptions: CreateServerAuthenticationOptions(serverCertificate));
server.Listen();
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="../../../examples/common/Program.Authentication.cs" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="IceRpc" />
<PackageReference Include="IceRpc.Slice" />
Expand Down
Loading