当前位置: 首页>>代码示例>>C#>>正文


C# Manifest.ModifyPages方法代码示例

本文整理汇总了C#中Manifest.ModifyPages方法的典型用法代码示例。如果您正苦于以下问题:C# Manifest.ModifyPages方法的具体用法?C# Manifest.ModifyPages怎么用?C# Manifest.ModifyPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Manifest的用法示例。


在下文中一共展示了Manifest.ModifyPages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ManifestAddPages

        public void ManifestAddPages()
        {
            var path = Path.GetFullPath("TestData\\ManifestAddPages");
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            // Remove the file if it exists
            var filename = Config.ManifestFile(path);
            if (File.Exists(filename))
                File.Delete(filename);

            var mf = new Manifest(path);
            mf.AddPage(1, 5, Key.FromBytes(new byte[] { 5 }), Key.FromBytes(new byte[] { 5, 1 }));
            mf.AddPage(1, 6, Key.FromBytes(new byte[] { 6 }), Key.FromBytes(new byte[] { 6, 1 }));
            mf.AddPage(1, 4, Key.FromBytes(new byte[] { 4 }), Key.FromBytes(new byte[] { 4, 1 }));

            using (var mfSnap = mf.GetLatestManifest()) {
                PageRecord[] pg = mfSnap.GetPagesAtLevel(1);
                Assert.AreEqual(1, pg[0].Level);
                Assert.AreEqual(4, pg[0].Version);
                Assert.AreEqual(1, pg[1].Level);
                Assert.AreEqual(5, pg[1].Version);
                Assert.AreEqual(1, pg[2].Level);
                Assert.AreEqual(6, pg[2].Version);
            }

            mf = new Manifest(path);

            mf.ModifyPages(new List<PageRecord>{
                new PageRecord(1, 8, Key.FromBytes( new byte[] { 16 }), Key.FromBytes(new byte[] { 16, 1 }) ),
                new PageRecord(1, 9, Key.FromBytes( new byte[] { 1 }), Key.FromBytes(new byte[] { 1, 1 }) ),
                new PageRecord(1, 16, Key.FromBytes( new byte[] { 10 }), Key.FromBytes(new byte[] { 10, 1 }) )
            }, new List<PageRef>{
                new PageRef{ Level = 1, Version = 6},
                new PageRef{ Level = 1, Version = 4},
            });

            mf = new Manifest(path);

            using (var mfSnap = mf.GetLatestManifest()) {
                var pg = mfSnap.GetPagesAtLevel(1);
                Assert.AreEqual(1, pg[0].Level);
                Assert.AreEqual(9, pg[0].Version);
                Assert.AreEqual(1, pg[1].Level);
                Assert.AreEqual(5, pg[1].Version);
                Assert.AreEqual(1, pg[2].Level);
                Assert.AreEqual(16, pg[2].Version);
                Assert.AreEqual(1, pg[3].Level);
                Assert.AreEqual(8, pg[3].Version);
            }
        }
开发者ID:gnoso,项目名称:razordb,代码行数:51,代码来源:ManifestTests.cs

示例2: Main

        static void Main(string[] args)
        {
            Console.WriteLine("RazorDB Utility\n");

            if (args.Length == 0) {
                Console.WriteLine("Commands:");
                Console.WriteLine("\tdump-journal  <basedir> <version>");
                Console.WriteLine("\tdump-table <basedir> <level> <version>");
                Console.WriteLine("\tdump-manifest <manifest file> ");
                Console.WriteLine("\tdump-manifest-all <basedir>");
                Console.WriteLine("\tsplit-manifest <basedir>");
                Console.WriteLine("\tcheck-each-table <basedir>");
                Console.WriteLine("\tcheck-database <basedir>");
                Console.WriteLine("\tremove-orphans <basedir>");
                Console.WriteLine("\tremove-page <basedir> <level> <version>");
            } else {
                switch (args[0].ToLower()) {
                    case "dump-journal":
                        if (args.Length < 3) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            DumpJournal(args[1], int.Parse(args[2]));
                        }
                        break;
                    case "dump-table":
                        if (args.Length < 4) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            DumpFile(args[1], int.Parse(args[2]), int.Parse(args[3]));
                        }
                        break;
                    case "dump-manifest":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var mf = new Manifest(args[1]);
                            mf.Logger = msg => Console.WriteLine(msg);
                            mf.LogContents();
                        }
                        break;
                    case "dump-manifest-all":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var dummyMf = Manifest.NewDummyManifest();
                            dummyMf.Logger = msg => Console.WriteLine(msg);
                            foreach (var mf in Manifest.ReadAllManifests(args[1])) {
                                mf.LogContents(dummyMf);
                            }
                        }
                        break;
                    case "split-manifest":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var dummyMf = Manifest.NewDummyManifest();
                            dummyMf.Logger = msg => Console.WriteLine(msg);
                            int ct = 0;
                            foreach (var mf in Manifest.ReadAllManifests(args[1])) {
                                using (var bw = new BinaryWriter(new FileStream(Path.Combine(args[1], "S" + ct.ToString() + ".mf"), FileMode.CreateNew, FileAccess.Write, FileShare.None, 40096))) {
                                    mf.WriteManifestContents(bw);
                                }
                                ct++;
                            }
                        }
                        break;
                    case "check-each-table":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            CheckBlockTableFiles(args[1]);
                        }
                        break;
                    case "check-database":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            CheckDatabase(args[1]);
                        }
                        break;
                    case "remove-orphans":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            RemoveOrphanedTables(args[1]);
                        }
                        break;
                    case "remove-page":
                        if (args.Length < 4) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var pageRef = new PageRef { Level = int.Parse(args[2]), Version = int.Parse(args[3]) };
                            var mf = new Manifest(args[1]);
                            mf.ModifyPages(new List<PageRecord>(), new List<PageRef> { { pageRef } });
                        }
                        break;
                    default:
                        Console.WriteLine("Unknown command: {0}", args[0]);
                        break;
                }
//.........这里部分代码省略.........
开发者ID:gnoso,项目名称:razordb,代码行数:101,代码来源:Program.cs

示例3: TestManifestSnapshot

        public void TestManifestSnapshot()
        {
            var path = Path.GetFullPath ("TestData\\TestManifestSnapshot");
            if (!Directory.Exists (path)) Directory.CreateDirectory (path);

            // Remove the file if it exists
            var filename = Config.ManifestFile (path);
            if (File.Exists (filename)) File.Delete (filename);

            var mf = new Manifest (path);
            // Add pages and dummy files to represent their contents
            mf.AddPage (1, 5, Key.FromBytes (new byte[] { 5 }), Key.FromBytes (new byte[] { 5, 1 }));
            using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 5))) file.Write ("Test");
            mf.AddPage (1, 6, Key.FromBytes (new byte[] { 6 }), Key.FromBytes (new byte[] { 6, 1 }));
            using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 6))) file.Write ("Test");
            mf.AddPage (1, 4, Key.FromBytes (new byte[] { 4 }), Key.FromBytes (new byte[] { 4, 1 }));
            using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 4))) file.Write ("Test");

            using (var manifestSnapshot = mf.GetLatestManifest()) {
                mf.ModifyPages (new List<PageRecord> {
                    new PageRecord(1, 8, Key.FromBytes( new byte[] { 16 }), Key.FromBytes(new byte[] { 16, 1 }) ),
                    new PageRecord(1, 9, Key.FromBytes( new byte[] { 1 }), Key.FromBytes(new byte[] { 1, 1 }) ),
                    new PageRecord(1, 16, Key.FromBytes( new byte[] { 10 }), Key.FromBytes(new byte[] { 10, 1 }) )
                }, new List<PageRef> {
                    new PageRef{ Level = 1, Version = 6},
                    new PageRef{ Level = 1, Version = 4},
                });

                PageRecord[] pg = manifestSnapshot.GetPagesAtLevel (1);
                Assert.AreEqual (1, pg [0].Level);
                Assert.AreEqual (4, pg [0].Version);
                Assert.AreEqual (1, pg [1].Level);
                Assert.AreEqual (5, pg [1].Version);
                Assert.AreEqual (1, pg [2].Level);
                Assert.AreEqual (6, pg [2].Version);

                // The files should still exist for now
                Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 4)));
                Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 5)));
                Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 6)));
            }

            // The files should be deleted now since we closed the snapshot
            Assert.IsFalse (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 4)));
            Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 5)));
            Assert.IsFalse (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 6)));
        }
开发者ID:T145,项目名称:razordbx,代码行数:47,代码来源:ManifestTests.cs


注:本文中的Manifest.ModifyPages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。