示例#1
0
        public void Parse_ProductModel(string dbPath, int pageID)
        {
            var db     = new RawDataFile(dbPath);
            var page   = db.GetPage(pageID);
            var record = page.Records.First() as RawPrimaryRecord;

            var result = RawColumnParser.Parse(record, new IRawType[] {
                RawType.Int("ProductModelID"),
                RawType.NVarchar("Name"),
                RawType.Xml("CatalogDescription"),
                RawType.UniqueIdentifier("rowguid"),
                RawType.DateTime("ModifiedDate")
            });

            Assert.AreEqual(5, ((Dictionary <string, object>)result).Count);
            Assert.AreEqual(1, result.ProductModelID);
            Assert.AreEqual("Classic Vest", result.Name);
            Assert.AreEqual(null, result.CatalogDescription);
            Assert.AreEqual(new Guid("29321d47-1e4c-4aac-887c-19634328c25e"), result.rowguid);
            Assert.AreEqual(Convert.ToDateTime("2003-06-01"), result.ModifiedDate);
        }
示例#2
0
        public void Parse_ProductCategory(string dbPath, int pageID)
        {
            var db     = new RawDataFile(dbPath);
            var page   = db.GetPage(pageID);
            var record = page.Records.First() as RawPrimaryRecord;

            var result = RawColumnParser.Parse(record, new IRawType[] {
                RawType.Int("ProductCategoryID"),
                RawType.Int("ParentProductCategoryID"),
                RawType.NVarchar("Name"),
                RawType.UniqueIdentifier("rowguid"),
                RawType.DateTime("ModifiedDate")
            });

            Assert.AreEqual(5, ((Dictionary <string, object>)result).Count);
            Assert.AreEqual(1, result.ProductCategoryID);
            Assert.AreEqual(null, result.ParentProductCategoryID);
            Assert.AreEqual("Bikes", result.Name);
            Assert.AreEqual(new Guid("cfbda25c-df71-47a7-b81b-64ee161aa37c"), result.rowguid);
            Assert.AreEqual(Convert.ToDateTime("1998-06-01"), result.ModifiedDate);
        }
示例#3
0
        public void Parse_CustomerAddress(string dbPath, int pageID, int customerID, int addressID, string rowguid, string modifiedDate)
        {
            var db     = new RawDataFile(dbPath);
            var page   = db.GetPage(pageID);
            var record = page.Records.First() as RawPrimaryRecord;

            var result = RawColumnParser.Parse(record, new IRawType[] {
                RawType.Int("CustomerID"),
                RawType.Int("AddressID"),
                RawType.NVarchar("AddressType"),
                RawType.UniqueIdentifier("rowguid"),
                RawType.DateTime("ModifiedDate")
            });

            Assert.AreEqual(5, ((Dictionary <string, object>)result).Count);
            Assert.AreEqual(customerID, result.CustomerID);
            Assert.AreEqual(addressID, result.AddressID);
            Assert.AreEqual("Main Office", result.AddressType);
            Assert.AreEqual(new Guid(rowguid), result.rowguid);
            Assert.AreEqual(Convert.ToDateTime(modifiedDate), result.ModifiedDate);
        }
示例#4
0
        public void BranchLevelNonClusteredWithNullBitmapAndVariableLength2012_SecondRecord()
        {
            var rawBytes = TestHelper.GetBytesFromByteString(@"
				36d90000 00780200 00010002 00000100 46006300
				68007200 69007300 36004000 61006400 76006500
				6e007400 75007200 65002d00 77006f00 72006b00
				73002e00 63006f00 6d00
			"            );

            var record = new RawIndexRecord(new ArrayDelimiter <byte>(rawBytes), 11, 1);

            Assert.AreEqual(1, record.ChildFileID);
            Assert.AreEqual(632, record.ChildPageID);

            dynamic row = RawColumnParser.Parse(record, new IRawType[] {
                RawType.NVarchar("EmailAddress"),
                RawType.Int("CustomerID")
            });

            Assert.AreEqual("*****@*****.**", row.EmailAddress);
            Assert.AreEqual(217, row.CustomerID);
        }
示例#5
0
文件: Main.cs 项目: sicmx/OrcaMDF
        private void loadRawTable(string table)
        {
            try
            {
                var rawTable = rawtables
                               .Where(x => x.name == table).First();

                var rawSchema = RawTablesSchemas[table];

                var records = dbf.Pages
                              .Where(x => x.Header.ObjectID == rawTable.id && x.Header.Type == PageType.Data)
                              .SelectMany(x => x.Records);

                var rawRows = records.Select(x => RawColumnParser.Parse((RawRecord)x, rawSchema));

                showrawRows(rawRows, rawSchema);
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
示例#6
0
        public void sysallocunits()
        {
            var db    = new RawDataFile(AW2012Path);
            var pages = db.Pages.Where(x => x.Header.ObjectID == SQL2012Sysallocunits.ObjectID && x.Header.Type == PageType.Data);
            var rows  = RawColumnParser.Parse(pages, SQL2012Sysallocunits.Schema).Select(SQL2012Sysallocunits.Row).ToList();

            // Aggregates
            Assert.AreEqual(181, rows.Count);
            Assert.AreEqual(27335730062154916, (long)rows.Average(x => x.auid));
            Assert.AreEqual(3, (int)rows.Average(x => x.pcdata));

            // Individual rows
            var testRow = rows.Single(x => x.auid == 562949958533120);

            Assert.AreEqual(562949958533120, testRow.ownerid);
            Assert.AreEqual(0, testRow.pcdata);

            testRow = rows.Single(x => x.auid == 196608);
            Assert.AreEqual(1, testRow.type);
            Assert.AreEqual(17, testRow.pcreserved);
            Assert.AreEqual(13, testRow.pcused);
            Assert.AreEqual(new byte[] { 0x57, 0x00, 0x00, 0x00, 0x01, 0x00 }, testRow.pgroot);
        }
示例#7
0
        public void syscolpars()
        {
            var db    = new RawDataFile(AW2012Path);
            var pages = db.Pages.Where(x => x.Header.ObjectID == SQL2012Syscolpars.ObjectID && x.Header.Type == PageType.Data);
            var rows  = RawColumnParser.Parse(pages, SQL2012Syscolpars.Schema).Select(SQL2012Syscolpars.Row).ToList();

            // Aggregates
            Assert.AreEqual(860, rows.Count);
            Assert.AreEqual(317769461, (int)rows.Average(x => x.id));
            Assert.AreEqual(105, (int)rows.Average(x => x.xtype));
            Assert.AreEqual(8, (int)rows.Average(x => x.name.Length));

            // Individual rows
            var testRow = rows.Single(x => x.id == 25 && x.colid == 12);

            Assert.AreEqual("bXVTDocidUseBaseT", testRow.name);
            Assert.AreEqual(48, testRow.utype);

            testRow = rows.Single(x => x.id == 73 && x.colid == 13);
            Assert.AreEqual("enddlgseq", testRow.name);
            Assert.AreEqual(127, testRow.utype);
            Assert.AreEqual(null, testRow.idtval);
        }
        public void sysrowsets()
        {
            var db    = new RawDataFile(AW2012Path);
            var pages = db.Pages.Where(x => x.Header.ObjectID == SQL2012Sysrowsets.ObjectID && x.Header.Type == PageType.Data);
            var rows  = RawColumnParser.Parse(pages, SQL2012Sysrowsets.Schema).Select(SQL2012Sysrowsets.Row).ToList();

            // Aggregates
            Assert.AreEqual(158, rows.Count);
            Assert.AreEqual(72057594041729024, rows.Max(x => x.rowsetid));
            Assert.AreEqual(196608, rows.Min(x => x.rowsetid));
            Assert.AreEqual(20827366792640280, (long)rows.Average(x => x.rowsetid));
            Assert.AreEqual(7662, (long)rows.Average(x => x.status));
            Assert.AreEqual(2266, (long)rows.Average(x => x.maxleaf));

            // Individual rows
            var testRow = rows.Single(x => x.rowsetid == 562949954535424);

            Assert.AreEqual(70, testRow.status);
            Assert.AreEqual(534, testRow.maxint);

            testRow = rows.Single(x => x.rowsetid == 72057594039697408);
            Assert.AreEqual(117575457, testRow.idmajor);
            Assert.AreEqual(1453, testRow.maxleaf);
        }
示例#9
0
文件: Main.cs 项目: sicmx/OrcaMDF
        private void openToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            var result = openDatabaseDialog.ShowDialog();

            file = "";

            if (result == DialogResult.OK)
            {
                try
                {
                    var files = openDatabaseDialog.FileNames;
                    file = files[0];
                    db   = new Database(files);

                    refreshTreeview();
                } catch (Exception ex)
                {
                    logException(ex);

                    try
                    {
                        dbf = new RawDataFile(file);

                        var records = dbf.Pages
                                      .Where(x => x.Header.ObjectID == 34 && x.Header.Type == PageType.Data)
                                      .SelectMany(x => x.Records);

                        var rows = records.Select(x => RawColumnParser.Parse((RawRecord)x, new IRawType[] {
                            RawType.Int("id"),
                            RawType.NVarchar("name"),
                            RawType.Int("nsid"),
                            RawType.TinyInt("nsclass"),
                            RawType.Int("status"),
                            RawType.Char("type", 2),
                            RawType.Int("pid"),
                            RawType.TinyInt("pclass"),
                            RawType.Int("intprop"),
                            RawType.DateTime("created"),
                            RawType.DateTime("modified")
                        }));

                        rawtables = rows
                                    .Where(x => x.GetColumnValue("type").ToString().Trim() == "U");

                        rawrefreshTreeview();
                    }
                    catch (Exception rawex)
                    {
                        logException(rawex);

                        try
                        {
                            var bestdbf = new RawDataFile(file);

                            var SysschobjsPages = bestdbf.Pages
                                                  .Where(x => x.Header.ObjectID == 34 && x.Header.Type == PageType.Data);

                            var bestRecords = RawColumnParser.BestEffortParse(SysschobjsPages, new IRawType[] {
                                RawType.Int("id"),
                                RawType.NVarchar("name"),
                                RawType.Int("nsid"),
                                RawType.TinyInt("nsclass"),
                                RawType.Int("status"),
                                RawType.Char("type", 2),
                                RawType.Int("pid"),
                                RawType.TinyInt("pclass"),
                                RawType.Int("intprop"),
                                RawType.DateTime("created"),
                                RawType.DateTime("modified")
                            });

                            rawtables = bestRecords
                                        .Where(x => x.GetColumnValue("type").ToString().Trim() == "U");

                            var syscolparspages   = bestdbf.Pages.Where(x => x.Header.ObjectID == 41 && x.Header.Type == PageType.Data);
                            var syscolparsrecords = syscolparspages.SelectMany(x => x.Records).Select(x => (RawPrimaryRecord)x);
                            var syscolparsrows    = RawColumnParser.BestEffortParse(syscolparspages, new IRawType[] {
                                RawType.Int("id"),
                                RawType.SmallInt("number"),
                                RawType.Int("colid"),
                                RawType.NVarchar("name"),
                                RawType.TinyInt("xtype"),
                                RawType.Int("utype"),
                                RawType.SmallInt("length"),
                                RawType.TinyInt("prec"),
                                RawType.TinyInt("scale"),
                                RawType.Int("collationid"),
                                RawType.Int("status"),
                                RawType.SmallInt("maxinrow"),
                                RawType.Int("xmlns"),
                                RawType.Int("dflt"),
                                RawType.Int("chk"),
                                RawType.VarBinary("idtval")
                            });

                            rawcolumns = syscolparsrows.Select(x => new
                            {
                                ObjectID = (int?)x.GetColumnValue("id"),
                                ColumnID = (int?)x.GetColumnValue("colid"),
                                Number   = (short?)x.GetColumnValue("number"),
                                TypeID   = (byte?)x.GetColumnValue("xtype"),
                                Length   = (short?)x.GetColumnValue("length"),
                                Name     = x.GetColumnValue("name")
                            });

                            rawrefreshTreeview();
                        }
                        catch (Exception bestrawex)
                        {
                            logException(bestrawex);
                        }
                    }
                }
            }
        }