Skip to content

Commit

Permalink
Cleanup code in a few projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Nov 8, 2023
1 parent 83b5257 commit 726ab01
Show file tree
Hide file tree
Showing 221 changed files with 11,095 additions and 11,347 deletions.
7 changes: 3 additions & 4 deletions src/Abc.Zebus.Contracts/ICommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Abc.Zebus
namespace Abc.Zebus;

public interface ICommand : IMessage
{
public interface ICommand : IMessage
{
}
}
7 changes: 3 additions & 4 deletions src/Abc.Zebus.Contracts/IEvent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Abc.Zebus
namespace Abc.Zebus;

public interface IEvent : IMessage
{
public interface IEvent : IMessage
{
}
}
7 changes: 3 additions & 4 deletions src/Abc.Zebus.Contracts/IMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Abc.Zebus
namespace Abc.Zebus;

public interface IMessage
{
public interface IMessage
{
}
}
17 changes: 8 additions & 9 deletions src/Abc.Zebus.Contracts/MessageTypeIdAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;

namespace Abc.Zebus
namespace Abc.Zebus;

[AttributeUsage(AttributeTargets.Class)]
public sealed class MessageTypeIdAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class MessageTypeIdAttribute : Attribute
{
public Guid MessageTypeId { get; }
public Guid MessageTypeId { get; }

public MessageTypeIdAttribute(string typeId)
{
MessageTypeId = Guid.Parse(typeId);
}
public MessageTypeIdAttribute(string typeId)
{
MessageTypeId = Guid.Parse(typeId);
}
}
41 changes: 20 additions & 21 deletions src/Abc.Zebus.Contracts/Routing/Routable.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using System;

namespace Abc.Zebus.Routing
namespace Abc.Zebus.Routing;

/// <summary>
/// Indicates that the target message is routable.
/// </summary>
/// <remarks>
/// <para>
/// A routable message must have routable members. The routable members must be explicitly specified using <see cref="RoutingPositionAttribute"/>.
/// </para>
/// <para>
/// The default subscription mode of routable message is <c>Manual</c>, i.e.: subscriptions must be manually created with <c>IBus.Subscribe</c>.
/// If you update an existing message to make it routable, consider specifying <c>AutoSubscribe = true</c> to keep previous subscription mode.
/// </para>
/// </remarks>
[AttributeUsage(AttributeTargets.Class)]
public sealed class Routable : Attribute
{
/// <summary>
/// Indicates that the target message is routable.
/// Indicates whether the default subscription mode for the target message is Auto (<c>AutoSubscribe == true</c>) or Manual.
/// </summary>
/// <remarks>
/// <para>
/// A routable message must have routable members. The routable members must be explicitly specified using <see cref="RoutingPositionAttribute"/>.
/// </para>
/// <para>
/// The default subscription mode of routable message is <c>Manual</c>, i.e.: subscriptions must be manually created with <c>IBus.Subscribe</c>.
/// If you update an existing message to make it routable, consider specifying <c>AutoSubscribe = true</c> to keep previous subscription mode.
/// </para>
/// <see cref="AutoSubscribe"/> configures the default subscription mode for the target message. The subscription mode
/// can still be overriden per message handler using the <c>SubscriptionMode</c> attribute.
/// </remarks>
[AttributeUsage(AttributeTargets.Class)]
public sealed class Routable : Attribute
{
/// <summary>
/// Indicates whether the default subscription mode for the target message is Auto (<c>AutoSubscribe == true</c>) or Manual.
/// </summary>
/// <remarks>
/// <see cref="AutoSubscribe"/> configures the default subscription mode for the target message. The subscription mode
/// can still be overriden per message handler using the <c>SubscriptionMode</c> attribute.
/// </remarks>
public bool AutoSubscribe { get; set; }
}
public bool AutoSubscribe { get; set; }
}
17 changes: 8 additions & 9 deletions src/Abc.Zebus.Contracts/Routing/RoutingPositionAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;

namespace Abc.Zebus.Routing
namespace Abc.Zebus.Routing;

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class RoutingPositionAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class RoutingPositionAttribute : Attribute
{
public int Position { get; }
public int Position { get; }

public RoutingPositionAttribute(int position)
{
Position = position;
}
public RoutingPositionAttribute(int position)
{
Position = position;
}
}
9 changes: 4 additions & 5 deletions src/Abc.Zebus.Contracts/TransientAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;

namespace Abc.Zebus
namespace Abc.Zebus;

[AttributeUsage(AttributeTargets.Class)]
public sealed class TransientAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class TransientAttribute : Attribute
{
}
}
123 changes: 61 additions & 62 deletions src/Abc.Zebus.Log4Net/Log4NetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,86 @@
using log4net;
using Microsoft.Extensions.Logging;

namespace Abc.Zebus.Log4Net
namespace Abc.Zebus.Log4Net;

public sealed class Log4NetFactory : ILoggerFactory
{
public sealed class Log4NetFactory : ILoggerFactory
public void Dispose()
{
public void Dispose()
{
}
}

public ILogger CreateLogger(string categoryName)
{
return new Logger(LogManager.GetLogger(categoryName));
}
public ILogger CreateLogger(string categoryName)
{
return new Logger(LogManager.GetLogger(categoryName));
}

public void AddProvider(ILoggerProvider provider)
{
}

public void AddProvider(ILoggerProvider provider)
private class Logger : ILogger
{
private readonly ILog _log;

public Logger(ILog log)
{
_log = log;
}

private class Logger : ILogger
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
private readonly ILog _log;

public Logger(ILog log)
switch (logLevel)
{
_log = log;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
switch (logLevel)
{
case LogLevel.Debug:
if (_log.IsDebugEnabled)
_log.Debug(formatter(state, exception), exception);
break;
case LogLevel.Debug:
if (_log.IsDebugEnabled)
_log.Debug(formatter(state, exception), exception);
break;

case LogLevel.Information:
if (_log.IsInfoEnabled)
_log.Info(formatter(state, exception), exception);
break;
case LogLevel.Information:
if (_log.IsInfoEnabled)
_log.Info(formatter(state, exception), exception);
break;

case LogLevel.Warning:
if (_log.IsWarnEnabled)
_log.Warn(formatter(state, exception), exception);
break;
case LogLevel.Warning:
if (_log.IsWarnEnabled)
_log.Warn(formatter(state, exception), exception);
break;

case LogLevel.Error:
if (_log.IsErrorEnabled)
_log.Error(formatter(state, exception), exception);
break;
case LogLevel.Error:
if (_log.IsErrorEnabled)
_log.Error(formatter(state, exception), exception);
break;

case LogLevel.Critical:
if (_log.IsFatalEnabled)
_log.Fatal(formatter(state, exception), exception);
break;
}
case LogLevel.Critical:
if (_log.IsFatalEnabled)
_log.Fatal(formatter(state, exception), exception);
break;
}
}

public bool IsEnabled(LogLevel logLevel)
public bool IsEnabled(LogLevel logLevel)
{
return logLevel switch
{
return logLevel switch
{
LogLevel.Debug => _log.IsDebugEnabled,
LogLevel.Information => _log.IsInfoEnabled,
LogLevel.Warning => _log.IsWarnEnabled,
LogLevel.Error => _log.IsErrorEnabled,
LogLevel.Critical => _log.IsFatalEnabled,
_ => false
};
}

public IDisposable BeginScope<TState>(TState state)
=> EmptyDisposable.Instance;
LogLevel.Debug => _log.IsDebugEnabled,
LogLevel.Information => _log.IsInfoEnabled,
LogLevel.Warning => _log.IsWarnEnabled,
LogLevel.Error => _log.IsErrorEnabled,
LogLevel.Critical => _log.IsFatalEnabled,
_ => false
};
}

private class EmptyDisposable : IDisposable
{
public static EmptyDisposable Instance { get; } = new EmptyDisposable();
public IDisposable BeginScope<TState>(TState state)
=> EmptyDisposable.Instance;
}

public void Dispose()
{
}
private class EmptyDisposable : IDisposable
{
public static EmptyDisposable Instance { get; } = new();

public void Dispose()
{
}
}
}
75 changes: 37 additions & 38 deletions src/Abc.Zebus.Testing/Comparison/ComparisonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,55 @@
using KellermanSoftware.CompareNetObjects.TypeComparers;
using ProtoBuf;

namespace Abc.Zebus.Testing.Comparison
namespace Abc.Zebus.Testing.Comparison;

internal static class ComparisonExtensions
{
internal static class ComparisonExtensions
public static bool DeepCompare<T>(this T firstObj, T secondObj, params string[] elementsToIgnore)
{
public static bool DeepCompare<T>(this T firstObj, T secondObj, params string[] elementsToIgnore)
{
var comparer = CreateComparer();
comparer.Config.MembersToIgnore.AddRange(elementsToIgnore);
var comparer = CreateComparer();
comparer.Config.MembersToIgnore.AddRange(elementsToIgnore);

return comparer.Compare(firstObj, secondObj).AreEqual;
}
return comparer.Compare(firstObj, secondObj).AreEqual;
}

public static CompareLogic CreateComparer()
public static CompareLogic CreateComparer()
{
return new CompareLogic
{
return new CompareLogic
Config =
{
Config =
CompareStaticProperties = false,
CompareStaticFields = false,
CustomComparers =
{
CompareStaticProperties = false,
CompareStaticFields = false,
CustomComparers =
{
// TODO : Is this still used?
new EquatableComparer()
},
AttributesToIgnore = new List<Type> { typeof(ProtoIgnoreAttribute) },
}
};
}
// TODO : Is this still used?
new EquatableComparer()
},
AttributesToIgnore = new List<Type> { typeof(ProtoIgnoreAttribute) },
}
};
}

private class EquatableComparer : BaseTypeComparer
private class EquatableComparer : BaseTypeComparer
{
public EquatableComparer()
: base(RootComparerFactory.GetRootComparer())
{
public EquatableComparer()
: base(RootComparerFactory.GetRootComparer())
{
}
}

public override bool IsTypeMatch(Type type1, Type type2)
{
if (type1 != type2)
return false;
public override bool IsTypeMatch(Type type1, Type type2)
{
if (type1 != type2)
return false;

return typeof(IEquatable<>).MakeGenericType(type1).IsAssignableFrom(type1);
}
return typeof(IEquatable<>).MakeGenericType(type1).IsAssignableFrom(type1);
}

public override void CompareType(CompareParms parms)
{
if (!Equals(parms.Object1, parms.Object2))
AddDifference(parms);
}
public override void CompareType(CompareParms parms)
{
if (!Equals(parms.Object1, parms.Object2))
AddDifference(parms);
}
}
}
Loading

0 comments on commit 726ab01

Please sign in to comment.