EncodingConfigurationFactory.cs 1.7 KB

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