/// <summary> /// Writes ChangeLog, Version and Change files using given instance of <see cref="IFileSaver"/> /// </summary> /// <param name="changeLog">ChangeLog to serialize.</param> /// <param name="saver">Service to save json strings to file paths.</param> /// <returns>True if was successful, false otherwise.</returns> public async Task <bool> Serialize(ChangeLog changeLog, IFileSaver saver) { if (changeLog == null) { return(false); } try { changeLog.Validate(); } catch (ChangeLogValidationException) { await saver.CancelPublish(); throw; } if (!(await saver.SaveFile(Path.Combine("temp", "changelog.json"), changeLog.ToJson()))) { return(false); } foreach (VersionRef versionRef in changeLog.Versions) { Version version = await versionRef.GetVersion(false); version.Changes.RemoveAll(c => c == null); if (version == null) { continue; } try { version.Validate(); } catch (ChangeLogValidationException) { await saver.CancelPublish(); throw; } if (!(await saver.SaveFile(Path.Combine("temp", version.VersionName, "version.json"), version.ToJson()))) { return(false); } foreach (ChangeRef changeRef in version.Changes) { Change change = await changeRef.GetChange(false); if (change == null) { continue; } try { change.Validate(changeLog); } catch (ChangeLogValidationException) { await saver.CancelPublish(); throw; } if (!(await saver.SaveFile(Path.Combine("temp", version.VersionName, "changes", $"{change.Guid}.json"), change.ToJson()))) { return(false); } } } bool success = await saver.PublishFromTemp(); // Clear caches CachedChangeLog = null; CachedVersions = new List <Version>(); CachedChanges = new List <Change>(); return(success); }