/// <summary> /// Loads an entire json document into spatial frames. /// </summary> /// <param name="reader"> /// The reader used to read the document. /// </param> /// <returns> /// A <see cref="Task"/> that yields the loaded frames. /// </returns> public async Task <List <SpatialFrame> > LoadFramesAsync(JsonReader reader) { // Validate if (reader == null) { throw new ArgumentNullException(nameof(reader)); } // Create the serializer JsonSerializer ser = CreateSerializer(); // Deserialize the list of frames List <SpatialFrame> frames = ser.Deserialize <List <SpatialFrame> >(reader); // If any of the alignment strategies uses native persistence, // load them now if (frames != null) { foreach (SpatialFrame frame in frames) { INativePersistence nativePersist = frame.AlignmentStrategy as INativePersistence; if (nativePersist != null) { await nativePersist.LoadNativeAsync(); } } } // Return loaded frames return(frames); }
/// <summary> /// Saves the list of frames using the specified writer. /// </summary> /// <param name="frames"> /// The list of frames to save. /// </param> /// <param name="writer"> /// The <see cref="JsonWriter"/> used to save the frames. /// </param> /// <returns> /// A <see cref="Task"/> that represents the operation. /// </returns> public async Task SaveFramesAsync(List <SpatialFrame> frames, JsonWriter writer) { // Validate if (frames == null) { throw new ArgumentNullException(nameof(frames)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } // If any of the alignment strategies uses native persistence, // save them now foreach (SpatialFrame frame in frames) { INativePersistence np = frame.AlignmentStrategy as INativePersistence; if (np != null) { await np.SaveNativeAsync(); } } // Create the serializer JsonSerializer ser = CreateSerializer(); // Serialize the list of frames ser.Serialize(writer, frames); }