예제 #1
0
        // reads a resource or a reservation data item
        protected virtual bool Read <I, R>(Transaction context, StorageContext storageContext, StorageIndex <I> index, I rID, bool lockPage, out R data)
        {
            // look for the resource in the index
            IndexItem <I> address = index.GetResourceAddress(rID);

            if (null == address)
            {
                data = default(R);
                return(false);
            }

            if (lockPage)
            {
                // Aquire a lock on the logical page address to ensure that the page is not
                // being written while we read the data
                this.LockPage(context, MyLM.LockMode.Read, address.Page);
            }

            // find the physical page
            int fileAddress = storageContext.PageTable.GetPhysicalPage(address.Page);

            // get the page
            StoragePage page = new StoragePage();

            this.aReadPageData(page, fileAddress);

            // read the data
            data = (R)page.ReadRecord(address.Record);

            return(true);
        }
예제 #2
0
        private DBHdr ReadDBRoot()
        {
            DBHdr dbRoot = null;

            try
            {
                StoragePage rootPage = new StoragePage();
                rootPage.ReadPageData(this.dataFile, RootPage);
                dbRoot = (DBHdr)rootPage.ReadRecord(0);
            }
            catch (Exception)
            {
                dbRoot = null;
            }

            return(dbRoot);
        }
예제 #3
0
 private void ReadRecords(StoragePage page, TestData[] data)
 {
     foreach (TestData test in data)
     {
         try
         {
             string result = (string)page.ReadRecord(test.recordIdx);
             Assert.AreEqual(test.data, result,
                 "Read record did not match. Test Data = [{0}]", test.ToString());
         }
         catch (Exception e)
         {
             Assert.AreEqual(test.exception, e.GetType().Name,
                 "Unexpected exception. Test Data = [{0}]", test.ToString());
         }
     }
 }