|
|
@@ -146,6 +146,26 @@ namespace InABox.Core
|
|
|
var blobs = Serialization.Deserialize<Dictionary<string, object?>>(blobData);
|
|
|
return new DFLoadStorage(values, blobs);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Takes a serialized FormData string and BlobData string and deserializes into a <see cref="DFSaveStorage"/> object.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// Returns <see langword="null"/> if <paramref name="formData"/> is not a valid JSON object.
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="formData"></param>
|
|
|
+ /// <param name="blobData"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static DFSaveStorage? DeserializeFormSaveData(string formData, string? blobData)
|
|
|
+ {
|
|
|
+ var values = Serialization.Deserialize<Dictionary<string, object?>>(formData);
|
|
|
+ if (values is null)
|
|
|
+ return null;
|
|
|
+ if (blobData.IsNullOrWhiteSpace())
|
|
|
+ return new DFSaveStorage(values, null);
|
|
|
+ var blobs = Serialization.Deserialize<Dictionary<string, object?>>(blobData);
|
|
|
+ return new DFSaveStorage(values, blobs);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Like <see cref="DeserializeFormData(string, string?)"/>, but takes the FormData and BlobData from <paramref name="form"/>,
|
|
|
@@ -160,19 +180,28 @@ namespace InABox.Core
|
|
|
=> DeserializeFormData(form.FormData, form.BlobData);
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Takes a form instance, set of variables and some saved values, and serializes the FormData and BlobData into the respective
|
|
|
+ /// Like <see cref="DeserializeFormSaveData(string, string?)"/>, but takes the FormData and BlobData from <paramref name="form"/>,
|
|
|
+ /// rather than having to specify them manually.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// Returns <see langword="null"/> if <c>form.FormData</c> is not a valid JSON object.
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="form"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static DFSaveStorage? DeserializeFormSaveData(IDigitalFormInstance form)
|
|
|
+ => DeserializeFormSaveData(form.FormData, form.BlobData);
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Takes a form instance and some saved values, and serializes the FormData and BlobData into the respective
|
|
|
/// fields of <paramref name="form"/>.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// Doesn't return anything, but saves the serialized results directly into form.FormData and form.BlobData.
|
|
|
/// It choose which fields should be saved into BlobData based on whether the form field has the <see cref="IDFBlobField"/> interface.
|
|
|
- /// <br/>
|
|
|
- /// <paramref name="values"/> should be the same as what you pass into <see cref="Serialization.Serialize(object?, bool)"/>.
|
|
|
/// </remarks>
|
|
|
/// <param name="form">The form instance.</param>
|
|
|
- /// <param name="variables">The variables associated with the digital form.</param>
|
|
|
/// <param name="storage">The values to save.</param>
|
|
|
- public static void SerializeFormData(IDigitalFormInstance form, ICollection<DigitalFormVariable> variables, DFSaveStorage storage)
|
|
|
+ public static void SerializeFormData(IDigitalFormInstance form, DFSaveStorage storage)
|
|
|
{
|
|
|
form.FormData = Serialization.Serialize(storage.FormData);
|
|
|
form.BlobData = Serialization.Serialize(storage.BlobData);
|