EncodingConfigurationFactory.cs 1.4 KB

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