Opc.Ua.Configuration.PseudoComServer.LoadConfiguredEndpointFromRegistry C# (CSharp) Method

LoadConfiguredEndpointFromRegistry() private static method

Reads the ConfiguredEndpoint from the registry.
private static LoadConfiguredEndpointFromRegistry ( System.Guid clsid ) : ConfiguredEndpoint
clsid System.Guid
return ConfiguredEndpoint
        private static ConfiguredEndpoint LoadConfiguredEndpointFromRegistry(Guid clsid)
		{
			RegistryKey key = Registry.ClassesRoot.OpenSubKey(String.Format(@"CLSID\{{{0}}}\{1}", clsid, "Endpoint"));

			if (key != null)
			{                
                byte[] encodedEndpoint = null;

				try
				{
                    encodedEndpoint = key.GetValue(null) as byte[];
				}
				finally
				{
					key.Close();
				}

                if (encodedEndpoint == null)
                {
                    key = Registry.LocalMachine.OpenSubKey(String.Format(@"SOFTWARE\Wow6432Node\Classes\CLSID\{{{0}}}\{1}", clsid, "Endpoint"), true);

                    if (key != null)
                    {
                        try
                        {
                            encodedEndpoint = key.GetValue(null) as byte[];
                        }
                        finally
                        {
                            key.Close();
                        }
                    }
                }

                if (encodedEndpoint == null)
                {
                    return null;
                }

                MemoryStream istrm = new MemoryStream(encodedEndpoint, false);

                try
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(ConfiguredEndpoint));
                    return (ConfiguredEndpoint)serializer.ReadObject(istrm);
                }
                finally
                {
                    istrm.Close();
                }
            }

            return null;
		}