/// <summary> /// Create a <see cref="ModelSaveContext"/> supporting saving to a repository, for implementors of <see cref="ICanSaveModel"/>. /// </summary> internal ModelSaveContext(RepositoryWriter rep, string dir, string name) { Contracts.CheckValue(rep, nameof(rep)); Repository = rep; _ectx = rep.ExceptionContext; _ectx.CheckValueOrNull(dir); _ectx.CheckNonEmpty(name, nameof(name)); Directory = dir; Strings = new NormStr.Pool(); _ent = rep.CreateEntry(dir, name); try { Writer = new BinaryWriter(_ent.Stream, Encoding.UTF8, leaveOpen: true); try { ModelHeader.BeginWrite(Writer, out FpMin, out Header); } catch { Writer.Dispose(); throw; } } catch { _ent.Dispose(); throw; } }
/// <summary> /// Create a <see cref="ModelSaveContext"/> supporting saving to a single-stream, for implementors of <see cref="ICanSaveInBinaryFormat"/>. /// </summary> internal ModelSaveContext(BinaryWriter writer, IExceptionContext ectx = null) { Contracts.AssertValueOrNull(ectx); _ectx = ectx; _ectx.CheckValue(writer, nameof(writer)); Repository = null; Directory = null; _ent = null; Strings = new NormStr.Pool(); Writer = writer; ModelHeader.BeginWrite(Writer, out FpMin, out Header); }