Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 void AddInteger(int number)
 {
     CurData.Add((byte)((number & 0xFF000000) >> 24));
     CurData.Add((byte)((number & 0x00FF0000) >> 16));
     CurData.Add((byte)((number & 0x0000FF00) >> 8));
     CurData.Add((byte)((number & 0x000000FF)));
 }
Esempio n. 3
0
 public void Get()
 {
     CurData.Add((byte)DataBaseCommand.Serialize);
     if (RealTimeCommit)
     {
         Commit();
     }
 }
Esempio n. 4
0
        // 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();
                    }
                }
            }
        }
Esempio n. 5
0
        // 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();
            }
        }
Esempio n. 6
0
        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();
                }
            }
        }
Esempio n. 7
0
        new public void RemoveAt(int index)
        {
            if (IsUpdating)
            {
                if (Invoke != null)
                {
                    Invoke((Action) delegate { base.RemoveAt(index); });
                }
                else
                {
                    base.RemoveAt(index);
                }
            }
            else
            {
                CurData.Add((byte)DataBaseCommand.RemoveAt);
                AddInteger(index);
                if (TransactionRequest)
                {
                    Argums = new Queue();
                    Argums.Enqueue(DataBaseCommand.RemoveAt);
                    Argums.Enqueue(index);
                }
                else
                {
                    if (Invoke != null)
                    {
                        Invoke((Action) delegate { base.RemoveAt(index); });
                    }
                    else
                    {
                        base.RemoveAt(index);
                    }
                }

                if (RealTimeCommit)
                {
                    Commit();
                }
            }
        }
Esempio n. 8
0
 public void TransactCommit()
 {
     CurData.Add((Byte)DataBaseCommand.TransactCommited);
     Commit();
 }