DFLayoutMultiImageProperties.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace InABox.Core
  6. {
  7. public class DFLayoutMultiImageProperties : DFLayoutFieldProperties<List<byte[]>>
  8. {
  9. [CheckBoxEditor]
  10. public bool DisableLibrary { get; set; } = false;
  11. public override string FormatValue(object value)
  12. {
  13. return value != null ? "Yes" : "";
  14. }
  15. public override object? ParseValue(object value)
  16. {
  17. List<string>? values = null;
  18. if (value is List<byte[]> list)
  19. return list;
  20. else if(value is JArray jArray)
  21. values = jArray.Select(x => x.ToString()).ToList();
  22. else if(value is string str)
  23. values = Serialization.Deserialize<List<string>>(str);
  24. if(values != null)
  25. {
  26. try
  27. {
  28. var convertedValues = new List<byte[]>();
  29. foreach (var v in values) convertedValues.Add(Convert.FromBase64String(v));
  30. return convertedValues;
  31. }
  32. catch (Exception)
  33. {
  34. return null;
  35. }
  36. }
  37. return null;
  38. }
  39. protected override void LoadProperties()
  40. {
  41. base.LoadProperties();
  42. DisableLibrary = GetProperty("DisableLibrary", false);
  43. }
  44. protected override void SaveProperties()
  45. {
  46. base.SaveProperties();
  47. SetProperty("DisableLibrary", DisableLibrary);
  48. }
  49. }
  50. }