public void Load(string FileName) { XmlSerializer Serializer = new XmlSerializer(typeof(List <Book>)); StreamReader Reader = new StreamReader(FileName); if (!IsUpdating) { CurData.Add((byte)DataBaseCommand.Load); byte[] buffer = new byte[Reader.BaseStream.Length]; Reader.BaseStream.Read(buffer, 0, (int)Reader.BaseStream.Length); CurData.AddRange(buffer); if (RealTimeCommit) { Commit(); } } base.Clear(); List <Book> Books = (List <Book>)Serializer.Deserialize(Reader); foreach (Book B in Books) { base.Add(B); } Reader.Close(); }
// Write methods. Commit is required new public Book this[int index] { get { return(base[index]); } set { if (IsUpdating) { if (Invoke != null) { //Invoke((Action)delegate { base.SetItem(index, value); }); // надо что-то с этим делать Invoke((Action) delegate { base.RemoveAt(index); }); Invoke((Action) delegate { base.Insert(index, value); }); } else { this[index] = value; } } else { CurData.Add((byte)DataBaseCommand.Change); AddInteger(index); CurData.AddRange(Encoding.UTF8.GetBytes(value.ToString())); if (TransactionRequest) { Argums = new Queue(); Argums.Enqueue(DataBaseCommand.Change); Argums.Enqueue(index); Argums.Enqueue(value); } else { if (Invoke != null) { //Invoke((Action)delegate { base.SetItem(index, value); }); // надо что-то с этим делать Invoke((Action) delegate { base.RemoveAt(index); }); Invoke((Action) delegate { base.Insert(index, value); }); } else { this[index] = value; } } if (RealTimeCommit) { Commit(); } } } }
// server save to stream public void Serialize() { XmlSerializer Serializer = new XmlSerializer(typeof(List <Book>)); byte[] ar = new byte[8192]; MemoryStream Stream = new MemoryStream(ar); Serializer.Serialize(Stream, base.Items); Array.Resize(ref ar, (int)Stream.Position); Stream.Close(); CurData.Add((byte)DataBaseCommand.Load); CurData.AddRange(ar); if (RealTimeCommit) { Commit(); } }
public void Insert(int index, Book item) { if (IsUpdating) { if (Invoke != null) { Invoke((Action) delegate { base.Insert(index, item); }); } else { base.Insert(index, item); } } else { CurData.Add((byte)DataBaseCommand.Add); AddInteger(index); CurData.AddRange(Encoding.Unicode.GetBytes(item.ToString())); if (TransactionRequest) { Argums = new Queue(); Argums.Enqueue(DataBaseCommand.Add); Argums.Enqueue(index); Argums.Enqueue(item); } else { if (Invoke != null) { Invoke((Action) delegate { base.Insert(index, item); }); } else { base.Insert(index, item); } } if (RealTimeCommit) { Commit(); } } }