123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- namespace InABox.Core
- {
- public class DFLayoutEmbeddedImageProperties : DFLayoutFieldProperties<byte[]>
- {
- [CheckBoxEditor]
- [EditorSequence(1)]
- public bool DisableLibrary { get; set; }
- public override string FormatValue(object? value)
- {
- return value != null ? "Yes" : "";
- }
- public override object? ParseValue(object? value)
- {
- if (value is byte[])
- return value;
- if (value is string str)
- {
- try
- {
- var tuple = Serialization.Deserialize<Tuple<Guid, byte[]>>(str, true);
- if ((tuple != null) && (tuple.Item1 != Guid.Empty))
- return DigitalFormDocumentFactory.LoadDocument(tuple.Item1);
- return null;
- }
- catch
- {
-
- }
-
- if (Guid.TryParse(str, out var id))
- {
- return Array.Empty<byte>();
- }
- try
- {
- return Convert.FromBase64String(str);
- }
- catch (Exception e)
- {
- Logger.Send(LogType.Error, "", $"Error in image data; invalid Base-64: {e.Message}");
- return null;
- }
- }
- return null;
- }
- protected override void LoadProperties()
- {
- base.LoadProperties();
- DisableLibrary = GetProperty("DisableLibrary", false);
- }
- protected override void SaveProperties()
- {
- base.SaveProperties();
- SetProperty("DisableLibrary", DisableLibrary);
- }
- }
- }
|