aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-10-30 03:29:27 -0400
committerGitHub <noreply@github.com>2016-10-30 03:29:27 -0400
commitd31b0f7be4b14e4ada999c97e675b856ad68352b (patch)
treea4619513efbb3be62a6204c996526df606cb62c5 /MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs
parentb19f75fcae017cb51f1e58eb2d54ca84620b6ee0 (diff)
parent3094cd7ff3e51578808ce1b6f56b141930c18004 (diff)
Merge pull request #2258 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs')
-rw-r--r--MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs59
1 files changed, 0 insertions, 59 deletions
diff --git a/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs
deleted file mode 100644
index 419b85fa73..0000000000
--- a/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using MediaBrowser.Model.Serialization;
-using System;
-using System.IO;
-using System.Linq;
-
-namespace MediaBrowser.Common.Implementations.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;
- }
- }
- }
-}