internal async Task SaveOdiDocuments(dynamic doc, StorageAdapter adapter, string newName) { if (doc == null) { throw new ArgumentNullException($"Failed to persist document because {nameof(doc)} is null."); } // Ask the adapter to make it happen. try { var oldDocumentPath = doc.DocumentPath; var newDocumentPath = oldDocumentPath.Substring(0, oldDocumentPath.Length - FetchOdiExtension().Length) + newName; var content = JsonConvert.SerializeObject(doc, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() }); await adapter.WriteAsync(newDocumentPath, content); } catch (Exception e) { Logger.Error(nameof(PersistenceLayer), (ResolveContext)this.Ctx, $"Failed to write to the file '{doc.DocumentPath}' for reason {e.Message}.", nameof(SaveOdiDocuments)); } // Save linked documents. if (doc.LinkedDocuments != null) { foreach (var linkedDoc in doc.LinkedDocuments) { await SaveOdiDocuments(linkedDoc, adapter, newName); } } }
/// <summary> /// Saves adapters config into a file. /// </summary> /// <param name="name">The name of a file.</param> /// <param name="adapter">The adapter used to save the config to a file.</param> public async Task SaveAdaptersConfigAsync(string name, StorageAdapter adapter) { await adapter.WriteAsync(name, FetchConfig()); }
/// <summary> /// Saves adapters config into a file. /// </summary> /// <param name="name">The name of a file.</param> /// <param name="adapter">The adapter used to save the config to a file.</param> public void SaveAdaptersConfig(string name, StorageAdapter adapter) { adapter.WriteAsync(name, FetchConfig()); }