Esempio n. 1
0
        public IB Reserve(AllocationInfo allocationInfo)
        {
            amapRegionUpdater.Update(
                allocationInfo.MapOffset,
                map =>
            {
                var bits = map.Data.Value.ToBits();

                for (var i = allocationInfo.BitStartIndex; i <= allocationInfo.BitEndIndex; i++)
                {
                    bits[i] = 1;
                }

                var bytes = bits.ToBytes();

                return
                (new AMap(
                     BinaryData.OfValue(bytes),
                     new PageTrailer(
                         Constants.ptypeAMap,
                         Constants.ptypeAMap,
                         0x0000,
                         Crc32.ComputeCrc32(bytes),
                         BID.OfValue(allocationInfo.MapOffset))));
            });

            var allocateSize = (allocationInfo.BitEndIndex - allocationInfo.BitStartIndex + 1) * 64;

            headerUsageProvider.Use(header => header.SetRoot(header.Root.SetFreeSpaceInAllAMaps(header.Root.AMapFree - allocateSize)));

            return(IB.OfValue(allocationInfo.MapOffset + allocationInfo.BitStartIndex * 64));
        }
Esempio n. 2
0
        //加载窗口
        private void A_returnBook_Load(object sender, EventArgs e)
        {
            SqlConnection conn = SQLbase.getConn();

            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Open();
                SqlCommand    selectCmd = new SqlCommand("select * from returntable", conn);
                SqlDataReader datareader = selectCmd.ExecuteReader();
                string        RID, BID, Bname;
                int           rowindex = 0;
                this.datagridview.Rows.Clear();
                while (datareader.Read())
                {
                    RID   = datareader["RID"].ToString();
                    Bname = datareader["Bname"].ToString();
                    BID   = datareader["BID"].ToString();

                    rowindex = this.datagridview.Rows.Add();
                    //trim函数同于去除字符串两头的空格
                    this.datagridview.Rows[rowindex].Cells[0].Value = RID.Trim();
                    this.datagridview.Rows[rowindex].Cells[1].Value = BID.Trim();
                    this.datagridview.Rows[rowindex].Cells[2].Value = Bname.Trim();
                }
            }
            catch
            {
                MessageBox.Show("操作错误!");
            }
        }
Esempio n. 3
0
        private SLEntry[] EnumerateAndAdd(BID blockId, int currentDepth)
        {
            if (currentDepth == 1)
            {
                var subnodeBlock = subnodeBlockLoader.LoadNode(blockId);

                var intermediateKeys = entriesFromIntermediateSubnodeBlockExtractor.Extract(subnodeBlock);

                var allLeafKeys = new List <SLEntry>();

                foreach (var key in intermediateKeys)
                {
                    var leafKeys = EnumerateAndAdd(key.SLBlockId, currentDepth - 1);

                    allLeafKeys.AddRange(leafKeys);
                }

                return(allLeafKeys.ToArray());
            }
            else
            {
                var subnodeBlock = subnodeBlockLoader.LoadNode(blockId);

                return(entriesFromLeafSubnodeBlockExtractor.Extract(subnodeBlock));
            }
        }
Esempio n. 4
0
        private BID[] EnumerateAndAdd(BID blockId, int currentDepth)
        {
            if (currentDepth == 2)
            {
                var blockEntry = GetDataBlockEntry(blockId).Value;

                var internalDataBlock = internalDataBlockLoader.LoadNode(blockEntry);

                var intermediateKeys = blockIdsFromInternalDataBlockExtractor.Extract(internalDataBlock);

                var allLeafKeys = new List <BID>();

                foreach (var key in intermediateKeys)
                {
                    var leafKeys = EnumerateAndAdd(key, currentDepth - 1);

                    allLeafKeys.AddRange(leafKeys);
                }

                return(allLeafKeys.ToArray());
            }

            if (currentDepth == 1)
            {
                var blockEntry = GetDataBlockEntry(blockId).Value;

                var internalDataBlock = internalDataBlockLoader.LoadNode(blockEntry);

                return(blockIdsFromInternalDataBlockExtractor.Extract(internalDataBlock));
            }

            return(new[] { blockId });
        }
Esempio n. 5
0
 public BlockTrailer(int amountOfData, int blockSignature, int dataCrc, BID blockId)
 {
     AmountOfData   = amountOfData;
     BlockSignature = blockSignature;
     DataCrc        = dataCrc;
     BlockId        = blockId;
 }
Esempio n. 6
0
        public ActionResult CreateBid(int id, FormCollection collection)
        {
            try
            {
                BID bid = db.BIDS.Create();

                bid.ItemID      = id;
                bid.BuyerID     = 1;
                bid.Price       = collection["price"];
                bid.BidDateTime = DateTime.Now;

                Debug.WriteLine(bid.ItemID);
                Debug.WriteLine(bid.Price);
                Debug.WriteLine(bid.BidDateTime);

                db.BIDS.Add(bid);
                db.SaveChanges();

                return(RedirectToAction("items"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 7
0
        private BinaryData Process(BinaryData blockData, BID blockId)
        {
            var stream = new MemoryStream();

            var dwKey = (int)(blockId.Value & 0x0000FFFF);

            var w = (short)(dwKey ^ (dwKey >> 16));

            for (var i = 0; i < blockData.Length; i++)
            {
                var b = (byte)(blockData.Value[i] + (byte)w);
                b = Constants.mpbbCrypt[b];
                b = (byte)(b + (byte)(w >> 8));
                b = Constants.mpbbCrypt[b + 256];
                b = (byte)(b - (byte)(w >> 8));
                b = Constants.mpbbCrypt[b + 512];
                b = (byte)(b - (byte)w);

                stream.WriteByte(b);

                w++;
            }

            return(BinaryData.OfValue(stream.ToArray()));
        }
Esempio n. 8
0
 public LNBTEntry(NID nodeId, BID dataBlockId, BID subnodeBlockId, NID parentNodeId, BinaryData padding)
 {
     NodeId         = nodeId;
     DataBlockId    = dataBlockId;
     SubnodeBlockId = subnodeBlockId;
     ParentNodeId   = parentNodeId;
     Padding        = padding;
 }
Esempio n. 9
0
 public PageTrailer(int pageType, int pageTypeRepeat, int pageSignature, int crc32ForPageData, BID pageBlockId)
 {
     PageType         = pageType;
     PageTypeRepeat   = pageTypeRepeat;
     PageSignature    = pageSignature;
     Crc32ForPageData = crc32ForPageData;
     PageBlockId      = pageBlockId;
 }
Esempio n. 10
0
        public ActionResult DeleteConfirmed(int id)
        {
            BID bID = db.BIDs.Find(id);

            db.BIDs.Remove(bID);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 private void BindPODetail()
 {
     foreach (BidderItemDetail BID in _presenter.CurrentBidAnalysisRequest.BidderItemDetails)
     {
         if (BID.GetBidderbyRank() != null)
         {
             dgPODetail.DataSource = BID.Bidders;
             dgPODetail.DataBind();
         }
     }
 }
Esempio n. 12
0
        public BinaryData Read(BID blockId)
        {
            var header = headerReader.GetHeader();

            var lbbtEntry = blockBTreeEntryFinder.Find(blockId, header.Root.BBTRootPage);

            return
                (dataReader.Read(
                     lbbtEntry.Value.BlockReference.ByteIndex.Value,
                     lbbtEntry.Value.ByteCountOfRawDataInReferencedBlockExcludingTrailerAndAlignmentPadding));
        }
Esempio n. 13
0
 public ActionResult Edit([Bind(Include = "ID,ITEM,BUYER,PRICE,TIME")] BID bID)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bID).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BUYER = new SelectList(db.BUYERs, "ID", "NAME", bID.BUYER);
     ViewBag.ITEM  = new SelectList(db.ITEMs, "ID", "NAME", bID.ITEM);
     return(View(bID));
 }
Esempio n. 14
0
        public ExternalDataBlock Create(IB blockOffset, BID blockId, BinaryData data)
        {
            var obfuscatedData = dataObfuscator.Obfuscate(data, blockId);

            return
                (new ExternalDataBlock(
                     obfuscatedData,
                     BinaryData.OfSize(Utilities.GetExternalDataBlockPaddingSize(obfuscatedData.Length)),
                     new BlockTrailer(
                         obfuscatedData.Length,
                         BlockSignature.Calculate(blockOffset, blockId),
                         Crc32.ComputeCrc32(obfuscatedData),
                         blockId)));
        }
Esempio n. 15
0
        // GET: BIDs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BID bID = db.BIDs.Find(id);

            if (bID == null)
            {
                return(HttpNotFound());
            }
            return(View(bID));
        }
Esempio n. 16
0
        private FPMap CreateFPMap(long mapOffset)
        {
            var data = BinaryData.OfSize(496, 0xFF);

            return
                (new FPMap(
                     data,
                     new PageTrailer(
                         Constants.ptypeFPMap,
                         Constants.ptypeFPMap,
                         0x0000,
                         (int)Crc32.ComputeCrc32(data.Value),
                         BID.OfValue(mapOffset))));
        }
Esempio n. 17
0
        // GET: BIDs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BID bID = db.BIDs.Find(id);

            if (bID == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BUYER = new SelectList(db.BUYERs, "ID", "NAME", bID.BUYER);
            ViewBag.ITEM  = new SelectList(db.ITEMs, "ID", "NAME", bID.ITEM);
            return(View(bID));
        }
Esempio n. 18
0
        public BID Allocate(IB blockOffset, int rawDataSize, bool internalBlock)
        {
            var bidIndex = headerUsageProvider.GetHeader().NextBID;

            headerUsageProvider.Use(header => header.IncrementBIDIndexForDataBlocks());

            var blockId = internalBlock ? BID.ForInternalBlock(bidIndex) : BID.ForExternalBlock(bidIndex);

            allocatedBlockBTreeEntries.Add(
                new LBBTEntry(
                    BREF.OfValue(blockId, blockOffset),
                    rawDataSize,
                    numberOfReferencesToThisBlock: 2,
                    padding: BinaryData.OfSize(4)));

            return(blockId);
        }
Esempio n. 19
0
 public Tile(bool isFilled,
             bool isBacked,
             TID tileID,
             BID backID,
             bool randomSprite = false, int spriteIndex = 0, bool hasBehavior = false, bool hasWire = false, bool hasOverlay = false)
 {
     this.data = isFilled ? Masks.FILL : 0;
     data      = data | (isBacked ? Masks.BACK : 0);
     data      = data | (hasBehavior ? Masks.BEHAVIOR : 0);
     data      = data | (hasWire ? Masks.WIRE : 0);
     data      = data | (hasOverlay ? Masks.OVERLAY : 0);
     data      = data | (randomSprite ? Masks.RANDOM_SPRITE : 0);
     data      = data | (Masks.TID & (int)tileID);
     data      = data | (Masks.BID & ((int)backID << Masks.BID_SHIFT));
     data      = data | (Masks.SPRITE & (spriteIndex << Masks.SPRITE_SHIFT));
     //this.data = data32;
 }
Esempio n. 20
0
        private Maybe <NodeEntry> GetEntry(NID[] nodePath, int currentDepth, BID parentNodeSubnodeDataBlockId)
        {
            var parentSubnodes = subnodesEnumerator.Enumerate(parentNodeSubnodeDataBlockId);

            var subnodeEntry = parentSubnodes.First(s => s.LocalSubnodeId.Equals(nodePath[currentDepth]));

            if (currentDepth < nodePath.Length - 1)
            {
                return(GetEntry(nodePath, currentDepth + 1, subnodeEntry.SubnodeBlockId));
            }

            var subnodes =
                subnodeEntry.SubnodeBlockId.Equals(BID.Zero)
                ? new SLEntry[0]
                : subnodesEnumerator.Enumerate(subnodeEntry.SubnodeBlockId);

            return(Maybe <NodeEntry> .OfValue(new NodeEntry(subnodeEntry.DataBlockId, subnodeEntry.SubnodeBlockId, subnodes)));
        }
Esempio n. 21
0
        private AMap CreateAMap(long mapOffset, params byte[] defaultAllocations)
        {
            var data = new byte[496];

            for (var i = 0; i < defaultAllocations.Length; i++)
            {
                data[i] = defaultAllocations[i];
            }

            return
                (new AMap(
                     BinaryData.OfValue(data),
                     new PageTrailer(
                         Constants.ptypeAMap,
                         Constants.ptypeAMap,
                         0x0000,
                         (int)Crc32.ComputeCrc32(data),
                         BID.OfValue(mapOffset))));
        }
Esempio n. 22
0
        public InternalDataBlock Create(
            IB blockOffset,
            BID blockId,
            BlockIdsWithTotalNumberOfBytesInReferencedBlocks data)
        {
            var encodedExternalBlockIds = data.BlockIds.Encode(bidEncoder);

            return
                (new InternalDataBlock(
                     0x01,
                     blockLevel,
                     data.BlockIds.Length,
                     data.TotalNumberOfBytesInReferencedBlocks,
                     encodedExternalBlockIds,
                     BinaryData.OfSize(Utilities.GetInternalDataBlockPaddingSize(encodedExternalBlockIds.Length)),
                     new BlockTrailer(
                         encodedExternalBlockIds.Length + 8,
                         BlockSignature.Calculate(blockOffset, blockId),
                         Crc32.ComputeCrc32(GetDataToCalculateCrc32(encodedExternalBlockIds, data.BlockIds.Length, data.TotalNumberOfBytesInReferencedBlocks)),
                         blockId)));
        }
        public BinaryData DeObfuscate(BinaryData blockData, BID blockId)
        {
            var header = headerReader.GetHeader();

            if (header.CryptMethod == Constants.NDB_CRYPT_NONE)
            {
                return(noEncoding.DeObfuscate(blockData, blockId));
            }

            if (header.CryptMethod == Constants.NDB_CRYPT_CYCLIC)
            {
                return(cyclicEncoding.DeObfuscate(blockData, blockId));
            }

            if (header.CryptMethod == Constants.NDB_CRYPT_PERMUTE)
            {
                return(permutativeEncoding.DeObfuscate(blockData, blockId));
            }

            throw new Exception($"Unexpected bCryptMethod {header.CryptMethod}");
        }
Esempio n. 24
0
        private BinaryData[] Read(BID dataTreeRootBlockId, Maybe <int> blockIndex)
        {
            var header = headerReader.GetHeader();

            var lbbtEntry = blockBTreeEntryFinder.Find(dataTreeRootBlockId, header.Root.BBTRootPage);

            var externalDataBlockIds = externalDataBlockIdsReader.Read(lbbtEntry.Value);

            if (blockIndex.HasNoValue)
            {
                return(externalDataBlockIds.Select(ReadExternalBlock).ToArray());
            }

            if (externalDataBlockIds.Length > 0)
            {
                var leafBlockId = externalDataBlockIds[blockIndex.Value];

                return(new[] { ReadExternalBlock(leafBlockId) });
            }

            return(new BinaryData[0]);
        }
Esempio n. 25
0
        public ActionResult Create([Bind(Include = "ID,ITEM,BUYER,PRICE")] BID bID)
        {
            bID.TIME = new DateTime(
                DateTime.Now.Year,
                DateTime.Now.Month,
                DateTime.Now.Day,
                DateTime.Now.Hour,
                DateTime.Now.Minute,
                DateTime.Now.Second
                ); //Update the time when the user submits the bid

            if (ModelState.IsValid)
            {
                db.BIDs.Add(bID);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BUYER = new SelectList(db.BUYERs, "ID", "NAME", bID.BUYER);
            ViewBag.ITEM  = new SelectList(db.ITEMs, "ID", "NAME", bID.ITEM);
            return(View(bID));
        }
Esempio n. 26
0
 public BinaryData Obfuscate(BinaryData blockData, BID blockId)
 {
     return(Process(blockData, true));
 }
Esempio n. 27
0
 public BinaryData DeObfuscate(BinaryData blockData, BID blockId)
 {
     return(Process(blockData, false));
 }
Esempio n. 28
0
 public DataTreeWithPossibleSubnodes(BID dataTreeRootBlockId, Maybe <Tuple <NID, BID>[]> subnodes)
 {
     DataTreeRootBlockId = dataTreeRootBlockId;
     Subnodes            = subnodes;
 }
Esempio n. 29
0
        public static int Calculate(IB blockOffset, BID blockId)
        {
            var result = blockOffset.Value ^ blockId.Value;

            return((int)(result >> 16) ^ (int)result);
        }
Esempio n. 30
0
        //查询按钮
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = SQLbase.getConn();

            try
            {
                this.datagridview.Rows.Clear();   //清空表格
                //打开连接
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Open();
                string selectStr = "select * from Borrow";
                //按读者号查询
                if (comboBox_QueryStyle.SelectedIndex == 0)
                {
                    string rid = txt_query.Text.ToString();
                    //建立查询命令
                    selectStr = "select * from Borrow where RID=" + rid;
                }
                //按书号查询
                else if (comboBox_QueryStyle.SelectedIndex == 1)
                {
                    string bid = txt_query.Text.ToString();
                    //建立查询命令
                    selectStr = "select * from Borrow where BID=" + bid;
                }
                //没有选择下拉框,则查询全部
                SqlCommand    selectCmd = new SqlCommand(selectStr, conn);
                SqlDataReader datareader = selectCmd.ExecuteReader();
                string        BID, Bname, RID, Rname, BorrowDate, RealDate, Note;
                int           rowindex = 0;
                this.datagridview.Rows.Clear();

                while (datareader.Read())
                {
                    RID        = datareader["RID"].ToString();
                    BID        = datareader["BID"].ToString();
                    BorrowDate = datareader["BorrowDate"].ToString();
                    RealDate   = datareader["RealDate"].ToString();
                    Note       = datareader["Note"].ToString();

                    rowindex = this.datagridview.Rows.Add();
                    //trim函数同于去除字符串两头的空格
                    this.datagridview.Rows[rowindex].Cells[0].Value = BID.Trim();
                    this.datagridview.Rows[rowindex].Cells[2].Value = RID.Trim();
                    this.datagridview.Rows[rowindex].Cells[4].Value = BorrowDate.Trim();
                    this.datagridview.Rows[rowindex].Cells[5].Value = RealDate.Trim();
                    this.datagridview.Rows[rowindex].Cells[6].Value = Note.Trim();
                }
                datareader.Close();
                SQLbase.close(selectCmd);
                int n = this.datagridview.RowCount;
                for (int i = 0; i < n; i++)
                {
                    //填充书名
                    BID   = this.datagridview.Rows[i].Cells[0].Value.ToString();
                    Bname = selectBook(conn, BID);
                    this.datagridview.Rows[i].Cells[1].Value = Bname.Trim();
                    //填充作者名
                    RID   = this.datagridview.Rows[i].Cells[2].Value.ToString();
                    Rname = selectReader(conn, RID);
                    this.datagridview.Rows[i].Cells[3].Value = Rname.Trim();
                }
            }
            catch
            {
                MessageBox.Show("查无此记录!");
            }
            SQLbase.close(conn);
        }