DFLayoutVideoFieldProperties.cs 1010 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace InABox.Core
  5. {
  6. public class DFLayoutVideoFieldProperties : DFLayoutFieldProperties<byte[]>
  7. {
  8. public override string FormatValue(object? value)
  9. {
  10. return value != null ? "Yes" : "";
  11. }
  12. public override object? ParseValue(object? value)
  13. {
  14. if (value is byte[])
  15. return value;
  16. if (value is string str)
  17. {
  18. if (Guid.TryParse(str, out var id))
  19. {
  20. return Array.Empty<byte>();
  21. }
  22. try
  23. {
  24. return Convert.FromBase64String(str);
  25. }
  26. catch (Exception e)
  27. {
  28. Logger.Send(LogType.Error, "", $"Error in video data; invalid Base-64: {e.Message}");
  29. return null;
  30. }
  31. }
  32. return null;
  33. }
  34. }
  35. }