From 438d7fc0051713cabad492a430efb40df8696bd7 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 3 Sep 2012 12:54:20 -0400 Subject: [PATCH] Switched plugin config to use xml --- MediaBrowser.Common/Plugins/BasePlugin.cs | 2 +- .../Serialization/XmlSerializer.cs | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 4b6f9cba48..d92d4a8c20 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -164,7 +164,7 @@ namespace MediaBrowser.Common.Plugins } else { - Configuration = JsonSerializer.DeserializeFromFile(ConfigurationType, ConfigurationFilePath) as BasePluginConfiguration; + Configuration = XmlSerializer.DeserializeFromFile(ConfigurationType, ConfigurationFilePath) as BasePluginConfiguration; Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationFilePath); } } diff --git a/MediaBrowser.Common/Serialization/XmlSerializer.cs b/MediaBrowser.Common/Serialization/XmlSerializer.cs index 45c416f3b0..c85a1f2658 100644 --- a/MediaBrowser.Common/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common/Serialization/XmlSerializer.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace MediaBrowser.Common.Serialization { @@ -9,14 +10,14 @@ namespace MediaBrowser.Common.Serialization { public static void SerializeToStream(T obj, Stream stream) { - GetSerializer().Serialize(stream, obj); + GetSerializer(typeof(T)).Serialize(stream, obj); } public static void SerializeToFile(T obj, string file) { using (FileStream stream = new FileStream(file, FileMode.Create)) { - GetSerializer().Serialize(stream, obj); + GetSerializer(typeof(T)).Serialize(stream, obj); } } @@ -24,18 +25,26 @@ namespace MediaBrowser.Common.Serialization { using (Stream stream = File.OpenRead(file)) { - return (T)GetSerializer().Deserialize(stream); + return (T)GetSerializer(typeof(T)).Deserialize(stream); + } + } + + public static object DeserializeFromFile(Type type, string file) + { + using (Stream stream = File.OpenRead(file)) + { + return GetSerializer(type).Deserialize(stream); } } public static T DeserializeFromStream(Stream stream) { - return (T)GetSerializer().Deserialize(stream); + return (T)GetSerializer(typeof(T)).Deserialize(stream); } - private static System.Xml.Serialization.XmlSerializer GetSerializer() + private static System.Xml.Serialization.XmlSerializer GetSerializer(Type type) { - return new System.Xml.Serialization.XmlSerializer(typeof(T)); + return new System.Xml.Serialization.XmlSerializer(type); } } }