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 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;
        }
 void InitializeServicePerformanceCounters(ServiceHostBase serviceHost)
 {
     if (PerformanceCounters.PerformanceCountersEnabled)
     {
         ServicePerformanceCountersBase tempCounters = PerformanceCountersFactory.CreateServiceCounters(serviceHost);
         if (tempCounters != null && tempCounters.Initialized)
         {
             serviceHost.Counters = tempCounters;
         }
     }
     // Some perf. counters are enabled by default
     else if (PerformanceCounters.MinimalPerformanceCountersEnabled)
     {
         DefaultPerformanceCounters tempCounters = new DefaultPerformanceCounters(serviceHost);
         if (tempCounters.Initialized)
         {
             serviceHost.DefaultCounters = tempCounters;
         }
     }
 }
 public ServiceModelPerformanceCountersEntry(DefaultPerformanceCounters defaultServiceCounters)
 {
     this.defaultPerformanceCounters = defaultServiceCounters;
     this.performanceCounters        = new List <ServiceModelPerformanceCounters>();
 }
 private void InitializeServicePerformanceCounters(ServiceHostBase serviceHost)
 {
     if (PerformanceCounters.PerformanceCountersEnabled)
     {
         ServicePerformanceCountersBase base2 = PerformanceCountersFactory.CreateServiceCounters(serviceHost);
         if ((base2 != null) && base2.Initialized)
         {
             serviceHost.Counters = base2;
         }
     }
     else if (PerformanceCounters.MinimalPerformanceCountersEnabled)
     {
         DefaultPerformanceCounters counters = new DefaultPerformanceCounters(serviceHost);
         if (counters.Initialized)
         {
             serviceHost.DefaultCounters = counters;
         }
     }
 }
 public ServiceModelPerformanceCountersEntry(DefaultPerformanceCounters defaultServiceCounters)
 {
     this.defaultPerformanceCounters = defaultServiceCounters;
     this.performanceCounters = new List<ServiceModelPerformanceCounters>();
 }