コード例 #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;
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateQuotationsScheduledJob" /> class.
 /// </summary>
 /// <param name="queryDispatcher">The query dispatcher.</param>
 /// <param name="commandDispatcher">The command dispatcher.</param>
 /// <param name="quotationServiceClient">The quotation service client.</param>
 public UpdateQuotationsScheduledJob(
     IQueryDispatcher queryDispatcher,
     ICommandDispatcher commandDispatcher,
     IQuotationServiceClient quotationServiceClient)
 {
     _queryDispatcher        = queryDispatcher;
     _commandDispatcher      = commandDispatcher;
     _quotationServiceClient = quotationServiceClient;
     Status = ScheduledJobStatus.Stopped;
 }