Example #1
0
 public ItemCountsAggregate(ItemCountAggregateDefinition definition)
 {
     foreach (var countDef in definition.Counts) {
         var a = new PhysicalItemType(countDef.TypeName, countDef.SubtypeName);
         this.Set(a.DefinitionId, (MyFixedPoint)countDef.Count);
     }
 }
 private void TestByteSerialization(SpecCase x)
 {
     var stream = new ByteStream(0, true);
     var a = new ItemCountAggregateDefinition() {
         Counts = new List<ItemCountDefinition>() {
             new ItemCountDefinition() {
                 TypeName = "type 1"
             },
             new ItemCountDefinition() {
                 TypeName = "type 2"
             }
         }
     };
     //Log.Trace("serializing", "TestByteSerialization");
     a.AddToByteSteam(stream);
     stream = new ByteStream(stream.Data, stream.Data.Length);
     //Log.Trace("deserializing", "TestByteSerialization");
     var a2 = new ItemCountAggregateDefinition(stream);
     x.Assert(a2.Counts[0].TypeName == "type 1",
         "First item serializes/deserializes correctly.");
     x.Assert(a2.Counts[1].TypeName == "type 2",
         "Second item serializes/deserializes correctly.");
 }
Example #3
0
        public ItemCountAggregateDefinition GetDefinition()
        {
            var result = new ItemCountAggregateDefinition();

            foreach (var kvp in Counts) {
                if (kvp.Value <= 0) continue;
                var item = new PhysicalItemType(kvp.Key);
                var countDef = new ItemCountDefinition() {
                    TypeName = item.TypeName,
                    SubtypeName = item.SubtypeName,
                    Count = (double)kvp.Value,
                };
                result.Counts.Add(countDef);
            }

            return result;
        }