Beispiel #1
0
        /// <summary>
        /// Executes this job.
        /// </summary>
        public void Execute()
        {
            //TODO: Duplicate code, see QuotationController.UpdateQuotation

            Status = ScheduledJobStatus.Running;

            try
            {
                foreach (var stock in _queryDispatcher.Execute(new StockAllQuery()))
                {
                    var latestUpdate = stock.Quotations != null && stock.Quotations.Any() ? stock.Quotations.Max(q => q.Changed) : DateTime.MinValue;

                    var quotations = _quotationServiceClient.Get(stock.Id, latestUpdate.Date).ToList();

                    if (quotations.Any())
                    {
                        var cmd = new StockQuotationsAddOrChangeCommand(
                            stock.Id,
                            stock.OriginalVersion,
                            quotations);

                        _commandDispatcher.Execute(cmd);
                    }
                }
            }
            finally
            {
                Status = ScheduledJobStatus.Stopped;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Downloads the quotes.
        /// </summary>
        /// <param name="stockId">The stock identifier.</param>
        private void DownloadQuotes(Guid stockId)
        {
            var quotes = _quoteServiceClient.Get(stockId).ToList();

            if (quotes.Any())
            {
                var cmd = new StockQuotationsAddOrChangeCommand(stockId, 0, quotes);
                _commandDispatcher.Execute(cmd);
            }
        }
        // GET: Stock/UpdateQuotation/5
        public IActionResult UpdateQuotation(Guid id)
        {
            //TODO: Duplicate code, see QuotationController.UpdateQuotation
            var stock = _queryDispatcher.Execute(new StockByIdQuery(id));

            if (stock == null)
            {
                return(PartialView("DisplayTemplates/UpdateStatus", new UpdateQuotationStatusViewModel()
                {
                    Message = Resources.NoSuchStock,
                    Successfull = false
                }));
            }

            //Quotations before
            var quotationsBefore = _queryDispatcher.Execute(new StockQuotationsCountByIdQuery(id));

            var quotations = _quotationServiceClient.Get(stock.Id).ToList();

            if (quotations.Any())
            {
                var cmd = new StockQuotationsAddOrChangeCommand(
                    stock.Id,
                    stock.OriginalVersion,
                    quotations);

                _commandDispatcher.Execute(cmd);
            }

            //Statistics
            var existentQuotations = _queryDispatcher.Execute(new StockQuotationsCountByIdQuery(id));

            return(PartialView("DisplayTemplates/UpdateStatus", new UpdateQuotationStatusViewModel()
            {
                Id = stock.Id,
                Message = string.Format(Resources.StatusQuotations, existentQuotations, existentQuotations - quotationsBefore),
                Successfull = quotations.Any()
            }));
        }