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


C# Structure.Set方法代码示例

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


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

示例1: ShouldThrowWhenSettingUndefinedField

		public void ShouldThrowWhenSettingUndefinedField()
		{
			var schema = new StructureSchema<SchemaFields>()
				.Add<int>(SchemaFields.Count)
				.Add<string>(SchemaFields.Message);

			var structure = new Structure<SchemaFields>(schema);

			Assert.DoesNotThrow(() => structure.Set(SchemaFields.Count, 1));
			Assert.DoesNotThrow(() => structure.Set(SchemaFields.Message, "hello"));

			var ae = Assert.Throws<ArgumentException>(() => structure.Set(SchemaFields.Does_Not_Exist, 1));
			Assert.Equal("No such field in schema defined. Field name: Does_Not_Exist", ae.Message);

			ae = Assert.Throws<ArgumentException>(() => structure.Set(SchemaFields.Does_Not_Exist, "hello"));
			Assert.Equal("No such field in schema defined. Field name: Does_Not_Exist", ae.Message);

			ae = Assert.Throws<ArgumentException>(() => structure.Increment(SchemaFields.Does_Not_Exist, 1));
			Assert.Equal("No such field in schema defined. Field name: Does_Not_Exist", ae.Message);
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:20,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例2: ScheduleReductions

		public void ScheduleReductions(int view, int level, ReduceKeyAndBucket reduceKeysAndBuckets)
		{
			var scheduledReductionsByView = tableStorage.ScheduledReductions.GetIndex(Tables.ScheduledReductions.Indices.ByView);
			var scheduledReductionsByViewAndLevelAndReduceKey = tableStorage.ScheduledReductions.GetIndex(Tables.ScheduledReductions.Indices.ByViewAndLevelAndReduceKey);

			var id = generator.CreateSequentialUuid(UuidType.ScheduledReductions);
            var idSlice = (Slice)id.ToString();
		    var reduceHashKey = HashKey(reduceKeysAndBuckets.ReduceKey);

			var scheduledReduction = new Structure<ScheduledReductionFields>(tableStorage.ScheduledReductions.Schema);

			scheduledReduction.Set(ScheduledReductionFields.IndexId, view)
				.Set(ScheduledReductionFields.ReduceKey, reduceKeysAndBuckets.ReduceKey)
				.Set(ScheduledReductionFields.Bucket, reduceKeysAndBuckets.Bucket)
				.Set(ScheduledReductionFields.Level, level)
				.Set(ScheduledReductionFields.Etag, id.ToByteArray())
				.Set(ScheduledReductionFields.Timestamp, SystemTime.UtcNow.ToBinary());

			tableStorage.ScheduledReductions.AddStruct(writeBatch.Value, idSlice, scheduledReduction);

            var viewKey = CreateKey(view);
            var viewKeySlice = (Slice)viewKey;


            scheduledReductionsByView.MultiAdd(writeBatch.Value, viewKeySlice, idSlice);
            scheduledReductionsByViewAndLevelAndReduceKey.MultiAdd(writeBatch.Value, (Slice)AppendToKey(viewKey, level, ReduceKeySizeLimited(reduceKeysAndBuckets.ReduceKey), reduceHashKey), idSlice);
		}
开发者ID:jrusbatch,项目名称:ravendb,代码行数:27,代码来源:MappedResultsStorageActions.cs

示例3: ShouldThrowOnAttemptToPartialWriteOfVariableFields

		public void ShouldThrowOnAttemptToPartialWriteOfVariableFields()
		{
			var schema = new StructureSchema<SchemaFields>()
				.Add<string>(SchemaFields.Message)
				.Add<string>(SchemaFields.Additional_Info);

			var structure = new Structure<SchemaFields>(schema);

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

				structure.Set(SchemaFields.Message, "hello");

				var invalidOperationException = Assert.Throws<InvalidOperationException>(() => tree.WriteStruct("items/1", structure));

				Assert.Equal("Your structure has variable size fields. You have to set all of them to properly write a structure and avoid overlapping fields. Missing fields: Additional_Info", invalidOperationException.Message);
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:19,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例4: ShouldThrowWhenSettingDifferentValueTypeThanDefinedInSchema

		public void ShouldThrowWhenSettingDifferentValueTypeThanDefinedInSchema()
		{
			var schema = new StructureSchema<SchemaFields>()
				.Add<int>(SchemaFields.Count);

			var structure = new Structure<SchemaFields>(schema);

			var invalidData = Assert.Throws<InvalidDataException>(() => structure.Set(SchemaFields.Count, (long) 1));
			Assert.Equal("Attempt to set a field value which type is different than defined in the structure schema. Expected: System.Int32, got: System.Int64", invalidData.Message);
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:10,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例5: MultipleStringFieldsShouldBeWrittenInProperOrder

		public void MultipleStringFieldsShouldBeWrittenInProperOrder()
		{
			var schema = new StructureSchema<HelloWorld>()
				.Add<string>(HelloWorld.Hello)
				.Add<string>(HelloWorld.World);

			var structure = new Structure<HelloWorld>(schema);

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

				structure.Set(HelloWorld.World, "W0rld!"); // set 2nd value first
				structure.Set(HelloWorld.Hello, "Hell0"); // set 1st value in second operation

				tree.WriteStruct("items/1", structure);

				var structReader = tree.ReadStruct("items/1", schema).Reader;

				Assert.Equal("Hell0", structReader.ReadString(HelloWorld.Hello));
				Assert.Equal("W0rld!", structReader.ReadString(HelloWorld.World));
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:23,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例6: CanDeleteStructsFromTrees

		public void CanDeleteStructsFromTrees()
		{
			var schema = new StructureSchema<IndexingStatsFields>()
				.Add<int>(IndexingStatsFields.Attempts)
				.Add<int>(IndexingStatsFields.Errors)
				.Add<int>(IndexingStatsFields.Successes);

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

				var stats = new Structure<IndexingStatsFields>(schema);

				stats.Set(IndexingStatsFields.Attempts, 5);
				stats.Set(IndexingStatsFields.Errors, -1);
				stats.Set(IndexingStatsFields.Successes, 4);

				tree.WriteStruct("stats/1", stats);

				tx.Commit();
			}

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				var tree = tx.ReadTree("stats");

				tree.Delete("stats/1");

				var stats = tree.ReadStruct("stats/1", schema);

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

示例7: CanReadAndWriteStructsFromTrees

		public void CanReadAndWriteStructsFromTrees()
		{
			var indexedAt = new DateTime(2015, 1, 20);

			var schema = new StructureSchema<IndexingStatsFields>()
				.Add<int>(IndexingStatsFields.Attempts)
				.Add<int>(IndexingStatsFields.Errors)
				.Add<int>(IndexingStatsFields.Successes)
				.Add<byte>(IndexingStatsFields.IsValid)
				.Add<long>(IndexingStatsFields.IndexedAt);

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

				var stats = new Structure<IndexingStatsFields>(schema);

				stats.Set(IndexingStatsFields.Attempts, 5);
				stats.Set(IndexingStatsFields.Errors, -1);
				stats.Set(IndexingStatsFields.Successes, 4);
				stats.Set(IndexingStatsFields.IsValid, (byte) 1);
				stats.Set(IndexingStatsFields.IndexedAt, indexedAt.ToBinary());

				tree.WriteStruct("stats/1", stats);

				tx.Commit();
			}

			using (var tx = Env.NewTransaction(TransactionFlags.Read))
			{
				var tree = tx.ReadTree("stats");

				var stats = tree.ReadStruct("stats/1", schema).Reader;

				Assert.Equal(5, stats.ReadInt(IndexingStatsFields.Attempts));
				Assert.Equal(-1, stats.ReadInt(IndexingStatsFields.Errors));
				Assert.Equal(4, stats.ReadInt(IndexingStatsFields.Successes));
				Assert.Equal(1, stats.ReadByte(IndexingStatsFields.IsValid));
				Assert.Equal(indexedAt, DateTime.FromBinary(stats.ReadLong(IndexingStatsFields.IndexedAt)));
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:41,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例8: ScheduleReductions

		public void ScheduleReductions(int view, int level, ReduceKeyAndBucket reduceKeysAndBuckets)
		{
			var scheduledReductionsByView = tableStorage.ScheduledReductions.GetIndex(Tables.ScheduledReductions.Indices.ByView);
			var scheduledReductionsByViewAndLevelAndReduceKey = tableStorage.ScheduledReductions.GetIndex(Tables.ScheduledReductions.Indices.ByViewAndLevelAndReduceKey);

			var id = generator.CreateSequentialUuid(UuidType.ScheduledReductions);
            var idSlice = (Slice)id.ToString();

			var scheduledReduction = new Structure<ScheduledReductionFields>(tableStorage.ScheduledReductions.Schema);

			scheduledReduction.Set(ScheduledReductionFields.IndexId, view)
				.Set(ScheduledReductionFields.ReduceKey, reduceKeysAndBuckets.ReduceKey)
				.Set(ScheduledReductionFields.Bucket, reduceKeysAndBuckets.Bucket)
				.Set(ScheduledReductionFields.Level, level)
				.Set(ScheduledReductionFields.Etag, id.ToByteArray())
				.Set(ScheduledReductionFields.Timestamp, SystemTime.UtcNow.ToBinary());

			tableStorage.ScheduledReductions.AddStruct(writeBatch.Value, idSlice, scheduledReduction);

            var viewKey = CreateViewKey(view);

            scheduledReductionsByView.MultiAdd(writeBatch.Value, viewKey, idSlice);
		    var scheduleReductionKey = CreateScheduleReductionKey(view, level, reduceKeysAndBuckets.ReduceKey);
		    scheduledReductionsByViewAndLevelAndReduceKey.MultiAdd(writeBatch.Value, scheduleReductionKey, CreateBucketAndEtagKey(reduceKeysAndBuckets.Bucket, id));
			if (scheduledReductionsPerViewAndLevel != null)
				scheduledReductionsPerViewAndLevel.AddOrUpdate(view, new RemainingReductionPerLevel(level), (key, oldvalue) => oldvalue.IncrementPerLevelCounters(level));
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:27,代码来源:MappedResultsStorageActions.cs


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