• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# WriteBatch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Read

		public ReadResult Read(string treeName, Slice key, WriteBatch writeBatch = null)
		{
		    Tree tree = null;

			if (writeBatch != null)
			{
				WriteBatch.BatchOperationType operationType;
			    Stream stream;
			    ushort? version;
			    if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType))
			    {
			        if (!version.HasValue) 
                        tree = GetTree(treeName);

					switch (operationType)
					{
						case WriteBatch.BatchOperationType.Add:
					    {
					        var reader = new ValueReader(stream);
					        return new ReadResult(reader, version.HasValue ? (ushort)(version.Value + 1) : tree.ReadVersion(key));
					    }
						case WriteBatch.BatchOperationType.Delete:
							return null;
					}
				}
			}

		    if (tree == null) 
                tree = GetTree(treeName);

			return tree.Read(key);
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:32,代码来源:SnapshotReader.cs


示例2: CanGetLatestVersion

		public async Task CanGetLatestVersion()
		{
			var storage = await NewStorageAsync();
			var name = storage.Name;

			for (int j = 0; j < 3; j++)
			{
				for (int i = 0; i < 65; i++)
				{
					for (int k = 0; k < 4; k++)
					{
						var writeBatch = new WriteBatch();
						writeBatch.Put("A" + k, new MemoryStream(new[] { (byte)i, (byte)k }));
						await storage.Writer.WriteAsync(writeBatch);
					}
				}
			}

			var fileSystem = storage.StorageState.FileSystem;

			storage.Dispose();

			using (var newStorage = new Storage(new StorageState(name, new StorageOptions())
			{
				FileSystem = fileSystem
			}))
			{
				await newStorage.InitAsync();
				var stream = newStorage.Reader.Read("A2");
				Assert.Equal(64, stream.ReadByte());
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:32,代码来源:RecoveryTests.cs


示例3: Accept

		public override void Accept(Disk d)
		{
			var ms = new MemoryStream();
			_serializer.Serialize(new JsonTextWriter(new StreamWriter(ms)), d);
			ms.Position = 0;
			var key = new Slice(EndianBitConverter.Big.GetBytes(counter++));
			_currentBatch.Add(key, ms, "albums");

			foreach (var diskId in d.DiskIds)
			{
				_currentBatch.MultiAdd(diskId, key, "ix_diskids");
			}

			if(d.Artist != null)
				_currentBatch.MultiAdd(d.Artist.ToLower(), key, "ix_artists");
			if (d.Title != null)
				_currentBatch.MultiAdd(d.Title.ToLower(), key, "ix_titles");

			if (counter%1000 == 0)
			{
				_storageEnvironment.Writer.Write(_currentBatch);
				_currentBatch = new WriteBatch();
			}

		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:25,代码来源:VoronDisksDestination.cs


示例4: CanOpenAndCloseWithUpdate

		public async Task CanOpenAndCloseWithUpdate()
		{
			var storage = await NewStorageAsync();
			var name = storage.Name;

			var str1 = "test1";
			var str2 = "test2";

			var s1 = new MemoryStream(Encoding.UTF8.GetBytes(str1));
			var s2 = new MemoryStream(Encoding.UTF8.GetBytes(str2));

			var writeBatch = new WriteBatch();
			writeBatch.Put("A", s1);
			await storage.Writer.WriteAsync(writeBatch);

			writeBatch = new WriteBatch();
			writeBatch.Put("A", s2);
			await storage.Writer.WriteAsync(writeBatch);

			var fileSystem = storage.StorageState.FileSystem;

			storage.Dispose();


			using (var newStorage = new Storage(new StorageState(name, new StorageOptions())
			{
				FileSystem = fileSystem
			}))
			{
				await newStorage.InitAsync();
				AssertEqual(str2, newStorage.Reader.Read("A"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:33,代码来源:RecoveryTests.cs


示例5: ReadVersion_Items_From_Both_WriteBatch_And_Snapshot_WithoutVersionNumber

        public void ReadVersion_Items_From_Both_WriteBatch_And_Snapshot_WithoutVersionNumber()
        {
            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                Env.CreateTree(tx, "tree");
                tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));

                tx.Commit();
            }

            using (var writeBatch = new WriteBatch())
            using (var snapshot = Env.CreateSnapshot())
            {
                writeBatch.Add("foo2", StreamFor("foo2"), "tree");

                var foor1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
                var foo2Version = snapshot.ReadVersion("tree", "foo2", writeBatch);
                var foo2VersionThatShouldBe0 = snapshot.ReadVersion("tree", "foo2");

                Assert.Equal(1, foor1Version);
                Assert.Equal(0, foo2Version); //added to write batch without version number, so 0 is version number that is fetched
                Assert.Equal(0, foo2VersionThatShouldBe0);

            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:25,代码来源:Batches.cs


示例6: Read_Items_From_Both_WriteBatch_And_Snapshot

        public void Read_Items_From_Both_WriteBatch_And_Snapshot()
        {
            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                Env.CreateTree(tx, "tree");
                tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));

                tx.Commit();
            }

            using (var writeBatch = new WriteBatch())
            using (var snapshot = Env.CreateSnapshot())
            {
                writeBatch.Add("foo2", StreamFor("foo2"), "tree");

                var foo1ReadResult = snapshot.Read("tree", "foo1", writeBatch);
                var foo2ReadResult = snapshot.Read("tree", "foo2", writeBatch);
                var foo2ReadResultThatShouldBeNull = snapshot.Read("tree", "foo2");

                Assert.NotNull(foo1ReadResult);
                Assert.NotNull(foo2ReadResult);
                Assert.Null(foo2ReadResultThatShouldBeNull);

                Assert.Equal(foo1ReadResult.Reader.ToStringValue(), "foo1");
                Assert.Equal(foo2ReadResult.Reader.ToStringValue(), "foo2");
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:27,代码来源:Batches.cs


示例7: CanAddMultiValuesUnderTheSameKeyToBatch

        public void CanAddMultiValuesUnderTheSameKeyToBatch()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                var rand = new Random();
                var testBuffer = new byte[168];
                rand.NextBytes(testBuffer);

                CreateTrees(env, 1, "multitree");

                var batch = new WriteBatch();

                batch.MultiAdd("key", "value1", "multitree0");
                batch.MultiAdd("key", "value2", "multitree0");

                env.Writer.Write(batch);

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    var tree = tx.Environment.CreateTree(tx,"multitree0");
                    using (var it = tree.MultiRead("key"))
                    {
                        Assert.True(it.Seek(Slice.BeforeAllKeys));

                        Assert.Equal("value1", it.CurrentKey.ToString());
                        Assert.True(it.MoveNext());

                        Assert.Equal("value2", it.CurrentKey.ToString());
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:32,代码来源:MultiAdds.cs


示例8: ReadVersion_Items_From_Both_WriteBatch_And_Snapshot

        public void ReadVersion_Items_From_Both_WriteBatch_And_Snapshot()
        {
            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                Env.CreateTree(tx, "tree");
                tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));

                tx.Commit();
            }

            using (var writeBatch = new WriteBatch())
            using (var snapshot = Env.CreateSnapshot())
            {
                writeBatch.Add("foo2", StreamFor("foo2"), "tree", 1);

                var foor1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
                var foo2Version = snapshot.ReadVersion("tree", "foo2", writeBatch);
                var foo2VersionThatShouldBe0 = snapshot.ReadVersion("tree", "foo2");

                Assert.Equal(1, foor1Version);
                Assert.Equal(2, foo2Version); //is not committed yet
                Assert.Equal(0, foo2VersionThatShouldBe0);

            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:25,代码来源:Batches.cs


示例9: SnapshotTest

		public async Task SnapshotTest()
		{
			using (var storage = await NewStorageAsync())
			{
				var str1 = "test1";
				var str2 = "test2";

				var s1 = new MemoryStream(Encoding.UTF8.GetBytes(str1));
				var s2 = new MemoryStream(Encoding.UTF8.GetBytes(str2));

				var writeBatch = new WriteBatch();
				writeBatch.Put("key1", s1);

				await storage.Writer.WriteAsync(writeBatch);

				var snapshot = storage.Commands.CreateSnapshot();

				writeBatch = new WriteBatch();
				writeBatch.Put("key1", s2);

				await storage.Writer.WriteAsync(writeBatch);

				AssertEqual(str2, storage.Reader.Read("key1"));
				AssertEqual(str1, storage.Reader.Read("key1", new ReadOptions
					                                                  {
						                                                  Snapshot = snapshot
					                                                  }));

				storage.Commands.ReleaseSnapshot(snapshot);
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:31,代码来源:SnapshotTests.cs


示例10: Should_be_able_to_read_and_write_lots_of_data

		public void Should_be_able_to_read_and_write_lots_of_data()
		{
			CreatTestSchema();
			var writeBatch = new WriteBatch();
			var testData = GenerateTestData().ToList();

			foreach (var dataPair in testData)
				writeBatch.Add(dataPair.Key, StreamFor(dataPair.Value), TestTreeName);				

			Env.Writer.Write(writeBatch);

			using (var snapshot = Env.CreateSnapshot())
			{
				using (var iterator = snapshot.Iterate(TestTreeName))
				{
					Assert.True(iterator.Seek(Slice.BeforeAllKeys));

					do
					{
						var value = iterator.CreateReaderForCurrent().ToStringValue();
						var extractedDataPair = new KeyValuePair<string, string>(iterator.CurrentKey.ToString(), value);
						Assert.Contains(extractedDataPair,testData);

					} while (iterator.MoveNext());
				}
				
			}
			
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:29,代码来源:MemoryMapWithoutBackingPagerTest.cs


示例11: ShouldRecoverDataFromLogFile

		public async Task ShouldRecoverDataFromLogFile()
		{
			var storage = await NewStorageAsync();

			var name = storage.Name;

			var writeBatch = new WriteBatch();
			writeBatch.Put("A", new MemoryStream(Encoding.UTF8.GetBytes("123")));
			writeBatch.Put("B", new MemoryStream(Encoding.UTF8.GetBytes("123")));
			writeBatch.Put("D", new MemoryStream(Encoding.UTF8.GetBytes("123")));
			storage.Writer.WriteAsync(writeBatch).Wait();

			var fileSystem = storage.StorageState.FileSystem;

			storage.Dispose();

			using (var newStorage = new Storage(new StorageState(name, new StorageOptions())
			{
				FileSystem = fileSystem
			}))
			{
				await newStorage.InitAsync();
				
				using(var it = newStorage.Reader.NewIterator(new ReadOptions()))
				{
					it.Seek("C");
					Assert.True(it.IsValid);
					it.Prev();
					Assert.True(it.IsValid);
					Assert.Equal("B", it.Key);
				}
			}
		} 
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:33,代码来源:CanIterateBackward.cs


示例12: TestIteratorWithSnapshot

        public void TestIteratorWithSnapshot()
        {
            using (var db = new DB(new Options { CreateIfMissing = true }, "test2.db"))
            {
                using (var batch = new WriteBatch())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        batch.Put(Slice.FromString($"key::{i,20:D20}"), Slice.FromString($"{i,32}"));
                    }

                    db.Write(new WriteOptions { Sync = true }, batch);
                }

                using (var snapshot = db.GetSnapshot())
                using (var batch = new WriteBatch())
                using (var itr = db.NewIterator(new ReadOptions { Snapshot = snapshot }))
                {
                    itr.Seek(Slice.FromString("key::"));
                    Assert.IsTrue(itr.Valid());
                    int entriesDeleted = 0;
                    while (itr.Valid())
                    {
                        batch.Delete(itr.Key());
                        itr.Next();
                        entriesDeleted++;
                    }

                    db.Write(new WriteOptions(), batch);
                    Assert.AreEqual(100, entriesDeleted);
                }
            }
        }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:33,代码来源:BasicTests.cs


示例13: SimpleIncrementShouldWorkUsingWriteBatch

		public void SimpleIncrementShouldWorkUsingWriteBatch()
		{
			CreateTrees(Env, 1, "tree");

			var writeBatch = new WriteBatch();
			writeBatch.Increment("key/1", 10, "tree0");

			Env.Writer.Write(writeBatch);

			writeBatch = new WriteBatch();
			writeBatch.Increment("key/1", 5, "tree0");

			Env.Writer.Write(writeBatch);

			writeBatch = new WriteBatch();
			writeBatch.Increment("key/1", -3, "tree0");

			Env.Writer.Write(writeBatch);

			using (var tx = Env.NewTransaction(TransactionFlags.Read))
			{
				var read = tx.ReadTree("tree0").Read("key/1");

				Assert.NotNull(read);
				Assert.Equal(3, read.Version);
				Assert.Equal(12, read.Reader.ReadLittleEndianInt64());
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:28,代码来源:Increments.cs


示例14: Contains

		public bool Contains(string treeName, Slice key, out ushort? version, WriteBatch writeBatch = null)
		{
			if (writeBatch != null)
			{
				WriteBatch.BatchOperationType operationType;
				Stream stream;
				if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType))
				{
					switch (operationType)
					{
						case WriteBatch.BatchOperationType.Add:
							return true;
						case WriteBatch.BatchOperationType.Delete:
							return false;
						default:
							throw new ArgumentOutOfRangeException(operationType.ToString());
					}
				}
			}

			var tree = GetTree(treeName);
			var readVersion = tree.ReadVersion(key);

			var exists = readVersion > 0;

			version = exists ? (ushort?)readVersion : null;

			return exists;
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:29,代码来源:SnapshotReader.cs


示例15: Add

		public virtual void Add(WriteBatch writeBatch, string key, byte[] value, ushort? expectedVersion = null)
		{
		    var stream = new BufferPoolMemoryStream(BufferPool);
            stream.Write(value, 0, value.Length);
		    stream.Position = 0;

			writeBatch.Add(key, stream, TableName, expectedVersion);
		}
开发者ID:randacc,项目名称:ravendb,代码行数:8,代码来源:TableBase.cs


示例16: ReadFromMemTable

		public async Task ReadFromMemTable()
		{
			using (var storage = await NewStorageAsync())
			{
				var batch = new WriteBatch();
				batch.Put("test1", new MemoryStream(Encoding.UTF8.GetBytes("test")));
				await storage.Writer.WriteAsync(batch);

				Assert.NotNull(storage.Reader.Read("test1"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:11,代码来源:StorageReaderTests.cs


示例17: WillNotFindMissingValue

		public async Task WillNotFindMissingValue()
		{
			using (var storage = await NewStorageAsync(new StorageOptions()))
			{
				var writeBatch = new WriteBatch();
				writeBatch.Put("system/config", new MemoryStream());
				await storage.Writer.WriteAsync(writeBatch);

				Assert.Null(storage.Reader.Read("system/Test"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:11,代码来源:WillNotFindMissingValues.cs


示例18: Write

 public void Write(WriteBatch writeBatch)
 {
     try
     {
         env.Writer.Write(writeBatch);
     }
     catch (AggregateException ae)
     {
         if (ae.InnerException is OperationCanceledException == false) // this can happen during storage disposal
             throw;
     }
 }
开发者ID:felixmm,项目名称:ravendb,代码行数:12,代码来源:TableStorage.cs


示例19: SingleItemBatchTest

		public void SingleItemBatchTest()
		{
			var batch = new WriteBatch();
            batch.Add("key/1", new MemoryStream(Encoding.UTF8.GetBytes("123")), Constants.RootTreeName);

			Env.Writer.Write(batch);

			using (var snapshot = Env.CreateSnapshot())
			{
			    var reader = snapshot.Read(null, "key/1").Reader;
			    Assert.Equal("123", reader.ToStringValue());
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:13,代码来源:Snapshots.cs


示例20: Should_be_able_to_read_and_write_small_values

		public void Should_be_able_to_read_and_write_small_values()
		{
			CreatTestSchema();
			var writeBatch = new WriteBatch();
			writeBatch.Add("key",StreamFor("value"),TestTreeName);
			Env.Writer.Write(writeBatch);

			using (var snapshot = Env.CreateSnapshot())
			{
				var storedValue = Encoding.UTF8.GetString(snapshot.Read(TestTreeName, "key").Reader.AsStream().ReadData());
				Assert.Equal("value",storedValue);
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:13,代码来源:MemoryMapWithoutBackingPagerTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WriteCallback类代码示例发布时间:2022-05-24
下一篇:
C# Wrapper类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap