2017-01-31 11:01:08 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Default
|
|
|
|
|
{
|
|
|
|
|
public class NamespaceMatchExchangeStrategy : IExchangeStrategy
|
|
|
|
|
{
|
|
|
|
|
public const string DefaultFormat = "^Messaging\\.(.[^\\.]+)";
|
|
|
|
|
|
|
|
|
|
private readonly Regex namespaceRegEx;
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 22:22:34 +00:00
|
|
|
|
public NamespaceMatchExchangeStrategy()
|
2017-01-31 11:01:08 +00:00
|
|
|
|
{
|
2017-02-05 22:22:34 +00:00
|
|
|
|
namespaceRegEx = new Regex(DefaultFormat, RegexOptions.Compiled | RegexOptions.Singleline);
|
2017-01-31 11:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string GetExchange(Type messageType)
|
|
|
|
|
{
|
|
|
|
|
if (messageType.Namespace == null)
|
|
|
|
|
throw new ArgumentException($"{messageType.FullName} does not have a namespace");
|
|
|
|
|
|
|
|
|
|
var match = namespaceRegEx.Match(messageType.Namespace);
|
|
|
|
|
if (!match.Success)
|
|
|
|
|
throw new ArgumentException($"Namespace for {messageType.FullName} does not match the specified format");
|
|
|
|
|
|
|
|
|
|
return match.Groups[1].Value.ToLower();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|