Beispiel #1
0
        /// <summary>
        /// Determines if the current system is configured
        /// </summary>
        public bool IsConfigured(System.Xml.XmlDocument configurationDom)
        {
            // This is a complex configuration so here we go.
            XmlElement configSectionNode = configurationDom.SelectSingleNode("//*[local-name() = 'configSections']/*[local-name() = 'section'][@name = 'marc.hi.ehrs.cr.messaging.admin']") as XmlElement,
                       configRoot        = configurationDom.SelectSingleNode("//*[local-name() = 'marc.hi.ehrs.cr.messaging.admin']") as XmlElement,
                       wcfRoot           = configurationDom.SelectSingleNode("//*[local-name() = 'system.serviceModel']") as XmlElement,
                       multiNode         = configurationDom.SelectSingleNode(String.Format("//*[local-name() = 'marc.hi.ehrs.svc.messaging.multi']//*[local-name() = 'add'][@type = '{0}']", typeof(ClientRegistryAdminInterface).AssemblyQualifiedName)) as XmlElement;

            XmlNodeList revisions = configurationDom.SelectNodes("//*[local-name() = 'marc.hi.ehrs.svc.messaging.everest']/*[local-name() = 'revision']");

            // Load the current config if applicable
            if (configRoot != null)
            {
                this.m_configuration = new ConfigurationSectionHandler().Create(null, null, configRoot) as ClientRegistryInterfaceConfiguration;
            }
            else
            {
                this.m_configuration = new ClientRegistryInterfaceConfiguration("adminSvc");
            }

            bool isConfigured = configSectionNode != null && configRoot != null &&
                                wcfRoot != null && this.m_configuration != null && multiNode != null;

            if (!this.m_needsSync)
            {
                return(isConfigured);
            }
            this.EnableConfiguration = isConfigured;
            this.m_needsSync         = false;

            if (configRoot == null) // makes the following logic clearer
            {
                configRoot = configurationDom.CreateElement("marc.hi.ehrs.cr.messaging.admin");
            }

            // Loop through the configuration templates
            if (wcfRoot != null)
            {
                this.m_panel.SetConfiguration(wcfRoot, this.m_configuration);
            }


            return(isConfigured);
        }
        /// <summary>
        /// Add a revision panel
        /// </summary>
        public void SetConfiguration(XmlElement wcfConfig, ClientRegistryInterfaceConfiguration configuration)
        {
            this.m_configuration = configuration;
            string behaviorConfigurationName = String.Empty,
                   endpointAddress           = string.Empty,
                   baseAddress = string.Empty,
                   bindingName = string.Empty,
                   bindingConfigurationName = string.Empty;

            string serviceName = configuration.WcfServiceName;

            // Have everything, now load from XML
            XmlElement serviceElement = wcfConfig.SelectSingleNode(String.Format("./*[local-name() = 'services']/*[local-name() = 'service'][@name = '{0}']", serviceName)) as XmlElement;

            if (serviceElement == null)
            {
                return;
            }
            if (serviceElement.Attributes["behaviorConfiguration"] != null)
            {
                behaviorConfigurationName = serviceElement.Attributes["behaviorConfiguration"].Value;
            }

            XmlElement endpointElement = serviceElement.SelectSingleNode("./*[local-name() = 'endpoint']") as XmlElement,
                       hostElement     = serviceElement.SelectSingleNode("./*[local-name() = 'host']/*[local-name() = 'baseAddresses']/*[local-name() = 'add']") as XmlElement;

            if (endpointElement == null)
            {
                return; // invalid WCF config with no ep element
            }
            // Base address
            if (hostElement != null && hostElement.Attributes["baseAddress"] != null)
            {
                baseAddress = hostElement.Attributes["baseAddress"].Value;
            }
            // EP element
            if (endpointElement != null)
            {
                if (endpointElement.Attributes["address"] != null)
                {
                    endpointAddress = endpointElement.Attributes["address"].Value;
                }
                if (endpointElement.Attributes["binding"] != null)
                {
                    bindingName = endpointElement.Attributes["binding"].Value;
                }
                if (endpointElement.Attributes["bindingConfiguration"] != null)
                {
                    bindingConfigurationName = endpointElement.Attributes["bindingConfiguration"].Value;
                }
            }

            this.Address = endpointAddress;

            // Behavior
            XmlElement behaviorElement = wcfConfig.SelectSingleNode(String.Format("./*[local-name() = 'behaviors']/*[local-name() = 'serviceBehaviors']/*[local-name() = 'behavior'][@name = '{0}']", behaviorConfigurationName)) as XmlElement;

            if (behaviorElement != null)
            {
                // Service debug?
                string addrScheme = "http";
                try
                {
                    Uri tUri = new Uri(endpointAddress);
                    addrScheme = tUri.Scheme;
                }
                catch { }

                XmlNode serviceDebug    = behaviorElement.SelectSingleNode("./*[local-name() = 'serviceDebug']/@includeExceptionDetailInFaults"),
                        serviceMetaData = behaviorElement.SelectSingleNode(String.Format("./*[local-name() = 'serviceMetadata']/@{0}GetEnabled", addrScheme.ToLower()));
                XmlElement credentials  = behaviorElement.SelectSingleNode("./*[local-name() = 'serviceCredentials']/*[local-name() = 'serviceCertificate']") as XmlElement;

                if (serviceDebug != null)
                {
                    this.ServiceDebugEnabled = Boolean.Parse(serviceDebug.Value);
                }
                if (serviceMetaData != null)
                {
                    this.ServiceMetaDataEnabled = Boolean.Parse(serviceMetaData.Value);
                }
                if (credentials != null)
                {
                    if (credentials.Attributes["storeName"] != null)
                    {
                        this.StoreName = (StoreName)Enum.Parse(typeof(StoreName), credentials.Attributes["storeName"].Value);
                    }
                    if (credentials.Attributes["storeLocation"] != null)
                    {
                        this.StoreLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), credentials.Attributes["storeLocation"].Value);
                    }
                    if (credentials.Attributes["findValue"] != null && credentials.Attributes["x509FindType"] != null)
                    {
                        X509FindType findType = (X509FindType)Enum.Parse(typeof(X509FindType), credentials.Attributes["x509FindType"].Value);
                        X509Store    store    = new X509Store(this.StoreName, this.StoreLocation);
                        try
                        {
                            store.Open(OpenFlags.ReadOnly);
                            var certs = store.Certificates.Find(findType, credentials.Attributes["findValue"].Value, false);
                            if (certs.Count == 1)
                            {
                                this.Certificate = certs[0];
                            }
                            else
                            {
                                MessageBox.Show("Could not locate the specified certificate for endpoint");
                            }
                        }
                        finally
                        {
                            store.Close();
                        }
                    }
                }
            }

            // Binding
            XmlElement bindingElement = wcfConfig.SelectSingleNode(String.Format("./*[local-name() = 'bindings']/*[local-name() = '{0}']/*[local-name() = 'binding'][@name = '{1}']", bindingName, bindingConfigurationName)) as XmlElement;

            if (bindingElement != null)
            {
                // Client credentials (ignore the rest)
                XmlElement credentials = bindingElement.SelectSingleNode("./*[local-name() = 'security']/*[local-name() = 'transport']") as XmlElement;
                this.RequireClientCerts = credentials != null && credentials.Attributes["clientCredentialType"] != null && credentials.Attributes["clientCredentialType"].Value == "Certificate";
            }
        }
 /// <summary>
 /// Creates a new instance of the client registry interface
 /// </summary>
 public ClientRegistryAdminInterface()
 {
     this.m_configuration = ConfigurationManager.GetSection("marc.hi.ehrs.cr.messaging.admin") as ClientRegistryInterfaceConfiguration;
 }