Example #1
0
        public decimal CalculateMargin(decimal lineCost, decimal linePrice, ICounterMeasure counter)
        {
            counter.Increment();
            var margin = (linePrice - lineCost) / linePrice;

            return(margin);
        }
 public DiagnosticsBehaviour()
 {
     _logger   = Log.Logger.ForContext(GetType());
     _received = Log.Logger.CountOperation(
         ReceivedCounterName,
         resolution: CounterResolution);
     _processed = Log.Logger.CountOperation(
         ProcessedCounterName,
         resolution: CounterResolution);
 }
Example #3
0
 public DoubleIteration(ITestOutputHelper output)
 {
     _output               = output;
     _logCapture           = LoggingHelper.Capture(_output);
     _calcLinePriceCounter = Log.Logger.CountOperation(
         "CalculateLinePrice Counter",
         "operation(s)",
         false);
     _calcLineCostCounter = Log.Logger.CountOperation(
         "CalculateLineCost Counter",
         "operation(s)",
         false);
     _calcMarginCounter = Log.Logger.CountOperation(
         "CalculateMargin Counter",
         "operation(s)",
         false);
 }
 public DoubleIteration(ITestOutputHelper output)
 {
     _output = output;
     _logCapture = LoggingHelper.Capture(_output);
     _calcLinePriceCounter = Log.Logger.CountOperation(
         "CalculateLinePrice Counter",
         "operation(s)",
         false);
     _calcLineCostCounter = Log.Logger.CountOperation(
         "CalculateLineCost Counter",
         "operation(s)",
         false);
     _calcMarginCounter = Log.Logger.CountOperation(
         "CalculateMargin Counter",
         "operation(s)",
         false);
 }
        public async Task Handle(IBotNotification <IClientEvent> notification)
        {
            var context = notification.Context;
            var @event  = notification.Event;

            _processed = _processed ??
                         context.Logger.CountOperation(ProcessedCounterName, resolution: ProcessedCounterResolution);
            var diagnosticProperties = new ILogEventEnricher[]
            {
                new PropertyEnricher("ConnectionId", context.Connection.Id),
                new PropertyEnricher("BotId", context.BotId),
                new PropertyEnricher("UserId", context.UserId),
                new PropertyEnricher("EventType", notification.Event.GetType().Name)
            };

            using (LogContext.Push(diagnosticProperties))
            {
                context.Logger.Debug("[Bot:{BotId}:{UserId}] Started to handle {EventType}.",
                                     context.BotId,
                                     context.UserId,
                                     @event.GetType().Name);
                try
                {
                    using (context.Logger.BeginTimedOperation(OperationDescription))
                    {
                        await _next.Handle(notification);
                    }
                }
                finally
                {
                    _processed.Increment();
                    context.Logger.Debug("[Bot:{BotId}:{UserId}] Finished to handle {EventType}.",
                                         context.BotId,
                                         context.UserId,
                                         @event.GetType().Name);
                }
            }
        }
Example #6
0
        public Bot(string botId, IClientConnection connection, params IBotBehaviour[] behaviours)
        {
            if (string.IsNullOrEmpty(botId))
            {
                throw new ArgumentException("Bot id cannot be null or empty.", nameof(botId));
            }
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            _state        = BotState.Idle;
            _context      = new BotContext(botId, connection, Stop, Notify);
            _subscription = connection.Events.Subscribe(OnClientEvent, OnClientException, OnClientCompleted);
            var allBehaviours = behaviours.ToList();
            var dispatcher    = new DispatcherBehaviour(allBehaviours);
            //var retry = new RetryBehaviour(dispatcher);
            var errorHandling = new ErrorHandlingBehaviour(dispatcher);
            var diagnostics   = new DiagnosticsBehaviour(errorHandling);

            _entryBehaviour = diagnostics;
            _received       = _context.Logger.CountOperation(ReceivedCounterName, resolution: ReceivedCounterResolution);
            Events          = Observable.Empty <IBotEvent>();
        }
Example #7
0
 public decimal CalculateLineCost(short qty, decimal unitCost, ICounterMeasure counter)
 {
     Thread.Sleep(500);
     counter.Increment();
     return(qty * unitCost);
 }
Example #8
0
 public CounterRecorder(ICounterMeasure meterMeasure)
 {
     this.counter = meterMeasure;
 }
 public decimal CalculateMargin(decimal lineCost, decimal linePrice, ICounterMeasure counter)
 {
     counter.Increment();
     var margin = (linePrice - lineCost) / linePrice;
     return margin;
 }
 public decimal CalculateLinePrice(short qty, decimal unitPrice, ICounterMeasure counter)
 {
     Thread.Sleep(500);
     counter.Increment();
     return qty * unitPrice;
 }
 public ErrorLoggingBehaviour()
 {
     _logger  = Log.Logger.ForContext(GetType());
     _counter = _logger.CountOperation(ErrorsCounterName);
 }