SubRouteConfiguration FillSubRoute( IActivityMonitor monitor, XElement xml, SubRouteConfiguration sub )
{
using( monitor.OpenGroup( LogLevel.Trace, string.Format( "Reading subordinated channel '{0}'.", sub.Name ), null ) )
{
var matchOptions = (string)xml.Attribute( "MatchOptions" );
var filter = (string)xml.Attribute( "TopicFilter" );
var regex = (string)xml.Attribute( "TopicRegex" );
if( (filter == null) == (regex == null) )
{
throw new XmlException( "Subordinated Channel must define one TopicFilter or TopicRegex attribute (and not both)." + xml.GetLineColumnString() );
}
RegexOptions opt = RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.ExplicitCapture;
if( !String.IsNullOrWhiteSpace( matchOptions ) )
{
if( !Enum.TryParse( matchOptions, true, out opt ) )
{
var expected = String.Join( ", ", Enum.GetNames( typeof( RegexOptions ) ).Where( n => n != "None" ) );
throw new XmlException( "MatchOptions value must be a subset of: " + expected + xml.GetLineColumnString() );
}
monitor.SendLine( LogLevel.Trace, string.Format( "MatchOptions for Channel '{0}' is: {1}.", sub.Name, opt ), null );
}
else monitor.SendLine( LogLevel.Trace, string.Format( "MatchOptions for Channel '{0}' defaults to: IgnoreCase, CultureInvariant, Multiline, ExplicitCapture.", sub.Name ), null );
sub.RoutePredicate = filter != null ? CreatePredicateFromWildcards( filter, opt ) : CreatePredicateRegex( regex, opt );
FillRoute( monitor, xml, sub );
return sub;
}
}