本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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));
}
}
示例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);
}
}
示例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)));
}
}
示例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));
}