public static async Task Use2() { var builder = new DisruptorPipelineBuilder(); var results = new HashSet <string>(); var pipeline = builder.Build <string, char>(x => x.Max(), 2) .AddStep(x => new string(x, 20), 2) .AddStep(x => $"[{x}]", 1) .AddStep(x => results.Add(x), 1) .Create(); for (var i = 0; i < 1_000_000; i++) { _ = pipeline.Execute(i.ToString()); } await pipeline.Execute("X"); Console.WriteLine("Completed!"); foreach (var result in results) { Console.WriteLine(result); } pipeline.Dispose(); }
private void InitPipeline() { var builder = new DisruptorPipelineBuilder(); _pipeline = builder.Build <Deal, Deal>(deal => { // count volume to balance ratio using (var ctx = new WatchdogDbContext()) { var dealEntity = ctx.Deals.First(d => d.Id == deal.Id); dealEntity.VolumeToBalanceRatio = deal.Volume / deal.Balance; ctx.SaveChanges(); } return(deal); }, 1).AddStep(deal => { // find connections based on rules using (var ctx = new WatchdogDbContext()) { // RULES DEFINITION - START var matches = ctx.Deals .Where(d => d.Id != deal.Id) .Where(d => DbFunctions.DiffSeconds(d.Date, deal.Date) < _openTimeDeltaInSeconds) .Where(d => d.SymbolId == deal.SymbolId) //.Where(d => d.VolumeToBalanceRatio) // TODO: what is the correct condition of the VtBR? .ToList(); // RULES DEFINITION - END if (matches.Any()) { var dealWithGroup = matches.FirstOrDefault(d => d.GroupId != null); var dealGroup = dealWithGroup != null ? dealWithGroup.Group : ctx.DealGroups.Add(new DealGroup()); var dealEntity = ctx.Deals.First(d => d.Id == deal.Id); dealEntity.Group = dealGroup; foreach (var match in matches) { match.Group = dealGroup; } // TODO: Cleanup empty groups, if any / could be scheduled as a periodic DB cleanup process ctx.SaveChanges(); // LOG it var sb = new StringBuilder($"Matches with [{deal}]:").AppendLine(); matches.ForEach(d => sb.AppendLine($" ==> [{d}]")); _logger.Log(sb.ToString()); } } return(true); }, 1).Create(); }
public static async Task Use1() { var builder = new DisruptorPipelineBuilder(); var pipeline = builder.Build <string, string>(FindMostCommon, 2) .AddStep(x => x.Length, 2) .AddStep(x => x % 2 == 1, 2) .Create(); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); Console.WriteLine(await pipeline.Execute("The pipeline patter is the best patter")); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); pipeline.Dispose(); }
public static async Task Use1() { var builder = new DisruptorPipelineBuilder(); var pipeline = builder .Build <string, string>(Utils.FindMostCommon, 2) .AddStep(x => Utils.CountChars(x), 2) .AddStep(x => Utils.IsOdd(x), 2) .Create(); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); Console.WriteLine(await pipeline.Execute("The pipeline patter is the best patter")); Console.WriteLine(await pipeline.Execute("The pipeline pattern is the best pattern")); pipeline.Dispose(); }