EncodingConfigurationFactory.cs 1.7 KB

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