public void Start(object message, Saga saga, Route route) { var adapter = _factory.Create <IMessageAdapter>(_configuration.MessageAdapterType); var interceptor = _factory.Create <IRouterInterceptor>(_configuration.RouterInterceptorType); var context = adapter.Read(message, route.ContentType, route.UseClaimCheck, route.IdentityConfiguration); var when = true; if (route.When != null) { when = route.When(context); } if (when) { interceptor.OnEntry(context); try { var middlewares = new List <Type> { typeof(MessageExceptionHandler) }; middlewares.AddRange(_configuration.InboundMiddlewareTypes); middlewares.AddRange(saga.FirstRoute.MiddlewareTypes); middlewares.Add(typeof(FirstMessageHandler)); context.Route = route; context.Saga = saga; _pipeline.Execute(middlewares.ToArray(), context); interceptor.OnSuccess(context); } catch (Exception ex) { interceptor.OnException(context, ex); throw; } finally { interceptor.OnExit(context); } } }
private void Listen() { while (true) { try { if (listener.IsListening) { var listenerContext = listener.GetContext(); pipeline.Execute(listenerContext); } else { Thread.Sleep(0); } } catch (ThreadAbortException e) { logger.Error(e, "Thread aborted"); return; } catch (Exception error) { logger.Error(error); } } }
private void ReadingMessagesThread(Object state) { while (!_disposed) { try { _connectedMres.Wait(); if (_bufferedClient.ReceivedMessageQueue.IsEmpty) { Thread.Sleep(10); continue; } if (_bufferedClient.ReceivedMessageQueue.TryDequeue(out NetworkMessage message)) { _networkMessagePipe.Execute(message); } } catch (Exception ex) { if (ex is SocketException || ex is IOException) { _connectedMres.Reset(); } Debug.WriteLine(ex.Message); throw; } } }
public ActionResult VariantExists(VariantPickerVariantExistsViewModel viewModel) { var getProductResponse = new GetProductResponse(); if (_getProductPipeline.Execute(new GetProductPipelineArgs(new GetProductRequest(new ProductIdentifier(viewModel.ProductSku, null)), getProductResponse)) == PipelineExecutionResult.Error) { return(Json(new { ProductVariantSku = "" })); } var product = getProductResponse.Product; if (!product.ProductDefinition.IsProductFamily()) { return(Json(new { ProductVariantSku = "" })); } if (!viewModel.VariantNameValueDictionary.Any()) { return(Json(new { ProductVariantSku = "" })); } var variant = product.Variants.FirstOrDefault(v => v.ProductProperties .Where(pp => pp.ProductDefinitionField.DisplayOnSite) .Where(pp => pp.ProductDefinitionField.IsVariantProperty) .Where(pp => !pp.ProductDefinitionField.Deleted) .All(p => viewModel.VariantNameValueDictionary .Any(kv => kv.Key.Equals(p.ProductDefinitionField.Name, StringComparison.InvariantCultureIgnoreCase) && kv.Value.Equals(p.Value, StringComparison.InvariantCultureIgnoreCase))) ); var variantSku = variant != null ? variant.VariantSku : ""; return(Json(new { ProductVariantSku = variantSku })); }
/// <inheritdoc /> protected override TOutput ExecuteSubPipeline(TInput input, PipelineContext ctx) { var previousPipelineResult = _previousPipeline.Execute(input, ctx); if (!ctx.Success) { Console.WriteLine($"The pipeline step before {CurrentStep.Name} failed."); return(default);
public ActionResult SaveReview(ReviewFormSaveReviewViewModel viewModel) { var product = _productRepository.SingleOrDefault(x => x.Guid.ToString() == viewModel.ProductGuid); var catalogGroup = _catalogContext.CurrentCatalogGroup; var catalogGroupV2 = ProductCatalogGroup.FirstOrDefault(x => x.Guid == catalogGroup.Guid); var request = System.Web.HttpContext.Current.Request; var basket = _orderContext.GetBasket(); var name = viewModel.Name; var email = viewModel.Email; var rating = viewModel.Rating * 20; var reviewHeadline = viewModel.Title; var reviewText = viewModel.Comments; if (basket.PurchaseOrder.Customer == null) { basket.PurchaseOrder.Customer = new Customer() { FirstName = name, LastName = String.Empty, EmailAddress = email }; } else { basket.PurchaseOrder.Customer.FirstName = name; if (basket.PurchaseOrder.Customer.LastName == null) { basket.PurchaseOrder.Customer.LastName = String.Empty; } basket.PurchaseOrder.Customer.EmailAddress = email; } basket.PurchaseOrder.Customer.Save(); var review = new ProductReview(); review.ProductCatalogGroup = catalogGroupV2; review.ProductReviewStatus = _productReviewStatusRepository.SingleOrDefault(s => s.Name == "New"); review.CreatedOn = DateTime.Now; review.CreatedBy = "System"; review.Product = product; review.Customer = basket.PurchaseOrder.Customer; review.Rating = rating; review.ReviewHeadline = reviewHeadline; review.ReviewText = reviewText; review.Ip = request.UserHostName; product.AddProductReview(review); _productReviewPipeline.Execute(review); return(Json(new { Rating = review.Rating, ReviewHeadline = review.ReviewHeadline, CreatedBy = review.CreatedBy, CreatedOn = review.CreatedOn.ToString("MMM dd, yyyy"), CreatedOnForMeta = review.CreatedOn.ToString("yyyy-MM-dd"), Comments = review.ReviewText }, JsonRequestBehavior.AllowGet)); }
public PipelineExecutionResult Execute(InitializeArgs subject) { if (_productCatalogGroupRepository.Select(x => x.Name == "Avenue-Clothing.com").Any()) { return(PipelineExecutionResult.Success); } return(_installationPipeline.Execute(new InstallationPipelineArgs())); }
public object Execute(IContext context, IPipeline pipeline) { if (_instance == null) lock (this) if (_instance == null) _instance = pipeline.Execute(); return _instance; }
/// <summary> /// Retrieve data from preparer and process it through pipeline. /// </summary> public virtual void Execute() { var data = _dataPreparer.GetData(); foreach (var item in data) { _pipeline.Execute(item); } }
private TResult Reply <TResult>(MessageContext message, Options options) { var interceptor = _factory.Create <IBusInterceptor>(_configuration.BusInterceptorType); interceptor.OnEntry(message, options); try { if (message.EndPoint.Channels.Any()) { var middlewares = new List <Type> { typeof(DistributionHandler) }; middlewares.AddRange(_configuration.OutboundMiddlewareTypes); middlewares.AddRange(message.EndPoint.MiddlewareTypes); middlewares.Add(typeof(RequestReplyHandler)); var result = _pipeline.Execute(middlewares.ToArray(), message, options, "Reply", typeof(TResult)); interceptor.OnSuccess(message, options); return((TResult)result); } else { throw new ApplicationException($"Endpoint {message.EndPoint.Name}, missing channels"); } } catch (Exception ex) { interceptor.OnError(message, options, ex); throw; } finally { interceptor.OnExit(message, options); } }
public async Task BothSuccessExecutionTest() { // arrange var configuration = new Dictionary <string, IHandlerBehavior> { { "Foo", new HandlerBehavior() }, { "Bar", new HandlerBehavior() }, }; _kernel.Bind <IHandler <string> >().To <FooHandler>().Named("Foo"); _kernel.Bind <IHandler <string> >().To <BarHandler>().Named("Bar"); _pipeline.Configure(configuration); // act var result = await _pipeline.Execute(new HandleContext <string>("Foo and Bar")).ConfigureAwait(false); // assert result.Success.Should().BeTrue(); }
public PipelineExecutionResult Execute(Ucommerce.EntitiesV2.ProductDefinition subject) { if (_productDefinitionRepository.Select().Any(x => x.Name == subject.Name)) { return(PipelineExecutionResult.Success); } _saveDefinitionPipeline.Execute(subject); return(PipelineExecutionResult.Success); }
private static void GetXMLResponseWithError(IPipeline pipeline) { try { Console.WriteLine("************ XML OUTPUT ************"); var result = pipeline.Execute(new RequestObject("http://maps.", "XML")); Console.WriteLine((result.Output as XmlDocument).InnerXml); } catch (Exception) { //throw Console.WriteLine("oops Something went wrong"); } }
public PipelineExecutionResult Execute(UCommerce.EntitiesV2.ProductDefinition subject) { var existingShoeDefinition = _productDefinitionRepository.Select().FirstOrDefault(x => x.Name == subject.Name); if (existingShoeDefinition == null) { return(PipelineExecutionResult.Success); } MergeProductDefinitionFields(existingShoeDefinition, subject); _saveDefinitionPipeline.Execute(existingShoeDefinition); return(PipelineExecutionResult.Success); }
private static void GetJsonResponse(IPipeline pipeline) { try { Console.WriteLine("************ JSON OUTPUT ************"); var result = pipeline.Execute(new RequestObject("http://maps.googleapis.com/maps/api/geocode/json?address=Wakad", "json")); Console.WriteLine(result.Output); } catch (Exception) { // throw; Console.WriteLine("oops Something went wrong"); //Same as above } }
public void StartStateAction() { switch (_sprint.GetType().Name) { case "ReleaseSprint": _pipeline = new DevelopmentPipeline(_sprint, EPipelineConfig.Automatic); break; case "ReviewSprint": _pipeline = new TestPipeline(_sprint, EPipelineConfig.Automatic); break; } _pipeline.Execute(); }
public void Execute(TState state) { foreach (var change in changes) { change.StoreCurrentValueAndApplyChange(state); } inner.Execute(state); for (var i = changes.Length - 1; i >= 0; i--) { var change = changes[i]; change.RestoreToStoredValue(); } }
void StartFaceDetection_Pipeline(string imagesFolder) { // The refactor Detect-Face code using the parallel Pipeline var files = Directory.GetFiles(ImagesFolder); Func <string, Image <Bgr, byte> > imageFn = (fileName) => new Image <Bgr, byte>(fileName); Func <Image <Bgr, byte>, Tuple <Image <Bgr, byte>, Image <Gray, byte> > > grayFn = image => Tuple.Create(image, image.Convert <Gray, byte>()); Func <Tuple <Image <Bgr, byte>, Image <Gray, byte> >, Tuple <Image <Bgr, byte>, System.Drawing.Rectangle[]> > detectFn = frames => Tuple.Create(frames.Item1, CascadeClassifierThreadLocal.Value.DetectMultiScale( frames.Item2, 1.1, 3, System.Drawing.Size.Empty)); Func <Tuple <Image <Bgr, byte>, System.Drawing.Rectangle[]>, Bitmap> drawFn = faces => { foreach (var face in faces.Item2) { faces.Item1.Draw(face, new Bgr(System.Drawing.Color.BurlyWood), 3); } return(faces.Item1.ToBitmap()); }; // TODO : 2.8 // Replace Pipeline implementation with "CsPipeline" (look for TODO : 2.4) // suggestion look into the next mehoth that uses the F# Pipeline IPipeline <string, Bitmap> imagePipe = null; //DataParallelism.Pipelines.CsPipeline CancellationTokenSource cts = new CancellationTokenSource(); imagePipe.Execute(4, cts.Token); // TODO uncomment these code after Pipeline implementatation //foreach (string fileName in files) // imagePipe.Enqueue(fileName, // ((tup) => // { // Application.Current.Dispatcher.Invoke( // () => // Images.Add(tup.Item2.ToBitmapImage())); // return (Unit)Activator.CreateInstance(typeof(Unit), true); // })); }
private static void GetXMLResponse(IPipeline pipeline) { try { Console.WriteLine("************ XML OUTPUT ************"); var result = pipeline.Execute(new RequestObject("http://maps.googleapis.com/maps/api/geocode/json?address=Wakad", "XML")); Console.WriteLine((result.Output as XmlDocument).InnerXml); } catch (Exception) { //throw Console.WriteLine("oops Something went wrong"); //this is just doing a fallback; could have actually //tracked if the request failed and propogated teh error back //you could test this by altering the url :) } }
public object Execute(IContext context, IPipeline pipeline) { object instance; lock (_dictionary) if (_dictionary.TryGetValue(context.ContextId, out instance)) return instance; lock (context.ContextId.ToString()) { lock (_dictionary) if (_dictionary.TryGetValue(context.ContextId, out instance)) return instance; instance = pipeline.Execute(); lock (_dictionary) { _dictionary.Add(context.ContextId, instance); context.Disposed += () => Remove(context.ContextId); return instance; } } }
public object Execute(IContext context, IPipeline pipeline) { Executed = true; return pipeline.Execute(); }
public void Execute(TStateOuter state) { inner.Execute(selector(state)); }
public void Execute() { _pipeline.Execute(); }
/// <summary> /// Start receiving new deal events and logging /// based on the set-up rules. /// </summary> public void Start() { for (int i = 0; i < _servers.Count; i++) { var server = _servers[i]; var eventsApiInst = _eventsApiInst[i]; var getBalanceApiInst = _getBalanceApiInst[i]; async void DealEvents_OnDealAddEventHandler(object control, CIMTDeal deal) { using (var ctx = new WatchdogDbContext()) { // get user from db var userLogin = (long)deal.Login(); var user = ctx.Users.FirstOrDefault(u => u.Login == userLogin) ?? ctx.Users.Add(new User { Login = userLogin, }); // get symbol from db var symbolName = deal.Symbol(); var symbol = ctx.Symbols.FirstOrDefault(s => s.Name == symbolName) ?? ctx.Symbols.Add(new Symbol { Name = symbolName }); var externalId = deal.Deal(); var dealType = ToDealType(deal.Action()); var volume = deal.Volume(); var fromMilliseconds = new DateTime(1970, 1, 1) + TimeSpan.FromMilliseconds(deal.TimeMsc()); var dealEntity = ctx.Deals.Add(new Deal { Symbol = symbol, User = user, ServerId = server.Id, ExternalId = (long)externalId, Type = dealType, Volume = (long)volume, Date = fromMilliseconds, }); dealEntity.Balance = getBalanceApiInst.GetUserBalance(deal.Login()); // TODO how to do this correctly? ctx.SaveChanges(); //_logger.Log($"Incoming deal: {dealEntity} (Time: {deal.Time()} || TimeMSC: {deal.TimeMsc()})"); _logger.Log($"Incoming deal: {dealEntity}"); await _pipeline.Execute(dealEntity); } } eventsApiInst.DealEvents.DealAddEventHandler += DealEvents_OnDealAddEventHandler; _logger.Log($"Starting connecting to [{server.Name}, {server.IpAddress}] ..."); var connectionParams = new ConnectionParams { IP = server.IpAddress, Login = (ulong)server.Login, Password = server.Password, Name = server.Name, }; getBalanceApiInst.Connect(connectionParams); eventsApiInst.Connect(connectionParams); } }