private static void ProcessViaInMemoryDelegate(RulePipeline pipeline) { var userCases = UseCaseHelpers.GenerateRequests(10000); System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch(); Console.WriteLine("Initializing delegate chain compiled to single in-memory delegate"); w.Start(); Action <UserCase> compiled = pipeline.CompilePipeline <UserCase>(); Console.WriteLine($"Delegate chain compilationto single in-memory delegate took: {w.ElapsedMilliseconds}ms"); w.Reset(); Console.WriteLine("Compiled in-memory delegate start"); w.Start(); foreach (var userCase in userCases) { compiled(userCase); } Console.WriteLine($"Classic pipeline handler request completed: {w.ElapsedMilliseconds}ms; User cases processed total: {userCases.Count}"); Console.WriteLine($"Cases approved first stage: {userCases.Count(x => x.FirstCheckupApproved)}"); Console.WriteLine($"Cases approved second stage: {userCases.Count(x => x.SecondCheckupApproved)}"); Console.WriteLine($"Cases signed by supervisor: {userCases.Count(x => x.IsSigned)}"); Console.WriteLine($"Finally cards issued: {userCases.Count(x => x.CardIssued)}"); }
protected override void Process() { _monitoring.Notify(Name, 0); using (var unit = GetUnitOfWork()) { var orders = unit .Scope .Repository <OrderLine>() .GetAll(o => (o.Order.OrderType == (int)OrderTypes.SalesOrder || o.Order.OrderType == (int)OrderTypes.PurchaseOrder || o.Order.OrderType == (int)OrderTypes.PickTicketOrder) && !o.isDispatched && !o.Order.HoldOrder && (!o.CentralDelivery.HasValue || (o.CentralDelivery.HasValue && !o.CentralDelivery.Value))) .ToList(); log.AuditInfo(string.Format("Find {0} orders to dispatch", orders.Count)); var rulePipe = new RulePipeline(orders, unit, log); log.AuditInfo("Finished order dispatch logic"); log.InfoFormat("Found {0} orders to process", orders.Count()); log.Info("Order logic finished lets dispatch"); rulePipe.Dispatch(true); log.AuditInfo("Orders dispatched to vendor"); foreach (var e in rulePipe.Exceptions) { _monitoring.Notify(Name, -1); log.AuditError(e.Message, e.InnerException ?? e, "Order Dispatching"); } log.AuditComplete(string.Format("Finished order dispatching process. Dispatched Order Lines: {0} Failed: {1}", rulePipe.DispatchedOrders, rulePipe.FailedOrders), "Order Dispatching"); } _monitoring.Notify(Name, 1); }
private static void ProcessViaClassicPipeline(RulePipeline pipeline) { var userCases = UseCaseHelpers.GenerateRequests(10000); System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch(); Console.WriteLine("Initializing delegate chain - non-compiled"); w.Start(); Action <UserCase> compiled = (context) => { pipeline.Handle(context); }; Console.WriteLine($"Delegate chain initialized: {w.ElapsedMilliseconds}ms"); w.Reset(); Console.WriteLine("Delegate chain request start"); w.Start(); foreach (var userCase in userCases) { compiled(userCase); } Console.WriteLine($"Delegate chain request completed: {w.ElapsedMilliseconds}ms"); Console.WriteLine($"Cases approved first stage: {userCases.Count(x => x.FirstCheckupApproved)}"); Console.WriteLine($"Cases approved second stage: {userCases.Count(x => x.SecondCheckupApproved)}"); Console.WriteLine($"Cases signed by supervisor: {userCases.Count(x => x.IsSigned)}"); Console.WriteLine($"Finally cards issued: {userCases.Count(x => x.CardIssued)}"); }
protected override void Process() { using (var unit = GetUnitOfWork()) { var orders = unit.Scope.Repository <OrderLine>().GetAll(o => !o.isDispatched && (o.CentralDelivery.HasValue && o.CentralDelivery.Value)).ToList(); var rulePipe = new RulePipeline(orders, unit); rulePipe.Dispatch(false); foreach (var e in rulePipe.Exceptions) { log.AuditError(e.Message, e.InnerException ?? e, "Order Dispatching"); } log.AuditComplete(string.Format("Finished order dispatching process. Dispatched Order Lines: {0} Failed: {1}", rulePipe.DispatchedOrders, rulePipe.FailedOrders), "Order Dispatching"); } //check if any dispatch advices are available try { CheckDispatchAdvice(); log.AuditSuccess("Available dispatch advices processed"); } catch (Exception e) { log.AuditError("Sending dispatch advice to EDI failed", e, "Order Dispatching"); } }
public static RulePipeline InitPipeline() { var pipeline = new RulePipeline(); pipeline.AddHandler <InformationCorrectnessRule>("Support"); pipeline.AddHandler <MatchBusinessPrerequisitesRule>("OfficeManager"); pipeline.AddHandler <SupervisorSignRule>("DepartmentHead"); pipeline.AddHandler <MatchIssueCardPrerequisitesRule>("ClientManager"); return(pipeline); }
public int DispatchOrderLine(int orderLineID, IUnitOfWork work) { var orderLine = Repository <OrderLine>().GetSingle(c => c.OrderLineID == orderLineID); if (orderLine.isDispatched) { throw new InvalidOperationException("Order line is already dispatched"); } var pipeline = new RulePipeline(new List <OrderLine>() { orderLine }, work); pipeline.Dispatch(true); if (pipeline.Exceptions.Count > 0) { throw new Exception("Dispatching order line " + orderLineID + " failed.See logs for more information"); } return(pipeline.VendorOrderLines.First().Key); }
public POP3EmailConnector(List <Rule> rules, IRuleProcessorFactory ruleProcessorFactory, IUnitOfWork unitOfWork) { Pipeline = new RulePipeline(rules, ruleProcessorFactory, unitOfWork); }