EncodingConfigurationFactory.cs 1.8 KB

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