Esempio n. 1
0
 public static void ReadFromFile(IndexUnit indexPage, BinaryReader reader)
 {
     long initPos = reader.Seek(100L + (indexPage.UnitID * 0x1000L));
     if (reader.ReadByte() != 2)
     {
         throw new FileDBException("PageID {0} is not a Index Page", new object[] { indexPage.UnitID });
     }
     indexPage.NextUnitID = reader.ReadUInt32();
     indexPage.NodeIndex = reader.ReadByte();
     reader.Seek(initPos + 0x2eL);
     for (int i = 0; i <= indexPage.NodeIndex; i++)
     {
         IndexNode node = indexPage.Nodes[i];
         node.ID = reader.ReadGuid();
         node.IsDeleted = reader.ReadBoolean();
         node.Right.Index = reader.ReadByte();
         node.Right.PageID = reader.ReadUInt32();
         node.Left.Index = reader.ReadByte();
         node.Left.PageID = reader.ReadUInt32();
         node.DataPageID = reader.ReadUInt32();
         node.FileName = reader.ReadString(0x29);
         node.FileExtension = reader.ReadString(5);
         node.FileLength = reader.ReadUInt32();
     }
 }
Esempio n. 2
0
        public void AddPage(IndexUnit indexPage, bool markAsDirty)
        {
            if (!this._cache.ContainsKey(indexPage.UnitID))
            {
                if (this._cache.Count >= 200)
                {
					KeyValuePair<uint, IndexUnit> pageToRemove = default(KeyValuePair<uint, IndexUnit>);
					foreach (KeyValuePair<uint, IndexUnit> x in _cache)
					{
						if (x.Key != this._rootPageID)
						{
							pageToRemove = x;
							break;
						}
					}
                    if (pageToRemove.Value.IsDirty)
                    {
                        UnitFactory.WriteToFile(pageToRemove.Value, this._writer);
                        pageToRemove.Value.IsDirty = false;
                    }
                    this._cache.Remove(pageToRemove.Key);
                }
                this._cache.Add(indexPage.UnitID, indexPage);
            }
            if (markAsDirty)
            {
                indexPage.IsDirty = true;
            }
        }
Esempio n. 3
0
 public IndexUnit GetFreeIndexPage()
 {
     IndexUnit freeIndexPage = this.CacheIndexPage.GetPage(this.Header.FreeIndexPageID);
     if (freeIndexPage.NodeIndex >= 0x31)
     {
         Joy.Data.Header header = this.Header;
         header.LastPageID++;
         this.Header.IsDirty = true;
         IndexUnit newIndexPage = new IndexUnit(this.Header.LastPageID);
         freeIndexPage.NextUnitID = newIndexPage.UnitID;
         this.Header.FreeIndexPageID = this.Header.LastPageID;
         this.CacheIndexPage.AddPage(freeIndexPage, true);
         return newIndexPage;
     }
     freeIndexPage.NodeIndex = (byte) (freeIndexPage.NodeIndex + 1);
     return freeIndexPage;
 }
Esempio n. 4
0
 public static void CreateEmptyFile(BinaryWriter writer)
 {
     Header header = new Header {
         IndexRootPageID = 0,
         FreeIndexPageID = 0,
         FreeDataPageID = uint.MaxValue,
         LastFreeDataPageID = uint.MaxValue,
         LastPageID = 0
     };
     HeaderFactory.WriteToFile(header, writer);
     IndexUnit pageIndex = new IndexUnit(0) {
         NodeIndex = 0,
         NextUnitID = uint.MaxValue
     };
     IndexNode indexNode = pageIndex.Nodes[0];
     indexNode.ID = new Guid(new byte[] { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f });
     indexNode.IsDeleted = true;
     indexNode.Right = new IndexLink();
     indexNode.Left = new IndexLink();
     indexNode.DataPageID = uint.MaxValue;
     indexNode.FileName = string.Empty;
     indexNode.FileExtension = string.Empty;
     UnitFactory.WriteToFile(pageIndex, writer);
 }
Esempio n. 5
0
 public static void WriteToFile(IndexUnit indexPage, BinaryWriter writer)
 {
     long initPos = writer.Seek(100L + (indexPage.UnitID * 0x1000L));
     writer.Write((byte) indexPage.Type);
     writer.Write(indexPage.NextUnitID);
     writer.Write(indexPage.NodeIndex);
     writer.Seek(initPos + 0x2eL);
     for (int i = 0; i <= indexPage.NodeIndex; i++)
     {
         IndexNode node = indexPage.Nodes[i];
         writer.Write(node.ID);
         writer.Write(node.IsDeleted);
         writer.Write(node.Right.Index);
         writer.Write(node.Right.PageID);
         writer.Write(node.Left.Index);
         writer.Write(node.Left.PageID);
         writer.Write(node.DataPageID);
         writer.Write(node.FileName.ToBytes(0x29));
         writer.Write(node.FileExtension.ToBytes(5));
         writer.Write(node.FileLength);
     }
 }
Esempio n. 6
0
 public static IndexUnit GetIndexPage(uint pageID, BinaryReader reader)
 {
     IndexUnit indexPage = new IndexUnit(pageID);
     ReadFromFile(indexPage, reader);
     return indexPage;
 }
Esempio n. 7
0
 public void AddPage(IndexUnit indexPage)
 {
     this.AddPage(indexPage, false);
 }