-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override message name via attribute (#36)
* Extract InMemoryBusEngine into its own project * Add support for MessageAttribute to InMemoryBusEngine * Add support for MessageAttribute to RabbitMqBusEngine
- Loading branch information
Showing
48 changed files
with
1,245 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue"><data /></s:String> | ||
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters><Filter ModuleMask="Nybus*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /></IncludeFilters><ExcludeFilters><Filter ModuleMask="*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /></ExcludeFilters></data></s:String> | ||
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters><Filter ModuleMask="Nybus*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /></IncludeFilters><ExcludeFilters><Filter ModuleMask="*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /><Filter ModuleMask="Test*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /></ExcludeFilters></data></s:String> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nybus/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Nybus.Utils | ||
{ | ||
public interface IMessageDescriptorStore | ||
{ | ||
bool RegisterType(Type type); | ||
|
||
bool TryGetDescriptorForType(Type type, out MessageDescriptor descriptor); | ||
|
||
bool TryGetTypeForDescriptor(MessageDescriptor descriptor, out Type type); | ||
} | ||
|
||
public class MessageDescriptor | ||
{ | ||
public static MessageDescriptor CreateFromType(Type type) | ||
{ | ||
if (type == null) | ||
{ | ||
throw new ArgumentNullException(nameof(type)); | ||
} | ||
|
||
return new MessageDescriptor(type.Name, type.Namespace); | ||
} | ||
|
||
public static MessageDescriptor CreateFromAttribute (MessageAttribute attribute) | ||
{ | ||
if (attribute == null) | ||
{ | ||
throw new ArgumentNullException(nameof(attribute)); | ||
} | ||
|
||
return new MessageDescriptor(attribute.Name, attribute.Namespace); | ||
} | ||
|
||
|
||
private static readonly char[] Separators = new []{':'}; | ||
|
||
public static bool TryParse(string descriptorName, out MessageDescriptor descriptor) | ||
{ | ||
var strings = descriptorName.Split(':'); | ||
|
||
if (strings.Length != 2) | ||
{ | ||
descriptor = null; | ||
return false; | ||
} | ||
|
||
descriptor = new MessageDescriptor(strings[1], strings[0]); | ||
return true; | ||
} | ||
|
||
public MessageDescriptor(string name, string @namespace) | ||
{ | ||
Name = name ?? throw new ArgumentNullException(nameof(name)); | ||
Namespace = @namespace ?? throw new ArgumentNullException(nameof(@namespace)); | ||
} | ||
|
||
public string Name { get; } | ||
|
||
public string Namespace { get; } | ||
|
||
public override string ToString() => $"{Namespace}:{Name}"; | ||
|
||
public static implicit operator MessageDescriptor(Type type) => CreateFromType(type); | ||
|
||
public static readonly IEqualityComparer<MessageDescriptor> EqualityComparer = new MessageDescriptorEqualityComparer(); | ||
|
||
private class MessageDescriptorEqualityComparer : IEqualityComparer<MessageDescriptor> | ||
{ | ||
public bool Equals(MessageDescriptor x, MessageDescriptor y) | ||
{ | ||
if (x == null && y == null) return true; | ||
|
||
if ((x != null) != (y != null)) return false; | ||
|
||
return string.Equals(x.ToString(), y.ToString(), StringComparison.Ordinal); | ||
} | ||
|
||
public int GetHashCode(MessageDescriptor obj) | ||
{ | ||
return obj.ToString().GetHashCode(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.