DFLayoutMultiSignaturePadProperties.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace InABox.Core
  6. {
  7. public class DFLayoutMultiSignaturePadProperties : DFLayoutFieldProperties<Dictionary<string, byte[]>>
  8. {
  9. public override string FormatValue(object? value)
  10. {
  11. return value != null ? "Yes" : "";
  12. }
  13. public override object? ParseValue(object? value)
  14. {
  15. if (value is Dictionary<string, byte[]> dict)
  16. return dict;
  17. Dictionary<string, string>? values = null;
  18. if (value is JObject jObject)
  19. values = jObject.ToObject<Dictionary<string, string>>();
  20. else if(value is string str)
  21. {
  22. if (Guid.TryParse(str, out var id))
  23. {
  24. return new Dictionary<string, byte[]>();
  25. }
  26. values = Serialization.Deserialize<Dictionary<string, string>>(str);
  27. }
  28. if (values != null)
  29. try
  30. {
  31. var convertedValues = new Dictionary<string, byte[]>();
  32. foreach (var v in values.Keys)
  33. {
  34. convertedValues.Add(v, Convert.FromBase64String(values[v]));
  35. }
  36. return convertedValues;
  37. }
  38. catch (Exception)
  39. {
  40. return null;
  41. }
  42. return null;
  43. }
  44. }
  45. }