Esempio n. 1
0
        public void Product4()
        {
            string xmlMessage = Request.Content.ReadAsStringAsync().Result;

            if (xmlMessage.Contains("<Event"))
            {
                var productId = 4;
                ProductsEventsConcurencyQueue.GetInstance().Storage.store[productId].Enqueue(xmlMessage);
                // 5 is ProductId
            }
        }
Esempio n. 2
0
        public void Product5()
        {
            string xmlMessage = Request.Content.ReadAsStringAsync().Result;

            if (xmlMessage.Contains("<Event"))
            {
                xmlMessage = xmlMessage.Substring(5, xmlMessage.Length - 5);// removed 'data='

                var productId = 5;
                ProductsEventsConcurencyQueue.GetInstance().Storage.store[productId].Enqueue(xmlMessage);
                // 5 is ProductId
            }
        }
        protected override void Process(HttpListenerContext context)
        {
            try
            {
                log.Info("start downloading from push-service");

                using (StreamReader reader = new StreamReader(context.Request.InputStream))
                {
                    string xmlMessage = reader.ReadToEnd();

                    reader.Close();

                    context.Response.StatusCode = (int)HttpStatusCode.OK;

                    context.Response.Close();

                    //if (xmlMessage.Contains("<Event"))
                    {
                        if (xmlMessage.StartsWith("data="))
                        {
                            xmlMessage = xmlMessage.Substring(5, xmlMessage.Length - 5);
                        }

                        ProductsEventsConcurencyQueue.GetInstance().Storage.store[productId].Enqueue(xmlMessage);
                    }
                }
            }
            catch (Exception e)
            {
                var message = String.Format("{0}; {1}", e.Message, e.StackTrace);

                log.Error(message);

                context.Response.StatusCode = (int)HttpStatusCode.OK;

                context.Response.Close();
            }
        }
Esempio n. 4
0
        // Entry ppint. Here all services start.
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            // Checking. Is receiving of push messages was enabled?
            var isPushEnabled = bool.Parse(ConfigurationManager.AppSettings[SchedulerConfig.IsPushEnabledAlias]);

            if (isPushEnabled)
            {
                // Initialization global queue with push-services(products).
                var productsIds = new List <int> {
                    2, 3, 4, 5
                };
                foreach (var product in productsIds)
                {
                    ProductsEventsConcurencyQueue.GetInstance().Storage.store.Add(product, new ConcurrentQueue <string>());
                }

                // Push-scheduler start. It process all push messages.
                var pushScheduler = new LSports.Scheduler.Jobs.XmlPushSheduler();
                pushScheduler.Start();
            }

            // Is pull-service enabling? Pull service always download events from Lsports-server.
            var isPullEnabled = bool.Parse(ConfigurationManager.AppSettings[SchedulerConfig.IsPullEnabledAlias]);

            if (isPullEnabled)
            {
                var pullScheduler = new LSports.Scheduler.Jobs.XmlPullSheduler();
                pullScheduler.Start();
            }

            // This scheduler always each N hours sent report about DVS work. This email send in email, which was set in web.config.
            var reporter = new ReporterSheduler();

            reporter.Start();
        }
Esempio n. 5
0
        public override void Run()
        {
            try
            {
                // We do't all arrival messages for product #5, because it has thousands of identical messages.
                // We insert only one common message
                var SpecialProductId = 5;// special conditions for product 5

                // if 'true' - we check all push-products
                checkingProductIds = productRepository.GetListByType(true).Select(x => x.Id).ToList();

                InitDictionary();

                var validationRules    = GetValidationRules();
                var validationSettings = GetValidationSettingsForProducts(checkingProductIds);

                // mapping val.rules to val.settings(optimization for validation)
                SetRulesForSettings(validationSettings, validationRules);

                var productsTasks = new List <Task>();

                // one product - one parallel task
                foreach (var checkingProductId in checkingProductIds)
                {
                    var queue           = ProductsEventsConcurencyQueue.GetInstance().Storage.store[checkingProductId];
                    var productSettings = validationSettings.Where(x => x.ProductId == checkingProductId).ToList();

                    var count = Math.Min(queue.Count, MAX_DEQUE_COUNT);

                    if (count > 0)
                    {
                        var task = Task.Factory.StartNew(() =>
                        {
                            var messages = new List <string>();

                            // extraction from queue
                            for (var i = 0; i < count; i++)
                            {
                                var message = "";

                                if (queue.TryDequeue(out message))
                                {
                                    messages.Add(message);
                                } // pass
                            }

                            // processing all received messages from queue(by limit for each product)
                            ProcessArrivalMessagesForProduct(checkingProductId, messages, productSettings, count,
                                                             checkingProductId != SpecialProductId);
                        });

                        productsTasks.Add(task);
                    }
                }

                if (productsTasks.Count > 0)
                {
                    Task.WaitAll(productsTasks.ToArray());
                }
            }
            catch (Exception e)
            {
                var errorMessage = GetExceptionInfo(e);

                _log.Error(errorMessage);
            }
        }