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

SaveConfiguredEndpointToRegistry() private static method

Saves the ConfiguredEndpoint from the registry.
private static SaveConfiguredEndpointToRegistry ( System.Guid clsid, ConfiguredEndpoint endpoint ) : void
clsid System.Guid
endpoint ConfiguredEndpoint
return void
        private static void SaveConfiguredEndpointToRegistry(Guid clsid, ConfiguredEndpoint endpoint)
        {
            // serialize the object.
            MemoryStream ostrm = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(ostrm, System.Text.Encoding.UTF8);

            try
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(ConfiguredEndpoint));
                serializer.WriteObject(writer, endpoint);
            }
            finally
            {
                writer.Close();
            }

            // save it in the registry key.
			RegistryKey key = Registry.ClassesRoot.CreateSubKey(String.Format(@"CLSID\{{{0}}}\{1}", clsid, "Endpoint"));

			if (key != null)
			{              
				try
				{
                    key.SetValue(null, ostrm.ToArray(), RegistryValueKind.Binary);
				}
				finally
				{
					key.Close();
				}
            }

            // save it in the registry key.
            key = Registry.LocalMachine.OpenSubKey(String.Format(@"SOFTWARE\Wow6432Node\Classes\CLSID\{{{0}}}\{1}", clsid, "Endpoint"), true);

			if (key != null)
			{              
				try
				{
                    key.SetValue(null, ostrm.ToArray(), RegistryValueKind.Binary);
				}
				finally
				{
					key.Close();
				}
            }
		}
		#endregion