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


C# WriteBatch.AddStruct方法代码示例

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


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

示例1: CanWriteStructsByUsingWriteBatchAndReadFromSnapshot

		public void CanWriteStructsByUsingWriteBatchAndReadFromSnapshot()
		{
			var statsSchema = new StructureSchema<IndexingStatsFields>()
				.Add<int>(IndexingStatsFields.Attempts)
				.Add<int>(IndexingStatsFields.Errors)
				.Add<int>(IndexingStatsFields.Successes)
				.Add<string>(IndexingStatsFields.Message);

			var operationSchema = new StructureSchema<IndexingStatsFields>()
				.Add<int>(IndexingStatsFields.Attempts)
				.Add<int>(IndexingStatsFields.Successes)
				.Add<string>(IndexingStatsFields.Message);

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				Env.CreateTree(tx, "stats");
				Env.CreateTree(tx, "operations");

				tx.Commit();
			}
			var batch = new WriteBatch();

			batch.AddStruct("stats/1",
				new Structure<IndexingStatsFields>(statsSchema)
				.Set(IndexingStatsFields.Attempts, 5)
				.Set(IndexingStatsFields.Errors, -1)
				.Set(IndexingStatsFields.Successes, 4)
				.Set(IndexingStatsFields.Message, "hello world"),
				"stats");

			batch.AddStruct("operations/1",
				new Structure<IndexingStatsFields>(operationSchema)
				.Set(IndexingStatsFields.Attempts, 10)
				.Set(IndexingStatsFields.Successes, 10)
				.Set(IndexingStatsFields.Message, "hello world"),
				"operations");

			using (var snapshot = Env.CreateSnapshot())
			{
				var stats = snapshot.ReadStruct("stats", "stats/1", statsSchema, batch).Reader;

				Assert.Equal(5, stats.ReadInt(IndexingStatsFields.Attempts));
				Assert.Equal(-1, stats.ReadInt(IndexingStatsFields.Errors));
				Assert.Equal(4, stats.ReadInt(IndexingStatsFields.Successes));
				Assert.Equal("hello world", stats.ReadString(IndexingStatsFields.Message));
			}

			Env.Writer.Write(batch);

			using (var snapshot = Env.CreateSnapshot())
			{
				var operation = snapshot.ReadStruct("operations", "operations/1", operationSchema).Reader;

				Assert.Equal(10, operation.ReadInt(IndexingStatsFields.Attempts));
				Assert.Equal(10, operation.ReadInt(IndexingStatsFields.Successes));
				Assert.Equal("hello world", operation.ReadString(IndexingStatsFields.Message));
			}

			batch.Delete("stats/1", "stats");

			using (var snapshot = Env.CreateSnapshot())
			{
				var stats = snapshot.ReadStruct("stats", "stats/1", statsSchema, batch);

				Assert.Null(stats);
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:67,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例2: Record_debug_journal_and_replay_it

		public void Record_debug_journal_and_replay_it()
		{
			var structSchema = new StructureSchema<SampleStruct>()
					.Add<int>(SampleStruct.Foo)
					.Add<string>(SampleStruct.Bar);

			using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				env.DebugJournal = new DebugJournal(debugJouralName, env, true);
				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "test-tree");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("{ \"title\": \"foo\",\"name\":\"bar\"}"));
					writeBatch.Add("foo", valueBuffer, "test-tree");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2!"));
					writeBatch.Add("bar", valueBuffer, "test-tree");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2 3!"));
					writeBatch.Add("foo-bar", valueBuffer, "test-tree");

					writeBatch.MultiAdd("multi-foo", "AA", "test-tree");
					env.Writer.Write(writeBatch);
				}

                using (var writeBatch = new WriteBatch())
                {
                    writeBatch.Increment("incr-key", 5, "test-tree");
                    env.Writer.Write(writeBatch);
                }

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    Assert.Equal(5, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());

                    using (var writeBatch = new WriteBatch())
                    {
                        writeBatch.Increment("incr-key", 5, "test-tree");
                        env.Writer.Write(writeBatch);
                    }

                    Assert.Equal(5, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());
                }

			    using (var tx = env.NewTransaction(TransactionFlags.Read))
			    {
                    Assert.Equal(10, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());
			    }

			    using (var writeBatch = new WriteBatch())
				{
					writeBatch.MultiAdd("multi-foo", "BB", "test-tree");
					writeBatch.MultiAdd("multi-foo", "CC", "test-tree");

					writeBatch.Delete("foo-bar", "test-tree");
					env.Writer.Write(writeBatch);
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "test-tree2");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1!"));
					writeBatch.Add("foo", valueBuffer, "test-tree2");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2!"));
					writeBatch.Add("bar", valueBuffer, "test-tree2");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2 3!"));
					writeBatch.Add("foo-bar", valueBuffer, "test-tree2");
					env.Writer.Write(writeBatch);
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "structures-tree");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					writeBatch.AddStruct("structs/1", new Structure<SampleStruct>(structSchema)
						.Set(SampleStruct.Foo, 13)
						.Set(SampleStruct.Bar, "debug journal testing"),
						"structures-tree");

					env.Writer.Write(writeBatch);
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
//.........这里部分代码省略.........
开发者ID:jrusbatch,项目名称:ravendb,代码行数:101,代码来源:DebugJournalTest.cs


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