static void FillContractInfo(EndpointInfo endpoint, IWmiInstance instance)
        {
            Fx.Assert(null != endpoint, "");
            Fx.Assert(null != instance, "");

            instance.SetProperty(AdministrationStrings.Contract, ContractInstanceProvider.ContractReference(endpoint.Contract.Name));
        }
 internal static void FillEndpointInfo(EndpointInfo endpoint, IWmiInstance instance)
 {
     Fx.Assert(null != endpoint, "");
     Fx.Assert(null != instance, "");
     instance.SetProperty(AdministrationStrings.CounterInstanceName, PerformanceCounters.PerformanceCountersEnabled ? EndpointPerformanceCounters.GetFriendlyInstanceName(endpoint.ServiceName, endpoint.Contract.Name, endpoint.Address.AbsoluteUri.ToUpperInvariant()) : String.Empty);
     instance.SetProperty(AdministrationStrings.Name, endpoint.Name);
     instance.SetProperty(AdministrationStrings.ContractName, endpoint.Contract.Name);
     FillAddressInfo(endpoint, instance);
     FillContractInfo(endpoint, instance);
     FillBindingInfo(endpoint, instance);
     FillBehaviorsInfo(endpoint, instance);
 }
        string GetOperationCounterInstanceName(string operationName, IWmiInstance endpointInstance)
        {
            Fx.Assert(null != endpointInstance, "");
            string       address      = (string)endpointInstance.GetProperty(AdministrationStrings.ListenUri);
            string       contractName = (string)endpointInstance.GetProperty(AdministrationStrings.ContractName);
            EndpointInfo endpointInfo = FindEndpoint(address, contractName);

            string result = String.Empty;

            if (PerformanceCounters.PerformanceCountersEnabled && null != endpointInfo)
            {
                result = OperationPerformanceCounters.GetFriendlyInstanceName(endpointInfo.ServiceName, endpointInfo.Contract.Name, operationName, endpointInfo.Address.AbsoluteUri.ToUpperInvariant());
            }

            return(result);
        }
        static void FillBehaviorsInfo(EndpointInfo info, IWmiInstance instance)
        {
            Fx.Assert(null != instance, "");
            List <IWmiInstance> behaviors = new List <IWmiInstance>(info.Behaviors.Count);

            foreach (IEndpointBehavior behavior in info.Behaviors)
            {
                IWmiInstance behaviorInstance;
                FillBehaviorInfo(behavior, instance, out behaviorInstance);
                if (null != behaviorInstance)
                {
                    behaviors.Add(behaviorInstance);
                }
            }
            instance.SetProperty(AdministrationStrings.Behaviors, behaviors.ToArray());
        }
        static void FillAddressInfo(EndpointInfo endpoint, IWmiInstance instance)
        {
            Fx.Assert(null != endpoint, "");
            Fx.Assert(null != instance, "");
            string[] headers = new string[endpoint.Headers.Count];
            int      i       = 0;

            foreach (AddressHeader header in endpoint.Headers)
            {
                PlainXmlWriter xmlWriter = new PlainXmlWriter();
                header.WriteAddressHeader(xmlWriter);
                headers[i++] = xmlWriter.ToString();
            }
            ProviderBase.FillCollectionInfo(headers, instance, AdministrationStrings.AddressHeaders);
            instance.SetProperty(AdministrationStrings.Address, endpoint.Address == null ? String.Empty : endpoint.Address.ToString());
            instance.SetProperty(AdministrationStrings.ListenUri, endpoint.ListenUri == null ? String.Empty : endpoint.ListenUri.ToString());
            instance.SetProperty(AdministrationStrings.Identity, endpoint.Identity == null ? String.Empty : endpoint.Identity.ToString());
        }
        bool IWmiProvider.GetInstance(IWmiInstance instance)
        {
            Fx.Assert(null != instance, "");
            bool bFound = false;

            if (OwnInstance(instance))
            {
                string       address      = (string)instance.GetProperty(AdministrationStrings.ListenUri);
                string       contractName = (string)instance.GetProperty(AdministrationStrings.ContractName);
                EndpointInfo endpointInfo = FindEndpoint(address, contractName);

                if (null != endpointInfo)
                {
                    FillEndpointInfo(endpointInfo, instance);
                    bFound = true;
                }
            }

            return(bFound);
        }
        static void FillBindingInfo(EndpointInfo endpoint, IWmiInstance instance)
        {
            Fx.Assert(null != endpoint, "");
            Fx.Assert(null != instance, "");
            IWmiInstance binding = instance.NewInstance(AdministrationStrings.Binding);

            IWmiInstance[] bindings = new IWmiInstance[endpoint.Binding.Elements.Count];
            for (int j = 0; j < bindings.Length; ++j)
            {
                bindings[j] = binding;
                FillBindingInfo(endpoint.Binding.Elements[j], ref bindings[j]);
            }
            binding.SetProperty(AdministrationStrings.BindingElements, bindings);
            binding.SetProperty(AdministrationStrings.Name, endpoint.Binding.Name);
            binding.SetProperty(AdministrationStrings.Namespace, endpoint.Binding.Namespace);
            binding.SetProperty(AdministrationStrings.CloseTimeout, endpoint.Binding.CloseTimeout);
            binding.SetProperty(AdministrationStrings.Scheme, endpoint.Binding.Scheme);
            binding.SetProperty(AdministrationStrings.OpenTimeout, endpoint.Binding.OpenTimeout);
            binding.SetProperty(AdministrationStrings.ReceiveTimeout, endpoint.Binding.ReceiveTimeout);
            binding.SetProperty(AdministrationStrings.SendTimeout, endpoint.Binding.SendTimeout);

            instance.SetProperty(AdministrationStrings.Binding, binding);
        }
        static void FillBindingInfo(EndpointInfo endpoint, IWmiInstance instance)
        {
            Fx.Assert(null != endpoint, "");
            Fx.Assert(null != instance, "");
            IWmiInstance binding = instance.NewInstance(AdministrationStrings.Binding);

            IWmiInstance[] bindings = new IWmiInstance[endpoint.Binding.Elements.Count];
            for (int j = 0; j < bindings.Length; ++j)
            {
                bindings[j] = binding;
                FillBindingInfo(endpoint.Binding.Elements[j], ref bindings[j]);
            }
            binding.SetProperty(AdministrationStrings.BindingElements, bindings);
            binding.SetProperty(AdministrationStrings.Name, endpoint.Binding.Name);
            binding.SetProperty(AdministrationStrings.Namespace, endpoint.Binding.Namespace);
            binding.SetProperty(AdministrationStrings.CloseTimeout, endpoint.Binding.CloseTimeout);
            binding.SetProperty(AdministrationStrings.Scheme, endpoint.Binding.Scheme);
            binding.SetProperty(AdministrationStrings.OpenTimeout, endpoint.Binding.OpenTimeout);
            binding.SetProperty(AdministrationStrings.ReceiveTimeout, endpoint.Binding.ReceiveTimeout);
            binding.SetProperty(AdministrationStrings.SendTimeout, endpoint.Binding.SendTimeout);

            instance.SetProperty(AdministrationStrings.Binding, binding);
        }
 static void FillAddressInfo(EndpointInfo endpoint, IWmiInstance instance)
 {
     Fx.Assert(null != endpoint, "");
     Fx.Assert(null != instance, "");
     string[] headers = new string[endpoint.Headers.Count];
     int i = 0;
     foreach (AddressHeader header in endpoint.Headers)
     {
         PlainXmlWriter xmlWriter = new PlainXmlWriter();
         header.WriteAddressHeader(xmlWriter);
         headers[i++] = xmlWriter.ToString();
     }
     ProviderBase.FillCollectionInfo(headers, instance, AdministrationStrings.AddressHeaders);
     instance.SetProperty(AdministrationStrings.Address, endpoint.Address == null ? String.Empty : endpoint.Address.ToString());
     instance.SetProperty(AdministrationStrings.ListenUri, endpoint.ListenUri == null ? String.Empty : endpoint.ListenUri.ToString());
     instance.SetProperty(AdministrationStrings.Identity, endpoint.Identity == null ? String.Empty : endpoint.Identity.ToString());
 }
 static void FillBehaviorsInfo(EndpointInfo info, IWmiInstance instance)
 {
     Fx.Assert(null != instance, "");
     List<IWmiInstance> behaviors = new List<IWmiInstance>(info.Behaviors.Count);
     foreach (IEndpointBehavior behavior in info.Behaviors)
     {
         IWmiInstance behaviorInstance;
         FillBehaviorInfo(behavior, instance, out behaviorInstance);
         if (null != behaviorInstance)
         {
             behaviors.Add(behaviorInstance);
         }
     }
     instance.SetProperty(AdministrationStrings.Behaviors, behaviors.ToArray());
 }
 internal static void FillEndpointInfo(EndpointInfo endpoint, IWmiInstance instance)
 {
     Fx.Assert(null != endpoint, "");
     Fx.Assert(null != instance, "");
     instance.SetProperty(AdministrationStrings.CounterInstanceName, PerformanceCounters.PerformanceCountersEnabled ? EndpointPerformanceCounters.CreateFriendlyInstanceName(endpoint.ServiceName, endpoint.Contract.Name, endpoint.Address.AbsoluteUri.ToUpperInvariant()) : String.Empty);
     instance.SetProperty(AdministrationStrings.Name, endpoint.Name);
     instance.SetProperty(AdministrationStrings.ContractName, endpoint.Contract.Name);
     FillAddressInfo(endpoint, instance);
     FillContractInfo(endpoint, instance);
     FillBindingInfo(endpoint, instance);
     FillBehaviorsInfo(endpoint, instance);
 }
        static void FillContractInfo(EndpointInfo endpoint, IWmiInstance instance)
        {
            Fx.Assert(null != endpoint, "");
            Fx.Assert(null != instance, "");

            instance.SetProperty(AdministrationStrings.Contract, ContractInstanceProvider.ContractReference(endpoint.Contract.Name));
        }