public async Task ApplyTo(DataCollection collection, bool final = false) { foreach (var item in _removed.ToArray()) { collection.RemoveFile(item.Model.Name); } foreach (var item in _added.ToArray()) { var fs = _streams[item].Item2; if (final) { using (fs) { await collection.AddFile(item.Model.Name, fs); } } else { await collection.AddFile(item.Model.Name, fs); fs.Position = 0; } } foreach (var item in _renamed.ToArray()) { await collection.RenameFile(item.Item1, item.Item2); } if (final) { _added.Clear(); _removed.Clear(); _renamed.Clear(); } }
private static async Task InheritContent(SIDocument doc, SIDocument doc2, Question question) { foreach (var atom in question.Scenario) { if (atom.Type == AtomTypes.Text || atom.Type == AtomTypes.Oral) { continue; } var link = doc2.GetLink(atom); if (link.GetStream != null) { DataCollection collection = null; switch (atom.Type) { case AtomTypes.Video: collection = doc.Video; break; case AtomTypes.Audio: collection = doc.Audio; break; case AtomTypes.Image: collection = doc.Images; break; } if (collection != null) { using (var stream = link.GetStream().Stream) { await collection.AddFile(link.Uri, stream); } } } } }
public async Task Commit(DataCollection collection) { foreach (var item in _removed.ToArray()) { collection.RemoveFile(item.Model.Name); item.PropertyChanged -= Named_PropertyChanged; _removed.Remove(item); } foreach (var item in _added.ToArray()) { try { using (var fs = _streams[item].Item2) { await collection.AddFile(item.Model.Name, fs); } } catch (Exception exc) { OnError(exc); } _added.Remove(item); _streams.Remove(item); } foreach (var item in _renamed.ToArray()) { await collection.RenameFile(item.Item1, item.Item2); _renamed.Remove(item); } HasPendingChanges = false; }