Example #1
0
        private void SaveToFileInner()
        {
            ApiCallSource.AssertAccess(Permissions, Access.Write);

            long pos = SharedStream.Stream.Position;

            SharedStream.Seek(0);
            File.WriteAllBytes(SourcePath, SharedStream.ReadToEnd());
            SharedStream.Seek(pos);
        }
Example #2
0
        internal void SaveToFileInner()
        {
            ApiCallSource.AssertAccess(Permissions, Access.Write);

            var pos = SharedStream.Stream.Position;

            SharedStream.Seek(0);
            File.WriteAllText(SourcePath, SharedStream.ReadToEnd());
            SharedStream.Seek(pos);
        }
Example #3
0
 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));
 }
Example #4
0
        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());
            }
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
 internal byte[]? ReadToEndInner()
 {
     ApiCallSource.AssertAccess(Permissions, Access.Read);
     return(SharedStream?.ReadToEnd());
 }