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
11 changes: 9 additions & 2 deletions ClientProxyBase/ClientProxyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
case HttpStatusCode.NotFound:
throw new KeyNotFoundException(content);
case HttpStatusCode.InternalServerError:
throw new Exception("An internal error has occurred");
throw new ClientHttpException("An internal error has occurred");
default:
throw new Exception($"An internal error has occurred ({responseMessage.StatusCode})");
throw new ClientHttpException($"An internal error has occurred ({responseMessage.StatusCode})");
}
}

Expand Down Expand Up @@ -103,4 +103,11 @@
}

#endregion
}

public class ClientHttpException : Exception {
public ClientHttpException(string? message,

Check warning on line 109 in ClientProxyBase/ClientProxyBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests - Windows

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 109 in ClientProxyBase/ClientProxyBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests - Windows

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 109 in ClientProxyBase/ClientProxyBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests - Linux

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 109 in ClientProxyBase/ClientProxyBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests - Linux

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
Exception? innerException = null) : base(message, innerException) {

Check warning on line 110 in ClientProxyBase/ClientProxyBase.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

ClientProxyBase/ClientProxyBase.cs#L110

Use the overloading mechanism instead of the optional parameters.

}
}
16 changes: 8 additions & 8 deletions Shared.EventStore.Tests/ApplicationBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_WorkerListReturn
eventHandlerResolvers.Add("Main", deh.Object);
eventHandlerResolvers.Add("Domain", deh.Object);
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(3);
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_NoneEnabled_Work
eventHandlerResolvers.Add("Ordered", deh.Object);
eventHandlerResolvers.Add("Main", deh.Object);
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(0);
}
Expand All @@ -107,7 +107,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_NoWorkers_Worker
String eventStoreConnectionString = "esdb://192.168.0.133:2113?tls=true&tlsVerifyCert=false";
Dictionary<String, IDomainEventHandlerResolver> eventHandlerResolvers = new();
Action<TraceEventType, String, String> traceHandler = null;
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(0);
}
Expand All @@ -133,7 +133,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_OrderedOnlyWorke
Dictionary<String, IDomainEventHandlerResolver> eventHandlerResolvers = new();
eventHandlerResolvers.Add("Ordered", deh.Object);
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(1);
result.Single().InflightMessages.ShouldBe(1);
Expand All @@ -158,7 +158,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_OrderedOnlyWorke
String eventStoreConnectionString = "esdb://192.168.0.133:2113?tls=true&tlsVerifyCert=false";
Dictionary<String, IDomainEventHandlerResolver> eventHandlerResolvers = new();
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(0);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_MainOnlyWorkers_
Dictionary<String, IDomainEventHandlerResolver> eventHandlerResolvers = new();
eventHandlerResolvers.Add("Main", deh.Object);
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(1);
result.Single().InflightMessages.ShouldBe(500);
Expand All @@ -213,7 +213,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_MainOnlyWorkers_
String eventStoreConnectionString = "esdb://192.168.0.133:2113?tls=true&tlsVerifyCert=false";
Dictionary<String, IDomainEventHandlerResolver> eventHandlerResolvers = new();
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(0);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public void ApplicationBuilderExtensions_ConfigureSubscriptions_MainOnlyWorkers_
Dictionary<String, IDomainEventHandlerResolver> eventHandlerResolvers = new();
eventHandlerResolvers.Add("Main", deh.Object);
Action<TraceEventType, String, String> traceHandler = (et, type, msg) => TestOutputHelper.WriteLine(msg);
var result = IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository.Object, config,
var result = IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository.Object, config,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
result.Count.ShouldBe(2);
}
Expand Down
80 changes: 12 additions & 68 deletions Shared.EventStore/Aggregate/AggregateVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ public struct AggregateVersion : IComparable
{
#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="AggregateVersion" /> class.
/// </summary>
/// <param name="value">The Value.</param>
[Newtonsoft.Json.JsonConstructor]
private AggregateVersion(Int64 value) : this()
{
Expand All @@ -23,63 +19,34 @@ private AggregateVersion(Int64 value) : this()

#region Properties

/// <summary>
/// Gets the Value.
/// </summary>
/// <value>The value.</value>
[JsonProperty(Order = 1)]
public Int64 Value { get; private set; }

#endregion

#region Methods

/// <summary>
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
/// </summary>
/// <param name="obj">An object to compare with this instance.</param>
/// <returns>A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes <paramref name="obj" /> in the sort order. Zero This instance occurs in the same position in the sort order as <paramref name="obj" />. Greater than zero This instance follows <paramref name="obj" /> in the sort order.</returns>
/// <exception cref="System.NotImplementedException"></exception>
public Int32 CompareTo(Object obj)
{
AggregateVersion otherVersion = (AggregateVersion)obj;
return this.Value.CompareTo(otherVersion.Value);
}

/// <summary>
/// The create.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The <see cref="AggregateVersion" />.</returns>
public static AggregateVersion CreateFrom(Int64 value)
{
return new AggregateVersion(value);
}

/// <summary>
/// Creates the a new aggregate ID.
/// </summary>
/// <returns>AggregateVersion.</returns>
public static AggregateVersion CreateNew()
{
return new AggregateVersion(0);
}

/// <summary>
/// Equalses the specified other.
/// </summary>
/// <param name="other">The other.</param>
/// <returns>Boolean.</returns>
public Boolean Equals(AggregateVersion other)
{
return this.Value.Equals(other.Value);
}

/// <summary>
/// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
public override Boolean Equals(Object obj)
{
if (object.ReferenceEquals(null, obj))
Expand All @@ -90,77 +57,54 @@ public override Boolean Equals(Object obj)
return obj is AggregateVersion && this.Equals((AggregateVersion)obj);
}

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and aggregateEvent structures like a hash table.</returns>
public override Int32 GetHashCode()
{
return this.Value.GetHashCode();
}

/// <summary>
/// Parses the specified identifier.
/// </summary>
/// <param name="valueAsString">The value as string.</param>
/// <returns>AggregateVersion.</returns>
public static AggregateVersion Parse(String valueAsString)
{
return AggregateVersion.CreateFrom(Int64.Parse(valueAsString));
}

/// <summary>
/// Returns the underlying value of this instance as a string.
/// </summary>
/// <returns>A <see cref="T:System.String" /> containing a fully qualified type name.</returns>
public override String ToString()
{
return this.Value.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// Implements the operator ==.
/// </summary>
/// <param name="leftHand">The left hand.</param>
/// <param name="rightHand">The right hand.</param>
/// <returns>The result of the operator.</returns>
public static Boolean operator ==(AggregateVersion leftHand,
AggregateVersion rightHand)
{
return leftHand.Value == rightHand.Value;
}

/// <summary>
/// Performs an implicit conversion from <see cref="AggregateVersion" /> to <see cref="Int32" />.
/// </summary>
/// <param name="aggregateVersion">The aggregate version.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator Int64(AggregateVersion aggregateVersion)
{
return aggregateVersion.Value;
}

/// <summary>
/// Performs an implicit conversion from <see cref="Int32" /> to <see cref="AggregateVersion" />.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator AggregateVersion(Int64 value)
{
return AggregateVersion.CreateFrom(value);
}

/// <summary>
/// Implements the operator !=.
/// </summary>
/// <param name="leftHand">The left hand.</param>
/// <param name="rightHand">The right hand.</param>
/// <returns>The result of the operator.</returns>
public static Boolean operator !=(AggregateVersion leftHand,
AggregateVersion rightHand)
{
return leftHand.Value != rightHand.Value;
}

public static bool operator <(AggregateVersion left, AggregateVersion right) =>
left.Value < right.Value;

public static bool operator >(AggregateVersion left, AggregateVersion right) =>
left.Value > right.Value;

public static bool operator <=(AggregateVersion left, AggregateVersion right) =>
left.Value <= right.Value;

public static bool operator >=(AggregateVersion left, AggregateVersion right) =>
left.Value >= right.Value;

#endregion
}
4 changes: 2 additions & 2 deletions Shared.EventStore/Aggregate/DomainEventFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public DomainEvent CreateDomainEvent(Guid aggregateId, ResolvedEvent @event)
try{
eventType = TypeMap.GetType(@event.Event.EventType);
}
catch(Exception)
{
catch (Exception) {
// ignored
}

if (eventType == null)
Expand Down
2 changes: 1 addition & 1 deletion Shared.EventStore/Aggregate/TypeMapConvertor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static IDomainEvent Convertor(Guid aggregateId, ResolvedEvent @event)
}

if (eventType == null)
throw new Exception($"Could not find EventType {@event.Event.EventType} in mapping list.");
throw new NullReferenceException($"Could not find EventType {@event.Event.EventType} in mapping list.");

if (eventType.IsSubclassOf(typeof(DomainEvent)))
{
Expand Down
10 changes: 5 additions & 5 deletions Shared.EventStore/Extensions/IApplicationBuilderExtenstions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Microsoft.AspNetCore.Builder;
using SubscriptionWorker;

public static class IApplicationBuilderExtenstions
public static class IApplicationBuilderExtensions
{
#region Methods

Expand All @@ -27,13 +27,13 @@ public static async Task ConfigureSubscriptionService(this IApplicationBuilder a
using (CancellationTokenSource cts = new())
{
if (workerConfig == null)
throw new Exception("No Worker configuration supplied");
throw new ArgumentNullException("No Worker configuration supplied");
if (subscriptionRepositoryResolver == null)
throw new Exception("No Subscription Repository Resolver supplied");
throw new ArgumentNullException("No Subscription Repository Resolver supplied");
if (!workerConfig.InternalSubscriptionService)
return;
if (workerConfig.SubscriptionWorkers == null || !workerConfig.SubscriptionWorkers.Any())
throw new Exception("No SubscriptionWorkers supplied");
throw new ArgumentNullException("No SubscriptionWorkers supplied");

ISubscriptionRepository subscriptionRepository = subscriptionRepositoryResolver(eventStoreConnectionString,
workerConfig.InternalSubscriptionServiceCacheDuration);
Expand All @@ -46,7 +46,7 @@ public static async Task ConfigureSubscriptionService(this IApplicationBuilder a
await subscriptionRepository.PreWarm(cts.Token);

List<SubscriptionWorker> workers =
IApplicationBuilderExtenstions.ConfigureSubscriptions(subscriptionRepository, workerConfig,
IApplicationBuilderExtensions.ConfigureSubscriptions(subscriptionRepository, workerConfig,
eventStoreConnectionString, eventHandlerResolvers, traceHandler);
foreach (SubscriptionWorker subscriptionWorker in workers)
{
Expand Down
Loading
Loading