internal static string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
 {
     string firstAddress;
     ServiceInfo info = new ServiceInfo(serviceHost);
     string serviceName = info.ServiceName;
     if (!TryGetFullVirtualPath(serviceHost, out firstAddress))
     {
         firstAddress = info.FirstAddress;
     }
     int totalLen = (serviceName.Length + firstAddress.Length) + 2;
     if (totalLen > 0x40)
     {
         int num2 = 0;
         truncOptions options = GetCompressionTasks(totalLen, serviceName.Length, firstAddress.Length);
         if ((options & (truncOptions.NoBits | truncOptions.service32)) > truncOptions.NoBits)
         {
             num2 = 0x20;
             serviceName = PerformanceCountersBase.GetHashedString(serviceName, num2 - 2, (serviceName.Length - num2) + 2, true);
         }
         if ((options & (truncOptions.NoBits | truncOptions.uri31)) > truncOptions.NoBits)
         {
             num2 = 0x1f;
             firstAddress = PerformanceCountersBase.GetHashedString(firstAddress, 0, (firstAddress.Length - num2) + 2, false);
         }
     }
     return (serviceName + "@" + firstAddress.Replace('/', '|'));
 }
 internal static string GetReference(ServiceInfo serviceInfo)
 {
     Fx.Assert(null != serviceInfo, "");
     return String.Format(CultureInfo.InvariantCulture, AdministrationStrings.Service +
                             "." +
                             AdministrationStrings.DistinguishedName +
                             "='{0}'," +
                             AdministrationStrings.ProcessId +
                             "={1}",
                          serviceInfo.DistinguishedName,
                          AppDomainInfo.Current.ProcessId);
 }
 void FillBehaviorsInfo(ServiceInfo info, IWmiInstance instance)
 {
     Fx.Assert(null != instance, "");
     List<IWmiInstance> behaviors = new List<IWmiInstance>(info.Behaviors.Count);
     foreach (IServiceBehavior behavior in info.Behaviors)
     {
         IWmiInstance behaviorInstance;
         FillBehaviorInfo(behavior, instance, out behaviorInstance);
         if (null != behaviorInstance)
         {
             behaviors.Add(behaviorInstance);
         }
     }
     instance.SetProperty(AdministrationStrings.Behaviors, behaviors.ToArray());
 }
        void FillServiceInfo(ServiceInfo info, IWmiInstance instance)
        {
            Fx.Assert(null != instance, "");
            Fx.Assert(null != info, "");
            ProviderBase.FillCollectionInfo(info.Service.BaseAddresses, instance, AdministrationStrings.BaseAddresses);
            instance.SetProperty(AdministrationStrings.CounterInstanceName, PerformanceCounters.PerformanceCountersEnabled ? ServicePerformanceCounters.GetFriendlyInstanceName(info.Service) : String.Empty);
            instance.SetProperty(AdministrationStrings.ConfigurationName, info.ConfigurationName);
            instance.SetProperty(AdministrationStrings.DistinguishedName, info.DistinguishedName);
            instance.SetProperty(AdministrationStrings.Name, info.Name);
            instance.SetProperty(AdministrationStrings.Namespace, info.Namespace);
            instance.SetProperty(AdministrationStrings.Metadata, info.Metadata);
            instance.SetProperty(AdministrationStrings.Opened, ManagementExtension.GetTimeOpened(info.Service));


            FillBehaviorsInfo(info, instance);
            FillExtensionsInfo(info, instance);
            FillChannelsInfo(info, instance);
        }
 static void FillExtensionsInfo(ServiceInfo info, IWmiInstance instance)
 {
     Fx.Assert(null != instance, "");
     Fx.Assert(null != info, "");
     ProviderBase.FillCollectionInfo(info.Service.Extensions, instance, AdministrationStrings.Extensions);
 }
 internal static string GetReference(ServiceInfo serviceInfo)
 {
     return(string.Format(CultureInfo.InvariantCulture, "Service.DistinguishedName='{0}',ProcessId={1}", new object[] { serviceInfo.DistinguishedName, AppDomainInfo.Current.ProcessId }));
 }
 private static void FillExtensionsInfo(ServiceInfo info, IWmiInstance instance)
 {
     ProviderBase.FillCollectionInfo(info.Service.Extensions, instance, "Extensions");
 }
 private static string GetServiceUri(ServiceHostBase serviceHost, ServiceInfo serviceInfo)
 {
     string uri;
     if (!TryGetFullVirtualPath(serviceHost, out uri))
     {
         uri = serviceInfo.FirstAddress;
     }
     return uri;
 }
 private static string GetFullInstanceName(ServiceHostBase serviceHost)
 {
     // instance name is: serviceName@uri
     ServiceInfo serviceInfo = new ServiceInfo(serviceHost);
     string serviceName = serviceInfo.ServiceName;
     string uri = GetServiceUri(serviceHost, serviceInfo);
     return String.Format("{0}@{1}", serviceName, uri);
 }
 private void FillServiceInfo(ServiceInfo info, IWmiInstance instance)
 {
     ProviderBase.FillCollectionInfo((ICollection) info.Service.BaseAddresses, instance, "BaseAddresses");
     instance.SetProperty("CounterInstanceName", PerformanceCounters.PerformanceCountersEnabled ? ServicePerformanceCountersBase.CreateFriendlyInstanceName(info.Service) : string.Empty);
     instance.SetProperty("ConfigurationName", info.ConfigurationName);
     instance.SetProperty("DistinguishedName", info.DistinguishedName);
     instance.SetProperty("Name", info.Name);
     instance.SetProperty("Namespace", info.Namespace);
     instance.SetProperty("Metadata", info.Metadata);
     instance.SetProperty("Opened", ManagementExtension.GetTimeOpened(info.Service));
     this.FillBehaviorsInfo(info, instance);
     FillExtensionsInfo(info, instance);
     this.FillChannelsInfo(info, instance);
 }
 internal static string GetReference(ServiceInfo serviceInfo)
 {
     return string.Format(CultureInfo.InvariantCulture, "Service.DistinguishedName='{0}',ProcessId={1}", new object[] { serviceInfo.DistinguishedName, AppDomainInfo.Current.ProcessId });
 }
 private static void FillExtensionsInfo(ServiceInfo info, IWmiInstance instance)
 {
     ProviderBase.FillCollectionInfo(info.Service.Extensions, instance, "Extensions");
 }
 private void FillChannelsInfo(ServiceInfo info, IWmiInstance instance)
 {
     int num = 0;
     List<IWmiInstance> list = new List<IWmiInstance>();
     foreach (System.ServiceModel.InstanceContext context in info.Service.GetInstanceContexts())
     {
         lock (context.ThisLock)
         {
             num += context.WmiChannels.Count;
             foreach (IChannel channel in context.WmiChannels)
             {
                 IWmiInstance instance2 = instance.NewInstance("Channel");
                 this.FillChannelInfo(channel, instance2);
                 list.Add(instance2);
             }
         }
     }
     instance.SetProperty("OutgoingChannels", list.ToArray());
 }
 private void FillBehaviorsInfo(ServiceInfo info, IWmiInstance instance)
 {
     List<IWmiInstance> list = new List<IWmiInstance>(info.Behaviors.Count);
     foreach (IServiceBehavior behavior in info.Behaviors)
     {
         IWmiInstance instance2;
         this.FillBehaviorInfo(behavior, instance, out instance2);
         if (instance2 != null)
         {
             list.Add(instance2);
         }
     }
     instance.SetProperty("Behaviors", list.ToArray());
 }
        void FillChannelsInfo(ServiceInfo info, IWmiInstance instance)
        {
            Fx.Assert(null != instance, "");
            Fx.Assert(null != info, "");
            int channelsCount = 0;

            List<IWmiInstance> instances = new List<IWmiInstance>();
            IEnumerable<InstanceContext> contexts = info.Service.GetInstanceContexts();
            foreach (InstanceContext instanceContext in contexts)
            {
                lock (instanceContext.ThisLock)
                {
                    channelsCount += instanceContext.WmiChannels.Count;
                    foreach (IChannel channel in instanceContext.WmiChannels)
                    {
                        IWmiInstance channelInstance = instance.NewInstance(AdministrationStrings.Channel);
                        FillChannelInfo(channel, channelInstance);
                        instances.Add(channelInstance);
                    }
                }
            }

            instance.SetProperty(AdministrationStrings.Channels, instances.ToArray());
        }
        private static string GetShortInstanceName(ServiceHostBase serviceHost)
        {
            ServiceInfo serviceInfo = new ServiceInfo(serviceHost);
            string serviceName = serviceInfo.ServiceName;
            string uri = GetServiceUri(serviceHost, serviceInfo);

            int length = serviceName.Length + uri.Length + 2;

            if (length > maxCounterLength)
            {
                int count = 0;

                truncOptions tasks = ServicePerformanceCountersBase.GetCompressionTasks(
                    length, serviceName.Length, uri.Length);

                //if necessary, compress service name to 8 chars with a 2 char hash code
                if ((tasks & truncOptions.service32) > 0)
                {
                    count = 32;
                    serviceName = GetHashedString(serviceName, count - hashLength, serviceName.Length - count + hashLength, true);
                }

                //if necessary,  compress uri to 36 chars with a 2 char hash code
                if ((tasks & truncOptions.uri31) > 0)
                {
                    count = 31;
                    uri = GetHashedString(uri, 0, uri.Length - count + hashLength, false);
                }
            }

            // replace '/' with '|' because perfmon fails when '/' is in perfcounter instance name
            return serviceName + "@" + uri.Replace('/', '|');
        }
        static internal string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
        {
            // instance name is: serviceName@uri
            ServiceInfo serviceInfo = new ServiceInfo(serviceHost);
            string serviceName = serviceInfo.ServiceName;
            string uri;
            if (!TryGetFullVirtualPath(serviceHost, out uri))
            {
                uri = serviceInfo.FirstAddress;
            }
            int length = serviceName.Length + uri.Length + 2;

            if (length > maxCounterLength)
            {
                int count = 0;

                truncOptions tasks = ServicePerformanceCountersBase.GetCompressionTasks(
                    length, serviceName.Length, uri.Length);

                //if necessary, compress service name to 8 chars with a 2 char hash code
                if ((tasks & truncOptions.service32) > 0)
                {
                    count = 32;
                    serviceName = GetHashedString(serviceName, count - hashLength, serviceName.Length - count + hashLength, true);
                }

                //if necessary,  compress uri to 36 chars with a 2 char hash code
                if ((tasks & truncOptions.uri31) > 0)
                {
                    count = 31;
                    uri = GetHashedString(uri, 0, uri.Length - count + hashLength, false);
                }
            }

            // replace '/' with '|' because perfmon fails when '/' is in perfcounter instance name
            return serviceName + "@" + uri.Replace('/', '|');
        }
 static void FillExtensionsInfo(ServiceInfo info, IWmiInstance instance)
 {
     Fx.Assert(null != instance, "");
     Fx.Assert(null != info, "");
     ProviderBase.FillCollectionInfo(info.Service.Extensions, instance, AdministrationStrings.Extensions);
 }