Przeglądaj źródła

Added ability to transfer data from DFSaveStorage to DFLoadStorage
Fixed DFLayoutEmbeddedMediaValue to properly load old-style form data

frogsoftware 1 rok temu
rodzic
commit
bbf79ae660

+ 7 - 4
InABox.Core/DigitalForms/Layouts/Fields/DFStorage.cs

@@ -1,10 +1,7 @@
 using Newtonsoft.Json.Linq;
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Text;
 
 namespace InABox.Core
 {
@@ -89,9 +86,14 @@ namespace InABox.Core
 
     public class DFLoadStorage
     {
-        public Dictionary<string, object?> FormData { get; private set; }
+        public Dictionary<string, object?> FormData { get; private set; } = new Dictionary<string, object?>();
 
         public DFLoadStorage(Dictionary<string, object?> formData, Dictionary<string, object?>? blobData)
+        {
+            Load(formData, blobData);
+        }
+
+        public void Load(Dictionary<string, object?> formData, Dictionary<string, object?>? blobData)
         {
             FormData = formData;
 
@@ -106,6 +108,7 @@ namespace InABox.Core
                         updates.Add(new Tuple<string, object?>(key, blob));
                     }
                 }
+
                 foreach (var (key, value) in updates)
                 {
                     FormData[key] = value;

+ 24 - 3
InABox.Core/DigitalForms/Layouts/Values/DFLayoutEmbeddedMediaValue.cs

@@ -20,13 +20,34 @@ namespace InABox.Core
             else if (value is string str)
             {
                 if(Guid.TryParse(str, out id))
-                {
                     ID = id;
-                }
                 else
                 {
-                    ID = Guid.Empty;
+                    try
+                    {
+                        var tuple = Serialization.Deserialize<(Guid, byte[])>(str,true);
+                        ID = tuple.Item1;
+                        Thumbnail = tuple.Item2;
+                        return;
+                    }
+                    catch (Exception e)
+                    {
+                        try
+                        {
+                            var data = Convert.FromBase64String(str);
+                            ID = Guid.Empty;
+                            Thumbnail = data;
+                            Data = data;
+                            return;
+                        }
+                        catch (Exception e2)
+                        {
+                            ID = Guid.Empty;
+                        }
+
+                    }
                 }
+                
             }
 
             Thumbnail = storage.GetValue<byte[]>("Thumbnail");