Ejemplo n.º 1
0
        internal void Close(Table obj)
        {
            SyncOpen.WaitOne();
            View vw = obj.Order;

            obj.LoTable = null;
            obj.Order   = null;
            if (vw != null && vw.Close())
            {
                SyncView.WaitOne();
                ViewList.Remove(vw.getkey);
                SyncView.ReleaseMutex();
            }
            if (OpenCount == 1)
            {
                string tmpfile = "";
                if (MustPack)
                {
                    Struct.LastUpdate = DateTime.Now;
                    tmpfile           = String.Format("{0}{1:yyyy}{1:MM}{1:dd}{1:HH}{1:mm}{1:ss}", Alias, Struct.LastUpdate);
                    File.CopyTo(tmpfile, "BackupTable");
                    long r, w, x;
                    w = 1;
                    x = Struct.RowCount;
                    for (r = 1; r <= x; r++)
                    {
                        Read(obj, r);
                        if (!Deleted(obj))
                        {
                            if (w != r)
                            {
                                obj.Buffer.Position = Data + (w - 1) * Struct.RowLength;
                                File.Write(obj);
                            }
                            w++;
                        }
                    }
                    Struct.LastUpdate = DateTime.Now;
                    Struct.RowCount   = w - 1;
                    File.LoFile.SetLength(Data + Struct.RowLength * Struct.RowCount);
                }
                File.Write(Struct);
                File.Close();
                if (MustPack)
                {
                    DataFile.Delete(tmpfile, "BackupTable");
                }
                OpenList.Remove(Alias);
            }
            else
            {
                OpenCount--;
            }
            SyncOpen.ReleaseMutex();
        }