2
0

EncodingConfigurationFactory.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using MediaBrowser.Common.Configuration;
  6. using MediaBrowser.Model.Configuration;
  7. namespace MediaBrowser.MediaEncoding.Configuration
  8. {
  9. public class EncodingConfigurationFactory : IConfigurationFactory
  10. {
  11. public IEnumerable<ConfigurationStore> GetConfigurations()
  12. {
  13. return new[]
  14. {
  15. new EncodingConfigurationStore()
  16. };
  17. }
  18. }
  19. public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
  20. {
  21. public EncodingConfigurationStore()
  22. {
  23. ConfigurationType = typeof(EncodingOptions);
  24. Key = "encoding";
  25. }
  26. public void Validate(object oldConfig, object newConfig)
  27. {
  28. var newPath = ((EncodingOptions)newConfig).TranscodingTempPath;
  29. if (!string.IsNullOrWhiteSpace(newPath)
  30. && !string.Equals(((EncodingOptions)oldConfig).TranscodingTempPath, newPath, StringComparison.Ordinal))
  31. {
  32. // Validate
  33. if (!Directory.Exists(newPath))
  34. {
  35. throw new DirectoryNotFoundException(
  36. string.Format(
  37. CultureInfo.InvariantCulture,
  38. "{0} does not exist.",
  39. newPath));
  40. }
  41. }
  42. }
  43. }
  44. }