public SerializerProvider() { SecurityHelper.DemandPlugInSerializerPermissions(); List <SerializerDescriptor> list = new List <SerializerDescriptor>(); SerializerDescriptor serializerDescriptor = this.CreateSystemSerializerDescriptor(); if (serializerDescriptor != null) { list.Add(serializerDescriptor); } RegistryKey registryKey = SerializerProvider._rootKey.CreateSubKey("SOFTWARE\\Microsoft\\WinFX Serializers"); if (registryKey != null) { foreach (string keyName in registryKey.GetSubKeyNames()) { serializerDescriptor = SerializerDescriptor.CreateFromRegistry(registryKey, keyName); if (serializerDescriptor != null) { list.Add(serializerDescriptor); } } registryKey.Close(); } this._installedSerializers = list.AsReadOnly(); }
public static void UnregisterSerializer(SerializerDescriptor serializerDescriptor) { SecurityHelper.DemandPlugInSerializerPermissions(); if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } RegistryKey registryKey = SerializerProvider._rootKey.CreateSubKey("SOFTWARE\\Microsoft\\WinFX Serializers"); string text = string.Concat(new object[] { serializerDescriptor.DisplayName, "/", serializerDescriptor.AssemblyName, "/", serializerDescriptor.AssemblyVersion, "/", serializerDescriptor.WinFXVersion }); if (registryKey.OpenSubKey(text) == null) { throw new ArgumentException(SR.Get("SerializerProviderNotRegistered"), text); } registryKey.DeleteSubKeyTree(text); }
/// <summary> /// Load a SerializerDescriptor from the registry /// </summary> /// <remarks> /// Create a SerializerDescriptor from the registry /// /// This method currently requires full trust to run. /// </remarks> internal static SerializerDescriptor CreateFromRegistry(RegistryKey plugIns, string keyName) { SerializerDescriptor sd = new SerializerDescriptor(); try { RegistryKey key = plugIns.OpenSubKey(keyName); sd._displayName = GetNonEmptyRegistryString(key, "displayName"); sd._manufacturerName = GetNonEmptyRegistryString(key, "manufacturerName"); sd._manufacturerWebsite = new Uri(GetNonEmptyRegistryString(key, "manufacturerWebsite")); sd._defaultFileExtension = GetNonEmptyRegistryString(key, "defaultFileExtension"); sd._assemblyName = GetNonEmptyRegistryString(key, "assemblyName"); sd._assemblyPath = GetNonEmptyRegistryString(key, "assemblyPath"); sd._factoryInterfaceName = GetNonEmptyRegistryString(key, "factoryInterfaceName"); sd._assemblyVersion = new Version(GetNonEmptyRegistryString(key, "assemblyVersion")); sd._winFXVersion = new Version(GetNonEmptyRegistryString(key, "winFXVersion")); string uiLanguage = GetNonEmptyRegistryString(key, "uiLanguage"); key.Close(); // update language strings. if (!uiLanguage.Equals(CultureInfo.CurrentUICulture.Name)) { ISerializerFactory factory = sd.CreateSerializerFactory(); sd._displayName = factory.DisplayName; sd._manufacturerName = factory.ManufacturerName; sd._manufacturerWebsite = factory.ManufacturerWebsite; sd._defaultFileExtension = factory.DefaultFileExtension; key = plugIns.CreateSubKey(keyName); sd.WriteToRegistryKey(key); key.Close(); } } catch (KeyNotFoundException) { sd = null; } if (sd != null) { // This will be noted in the release notes as an unsupported API until 4479 is fixed. // https://github.com/dotnet/wpf/issues/4479 #pragma warning disable SYSLIB0018 // 'Assembly.ReflectionOnlyLoadFrom(string)' is obsolete: 'ReflectionOnly loading is not su pported and throws PlatformNotSupportedException.' Assembly plugIn = Assembly.ReflectionOnlyLoadFrom(sd._assemblyPath); #pragma warning restore SYSLIB0018 // 'Assembly.ReflectionOnlyLoadFrom(string)' is obsolete: 'ReflectionOnly loading is not supported and throws PlatformNotSupportedException.' if (typeof(System.Windows.Controls.Button).Assembly.GetName().Version == sd._winFXVersion && plugIn != null && plugIn.GetName().Version == sd._assemblyVersion) { sd._isLoadable = true; } } return(sd); }
public SerializerProvider() { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerDescriptor sd = null; List <SerializerDescriptor> installedSerializers = new List <SerializerDescriptor>(); sd = CreateSystemSerializerDescriptor(); if (sd != null) { installedSerializers.Add(sd); } RegistryKey plugIns = _rootKey.CreateSubKey(_registryPath); if (plugIns != null) { foreach (string keyName in plugIns.GetSubKeyNames()) { sd = SerializerDescriptor.CreateFromRegistry(plugIns, keyName); if (sd != null) { installedSerializers.Add(sd); } } plugIns.Close(); } _installedSerializers = installedSerializers.AsReadOnly(); }
public static void RegisterSerializer(SerializerDescriptor serializerDescriptor, bool overwrite) { SecurityHelper.DemandPlugInSerializerPermissions(); if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } RegistryKey registryKey = SerializerProvider._rootKey.CreateSubKey("SOFTWARE\\Microsoft\\WinFX Serializers"); string text = string.Concat(new object[] { serializerDescriptor.DisplayName, "/", serializerDescriptor.AssemblyName, "/", serializerDescriptor.AssemblyVersion, "/", serializerDescriptor.WinFXVersion }); if (!overwrite && registryKey.OpenSubKey(text) != null) { throw new ArgumentException(SR.Get("SerializerProviderAlreadyRegistered"), text); } RegistryKey registryKey2 = registryKey.CreateSubKey(text); serializerDescriptor.WriteToRegistryKey(registryKey2); registryKey2.Close(); }
internal static SerializerDescriptor CreateFromRegistry(RegistryKey plugIns, string keyName) { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerDescriptor sd = new SerializerDescriptor(); try { RegistryKey key = plugIns.OpenSubKey(keyName); sd._displayName = GetNonEmptyRegistryString(key, "displayName"); sd._manufacturerName = GetNonEmptyRegistryString(key, "manufacturerName"); sd._manufacturerWebsite = new Uri(GetNonEmptyRegistryString(key, "manufacturerWebsite")); sd._defaultFileExtension = GetNonEmptyRegistryString(key, "defaultFileExtension"); sd._assemblyName = GetNonEmptyRegistryString(key, "assemblyName"); sd._assemblyPath = GetNonEmptyRegistryString(key, "assemblyPath"); sd._factoryInterfaceName = GetNonEmptyRegistryString(key, "factoryInterfaceName"); sd._assemblyVersion = new Version(GetNonEmptyRegistryString(key, "assemblyVersion")); sd._winFXVersion = new Version(GetNonEmptyRegistryString(key, "winFXVersion")); string uiLanguage = GetNonEmptyRegistryString(key, "uiLanguage"); key.Close(); // update language strings. if (!uiLanguage.Equals(CultureInfo.CurrentUICulture.Name)) { ISerializerFactory factory = sd.CreateSerializerFactory(); sd._displayName = factory.DisplayName; sd._manufacturerName = factory.ManufacturerName; sd._manufacturerWebsite = factory.ManufacturerWebsite; sd._defaultFileExtension = factory.DefaultFileExtension; key = plugIns.CreateSubKey(keyName); sd.WriteToRegistryKey(key); key.Close(); } } catch (KeyNotFoundException) { sd = null; } if (sd != null) { Assembly plugIn = Assembly.ReflectionOnlyLoadFrom(sd._assemblyPath); if (typeof(System.Windows.Controls.Button).Assembly.GetName().Version == sd._winFXVersion && plugIn != null && plugIn.GetName().Version == sd._assemblyVersion) { sd._isLoadable = true; } } return(sd); }
/// <summary> /// Uses reflection to create the XpsSerializer /// </summary> /// <remarks> /// Creates the Xps default serializer /// </remarks> /// <returns>SerializerDescriptor for new serializer</returns> private SerializerDescriptor CreateSystemSerializerDescriptor() { SerializerDescriptor serializerDescriptor = null; // The XpsSerializer (our default document serializer) is defined in ReachFramework.dll // But callers can only get here if the above demand succeeds, so they are already fully trusted serializerDescriptor = SerializerDescriptor.CreateFromFactoryInstance( new XpsSerializerFactory() ); return(serializerDescriptor); }
/// <summary> /// Compares two SerializerDescriptor for equality /// </summary> public override bool Equals(object obj) { SerializerDescriptor sd = obj as SerializerDescriptor; if (sd != null) { return(sd._displayName == _displayName && sd._assemblyName == _assemblyName && sd._assemblyPath == _assemblyPath && sd._factoryInterfaceName == _factoryInterfaceName && sd._defaultFileExtension == _defaultFileExtension && sd._assemblyVersion == _assemblyVersion && sd._winFXVersion == _winFXVersion); } return(false); }
public static SerializerDescriptor CreateFromFactoryInstance( ISerializerFactory factoryInstance ) { SecurityHelper.DemandPlugInSerializerPermissions(); if (factoryInstance == null) { throw new ArgumentNullException("factoryInstance"); } if (factoryInstance.DisplayName == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderDisplayNameNull)); } if (factoryInstance.ManufacturerName == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderManufacturerNameNull)); } if (factoryInstance.ManufacturerWebsite == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderManufacturerWebsiteNull)); } if (factoryInstance.DefaultFileExtension == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderDefaultFileExtensionNull)); } SerializerDescriptor sd = new SerializerDescriptor(); sd._displayName = factoryInstance.DisplayName; sd._manufacturerName = factoryInstance.ManufacturerName; sd._manufacturerWebsite = factoryInstance.ManufacturerWebsite; sd._defaultFileExtension = factoryInstance.DefaultFileExtension; // When this is called with an instantiated factory object, it must be loadable sd._isLoadable = true; Type factoryType = factoryInstance.GetType(); sd._assemblyName = factoryType.Assembly.FullName; sd._assemblyPath = factoryType.Assembly.Location; sd._assemblyVersion = factoryType.Assembly.GetName().Version; sd._factoryInterfaceName = factoryType.FullName; sd._winFXVersion = typeof(System.Windows.Controls.Button).Assembly.GetName().Version; return(sd); }
/// <summary> /// Un-Registers the serializer plug-in identified by serializerDescriptor in the registry /// </summary> /// <remarks> /// Removes a previously installed plug-n serialiazer from the registry /// /// This method currently requires full trust to run. /// </remarks> public static void UnregisterSerializer(SerializerDescriptor serializerDescriptor) { if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } RegistryKey plugIns = _rootKey.CreateSubKey(_registryPath); string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion; if (plugIns.OpenSubKey(serializerKey) == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderNotRegistered), serializerKey); } plugIns.DeleteSubKeyTree(serializerKey); }
internal static SerializerDescriptor CreateFromRegistry(RegistryKey plugIns, string keyName) { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerDescriptor serializerDescriptor = new SerializerDescriptor(); try { RegistryKey registryKey = plugIns.OpenSubKey(keyName); serializerDescriptor._displayName = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "displayName"); serializerDescriptor._manufacturerName = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "manufacturerName"); serializerDescriptor._manufacturerWebsite = new Uri(SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "manufacturerWebsite")); serializerDescriptor._defaultFileExtension = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "defaultFileExtension"); serializerDescriptor._assemblyName = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "assemblyName"); serializerDescriptor._assemblyPath = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "assemblyPath"); serializerDescriptor._factoryInterfaceName = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "factoryInterfaceName"); serializerDescriptor._assemblyVersion = new Version(SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "assemblyVersion")); serializerDescriptor._winFXVersion = new Version(SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "winFXVersion")); string nonEmptyRegistryString = SerializerDescriptor.GetNonEmptyRegistryString(registryKey, "uiLanguage"); registryKey.Close(); if (!nonEmptyRegistryString.Equals(CultureInfo.CurrentUICulture.Name)) { ISerializerFactory serializerFactory = serializerDescriptor.CreateSerializerFactory(); serializerDescriptor._displayName = serializerFactory.DisplayName; serializerDescriptor._manufacturerName = serializerFactory.ManufacturerName; serializerDescriptor._manufacturerWebsite = serializerFactory.ManufacturerWebsite; serializerDescriptor._defaultFileExtension = serializerFactory.DefaultFileExtension; registryKey = plugIns.CreateSubKey(keyName); serializerDescriptor.WriteToRegistryKey(registryKey); registryKey.Close(); } } catch (KeyNotFoundException) { serializerDescriptor = null; } if (serializerDescriptor != null) { Assembly assembly = Assembly.ReflectionOnlyLoadFrom(serializerDescriptor._assemblyPath); if (typeof(Button).Assembly.GetName().Version == serializerDescriptor._winFXVersion && assembly != null && assembly.GetName().Version == serializerDescriptor._assemblyVersion) { serializerDescriptor._isLoadable = true; } } return(serializerDescriptor); }
/// <summary> /// Registers the serializer plug-in identified by serializerDescriptor in the registry /// </summary> public static void RegisterSerializer(SerializerDescriptor serializerDescriptor, bool overwrite) { if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } RegistryKey plugIns = _rootKey.CreateSubKey(_registryPath); string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion; if (!overwrite && plugIns.OpenSubKey(serializerKey) != null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderAlreadyRegistered), serializerKey); } RegistryKey newPlugIn = plugIns.CreateSubKey(serializerKey); serializerDescriptor.WriteToRegistryKey(newPlugIn); newPlugIn.Close(); }
public static SerializerDescriptor CreateFromFactoryInstance(ISerializerFactory factoryInstance) { SecurityHelper.DemandPlugInSerializerPermissions(); if (factoryInstance == null) { throw new ArgumentNullException("factoryInstance"); } if (factoryInstance.DisplayName == null) { throw new ArgumentException(SR.Get("SerializerProviderDisplayNameNull")); } if (factoryInstance.ManufacturerName == null) { throw new ArgumentException(SR.Get("SerializerProviderManufacturerNameNull")); } if (factoryInstance.ManufacturerWebsite == null) { throw new ArgumentException(SR.Get("SerializerProviderManufacturerWebsiteNull")); } if (factoryInstance.DefaultFileExtension == null) { throw new ArgumentException(SR.Get("SerializerProviderDefaultFileExtensionNull")); } SerializerDescriptor serializerDescriptor = new SerializerDescriptor(); serializerDescriptor._displayName = factoryInstance.DisplayName; serializerDescriptor._manufacturerName = factoryInstance.ManufacturerName; serializerDescriptor._manufacturerWebsite = factoryInstance.ManufacturerWebsite; serializerDescriptor._defaultFileExtension = factoryInstance.DefaultFileExtension; serializerDescriptor._isLoadable = true; Type type = factoryInstance.GetType(); serializerDescriptor._assemblyName = type.Assembly.FullName; serializerDescriptor._assemblyPath = type.Assembly.Location; serializerDescriptor._assemblyVersion = type.Assembly.GetName().Version; serializerDescriptor._factoryInterfaceName = type.FullName; serializerDescriptor._winFXVersion = typeof(Button).Assembly.GetName().Version; return(serializerDescriptor); }
public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream) { return default(SerializerWriter); }
/// <summary> /// Creates a SerializerDescriptor. The interface must be defined in the calling assembly /// The WinFX version, and assembly name, and version are initialized by reflecting on the calling assembly /// </summary> /// <remarks> /// Create a SerializerDescriptor from a ISerializerFactory instance /// /// This method currently requires full trust to run. /// </remarks> ///<SecurityNote> /// The DemandPlugInSerializerPermissions() ensures that this method only works in full trust. /// Full trust is required, so that partial trust applications do not load or use potentially /// unsafe serializer plug ins ///</SecurityNote> public static SerializerDescriptor CreateFromFactoryInstance( ISerializerFactory factoryInstance ) { SecurityHelper.DemandPlugInSerializerPermissions(); if (factoryInstance == null) { throw new ArgumentNullException("factoryInstance"); } if (factoryInstance.DisplayName == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderDisplayNameNull)); } if (factoryInstance.ManufacturerName == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderManufacturerNameNull)); } if (factoryInstance.ManufacturerWebsite == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderManufacturerWebsiteNull)); } if (factoryInstance.DefaultFileExtension == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderDefaultFileExtensionNull)); } SerializerDescriptor sd = new SerializerDescriptor(); sd._displayName = factoryInstance.DisplayName; sd._manufacturerName = factoryInstance.ManufacturerName; sd._manufacturerWebsite = factoryInstance.ManufacturerWebsite; sd._defaultFileExtension = factoryInstance.DefaultFileExtension; // When this is called with an instantiated factory object, it must be loadable sd._isLoadable = true; Type factoryType = factoryInstance.GetType(); sd._assemblyName = factoryType.Assembly.FullName; sd._assemblyPath = factoryType.Assembly.Location; sd._assemblyVersion = factoryType.Assembly.GetName().Version; sd._factoryInterfaceName = factoryType.FullName; sd._winFXVersion = typeof(System.Windows.Controls.Button).Assembly.GetName().Version; return sd; }
/// <summary> /// Load a SerializerDescriptor from the registry /// </summary> /// <remarks> /// Create a SerializerDescriptor from the registry /// /// This method currently requires full trust to run. /// </remarks> ///<SecurityNote> /// The DemandPlugInSerializerPermissions() ensures that this method only works in full trust. /// Full trust is required, so that partial trust applications do not load or use potentially /// unsafe serializer plug ins ///</SecurityNote> internal static SerializerDescriptor CreateFromRegistry(RegistryKey plugIns, string keyName) { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerDescriptor sd = new SerializerDescriptor(); try { RegistryKey key = plugIns.OpenSubKey(keyName); sd._displayName = GetNonEmptyRegistryString(key, "displayName"); sd._manufacturerName = GetNonEmptyRegistryString(key, "manufacturerName"); sd._manufacturerWebsite = new Uri(GetNonEmptyRegistryString(key, "manufacturerWebsite")); sd._defaultFileExtension = GetNonEmptyRegistryString(key, "defaultFileExtension"); sd._assemblyName = GetNonEmptyRegistryString(key, "assemblyName"); sd._assemblyPath = GetNonEmptyRegistryString(key, "assemblyPath"); sd._factoryInterfaceName = GetNonEmptyRegistryString(key, "factoryInterfaceName"); sd._assemblyVersion = new Version(GetNonEmptyRegistryString(key, "assemblyVersion")); sd._winFXVersion = new Version(GetNonEmptyRegistryString(key, "winFXVersion")); string uiLanguage = GetNonEmptyRegistryString(key, "uiLanguage"); key.Close(); // update language strings. if (!uiLanguage.Equals(CultureInfo.CurrentUICulture.Name)) { ISerializerFactory factory = sd.CreateSerializerFactory(); sd._displayName = factory.DisplayName; sd._manufacturerName = factory.ManufacturerName; sd._manufacturerWebsite = factory.ManufacturerWebsite; sd._defaultFileExtension = factory.DefaultFileExtension; key = plugIns.CreateSubKey(keyName); sd.WriteToRegistryKey(key); key.Close(); } } catch (KeyNotFoundException) { sd = null; } if (sd != null) { Assembly plugIn = Assembly.ReflectionOnlyLoadFrom(sd._assemblyPath); if (typeof(System.Windows.Controls.Button).Assembly.GetName().Version == sd._winFXVersion && plugIn != null && plugIn.GetName().Version == sd._assemblyVersion) { sd._isLoadable = true; } } return sd; }
public static void RegisterSerializer(SerializerDescriptor serializerDescriptor, bool overwrite) { }
public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream) { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerWriter serializerWriter = null; if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion; if (!serializerDescriptor.IsLoadable) { throw new ArgumentException(SR.Get(SRID.SerializerProviderWrongVersion), serializerKey); } if (stream == null) { throw new ArgumentNullException("stream"); } bool found = false; foreach (SerializerDescriptor sd in InstalledSerializers) { if (sd.Equals(serializerDescriptor)) { found = true; break; } } if (!found) { throw new ArgumentException(SR.Get(SRID.SerializerProviderUnknownSerializer), serializerKey); } try { ISerializerFactory factory = serializerDescriptor.CreateSerializerFactory(); serializerWriter = factory.CreateSerializerWriter(stream); } catch (FileNotFoundException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } catch (FileLoadException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } catch (BadImageFormatException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } catch (MissingMethodException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } return(serializerWriter); }
/// <summary> /// Registers the serializer plug-in identified by serializerDescriptor in the registry /// </summary> ///<SecurityNote> /// The DemandPlugInSerializerPermissions() ensures that this method only works in full trust. /// Full trust is required, so that partial trust applications install /// potentially unsafe serializer plug ins ///</SecurityNote> public static void RegisterSerializer(SerializerDescriptor serializerDescriptor, bool overwrite) { SecurityHelper.DemandPlugInSerializerPermissions(); if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } RegistryKey plugIns = _rootKey.CreateSubKey(_registryPath); string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion; if (!overwrite && plugIns.OpenSubKey(serializerKey) != null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderAlreadyRegistered), serializerKey); } RegistryKey newPlugIn = plugIns.CreateSubKey(serializerKey); serializerDescriptor.WriteToRegistryKey(newPlugIn); newPlugIn.Close(); }
public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream) { return(default(SerializerWriter)); }
/// <summary> /// Un-Registers the serializer plug-in identified by serializerDescriptor in the registry /// </summary> /// <remarks> /// Removes a previously installed plug-n serialiazer from the registry /// /// This method currently requires full trust to run. /// </remarks> ///<SecurityNote> /// The DemandPlugInSerializerPermissions() ensures that this method only works in full trust. /// Full trust is required, so that partial trust applications do not uninstall /// serializer plug ins ///</SecurityNote> public static void UnregisterSerializer(SerializerDescriptor serializerDescriptor) { SecurityHelper.DemandPlugInSerializerPermissions(); if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } RegistryKey plugIns = _rootKey.CreateSubKey(_registryPath); string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion; if (plugIns.OpenSubKey(serializerKey) == null) { throw new ArgumentException(SR.Get(SRID.SerializerProviderNotRegistered), serializerKey); } plugIns.DeleteSubKeyTree(serializerKey); }
public static void UnregisterSerializer(SerializerDescriptor serializerDescriptor) { }
public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream) { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerWriter result = null; if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } string paramName = string.Concat(new object[] { serializerDescriptor.DisplayName, "/", serializerDescriptor.AssemblyName, "/", serializerDescriptor.AssemblyVersion, "/", serializerDescriptor.WinFXVersion }); if (!serializerDescriptor.IsLoadable) { throw new ArgumentException(SR.Get("SerializerProviderWrongVersion"), paramName); } if (stream == null) { throw new ArgumentNullException("stream"); } bool flag = false; foreach (SerializerDescriptor serializerDescriptor2 in this.InstalledSerializers) { if (serializerDescriptor2.Equals(serializerDescriptor)) { flag = true; break; } } if (!flag) { throw new ArgumentException(SR.Get("SerializerProviderUnknownSerializer"), paramName); } try { ISerializerFactory serializerFactory = serializerDescriptor.CreateSerializerFactory(); result = serializerFactory.CreateSerializerWriter(stream); } catch (FileNotFoundException) { throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName); } catch (FileLoadException) { throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName); } catch (BadImageFormatException) { throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName); } catch (MissingMethodException) { throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName); } return(result); }
/// <summary>Tests two <see cref="T:System.Windows.Documents.Serialization.SerializerDescriptor" /> objects for equality.</summary> /// <param name="obj">The object to be compared with this <see cref="T:System.Windows.Documents.Serialization.SerializerDescriptor" />.</param> /// <returns> /// <see langword="true" /> if both are equal; otherwise, <see langword="false" />. </returns> // Token: 0x06003F9B RID: 16283 RVA: 0x00125880 File Offset: 0x00123A80 public override bool Equals(object obj) { SerializerDescriptor serializerDescriptor = obj as SerializerDescriptor; return(serializerDescriptor != null && (serializerDescriptor._displayName == this._displayName && serializerDescriptor._assemblyName == this._assemblyName && serializerDescriptor._assemblyPath == this._assemblyPath && serializerDescriptor._factoryInterfaceName == this._factoryInterfaceName && serializerDescriptor._defaultFileExtension == this._defaultFileExtension && serializerDescriptor._assemblyVersion == this._assemblyVersion) && serializerDescriptor._winFXVersion == this._winFXVersion); }
/// <summary> /// Create a SerializerWriter identified by the passed in SerializerDescriptor on the passed in stream /// </summary> /// <remarks> /// With a SerializerProvider (which requires full trust to ctor) and a SerializerDescriptor (which requires /// full trust to obtain) create a SerializerWriter /// /// This method currently requires full trust to run. /// </remarks> ///<SecurityNote> /// The DemandPlugInSerializerPermissions() ensures that this method only works in full trust. /// Full trust is required, so that partial trust applications do not load or use potentially /// unsafe serializer plug ins ///</SecurityNote> public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream) { SecurityHelper.DemandPlugInSerializerPermissions(); SerializerWriter serializerWriter = null; if (serializerDescriptor == null) { throw new ArgumentNullException("serializerDescriptor"); } string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion; if (!serializerDescriptor.IsLoadable) { throw new ArgumentException(SR.Get(SRID.SerializerProviderWrongVersion), serializerKey); } if (stream == null) { throw new ArgumentNullException("stream"); } bool found = false; foreach (SerializerDescriptor sd in InstalledSerializers) { if (sd.Equals(serializerDescriptor)) { found = true; break; } } if (!found) { throw new ArgumentException(SR.Get(SRID.SerializerProviderUnknownSerializer), serializerKey); } try { ISerializerFactory factory = serializerDescriptor.CreateSerializerFactory(); serializerWriter = factory.CreateSerializerWriter(stream); } catch (FileNotFoundException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } catch (FileLoadException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } catch (BadImageFormatException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } catch (MissingMethodException) { throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); } return serializerWriter; }
private SerializerDescriptor CreateSystemSerializerDescriptor() { SecurityHelper.DemandPlugInSerializerPermissions(); return(SerializerDescriptor.CreateFromFactoryInstance(new XpsSerializerFactory())); }