diff options
| author | Luke <luke.pulverenti@gmail.com> | 2015-01-04 09:27:54 -0500 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2015-01-04 09:27:54 -0500 |
| commit | c5ff30f66e368efc2ca7dea7813fba6d9f6a657c (patch) | |
| tree | c5552b898f66b7d510e9257eb8bbeafd6a003676 /MediaBrowser.Common/Configuration | |
| parent | 767590125b27c2498e3ad9544edbede30fb70f45 (diff) | |
| parent | 59b6bc28c332701d5e383fbf99170bdc740fb6cc (diff) | |
Merge pull request #965 from MediaBrowser/dev
3.0.5482.0
Diffstat (limited to 'MediaBrowser.Common/Configuration')
| -rw-r--r-- | MediaBrowser.Common/Configuration/ConfigurationHelper.cs | 74 | ||||
| -rw-r--r-- | MediaBrowser.Common/Configuration/IConfigurationFactory.cs | 5 |
2 files changed, 5 insertions, 74 deletions
diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs deleted file mode 100644 index 8c904b0db..000000000 --- a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs +++ /dev/null @@ -1,74 +0,0 @@ -using MediaBrowser.Model.Serialization; -using System; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Common.Configuration -{ - /// <summary> - /// Class ConfigurationHelper - /// </summary> - public static class ConfigurationHelper - { - /// <summary> - /// Reads an xml configuration file from the file system - /// It will immediately re-serialize and save if new serialization data is available due to property changes - /// </summary> - /// <param name="type">The type.</param> - /// <param name="path">The path.</param> - /// <param name="xmlSerializer">The XML serializer.</param> - /// <returns>System.Object.</returns> - public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer) - { - object configuration; - - byte[] buffer = null; - - // Use try/catch to avoid the extra file system lookup using File.Exists - try - { - buffer = File.ReadAllBytes(path); - - configuration = xmlSerializer.DeserializeFromBytes(type, buffer); - } - catch (Exception) - { - configuration = Activator.CreateInstance(type); - } - - using (var stream = new MemoryStream()) - { - xmlSerializer.SerializeToStream(configuration, stream); - - // Take the object we just got and serialize it back to bytes - var newBytes = stream.ToArray(); - - // If the file didn't exist before, or if something has changed, re-save - if (buffer == null || !buffer.SequenceEqual(newBytes)) - { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - // Save it after load in case we got new items - File.WriteAllBytes(path, newBytes); - } - - return configuration; - } - } - - /// <summary> - /// Reads an xml configuration file from the file system - /// It will immediately save the configuration after loading it, just - /// in case there are new serializable properties - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="path">The path.</param> - /// <param name="xmlSerializer">The XML serializer.</param> - /// <returns>``0.</returns> - public static T GetXmlConfiguration<T>(string path, IXmlSerializer xmlSerializer) - where T : class - { - return GetXmlConfiguration(typeof(T), path, xmlSerializer) as T; - } - } -} diff --git a/MediaBrowser.Common/Configuration/IConfigurationFactory.cs b/MediaBrowser.Common/Configuration/IConfigurationFactory.cs index d418d0a42..6ed638536 100644 --- a/MediaBrowser.Common/Configuration/IConfigurationFactory.cs +++ b/MediaBrowser.Common/Configuration/IConfigurationFactory.cs @@ -14,4 +14,9 @@ namespace MediaBrowser.Common.Configuration public Type ConfigurationType { get; set; } } + + public interface IValidatingConfiguration + { + void Validate(object oldConfig, object newConfig); + } } |
