DFLayoutVideoFieldProperties.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace InABox.Core
  5. {
  6. public class DFLayoutVideoFieldProperties : DFLayoutFieldProperties<DFLayoutEmbeddedMediaValue>
  7. {
  8. public enum VideoQuality
  9. {
  10. Default,
  11. Low,
  12. Medium,
  13. High
  14. }
  15. [CheckBoxEditor]
  16. [EditorSequence(100)]
  17. public bool DisableLibrary { get; set; }
  18. [IntegerEditor(ToolTip = "Maximum video length (sec)")]
  19. [EditorSequence(101)]
  20. public int MaximumVideoLength { get; set; } = 0;
  21. [EnumLookupEditor(typeof(VideoQuality))]
  22. [EditorSequence(102)]
  23. public VideoQuality Quality { get; set; } = VideoQuality.Default;
  24. public override string FormatValue(object? value)
  25. {
  26. return value != null ? "Yes" : "";
  27. }
  28. public override object? ParseValue(object? value)
  29. {
  30. if (value is byte[])
  31. return value;
  32. if (value is string str)
  33. {
  34. if (Guid.TryParse(str, out var id))
  35. {
  36. return Array.Empty<byte>();
  37. }
  38. try
  39. {
  40. return Convert.FromBase64String(str);
  41. }
  42. catch (Exception e)
  43. {
  44. Logger.Send(LogType.Error, "", $"Error in video data; invalid Base-64: {e.Message}");
  45. return null;
  46. }
  47. }
  48. return null;
  49. }
  50. protected override void LoadProperties()
  51. {
  52. base.LoadProperties();
  53. DisableLibrary = GetProperty(nameof(DisableLibrary), false);
  54. MaximumVideoLength = GetProperty(nameof(MaximumVideoLength), 0);
  55. Quality = GetProperty(nameof(Quality), VideoQuality.Default);
  56. }
  57. protected override void SaveProperties()
  58. {
  59. base.SaveProperties();
  60. SetProperty(nameof(DisableLibrary), DisableLibrary);
  61. SetProperty(nameof(MaximumVideoLength),MaximumVideoLength);
  62. SetProperty(nameof(Quality), Quality);
  63. }
  64. }
  65. }