Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
 }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
 internal byte[]? ReadToEndInner()
 {
     ApiCallSource.AssertAccess(Permissions, Access.Read);
     return(SharedStream?.ReadToEnd());
 }