示例#1
0
        private static void UseRedis(IConfiguration configuration, IDistributedCache cache)
        {
            var connectionString = configuration["TomatoLog:Flow:Redis:Connection"];
            var channel          = configuration["TomatoLog:Flow:Redis:Channel"];

            Check.NotNull(connectionString, "TomatoLog:Flow:Redis:Connection");
            Check.NotNull(channel, "TomatoLog:Flow:Redis:Channel");

            RedisHelper.Initialization(new CSRedis.CSRedisClient(connectionString));
            RedisHelper.Subscribe((channel, data =>
            {
                try
                {
                    LogMessage log = JsonConvert.DeserializeObject <LogMessage>(data.Body);
                    logWriter.Write(log);
                    filterService.Filter(log);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex.Message + "|" + data.Body, ex);
                }
            }
                                   ));

            lifeTime.ApplicationStopping.Register(() =>
            {
                RedisHelper.Instance.Dispose();
            });
        }
示例#2
0
        private static void UseRedis(IConfiguration configuration)
        {
            var connectionString = configuration["TomatoLog:Flow:Redis:Connection"];
            var channelName      = configuration["TomatoLog:Flow:Redis:Channel"];

            Check.NotNull(connectionString, "TomatoLog:Flow:Redis:Connection");
            Check.NotNull(channelName, "TomatoLog:Flow:Redis:Channel");

            multiplexer = ConnectionMultiplexer.Connect(connectionString);
            var channel = multiplexer.GetSubscriber().Subscribe(channelName);

            channel.OnMessage(message =>
            {
                try
                {
                    LogMessage log = JsonSerializer.Deserialize <LogMessage>(message.Message);
                    logWriter.Write(log);
                    filterService.Filter(log);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex.Message + "|" + message.Message, ex);
                }
            });
        }
        public SampleTestRunner()
        {
            var list = new List<Student>();
            var rand = new Random();
            const int total = 10000000;
            Console.WriteLine("Creating list ...");
            for(var i = 0; i < total; i++)
            {
                var student = new Student
                    {
                        FirstName = rand.Next().ToString(),
                        Id = i,
                        LastName = rand.Next().ToString(),
                        IsInternational = rand.Next(2) != 0,
                        Gender = rand.Next(2) == 0 ? "Male" : "Female",
                    };
                list.Add(student);
            }

            Console.WriteLine("Filtering ...");
            var st = DateTime.Now;
            var service = new FilterService<Student>();
            service.AddBinaryFilter(e => e.Id < total);
            service.AddBinaryFilter(e => e.FirstName.Contains("1"));
            service.AddBinaryFilter(e => e.LastName.Contains("2"));
            service.AddBinaryFilter(e => !e.IsInternational);
            service.AddBinaryFilter(e => e.Gender.Equals("Female"));
            var filtered = service.Filter(list);
            var et = DateTime.Now;
            Console.WriteLine("Done filtering...");
            Console.WriteLine("Filtering time (in ms): {0}", et.Subtract(st).TotalMilliseconds);

            Console.WriteLine("Total Count: {0}", list.Count);
            Console.WriteLine("Filtered Count: {0}", filtered.Count());
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var apple = new Product("Apple", Color.Green, Size.Small);
            var tree  = new Product("Tree", Color.Green, Size.Large);
            var house = new Product("House", Color.Blue, Size.Large);

            Product[] products = { apple, tree, house };

            var fs = new FilterService();

            Console.WriteLine("Green products (new):");
            var specification = new ColorSpecification(Color.Green);
            var filtered      = fs.Filter(products, specification);

            foreach (var p in filtered)
            {
                Console.WriteLine($" - {p.Name} is green");
            }

            Console.WriteLine("Large products");
            foreach (var p in fs.Filter(products, new SizeSpecification(Size.Large)))
            {
                Console.WriteLine($" - {p.Name} is large");
            }

            Console.WriteLine("Medium Red products");
            var redSpec           = new ColorSpecification(Color.Red);
            var mediumSpec        = new SizeSpecification(Size.Medium);
            var andSpecification  = new AndSpecification <Product>(redSpec, mediumSpec);
            var mediumRedFiltered = fs.Filter(products, andSpecification);

            foreach (var p in mediumRedFiltered)
            {
                Console.WriteLine($" - {p.Name} is large");
            }

            Console.WriteLine("Large blue items");
            foreach (var p in fs.Filter(products,
                                        new AndSpecification <Product>(
                                            new ColorSpecification(Color.Blue),
                                            new SizeSpecification(Size.Large)))
                     )
            {
                Console.WriteLine($" - {p.Name} is big and blue");
            }
        }
示例#5
0
        public ActionResult <DateComparisonObjectDto[]> Filter(String firstDate, String secondDate)
        {
            try {
                var mappedFirstDate  = _dateMapper.MapDate(firstDate);
                var mappedSecondDate = _dateMapper.MapDate(secondDate);

                if (mappedFirstDate > mappedSecondDate)
                {
                    return(Ok(Array.Empty <DateComparisonObjectDto>()));
                }

                return(Ok(_filterService.Filter(mappedFirstDate, mappedSecondDate)));
            } catch (ArgumentException) {
                return(BadRequest());
            } catch (NotSupportedException) {
                return(BadRequest());
            }
        }
示例#6
0
 public void SmsLog_OnReceived(MessageBody message)
 {
     if (message.Error)
     {
         logger.LogError(new EventId(1001), message.Exception, message.ErrorMessage);
         return;
     }
     try
     {
         var log = JsonConvert.DeserializeObject <LogMessage>(message.Content);
         logWriter.Write(log);
         filterService.Filter(log);
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message + "|" + message.Content, ex);
     }
     message.Consumer.Model.BasicAck(message.BasicDeliver.DeliveryTag, true);
 }
示例#7
0
 public static IQueryable <T> DynamicQueryNetFilter <T>(this IQueryable <T> input, FilterInput filterinput) => filterinput != null?FilterService.Filter(input, filterinput) : input;
示例#8
0
 public static IQueryable <T> DynamicQueryNetFilter <T>(this IQueryable <T> input, List <FilterInput> filterInputs) => filterInputs != null?FilterService.Filter(input, filterInputs) : input;
示例#9
0
 public static IQueryable <T> Filter <T>(this IQueryable <T> input, FilterInput filterinput)
 {
     return(filterinput != null?FilterService.Filter(input, filterinput) : input);
 }
示例#10
0
 public static IQueryable <T> Filter <T>(this IQueryable <T> input, List <FilterInput> filterInputs)
 {
     return(filterInputs != null?FilterService.Filter(input, filterInputs) : input);
 }