public Index(string nm, ushort kl, DateTime udTime) { int sz = DataFile.GetSize(Root); if (DataFile.Exists(nm, "Index")) { File = DataFile.Open(nm, "Index", FileMode.Open); File.Read(Root, DataFile.coSignatureSz, sz); if (DateTime.Compare(Root.LastUpdate, udTime) >= 0 && Root.Closed) { Root.Closed = false; File.Lock(Root); File.Write(Root); return; } File.Close(); DataFile.Delete(nm, "Index"); } File = DataFile.Open(nm, "Index", FileMode.CreateNew); DataFile.Blank(Root, sz); Root.KeyLength = kl; Root.Closed = false; Root.PageSize = (ushort)DataFile.GetSize(new IdxPage(0, 0, 0, kl)); File.Append(Root, sz); File.Lock(Root); }
internal static void Create(string nm, Table obj) { TableFile db; if (OpenList.TryGetValue(nm, out db)) { throw new System.InvalidOperationException("MinBase: Cannot create table " + nm + " because there is a perviously open table with the same name."); } db = new TableFile(); Struct stt = new Struct(); db.File = DataFile.Open(nm, "Table", FileMode.CreateNew); stt.RowLength = DataFile.GetSize(obj); stt.RowCount = 0; db.File.Append(stt, DataFile.GetSize(stt)); db.File.Close(); }
internal static void Open(string nm, Table obj, mpIndexKey gkey, string xn) { TableFile db; SyncOpen.WaitOne(); if (OpenList.TryGetValue(nm, out db)) { db.OpenCount++; } else { db = new TableFile(); db.Alias = nm; db.File = DataFile.Open(nm, "Table", FileMode.Open); db.Struct = new Struct(); int sz = DataFile.GetSize(db.Struct); db.File.Read(db.Struct, DataFile.coSignatureSz, sz); db.File.Lock(db.Struct); db.OpenCount = 1; db.Data = DataFile.coSignatureSz + sz; long cz = db.Data + db.Struct.RowLength * db.Struct.RowCount; long fz = db.File.LoFile.Length; if (cz != fz) { db.Struct.LastUpdate = DateTime.Now; db.File.Write(db.Struct); db.File.CopyTo(String.Format("{0}{1:yyyy}{1:MM}{1:dd}{1:HH}{1:mm}{1:ss}", nm, db.Struct.LastUpdate), "BackupTable"); db.File.LoFile.SetLength(cz); } OpenList.Add(nm, db); } SyncOpen.ReleaseMutex(); obj.LoTable = db; if (gkey == null) { obj.Order = null; } else { obj.Order = db.SetView(obj, xn, gkey); } obj.First(); }