Skip to content

Commit a4adce9

Browse files
committed
Update dotnet tutorials to use 7.0.0
* Specify unix line endings so that `christian-bromann/docusaurus-theme-github-codeblock` formats code blocks correctly * Fix RPC examples
1 parent b2e9a8d commit a4adce9

27 files changed

+549
-394
lines changed

dotnet/.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Auto detect text files and perform LF normalization
5+
*.cs text=auto eol=lf
6+
*.txt text=auto
7+
8+
# Declare files that will always have CRLF line endings on checkout.
9+
*.sln text eol=crlf
10+
*.csproj text eol=crlf
11+
12+
# Custom for Visual Studio
13+
*.cs diff=csharp
14+

dotnet/EmitLog/EmitLog.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
using System.Text;
21
using RabbitMQ.Client;
2+
using System.Text;
33

44
var factory = new ConnectionFactory { HostName = "localhost" };
5-
using var connection = factory.CreateConnection();
6-
using var channel = connection.CreateModel();
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
77

8-
channel.ExchangeDeclare(exchange: "logs", type: ExchangeType.Fanout);
8+
await channel.ExchangeDeclareAsync(exchange: "logs", type: ExchangeType.Fanout);
99

1010
var message = GetMessage(args);
1111
var body = Encoding.UTF8.GetBytes(message);
12-
channel.BasicPublish(exchange: "logs",
13-
routingKey: string.Empty,
14-
basicProperties: null,
15-
body: body);
12+
await channel.BasicPublishAsync(exchange: "logs", routingKey: string.Empty, body: body);
1613
Console.WriteLine($" [x] Sent {message}");
1714

1815
Console.WriteLine(" Press [enter] to exit.");
@@ -21,4 +18,4 @@
2118
static string GetMessage(string[] args)
2219
{
2320
return ((args.Length > 0) ? string.Join(" ", args) : "info: Hello World!");
24-
}
21+
}

dotnet/EmitLog/EmitLog.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
1212
</ItemGroup>
1313

1414
</Project>

dotnet/EmitLogDirect/EmitLogDirect.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
using System.Text;
21
using RabbitMQ.Client;
2+
using System.Text;
33

44
var factory = new ConnectionFactory { HostName = "localhost" };
5-
using var connection = factory.CreateConnection();
6-
using var channel = connection.CreateModel();
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
77

8-
channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct);
8+
await channel.ExchangeDeclareAsync(exchange: "direct_logs", type: ExchangeType.Direct);
99

1010
var severity = (args.Length > 0) ? args[0] : "info";
11-
var message = (args.Length > 1)
12-
? string.Join(" ", args.Skip(1).ToArray())
13-
: "Hello World!";
11+
var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World!";
1412
var body = Encoding.UTF8.GetBytes(message);
15-
channel.BasicPublish(exchange: "direct_logs",
16-
routingKey: severity,
17-
basicProperties: null,
18-
body: body);
13+
await channel.BasicPublishAsync(exchange: "direct_logs", routingKey: severity, body: body);
1914
Console.WriteLine($" [x] Sent '{severity}':'{message}'");
2015

2116
Console.WriteLine(" Press [enter] to exit.");
22-
Console.ReadLine();
17+
Console.ReadLine();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
1212
</ItemGroup>
1313

1414
</Project>

dotnet/EmitLogTopic/EmitLogTopic.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
using System.Text;
21
using RabbitMQ.Client;
2+
using System.Text;
33

44
var factory = new ConnectionFactory { HostName = "localhost" };
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
57

6-
using var connection = factory.CreateConnection();
7-
using var channel = connection.CreateModel();
8-
9-
channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic);
8+
await channel.ExchangeDeclareAsync(exchange: "topic_logs", type: ExchangeType.Topic);
109

1110
var routingKey = (args.Length > 0) ? args[0] : "anonymous.info";
12-
var message = (args.Length > 1)
13-
? string.Join(" ", args.Skip(1).ToArray())
14-
: "Hello World!";
11+
var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World!";
1512
var body = Encoding.UTF8.GetBytes(message);
16-
channel.BasicPublish(exchange: "topic_logs",
17-
routingKey: routingKey,
18-
basicProperties: null,
19-
body: body);
20-
Console.WriteLine($" [x] Sent '{routingKey}':'{message}'");
13+
await channel.BasicPublishAsync(exchange: "topic_logs", routingKey: routingKey, body: body);
14+
Console.WriteLine($" [x] Sent '{routingKey}':'{message}'");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
1212
</ItemGroup>
1313

1414
</Project>

dotnet/NewTask/NewTask.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
using System.Text;
21
using RabbitMQ.Client;
2+
using System.Text;
33

44
var factory = new ConnectionFactory { HostName = "localhost" };
5-
using var connection = factory.CreateConnection();
6-
using var channel = connection.CreateModel();
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
77

8-
channel.QueueDeclare(queue: "task_queue",
9-
durable: true,
10-
exclusive: false,
11-
autoDelete: false,
12-
arguments: null);
8+
await channel.QueueDeclareAsync(queue: "task_queue", durable: true, exclusive: false,
9+
autoDelete: false, arguments: null);
1310

1411
var message = GetMessage(args);
1512
var body = Encoding.UTF8.GetBytes(message);
1613

17-
var properties = channel.CreateBasicProperties();
18-
properties.Persistent = true;
14+
var properties = new BasicProperties
15+
{
16+
Persistent = true
17+
};
1918

20-
channel.BasicPublish(exchange: string.Empty,
21-
routingKey: "task_queue",
22-
basicProperties: properties,
23-
body: body);
19+
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "task_queue", mandatory: true,
20+
basicProperties: properties, body: body);
2421
Console.WriteLine($" [x] Sent {message}");
2522

26-
Console.WriteLine(" Press [enter] to exit.");
27-
Console.ReadLine();
28-
2923
static string GetMessage(string[] args)
3024
{
3125
return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!");
32-
}
26+
}

dotnet/NewTask/NewTask.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
1212
</ItemGroup>
1313

1414
</Project>

0 commit comments

Comments
 (0)