public MessageBusSendInterceptorInvocation(IMessageBusSendInterceptor interceptor, IColomboSendInvocation nextInvocation)
        {
            if (interceptor == null) throw new ArgumentNullException("interceptor");
            if (nextInvocation == null) throw new ArgumentNullException("nextInvocation");
            Contract.EndContractBlock();

            this.interceptor = interceptor;
            this.nextInvocation = nextInvocation;
        }
        /// <summary>
        /// Puts the key in the Context.
        /// </summary>
        public void Intercept(IColomboSendInvocation nextInvocation)
        {
            if (nextInvocation == null) throw new ArgumentNullException("nextInvocation");
            Contract.EndContractBlock();

            foreach (var request in nextInvocation.Requests)
            {
                if ((Thread.CurrentThread.CurrentUICulture != CultureInfo.InvariantCulture))
                    request.Context[CurrentCultureConstant.CultureContextKey] = Thread.CurrentThread.CurrentUICulture.Name;
            }

            nextInvocation.Proceed();
        }
        /// <summary>
        /// Monitor the performance.
        /// </summary>
        public void Intercept(IColomboSendInvocation invocation)
        {
            if (invocation == null) throw new ArgumentNullException("invocation");
            Contract.EndContractBlock();

            var watch = new Stopwatch();
            watch.Start();
            invocation.Proceed();
            watch.Stop();

            try
            {
                Contract.Assume(invocation.Requests != null);
                var instancesGroups = invocation.Requests.GroupBy(x => x.GetGroupName());

                foreach (var instanceGroups in instancesGroups)
                {
                    var instanceName = instanceGroups.Key;

                    using (var numMessagesSent = PerfCounterFactory.GetPerfCounter(PerfCounter.NumMessagesSent, instanceName))
                        numMessagesSent.IncrementBy(instanceGroups.LongCount());

                    using (var numMessagesSentPerSec = PerfCounterFactory.GetPerfCounter(PerfCounter.NumMessagesSentPerSec, instanceName))
                        numMessagesSentPerSec.IncrementBy(instanceGroups.LongCount());

                    using (var averageDurationForMessageSending = PerfCounterFactory.GetPerfCounter(PerfCounter.AverageDurationForMessageSending, instanceName))
                        averageDurationForMessageSending.IncrementBy(watch.ElapsedTicks);

                    using (var averageDurationForMessageSendingBase = PerfCounterFactory.GetPerfCounter(PerfCounter.AverageDurationForMessageSendingBase, instanceName))
                        averageDurationForMessageSendingBase.IncrementBy(instanceGroups.LongCount());
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("Error while computing performance counters values.", ex);
            }
        }
 public void Intercept(IColomboSendInvocation nextInvocation)
 {
     Contract.Requires<ArgumentNullException>(nextInvocation != null, "nextInvocation");
     throw new NotImplementedException();
 }