DigitalFormEmbeddedMediaValue.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Linq;
  3. using InABox.Core;
  4. namespace PRS.Mobile
  5. {
  6. public class DigitalFormEmbeddedMediaValue
  7. {
  8. public Guid ID { get; set; }
  9. public byte[] Data { get; set; }
  10. public DigitalFormEmbeddedMediaValue(String json = "")
  11. {
  12. if (String.IsNullOrWhiteSpace(json))
  13. return;
  14. if (Guid.TryParse(json, out Guid id) && (id != Guid.Empty))
  15. {
  16. DigitalFormDocumentHandler.LoadDocument(id,
  17. data =>
  18. {
  19. ID = id;
  20. Data = data;
  21. }
  22. );
  23. }
  24. else if (json.IsBase64String())
  25. {
  26. ID = Guid.Empty;
  27. Data = Convert.FromBase64String(json);
  28. }
  29. }
  30. public override string ToString()
  31. {
  32. if ((ID == Guid.Empty) && (Data.Any() == true))
  33. ID = DigitalFormDocumentHandler.SaveDocument(Data);
  34. return ID.ToString();
  35. }
  36. }
  37. }