internal ServiceModelPerformanceCounters(
            ServiceHostBase serviceHost,
            ContractDescription contractDescription,
            EndpointDispatcher endpointDispatcher)
        {
            this.perfCounterId = endpointDispatcher.PerfCounterId;

            if (PerformanceCounters.Scope == PerformanceCounterScope.All)
            {
                this.operationPerfCounters = new Dictionary <string, OperationPerformanceCountersBase>(contractDescription.Operations.Count);
                this.actionToOperation     = new SortedList <string, string>(contractDescription.Operations.Count);

                foreach (OperationDescription opDescription in contractDescription.Operations)
                {
                    Fx.Assert(null != opDescription.Messages, "OperationDescription.Messages should not be null");
                    Fx.Assert(opDescription.Messages.Count > 0, "OperationDescription.Messages should not be empty");
                    Fx.Assert(null != opDescription.Messages[0], "OperationDescription.Messages[0] should not be null");
                    if (null != opDescription.Messages[0].Action && !this.actionToOperation.Keys.Contains(opDescription.Messages[0].Action))
                    {
                        this.actionToOperation.Add(opDescription.Messages[0].Action, opDescription.Name);
                    }
                    OperationPerformanceCountersBase c;
                    if (!this.operationPerfCounters.TryGetValue(opDescription.Name, out c))
                    {
                        OperationPerformanceCountersBase counters =
                            PerformanceCountersFactory.CreateOperationCounters(serviceHost.Description.Name, contractDescription.Name, opDescription.Name, endpointDispatcher.PerfCounterBaseId);
                        if (counters != null && counters.Initialized)
                        {
                            this.operationPerfCounters.Add(opDescription.Name, counters);
                        }
                        else
                        {
                            // cleanup the others and return.
                            this.initialized = false;
                            return;
                        }
                    }
                }

                // add endpoint scoped perf counters
                EndpointPerformanceCountersBase endpointCounters = PerformanceCountersFactory.CreateEndpointCounters(serviceHost.Description.Name, contractDescription.Name, endpointDispatcher.PerfCounterBaseId);
                if (endpointCounters != null && endpointCounters.Initialized)
                {
                    this.endpointPerfCounters = endpointCounters;
                }
            }

            if (PerformanceCounters.PerformanceCountersEnabled)
            {
                this.servicePerfCounters = serviceHost.Counters;
            }
            if (PerformanceCounters.MinimalPerformanceCountersEnabled)
            {
                this.defaultPerfCounters = serviceHost.DefaultCounters;
            }
            this.initialized = true;
        }
 internal ServiceModelPerformanceCounters(ServiceHostBase serviceHost, ContractDescription contractDescription, EndpointDispatcher endpointDispatcher)
 {
     this.perfCounterId = endpointDispatcher.PerfCounterId;
     if (PerformanceCounters.Scope == PerformanceCounterScope.All)
     {
         this.operationPerfCounters = new Dictionary <string, OperationPerformanceCountersBase>(contractDescription.Operations.Count);
         this.actionToOperation     = new SortedList <string, string>(contractDescription.Operations.Count);
         foreach (OperationDescription description in contractDescription.Operations)
         {
             OperationPerformanceCountersBase base2;
             if ((description.Messages[0].Action != null) && !this.actionToOperation.Keys.Contains(description.Messages[0].Action))
             {
                 this.actionToOperation.Add(description.Messages[0].Action, description.Name);
             }
             if (!this.operationPerfCounters.TryGetValue(description.Name, out base2))
             {
                 OperationPerformanceCountersBase base3 = PerformanceCountersFactory.CreateOperationCounters(serviceHost.Description.Name, contractDescription.Name, description.Name, endpointDispatcher.PerfCounterBaseId);
                 if ((base3 != null) && base3.Initialized)
                 {
                     this.operationPerfCounters.Add(description.Name, base3);
                 }
                 else
                 {
                     this.initialized = false;
                     return;
                 }
             }
         }
         EndpointPerformanceCountersBase base4 = PerformanceCountersFactory.CreateEndpointCounters(serviceHost.Description.Name, contractDescription.Name, endpointDispatcher.PerfCounterBaseId);
         if ((base4 != null) && base4.Initialized)
         {
             this.endpointPerfCounters = base4;
         }
     }
     if (PerformanceCounters.PerformanceCountersEnabled)
     {
         this.servicePerfCounters = serviceHost.Counters;
     }
     if (PerformanceCounters.MinimalPerformanceCountersEnabled)
     {
         this.defaultPerfCounters = serviceHost.DefaultCounters;
     }
     this.initialized = true;
 }