private void SaveToFileInner() { ApiCallSource.AssertAccess(Permissions, Access.Write); long pos = SharedStream.Stream.Position; SharedStream.Seek(0); File.WriteAllBytes(SourcePath, SharedStream.ReadToEnd()); SharedStream.Seek(pos); }
internal void SaveToFileInner() { ApiCallSource.AssertAccess(Permissions, Access.Write); var pos = SharedStream.Stream.Position; SharedStream.Seek(0); File.WriteAllText(SourcePath, SharedStream.ReadToEnd()); SharedStream.Seek(pos); }
internal void SerializeInner <TObject>(TObject obj, WriteMode writeMode = WriteMode.Overwrite) { ApiCallSource.AssertAccess(Permissions, Access.Write); if (writeMode == WriteMode.Overwrite) { SharedStream.Seek(0); SharedStream.SetLength(0); } else { SharedStream.Seek(0, SeekOrigin.End); } SharedStream.WriteLine(JsonConvert.SerializeObject(obj, Formatting.Indented)); }
internal void SerializeInner <TObject>(TObject obj, WriteMode writeMode = WriteMode.Overwrite) { ApiCallSource.AssertAccess(Permissions, Access.Write); if (writeMode == WriteMode.Overwrite) { SharedStream.Seek(0); SharedStream.SetLength(0); } else { SharedStream.Seek(0, SeekOrigin.End); } using (var writer = new StringWriter()) { new XmlSerializer(typeof(TObject)).Serialize(writer, obj); SharedStream.WriteLine(writer.ToString()); } }
internal TObject DeserializeInner <TObject>(long offset = long.MaxValue, SeekOrigin loc = SeekOrigin.Begin, bool retainPosition = true) { ApiCallSource.AssertAccess(Permissions, Access.Read); long?returnPosition = null; if (offset != long.MaxValue) { if (retainPosition) { returnPosition = SharedStream.Stream.Position; } SharedStream.Seek(offset, loc); } TObject obj = (TObject) new XmlSerializer(typeof(TObject)).Deserialize(new StreamReader(SharedStream.Stream)); if (returnPosition != null) { SharedStream.Seek(returnPosition.Value); } return(obj); }
internal TObject DeserializeInner <TObject>(long offset = long.MaxValue, SeekOrigin loc = SeekOrigin.Begin, bool retainPosition = true) { ApiCallSource.AssertAccess(Permissions, Access.Read); long?returnPosition = null; if (offset != long.MaxValue) { if (retainPosition) { returnPosition = SharedStream.Stream.Position; } SharedStream.Seek(offset, loc); } var obj = JsonConvert.DeserializeObject <TObject>(SharedStream.ReadToEnd()); if (returnPosition != null) { SharedStream.Seek(returnPosition.Value); } return(obj); }
internal byte[]? ReadToEndInner() { ApiCallSource.AssertAccess(Permissions, Access.Read); return(SharedStream?.ReadToEnd()); }