Ejemplo n.º 1
0
        private void Handle(IReadOnlyCollection <FactOperation> operations)
        {
            _tracer.Debug("Handing fact operations started");
            var result = _factsReplicator.Replicate(operations);

            _telemetryPublisher.Publish <ErmProcessedOperationCountIdentity>(operations.Count);

            var statistics = result.OfType <RecalculateStatisticsOperation>().ToArray();
            var aggregates = result.OfType <AggregateOperation>().ToArray();

            // We always need to use different transaction scope to operate with operation sender because it has its own store
            using (var pushTransaction = new TransactionScope(TransactionScopeOption.RequiresNew,
                                                              new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.Zero
            }))
            {
                _tracer.Debug("Pushing events for statistics recalculation");
                _statisticsSender.Push(statistics);
                _telemetryPublisher.Publish <StatisticsEnqueuedOperationCountIdentity>(statistics.Length);

                _tracer.Debug("Pushing events for aggregates recalculation");
                _aggregateSender.Push(aggregates);
                _telemetryPublisher.Publish <AggregateEnqueuedOperationCountIdentity>(aggregates.Length);

                pushTransaction.Complete();
            }

            _tracer.Debug("Handing fact operations finished");
        }
Ejemplo n.º 2
0
        private StageResult Handle(Guid bucketId, IEnumerable <IAggregatableMessage> messages)
        {
            try
            {
                foreach (var message in messages.OfType <CorporateBusAggregatableMessage>())
                {
                    foreach (var dto in message.Dtos)
                    {
                        var importer   = _statisticsImporterFactory.Create(dto.GetType());
                        var opertaions = importer.Import(dto);
                        _telemetryPublisher.Publish <BitStatisticsEntityProcessedCountIdentity>(1);
                        _sender.Push(opertaions.Cast <RecalculateStatisticsOperation>());
                    }
                }

                return(MessageProcessingStage.Handling.ResultFor(bucketId).AsSucceeded());
            }
            catch (Exception ex)
            {
                _tracer.Error(ex, "Error when import facts for BIT");
                return(MessageProcessingStage.Handling.ResultFor(bucketId).AsFailed().WithExceptions(ex));
            }
        }