Skip to content

Commit 4ec6264

Browse files
authored
Merge branch 'main' into auth
2 parents db6a714 + 58fd328 commit 4ec6264

23 files changed

+987
-667
lines changed

.ci/windows/versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"erlang": "27.1.2",
3-
"rabbitmq": "4.0.4"
2+
"erlang": "27.2",
3+
"rabbitmq": "4.0.5"
44
}

.github/workflows/wf_build-and-test.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
path: |
2424
~/.nuget/packages
2525
~/AppData/Local/NuGet/v3-cache
26-
key: ${{ runner.os }}-v0-nuget-${{ hashFiles('**/*.csproj') }}
26+
key: ${{ runner.os }}-v0-nuget-${{ hashFiles('**/*.csproj','Directory.Packages.props') }}
2727
restore-keys: |
2828
${{ runner.os }}-v0-nuget-
2929
- name: Build (Debug)
@@ -55,6 +55,14 @@ jobs:
5555
runs-on: ubuntu-latest
5656
steps:
5757
- uses: actions/checkout@v4
58+
- uses: actions/cache@v4
59+
with:
60+
path: |
61+
~/.nuget/packages
62+
~/.local/share/NuGet/v3-cache
63+
key: ${{ runner.os }}-v0-nuget-${{ hashFiles('**/*.csproj','Directory.Packages.props') }}
64+
restore-keys: |
65+
${{ runner.os }}-v0-nuget-
5866
- name: Build (Debug)
5967
run: dotnet build ${{ github.workspace }}/Build.csproj
6068
- name: Verify

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<IncludeSymbols>true</IncludeSymbols>
1515
<IsPackable>false</IsPackable>
1616
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
17-
<NoWarn>$(NoWarn);CS1591</NoWarn>
1817
<PackageId>$(AssemblyName)</PackageId>
1918
<PackageProjectUrl>https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client</PackageProjectUrl>
2019
<PackageReleaseNotes>https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/releases/latest</PackageReleaseNotes>

RabbitMQ.AMQP.Client/ByteCapacity.cs

Lines changed: 105 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,114 @@
77

88
namespace RabbitMQ.AMQP.Client
99
{
10-
public partial class ByteCapacity : IEquatable<ByteCapacity>
10+
/// <summary>
11+
/// Class for specifying a binary size, with units
12+
/// </summary>
13+
public class ByteCapacity : IEquatable<ByteCapacity>
1114
{
15+
private const int KilobytesMultiplier = 1000;
16+
private const int MegabytesMultiplier = 1000 * 1000;
17+
private const int GigabytesMultiplier = 1000 * 1000 * 1000;
18+
private const long TerabytesMultiplier = 1000L * 1000L * 1000L * 1000L;
19+
20+
private static readonly Regex s_sizeRegex = new(@"^(\d+)([kKmMgGtTpP]?[bB]?)$", RegexOptions.Compiled);
21+
1222
private readonly long _bytes;
13-
private string _input;
1423

15-
private ByteCapacity(long bytes, string input)
24+
/// <summary>
25+
///
26+
/// </summary>
27+
/// <param name="bytes"></param>
28+
public ByteCapacity(long bytes)
1629
{
17-
_input = input;
1830
_bytes = bytes;
1931
}
2032

21-
private ByteCapacity(long bytes) : this(bytes, bytes.ToString())
22-
{
23-
}
24-
25-
private const int KilobytesMultiplier = 1000;
26-
private const int MegabytesMultiplier = 1000 * 1000;
27-
private const int GigabytesMultiplier = 1000 * 1000 * 1000;
28-
private const long TerabytesMultiplier = 1000L * 1000L * 1000L * 1000L;
29-
33+
/// <summary>
34+
/// Specify an amount in bytes
35+
/// </summary>
36+
/// <param name="bytes">The size, in bytes</param>
37+
/// <returns><see cref="ByteCapacity"/></returns>
3038
public static ByteCapacity B(long bytes)
3139
{
3240
return new ByteCapacity(bytes);
3341
}
3442

35-
public static ByteCapacity Kb(long megabytes)
43+
/// <summary>
44+
/// Specify an amount, in kilobytes
45+
/// </summary>
46+
/// <param name="kilobytes">The size, in kilobytes</param>
47+
/// <returns><see cref="ByteCapacity"/></returns>
48+
public static ByteCapacity Kb(long kilobytes)
3649
{
37-
return new ByteCapacity(megabytes * KilobytesMultiplier);
50+
return new ByteCapacity(kilobytes * KilobytesMultiplier);
3851
}
3952

53+
/// <summary>
54+
/// Specify an amount, in megabytes
55+
/// </summary>
56+
/// <param name="megabytes">The size, in megabytes</param>
57+
/// <returns><see cref="ByteCapacity"/></returns>
4058
public static ByteCapacity Mb(long megabytes)
4159
{
4260
return new ByteCapacity(megabytes * MegabytesMultiplier);
4361
}
4462

63+
/// <summary>
64+
/// Specify an amount, in gigabytes
65+
/// </summary>
66+
/// <param name="gigabytes">The size, in gigabytes</param>
67+
/// <returns><see cref="ByteCapacity"/></returns>
4568
public static ByteCapacity Gb(long gigabytes)
4669
{
4770
return new ByteCapacity(gigabytes * GigabytesMultiplier);
4871
}
4972

73+
/// <summary>
74+
/// Specify an amount, in terabytes
75+
/// </summary>
76+
/// <param name="terabytes">The size, in terabytes</param>
77+
/// <returns><see cref="ByteCapacity"/></returns>
5078
public static ByteCapacity Tb(long terabytes)
5179
{
5280
return new ByteCapacity(terabytes * TerabytesMultiplier);
5381
}
5482

55-
private static readonly Regex s_sizeRegex = new Regex(@"^(\d+)([kKmMgGtTpP]?[bB]?)$", RegexOptions.Compiled);
83+
/// <summary>
84+
/// Explicitly convert a string into a <see cref="ByteCapacity"/>
85+
/// </summary>
86+
/// <param name="value">The value, as string</param>
87+
/// <returns><see cref="ByteCapacity"/></returns>
88+
public static explicit operator ByteCapacity(string value)
89+
{
90+
return Parse(value);
91+
}
92+
93+
/// <summary>
94+
/// Cast a <see cref="ByteCapacity"/> into a <see cref="long"/>
95+
/// </summary>
96+
/// <param name="value">The value</param>
97+
/// <returns>The total number of bytes.</returns>
98+
public static implicit operator long(ByteCapacity value)
99+
{
100+
return value._bytes;
101+
}
56102

57-
public static ByteCapacity From(string value)
103+
/// <summary>
104+
/// Parse a string into a <see cref="ByteCapacity"/>
105+
/// </summary>
106+
/// <param name="value">The value, as string</param>
107+
/// <returns><see cref="ByteCapacity"/></returns>
108+
public static ByteCapacity Parse(string value)
58109
{
59110
Match match = s_sizeRegex.Match(value);
60111
if (!match.Success)
61112
{
62113
throw new ArgumentException("Invalid capacity size format.", nameof(value));
63114
}
64115

65-
var size = long.Parse(match.Groups[1].Value);
66-
var unit = match.Groups[2].Value.ToLower();
116+
long size = long.Parse(match.Groups[1].Value);
117+
string unit = match.Groups[2].Value.ToLowerInvariant();
67118

68119
return unit switch
69120
{
@@ -75,24 +126,53 @@ public static ByteCapacity From(string value)
75126
};
76127
}
77128

78-
public long ToBytes()
129+
/// <summary>
130+
/// Returns a value indicating whether this instance is equal to a specified <see cref="ByteCapacity"/> value.
131+
/// </summary>
132+
/// <param name="obj">An object to compare with this instance.</param>
133+
/// <returns>true if obj is an instance of <see cref="ByteCapacity"/>and equals the value of this instance; otherwise, false.</returns>
134+
public override bool Equals(object? obj)
79135
{
80-
return _bytes;
136+
if (obj is null)
137+
{
138+
return false;
139+
}
140+
141+
if (ReferenceEquals(this, obj))
142+
{
143+
return true;
144+
}
145+
146+
return Equals(obj as ByteCapacity);
81147
}
82148

83-
public bool Equals(ByteCapacity? other)
149+
/// <summary>
150+
/// Returns a value indicating whether this instance is equal to a specified <see cref="ByteCapacity"/> value.
151+
/// </summary>
152+
/// <param name="obj">An object to compare with this instance.</param>
153+
/// <returns>true if obj has the same value as this instance; otherwise, false.</returns>
154+
public bool Equals(ByteCapacity? obj)
84155
{
85-
if (ReferenceEquals(null, other))
156+
if (obj is null)
86157
{
87158
return false;
88159
}
89160

90-
if (ReferenceEquals(this, other))
161+
if (ReferenceEquals(this, obj))
91162
{
92163
return true;
93164
}
94165

95-
return _bytes == other._bytes;
166+
return _bytes == obj._bytes;
167+
}
168+
169+
/// <summary>
170+
/// Returns the hash code for this instance.
171+
/// </summary>
172+
/// <returns>A 32-bit signed integer hash code.</returns>
173+
public override int GetHashCode()
174+
{
175+
return _bytes.GetHashCode();
96176
}
97177
}
98178
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This source code is dual-licensed under the Apache License, version 2.0,
2+
// and the Mozilla Public License, version 2.0.
3+
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
5+
using System;
6+
7+
namespace RabbitMQ.AMQP.Client
8+
{
9+
/// <summary>
10+
/// Exception related to <see cref="IConnection"/>
11+
/// </summary>
12+
public class ConnectionException : Exception
13+
{
14+
/// <summary>
15+
/// Create a <see cref="ConnectionException"/> with the specified message.
16+
/// </summary>
17+
public ConnectionException(string message) : base(message)
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Create a <see cref="ConnectionException"/> with the specified message and inner <see cref="Exception"/>.
23+
/// </summary>
24+
public ConnectionException(string message, Exception innerException) : base(message, innerException)
25+
{
26+
}
27+
}
28+
}

RabbitMQ.AMQP.Client/IConnection.cs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,63 @@
22
// and the Mozilla Public License, version 2.0.
33
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
44

5-
using System;
65
using System.Collections.Generic;
76

87
namespace RabbitMQ.AMQP.Client
98
{
10-
public class ConnectionException : Exception
11-
{
12-
public ConnectionException(string message) : base(message)
13-
{
14-
}
15-
16-
public ConnectionException(string message, Exception innerException) : base(message, innerException)
17-
{
18-
}
19-
}
20-
219
public interface IConnection : ILifeCycle
2210
{
11+
/// <summary>
12+
/// The <see cref="IManagement"/> instance for this connection.
13+
/// </summary>
14+
/// <returns><see cref="IManagement"/> instance for this connection.</returns>
2315
IManagement Management();
2416

17+
/// <summary>
18+
/// Create an <see cref="IPublisherBuilder"/> instance for this connection.
19+
/// </summary>
20+
/// <returns><see cref="IPublisherBuilder"/> instance for this connection.</returns>
2521
IPublisherBuilder PublisherBuilder();
2622

23+
/// <summary>
24+
/// Create an <see cref="IConsumerBuilder"/> instance for this connection.
25+
/// </summary>
26+
/// <returns><see cref="IConsumerBuilder"/> instance for this connection.</returns>
2727
IConsumerBuilder ConsumerBuilder();
2828

29+
/// <summary>
30+
/// Create an <see cref="IRpcServerBuilder"/> instance for this connection.
31+
/// </summary>
32+
/// <returns><see cref="IRpcServerBuilder"/> instance for this connection.</returns>
2933
IRpcServerBuilder RpcServerBuilder();
3034

35+
/// <summary>
36+
/// Create an <see cref="IRpcClientBuilder"/> instance for this connection.
37+
/// </summary>
38+
/// <returns><see cref="IRpcClientBuilder"/> instance for this connection.</returns>
3139
IRpcClientBuilder RpcClientBuilder();
3240

41+
/// <summary>
42+
/// Get the properties for this connection.
43+
/// </summary>
44+
/// <returns><see cref="IReadOnlyDictionary{TKey, TValue}"/> of connection properties.</returns>
3345
public IReadOnlyDictionary<string, object> Properties { get; }
3446

47+
/// <summary>
48+
/// Get the <see cref="IPublisher"/> instances associated with this connection.
49+
/// </summary>
50+
/// <returns><see cref="IEnumerable{T}"/> of <see cref="IPublisher"/> instances.</returns>
3551
public IEnumerable<IPublisher> Publishers { get; }
3652

53+
/// <summary>
54+
/// Get the <see cref="IConsumer"/> instances associated with this connection.
55+
/// </summary>
56+
/// <returns><see cref="IEnumerable{T}"/> of <see cref="IConsumer"/> instances.</returns>
3757
public IEnumerable<IConsumer> Consumers { get; }
3858

59+
/// <summary>
60+
/// Get or set the Connection ID. Used by <see cref="IEnvironment"/>
61+
/// </summary>
3962
public long Id { get; set; }
4063
}
4164
}

0 commit comments

Comments
 (0)