private void initializePatterns() { if (_patterns == null) { _patterns = new List <PatternBase>(); foreach (ConfigurableElement patternConfiguration in AcroniManagerConfigurationSection.Instance.Patterns) { Type patternType = ConfigurableBase.GetType(patternConfiguration.Class, typeof(PatternBase), "pattern"); Data.Matcher matcher = MatcherFactory.GetMatcher(patternConfiguration); if (patternConfiguration.Configurations == null || patternConfiguration.Configurations.Count == 0) { CreatePattern(patternType, null, matcher); } else { foreach (ParameterizableConfigurationElement executionConfiguration in patternConfiguration.Configurations) { CreatePattern(patternType, executionConfiguration, matcher); } } } } }
public EndpointRoutingMiddleware( MatcherFactory matcherFactory, EndpointDataSource endpointDataSource, ILogger <EndpointRoutingMiddleware> logger, RequestDelegate next) { if (matcherFactory == null) { throw new ArgumentNullException(nameof(matcherFactory)); } if (endpointDataSource == null) { throw new ArgumentNullException(nameof(endpointDataSource)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (next == null) { throw new ArgumentNullException(nameof(next)); } _matcherFactory = matcherFactory; _endpointDataSource = endpointDataSource; _logger = logger; _next = next; }
public EndpointRoutingMiddleware( MatcherFactory matcherFactory, ILogger <EndpointRoutingMiddleware> logger, IEndpointRouteBuilder endpointRouteBuilder, RequestDelegate next) { if (matcherFactory == null) { throw new ArgumentNullException(nameof(matcherFactory)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (endpointRouteBuilder == null) { throw new ArgumentNullException(nameof(endpointRouteBuilder)); } if (next == null) { throw new ArgumentNullException(nameof(next)); } _matcherFactory = matcherFactory; _logger = logger; _next = next; _endpointDataSource = new CompositeEndpointDataSource(endpointRouteBuilder.DataSources); }
public DispatcherMiddleware( MatcherFactory matcherFactory, IOptions <DispatcherOptions> options, ILogger <DispatcherMiddleware> logger, RequestDelegate next) { if (matcherFactory == null) { throw new ArgumentNullException(nameof(matcherFactory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (next == null) { throw new ArgumentNullException(nameof(next)); } _matcherFactory = matcherFactory; _options = options; _logger = logger; _next = next; }
public void MatchesNull() { var expr = ToExpression <object>(() => It.IsAny <object>()).Body; var matcher = MatcherFactory.CreateMatcher(expr); Assert.True(matcher.Matches(null)); }
public void MatchesIfAssignableType() { var expr = ToExpression <object>(() => It.IsAny <object>()).Body; var matcher = MatcherFactory.CreateMatcher(expr); Assert.True(matcher.Matches("foo")); }
public void MatchesIfAssignableInterface() { var expr = ToExpression <IDisposable>(() => It.IsAny <IDisposable>()).Body; var matcher = MatcherFactory.CreateMatcher(expr); Assert.True(matcher.Matches(new Disposable())); }
public void Construct_GivenAlgorithm_CreatesTheRightMatcher() { FileScanner.PatternMatching.MatcherFactory factory = new MatcherFactory(); var patterns = new List<string>{ "a", "b", "c" }; Assert.AreEqual(factory.Create(patterns, MatcherFactory.MatchAlgorithm.AhoCorasick).GetType().Name, "AhoMatcher"); Assert.AreEqual(factory.Create(patterns, MatcherFactory.MatchAlgorithm.Regex).GetType().Name, "RegexMatcher"); }
public void DoesntMatchIfNotAssignableType() { var expr = ToExpression <IFormatProvider>(() => It.IsAny <IFormatProvider>()).Body; var matcher = MatcherFactory.CreateMatcher(expr); Assert.False(matcher.Matches("foo")); }
public void Construct_GivenNoAlgorithm_CreatesDefaultMatcher() { FileScanner.PatternMatching.MatcherFactory factory = new MatcherFactory(); var patterns = new List<string>{ "a", "b" }; Assert.AreEqual(factory.Create(patterns).GetType().Name, "RegexMatcher"); patterns = new List<string> { "a", "b", "c", "d" }; Assert.AreEqual(factory.Create(patterns).GetType().Name, "AhoMatcher"); }
public void Is_correctly_handled_by_MatcherFactory() { var expression = GetExpression(); var matchExpression = FindMatchExpression(expression); Debug.Assert(matchExpression != null); var(matcher, _) = MatcherFactory.CreateMatcher(matchExpression); Assert.IsType <Match <int> >(matcher); }
public void Matches_several_matchers_from_params_array(object first, object second, bool shouldMatch) { var methodCallExpr = (MethodCallExpression)ToExpression <IX>(x => x.Method(It.IsAny <int>(), It.IsAny <string>())).Body; var expr = methodCallExpr.Arguments.Single(); var parameter = typeof(IX).GetMethod("Method").GetParameters().Single(); var(matcher, _) = MatcherFactory.CreateMatcher(expr, parameter); Assert.Equal(shouldMatch, matcher.Matches(new object[] { first, second }, typeof(object[]))); }
public void MatchesIfAssignableInterface() { var expr = ToExpression <IDisposable>(() => It.IsAny <IDisposable>()).ToLambda().Body; var matcher = MatcherFactory.CreateMatcher(expr, false); matcher.Initialize(expr); Assert.IsTrue(matcher.Matches(new Disposable())); }
public void MatchesNull() { var expr = ToExpression <object>(() => It.IsAny <object>()).ToLambda().Body; var matcher = MatcherFactory.CreateMatcher(expr, false); matcher.Initialize(expr); Assert.True(matcher.Matches(null)); }
public void MatchesIfAssignableType() { var expr = ToExpression <object>(() => It.IsAny <object>()).ToLambda().Body; var matcher = MatcherFactory.CreateMatcher(expr, false); matcher.Initialize(expr); Assert.IsTrue(matcher.Matches("foo")); }
public void Construct_GivenAlgorithm_CreatesTheRightMatcher() { FileScanner.PatternMatching.MatcherFactory factory = new MatcherFactory(); var patterns = new List <string> { "a", "b", "c" }; Assert.AreEqual(factory.Create(patterns, MatcherFactory.MatchAlgorithm.AhoCorasick).GetType().Name, "AhoMatcher"); Assert.AreEqual(factory.Create(patterns, MatcherFactory.MatchAlgorithm.Regex).GetType().Name, "RegexMatcher"); }
public static Task <MatchResult> Run([OrchestrationTrigger] DurableOrchestrationContext context, TraceWriter log) { log.Info("Validation Starting"); var input = context.GetInput <EarningValidation>(); var factory = MatcherFactory.CreateMatcher(); var result = factory.Match(input.Commitments, input.Earning, input.Accounts); log.Info("Validation Finishing"); return(Task.FromResult(result)); }
public void SetupEvaluatedSuccessfully_succeeds_for_matching_values() { var seconds = new List <string>(); var methodCallExpr = (MethodCallExpression)ToExpression <IX>(x => x.Method(It.IsAny <int>(), Capture.In(seconds))).Body; var expr = methodCallExpr.Arguments.Single(); var parameter = typeof(IX).GetMethod("Method").GetParameters().Single(); var(matcher, _) = MatcherFactory.CreateMatcher(expr, parameter); matcher.SetupEvaluatedSuccessfully(new object[] { 42, "" }, typeof(object[])); }
private void Initialize() { if (this.arrayInitExpression != null) { this.matchers = this.arrayInitExpression.Expressions .Select(e => MatcherFactory.CreateMatcher(e, false)).ToArray(); } else { this.matchers = new IMatcher[0]; } }
public ParamArrayMatcher(NewArrayExpression expression) { if (expression != null) { this.matchers = expression.Expressions .Select(e => MatcherFactory.CreateMatcher(e)).ToArray(); } else { this.matchers = new IMatcher[0]; } }
public void Construct_GivenNoAlgorithm_CreatesDefaultMatcher() { FileScanner.PatternMatching.MatcherFactory factory = new MatcherFactory(); var patterns = new List <string> { "a", "b" }; Assert.AreEqual(factory.Create(patterns).GetType().Name, "RegexMatcher"); patterns = new List <string> { "a", "b", "c", "d" }; Assert.AreEqual(factory.Create(patterns).GetType().Name, "AhoMatcher"); }
public void IsMatch_GivenMultipleLinesStream_AndTextWithAMatch_ReturnsTrue(MatcherFactory.MatchAlgorithm algorithm) { var matcher = factory.Create(new List<string> { "p1" }, algorithm); using (var stream = new MemoryStream()) { var writer = new StreamWriter(stream); writer.WriteLine("12"); writer.WriteLine("p13456"); writer.WriteLine("7p189p10"); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); Assert.IsTrue(matcher.IsMatch(new StreamReader(stream))); } }
private EndpointRoutingMiddleware CreateMiddleware( Logger <EndpointRoutingMiddleware> logger = null, MatcherFactory matcherFactory = null, RequestDelegate next = null) { next ??= c => Task.CompletedTask; logger ??= new Logger <EndpointRoutingMiddleware>(NullLoggerFactory.Instance); matcherFactory ??= new TestMatcherFactory(true); var middleware = new EndpointRoutingMiddleware( matcherFactory, logger, new DefaultEndpointRouteBuilder(Mock.Of <IApplicationBuilder>()), next); return(middleware); }
private IServiceProvider CreateServices(MatcherFactory matcherFactory) { var services = new ServiceCollection(); if (matcherFactory != null) { services.AddSingleton <MatcherFactory>(matcherFactory); } services.AddLogging(); services.AddOptions(); services.AddRouting(); var serviceProvder = services.BuildServiceProvider(); return(serviceProvder); }
private EndpointRoutingMiddleware CreateMiddleware( Logger <EndpointRoutingMiddleware> logger = null, MatcherFactory matcherFactory = null) { RequestDelegate next = (c) => Task.FromResult <object>(null); logger = logger ?? new Logger <EndpointRoutingMiddleware>(NullLoggerFactory.Instance); matcherFactory = matcherFactory ?? new TestMatcherFactory(true); var middleware = new EndpointRoutingMiddleware( matcherFactory, logger, new DefaultEndpointRouteBuilder(Mock.Of <IApplicationBuilder>()), next); return(middleware); }
private EndpointRoutingMiddleware CreateMiddleware( Logger <EndpointRoutingMiddleware> logger = null, MatcherFactory matcherFactory = null) { RequestDelegate next = (c) => Task.FromResult <object>(null); logger = logger ?? new Logger <EndpointRoutingMiddleware>(NullLoggerFactory.Instance); matcherFactory = matcherFactory ?? new TestMatcherFactory(true); var options = Options.Create(new EndpointOptions()); var middleware = new EndpointRoutingMiddleware( matcherFactory, new CompositeEndpointDataSource(Array.Empty <EndpointDataSource>()), logger, next); return(middleware); }
private IServiceProvider CreateServices(MatcherFactory matcherFactory) { var services = new ServiceCollection(); if (matcherFactory != null) { services.AddSingleton <MatcherFactory>(matcherFactory); } services.AddLogging(); services.AddOptions(); services.AddRouting(); var listener = new DiagnosticListener("Microsoft.AspNetCore"); services.AddSingleton(listener); services.AddSingleton <DiagnosticSource>(listener); var serviceProvder = services.BuildServiceProvider(); return(serviceProvder); }
private EndpointRoutingMiddleware CreateMiddleware( Logger <EndpointRoutingMiddleware> logger = null, MatcherFactory matcherFactory = null, DiagnosticListener listener = null, RequestDelegate next = null) { next ??= c => Task.CompletedTask; logger ??= new Logger <EndpointRoutingMiddleware>(NullLoggerFactory.Instance); matcherFactory ??= new TestMatcherFactory(true); listener ??= new DiagnosticListener("Microsoft.AspNetCore"); var middleware = new EndpointRoutingMiddleware( matcherFactory, logger, new DefaultEndpointRouteBuilder(Mock.Of <IApplicationBuilder>()), new DefaultEndpointDataSource(), listener, next); return(middleware); }
public EndpointRoutingMiddleware( MatcherFactory matcherFactory, ILogger <EndpointRoutingMiddleware> logger, IEndpointRouteBuilder endpointRouteBuilder, EndpointDataSource rootCompositeEndpointDataSource, DiagnosticListener diagnosticListener, RequestDelegate next) { if (endpointRouteBuilder == null) { throw new ArgumentNullException(nameof(endpointRouteBuilder)); } _matcherFactory = matcherFactory ?? throw new ArgumentNullException(nameof(matcherFactory)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener)); _next = next ?? throw new ArgumentNullException(nameof(next)); // rootCompositeEndpointDataSource is a constructor parameter only so it always gets disposed by DI. This ensures that any // disposable EndpointDataSources also get disposed. _endpointDataSource is a component of rootCompositeEndpointDataSource. _ = rootCompositeEndpointDataSource; _endpointDataSource = new CompositeEndpointDataSource(endpointRouteBuilder.DataSources); }
public async Task <Metric> ProcessEarning(Earning earning) { var sw = Stopwatch.StartNew(); var cache = GetLocalCache(); var metric = new Metric { Actor = $"#{_actorNumber}({earning.Ukprn})" }; var payableEarnings = new List <PayableEarning>(); var nonPayableEarnings = new List <NonPayableEarning>(); var key = string.Concat(earning.Ukprn, "-", earning.LearnerReferenceNumber); var commitments = (List <Commitment>) await cache.Get(key); metric.InsideRead = sw.ElapsedTicks; sw.Restart(); //if (commitments != null && commitments.Count > 0) //{ // compare var matcher = MatcherFactory.CreateMatcher(); var accounts = new List <Account>(); var matchResult = matcher.Match(commitments, earning, accounts); var payable = matchResult.ErrorCodes.Count > 0; // create (non)payable earning if (payable) { payableEarnings.Add(new PayableEarning { Commitment = commitments[0], Earning = earning }); } else { nonPayableEarnings.Add(new NonPayableEarning { Earning = earning, Errors = matchResult.ErrorCodes }); } //} //else //{ // nonPayableEarnings.Add(new NonPayableEarning // { // Earning = earning, // Errors = new[] { "DLOCK_02" } // }); //} metric.InsideCalc = sw.ElapsedTicks; sw.Restart(); //if (commitments != null) //{ commitments[0].NegotiatedPrice += 100; metric.Other = await cache.Update(key, commitments); //} metric.InsideWrite = sw.ElapsedTicks; return(metric); }
public Searcher(IPreprocessor preprocessor, MatcherFactory matcherFactory) { _preprocessor = preprocessor; _matcherFactory = matcherFactory; }
public void Match_GivenTextWithNoMatches_ReturnsNull(MatcherFactory.MatchAlgorithm algorithm, List<string> patterns, String testString) { var matcher = factory.Create(patterns, algorithm); Assert.IsNull(matcher.Match(new StringReader(testString))); }
private void FindMatches(StreamReader streamReader, IEnumerable <string> phrases) { var matcher = new MatcherFactory().Create(phrases.ToList()); _matches = matcher.Matches(streamReader); }
public void Construct_GivenNoPatterns_ThrowsArgumentException() { FileScanner.PatternMatching.MatcherFactory factory = new MatcherFactory(); factory.Create(new List<string>()); }
public void Matches_GivenMultipleLinesSring_AndTextWithAMatch_ReturnsListWithTheMatch_CountingTheNewline(MatcherFactory.MatchAlgorithm algorithm) { var matcher = factory.Create(new List<string> { "p1" }, algorithm); var text = "12\r\np13456\r\n7p189p10"; var expectedMatches = new List<Match> { new Match(4, "p1"), new Match(13, "p1"), new Match(17, "p1") }; Assert.IsTrue(Enumerable.SequenceEqual(matcher.Matches(new StringReader(text)), expectedMatches)); }
public void Matches_GivenMultipleLinesStream_AndTextWithAMatch_ReturnsListWithTheMatch_CountingTheNewline(MatcherFactory.MatchAlgorithm algorithm) { var matcher = factory.Create(new List<string> { "p1" }, algorithm); using (var stream = new MemoryStream()) { var writer = new StreamWriter(stream); writer.WriteLine("12"); writer.WriteLine("p13456"); writer.WriteLine("7p189p10"); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); var expectedMatches = new List<Match> { new Match(4, "p1"), new Match(13, "p1"), new Match(17, "p1") }; Assert.IsTrue(Enumerable.SequenceEqual(matcher.Matches(new StreamReader(stream)), expectedMatches)); } }
public void IsMatch_GivenMultipleLinesString_AndTextWithAMatch_ReturnsTrue(MatcherFactory.MatchAlgorithm algorithm) { var matcher = factory.Create(new List<string> { "p1" }, algorithm); var text = "12\r\np13456\r\n7p189p10"; Assert.IsTrue(matcher.IsMatch(new StringReader(text))); }
public void Match_GivenMultipleLinesString_AndTextWithAMatch_ReturnsTheMatch_CountingTheNewline(MatcherFactory.MatchAlgorithm algorithm) { var matcher = factory.Create(new List<string> { "p1" }, algorithm); var text = "12\r\np13456\r\n7p189p10"; Assert.AreEqual(matcher.Match(new StringReader(text)), new Match(4, "p1")); }
public ArrayMatcher(IJsonArray value, MatcherFactory matcherFactory) { _matcherFactory = matcherFactory; Value = value; }
public void Construct_GivenNoPatterns_ThrowsArgumentException() { FileScanner.PatternMatching.MatcherFactory factory = new MatcherFactory(); factory.Create(new List <string>()); }
public void Matches_GivenTextWithMatches_ReturnsListWithMatches(MatcherFactory.MatchAlgorithm algorithm, List<string> patterns, String testString, List<Match> expectedMatches) { var matcher = factory.Create(patterns, algorithm); Assert.IsTrue(Enumerable.SequenceEqual(matcher.Matches(new StringReader(testString)), expectedMatches)); }
public void Match_GivenTextWithMatches_ReturnsMatch(MatcherFactory.MatchAlgorithm algorithm, List<string> patterns, String testString, Match expectedMatch) { var matcher = factory.Create(patterns, algorithm); Assert.AreEqual(matcher.Match(new StringReader(testString)), expectedMatch); }