コード例 #1
0
        public void TestRegisterOperations()
        {
            string key = GetRandomKey();

            var          id           = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string registerName = "Name";

            var registerMapUpdate = new MapUpdate
            {
                register_op = Serializer.Invoke("Alex"),
                field       = new MapField {
                    name = Serializer.Invoke(registerName), type = MapField.MapFieldType.REGISTER
                }
            };

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, new List <MapUpdate> {
                registerMapUpdate
            });

            Assert.AreEqual("Alex",
                            Deserializer.Invoke(updatedMap1.Values.Single(s => s.Field.Name == registerName).RegisterValue));

            registerMapUpdate.register_op = Serializer.Invoke("Luke");
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                                                 new List <MapUpdate> {
                registerMapUpdate
            });

            Assert.AreEqual("Luke",
                            Deserializer.Invoke(updatedMap2.Values.Single(s => s.Field.Name == registerName).RegisterValue));
        }
コード例 #2
0
        public void DtUpdateMapWithRecursiveDataWithoutContext_ThrowsException()
        {
            var nestedRemoves = new List <MapField>
            {
                new MapField {
                    name = "field_name".ToRiakString(), type = MapField.MapFieldType.SET
                }
            };

            var mapUpdateNested = new MapUpdate {
                map_op = new MapOp()
            };

            mapUpdateNested.map_op.removes.AddRange(nestedRemoves);

            var map_op = new MapOp();

            map_op.updates.Add(mapUpdateNested);

            var mapUpdate = new MapUpdate {
                map_op = new MapOp()
            };

            mapUpdate.map_op.updates.Add(mapUpdateNested);

            var updates = new List <MapUpdate> {
                mapUpdate
            };

            Assert.Throws <ArgumentNullException>(
                () => Client.DtUpdateMap(
                    "bucketType", "bucket", "key", Serializer, (byte[])null, null, updates, null)
                );
        }
コード例 #3
0
        public void UpdateMap(MapUpdate mapUpdate, MapEditor editor)
        {
            lock (mapUpdateLock) // não permitir salvar ao atualizar o mapa.
            {
                BatchAction batchAction = mapUpdate.batchAction;

                if (mapUpdate.updateType == UpdateType.UPDATE_TYPE_UNDO)
                {
                    foreach (Action action in batchAction.actions.Reverse <Action>())
                    {
                        action.SetMap(this);
                        action.SetEditor(editor);
                        action.undo();
                    }
                }
                else
                {
                    foreach (Action action in batchAction.actions)
                    {
                        action.SetMap(this);
                        action.SetEditor(editor);
                        switch (mapUpdate.updateType)
                        {
                        case UpdateType.UPDATE_TYPE_COMMIT:
                            action.commit();
                            break;

                        case UpdateType.UPDATE_TYPE_REDO:
                            action.redo();
                            break;
                        }
                    }
                }
            }
        }
コード例 #4
0
        public void Test4()
        {
            string key = GetRandomKey();

            var          id      = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string setName = "set";

            // New Map with Set
            var setMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET
                }
            };

            // Add X, Y to set
            var addSet = new List <string> {
                "X", "Y"
            }.Select(s => Serializer.Invoke(s)).ToList();

            setMapUpdate.set_op.adds.AddRange(addSet);

            // Store
            var updatedMap1 = Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals,
                                                 new List <MapUpdate> {
                setMapUpdate
            });

            updatedMap1.Result.IsSuccess.ShouldBeTrue();

            // Add Z
            var setMapUpdate2 = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET
                }
            };

            var addSet2 = new List <string> {
                "Z"
            }.Select(s => Serializer.Invoke(s)).ToList();

            setMapUpdate2.set_op.adds.AddRange(addSet2);

            // Remove Set
            var fieldToRemove = new RiakDtMapField(setMapUpdate.field);

            // Store again, no context
            Assert.Throws <ArgumentNullException>(() =>
                                                  Client.DtUpdateMap(id, Serializer, NoContext,
                                                                     new List <RiakDtMapField> {
                fieldToRemove
            },
                                                                     new List <MapUpdate> {
                setMapUpdate2
            }));
        }
コード例 #5
0
 private void insideCheck()
 {
     if (canGenerate && MapUpdate.insideMainRoom())
     {
         enabled = false;
         GenWorldPt.canGenerate = true;
     }
 }
コード例 #6
0
ファイル: LogicMap.cs プロジェクト: linxin8/Chinese-Chess
 public void MoveChess(int x, int y, int desX, int desY)
 {
     map[desY, desX] = map[y, x];
     map[y, x].Y     = desY;
     map[y, x].X     = desX;
     map[y, x]       = null;
     MapUpdate?.Invoke(map);
 }
コード例 #7
0
 public static TileType[,] GetUpdatedMap(TileType[,] knownMap, MapUpdate patch)
 {
     for (int x = 0; x < patch.SizeX; x++)
     {
         for (int y = 0; y < patch.SizeY; y++)
         {
             knownMap[x + patch.PositionX, y + patch.PositionY] = patch.mapFragment[x, y];
         }
     }
     return(knownMap);
 }
コード例 #8
0
        public void Test2()
        {
            // New Map with Counter of value 5
            string key = GetRandomKey();

            var          id          = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string counterName = "counter";

            var counterMapUpdate = new MapUpdate
            {
                counter_op = new CounterOp
                {
                    increment = 5
                },
                field = new MapField {
                    name = Serializer.Invoke(counterName), type = MapField.MapFieldType.COUNTER
                }
            };

            // Store
            var updatedMap = Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals,
                                                new List <MapUpdate> {
                counterMapUpdate
            });

            // Increment by 2
            var counterMapUpdate2 = new MapUpdate
            {
                counter_op = new CounterOp
                {
                    increment = 2
                },
                field = new MapField {
                    name = Serializer.Invoke(counterName), type = MapField.MapFieldType.COUNTER
                }
            };

            // Remove field
            var fieldToRemove = new RiakDtMapField(counterMapUpdate.field);

            // Store
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap.Context,
                                                 new List <RiakDtMapField> {
                fieldToRemove
            }, new List <MapUpdate> {
                counterMapUpdate2
            });

            Assert.AreEqual(1, updatedMap2.Values.Count);

            var counterField = updatedMap2.Values.Single(s => s.Field.Name == counterName);

            Assert.AreEqual(2, counterField.Counter.Value);
        }
コード例 #9
0
        public void TestMapSetOperations()
        {
            string key = GetRandomKey();

            var          id      = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string setName = "Name";

            var setMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET
                }
            };

            var addSet = new List <string> {
                "Alex"
            }.Select(s => Serializer.Invoke(s)).ToList();

            setMapUpdate.set_op.adds.AddRange(addSet);

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, new List <MapUpdate> {
                setMapUpdate
            });
            var setValues1 =
                updatedMap1.Values.Single(s => s.Field.Name == setName)
                .SetValue.Select(v => Deserializer.Invoke(v))
                .ToList();

            Assert.Contains("Alex", setValues1);
            Assert.AreEqual(1, setValues1.Count);

            setMapUpdate.set_op = new SetOp();
            var removeSet = addSet;
            var addSet2 = new List <string> {
                "Luke", "Jeremiah"
            }.Select(s => Serializer.Invoke(s)).ToList();

            setMapUpdate.set_op.adds.AddRange(addSet2);
            setMapUpdate.set_op.removes.AddRange(removeSet);

            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                                                 new List <MapUpdate> {
                setMapUpdate
            });
            var setValues2 =
                updatedMap2.Values.Single(s => s.Field.Name == setName)
                .SetValue.Select(v => Deserializer.Invoke(v))
                .ToList();

            Assert.Contains("Luke", setValues2);
            Assert.Contains("Jeremiah", setValues2);
            Assert.AreEqual(2, setValues2.Count);
        }
コード例 #10
0
ファイル: Connection.cs プロジェクト: squall-tech/akmapeditor
 public void SendMapUpdates(MapUpdate mapUpdate)
 {
     try
     {
         WriteMessage(MessageType.MAP_UPDATE, mapUpdate);
     }
     catch (Exception ex)
     {
         addLog("SendMapUpdates" + ex.Message + ex.StackTrace);
     }
 }
コード例 #11
0
ファイル: Connection.cs プロジェクト: squall-tech/akmapeditor
 public void MapUpdate(MapUpdate mapUpdate)
 {
     try
     {
         getMap().UpdateMap(mapUpdate, null);
         form.UpdateMaps(mapUpdate, this);
     }
     catch (Exception ex)
     {
         addLog("MapUpdate - " + ex.Message + "trace: " + ex.StackTrace);
     }
 }
コード例 #12
0
ファイル: Connection.cs プロジェクト: squall-tech/akmapeditor
 private void MapUpdate()
 {
     try
     {
         MapUpdate mapUpdate = Serializer.DeserializeWithLengthPrefix <MapUpdate>(stream, PrefixStyle.Base128);
         Thread    t         = new Thread(() => MapUpdate(mapUpdate));
         t.Start();
     }
     catch (Exception ex)
     {
         addLog("MapUpdate()" + ex.Message + "\n" + ex.StackTrace);
     }
 }
コード例 #13
0
        public async Task <IActionResult> UpdateMapping([FromBody] MapUpdate mapping)
        {
            try
            {
                await _actionService.SaveAccountMappingCmd(mapping.MapIndex, mapping.AccountCode, mapping.AccountTypeCode);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(BadRequest(ex.Message));
            }
        }
コード例 #14
0
 public void UpdateMaps(MapUpdate mapUpdate, Connection sender)
 {
     try
     {
         foreach (Connection connection in connections)
         {
             if (!sender.Equals(connection))
             {
                 Thread t = new Thread(() => connection.SendMapUpdates(mapUpdate));
                 t.Start();
             }
         }
     } catch (Exception ex)
     {
     }
 }
コード例 #15
0
        public override bool MouseDown(ScreenEventArgs args)
        {
            if (args.X < 1 || args.X > 81 || args.Y < 1 || args.Y > 81)
            {
                return(false);
            }
            int tileX = (int)Math.Floor(((double)args.X - 1) / 16);
            int tileY = (int)Math.Floor(((double)args.Y - 1) / 16);

            if (tileX < 0 || tileY < 0 || tileX > 4 || tileY > 4)
            {
                return(false);
            }

            _city.SetResourceTile(_city.CityRadius[tileX, tileY]);
            _update = true;
            MapUpdate?.Invoke(this, null);
            return(true);
        }
コード例 #16
0
        public void TestFlagOperations()
        {
            string key = GetRandomKey();

            var          id       = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string flagName = "Name";

            var flagMapUpdate = new MapUpdate
            {
                flag_op = MapUpdate.FlagOp.DISABLE,
                field   = new MapField {
                    name = Serializer.Invoke(flagName), type = MapField.MapFieldType.FLAG
                }
            };

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, new List <MapUpdate> {
                flagMapUpdate
            });

            Assert.True(updatedMap1.Result.IsSuccess, updatedMap1.Result.ErrorMessage);
            var mapEntry = updatedMap1.Values.Single(s => s.Field.Name == flagName);

            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsFalse(mapEntry.FlagValue.Value);

            var flagMapUpdate2 = new MapUpdate
            {
                flag_op = MapUpdate.FlagOp.ENABLE,
                field   = new MapField {
                    name = Serializer.Invoke(flagName), type = MapField.MapFieldType.FLAG
                }
            };

            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                                                 new List <MapUpdate> {
                flagMapUpdate2
            });

            Assert.True(updatedMap2.Result.IsSuccess, updatedMap2.Result.ErrorMessage);
            mapEntry = updatedMap2.Values.Single(s => s.Field.Name == flagName);
            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsTrue(mapEntry.FlagValue.Value);
        }
コード例 #17
0
        public void TestFlagOperations()
        {
            string key = GetRandomKey();

            var          id       = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string flagName = "Name";

            byte[] flagNameBytes = Serializer(flagName);

            var options = new RiakDtUpdateOptions();

            options.SetIncludeContext(true);
            options.SetTimeout(new Timeout(TimeSpan.FromSeconds(60)));

            var flagMapUpdate = new MapUpdate
            {
                flag_op = MapUpdate.FlagOp.ENABLE,
                field   = new MapField {
                    name = flagNameBytes, type = MapField.MapFieldType.FLAG
                }
            };
            var update = new List <MapUpdate> {
                flagMapUpdate
            };
            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, update, options);

            Assert.True(updatedMap1.Result.IsSuccess, updatedMap1.Result.ErrorMessage);
            var mapEntry = updatedMap1.Values.Single(s => s.Field.Name == flagName);

            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsTrue(mapEntry.FlagValue.Value);

            flagMapUpdate.flag_op = MapUpdate.FlagOp.DISABLE;
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null, update, options);

            Assert.True(updatedMap2.Result.IsSuccess, updatedMap2.Result.ErrorMessage);
            mapEntry = updatedMap2.Values.Single(s => s.Field.Name == flagName);
            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsFalse(mapEntry.FlagValue.Value);
        }
コード例 #18
0
        public void UpdateServer(BatchAction batchAction, int updateType)
        {
            try
            {
                if (batchAction.type != ActionIdentifier.ACTION_SELECT)
                {
                    lock (sendLock)
                    {
                        MapUpdate mapUpdate = new MapUpdate();
                        mapUpdate.batchAction = batchAction;
                        mapUpdate.updateType  = updateType;

                        stream.WriteByte(MessageType.MAP_UPDATE);
                        stream.Flush();
                        Serializer.SerializeWithLengthPrefix <MapUpdate>(stream, mapUpdate, PrefixStyle.Base128);
                    }
                }
            }
            catch (Exception ex)
            {
                Generic.AjustError(ex);
            }
        }
コード例 #19
0
ファイル: LogicMap.cs プロジェクト: linxin8/Chinese-Chess
        public void SetChess(int x, int y, Rule.ChessType chessType, Rule.Country country)
        {
            switch (chessType)
            {
            case Rule.ChessType.King:
                map[y, x] = new KingChess(this, x, y, country);
                break;

            case Rule.ChessType.Guard:
                map[y, x] = new GuardChess(this, x, y, country);
                break;

            case Rule.ChessType.Elephant:
                map[y, x] = new ElephantChess(this, x, y, country);
                break;

            case Rule.ChessType.Rook:
                map[y, x] = new RookChess(this, x, y, country);
                break;

            case Rule.ChessType.Knight:
                map[y, x] = new KnightChess(this, x, y, country);
                break;

            case Rule.ChessType.Cannon:
                map[y, x] = new CannonChess(this, x, y, country);
                break;

            case Rule.ChessType.Pawn:
                map[y, x] = new PawnChess(this, x, y, country);
                break;

            default:
                throw new NotSupportedException();
            }
            MapUpdate?.Invoke(map);
        }
コード例 #20
0
ファイル: LogicMap.cs プロジェクト: linxin8/Chinese-Chess
 public void SetChess(int x, int y, Chess chess)
 {
     map[y, x] = chess;
     MapUpdate?.Invoke(map);
 }
コード例 #21
0
ファイル: LogicMap.cs プロジェクト: linxin8/Chinese-Chess
 public void ForceTriggerMapUpdate() => MapUpdate?.Invoke(map);
コード例 #22
0
 internal void OnMapUpdate()
 {
     MapUpdate?.Invoke(this, EventArgs.Empty);
 }
コード例 #23
0
        public void Should_Build_DtUpdateReq_Correctly()
        {
            var mapOp = new UpdateMap.MapOperation()
                        .IncrementCounter("counter_1", 50)
                        .RemoveCounter("counter_2")
                        .AddToSet("set_1", "set_value_1")
                        .RemoveFromSet("set_2", "set_value_2")
                        .RemoveSet("set_3")
                        .SetRegister("register_1", "register_value_1")
                        .RemoveRegister("register_2")
                        .SetFlag("flag_1", true)
                        .RemoveFlag("flag_2")
                        .RemoveMap("map_3");

            mapOp.Map("map_2").IncrementCounter("counter_1", 50)
            .RemoveCounter("counter_2")
            .AddToSet("set_1", "set_value_1")
            .RemoveFromSet("set_2", "set_value_2")
            .RemoveSet("set_3")
            .SetRegister("register_1", "register_value_1")
            .RemoveRegister("register_2")
            .SetFlag("flag_1", true)
            .RemoveFlag("flag_2")
            .RemoveMap("map_3");

            var updateMapCommandBuilder = new UpdateMap.Builder(mapOp);

            var q1 = new Quorum(1);
            var q2 = new Quorum(2);
            var q3 = new Quorum(3);

            updateMapCommandBuilder
            .WithBucketType(BucketType)
            .WithBucket(Bucket)
            .WithKey(Key)
            .WithContext(Context)
            .WithW(q3)
            .WithPW(q1)
            .WithDW(q2)
            .WithReturnBody(true)
            .WithIncludeContext(false)
            .WithTimeout(TimeSpan.FromSeconds(20));

            UpdateMap updateMapCommand = updateMapCommandBuilder.Build();

            DtUpdateReq protobuf = (DtUpdateReq)updateMapCommand.ConstructRequest(false);

            Assert.AreEqual(Encoding.UTF8.GetBytes(BucketType), protobuf.type);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Bucket), protobuf.bucket);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Key), protobuf.key);
            Assert.AreEqual((uint)q3, protobuf.w);
            Assert.AreEqual((uint)q1, protobuf.pw);
            Assert.AreEqual((uint)q2, protobuf.dw);
            Assert.IsTrue(protobuf.return_body);
            Assert.IsFalse(protobuf.include_context);
            Assert.AreEqual(20000, protobuf.timeout);
            Assert.AreEqual(Context, protobuf.context);

            MapOp mapOpMsg = protobuf.op.map_op;

            VerifyRemoves(mapOpMsg.removes);
            MapUpdate innerMapUpdate = VerifyUpdates(mapOpMsg.updates, true);

            VerifyRemoves(innerMapUpdate.map_op.removes);
            VerifyUpdates(innerMapUpdate.map_op.updates, false);
        }
コード例 #24
0
        public static event EventHandler <MapUpdateInfo> MapUpdate;       // event

        public static void OnMapUpdate(object sender, MapUpdateInfo info) //if event is not null then call delegate
        {
            MapUpdate?.Invoke(sender, info);
        }
コード例 #25
0
        public void Test3()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);

            // New map w/ Nested Map w/ Nested Set; Add X,Y to set
            byte[]   innerMapName    = Serializer("innerMap");
            byte[]   innerMapSetName = Serializer("innerMap_innerSet");
            byte[][] adds            = { Serializer("X"), Serializer("Y") };

            var innerMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = innerMapSetName, type = MapField.MapFieldType.SET
                }
            };

            innerMapUpdate.set_op.adds.AddRange(adds);

            var parentMapUpdate = new MapUpdate
            {
                field = new MapField {
                    name = innerMapName, type = MapField.MapFieldType.MAP
                },
                map_op = new MapOp()
            };

            parentMapUpdate.map_op.updates.Add(innerMapUpdate);

            var updatedMap = Client.DtUpdateMap(id, Serializer, NoContext, null, new List <MapUpdate> {
                parentMapUpdate
            });

            Assert.AreEqual(1, updatedMap.Values.Count);

            var innerMapField = updatedMap.Values.Single(s => s.Field.Name == innerMapName.FromRiakString());

            Assert.AreEqual(1, innerMapField.MapValue.Count);

            var innerMapSetField =
                innerMapField.MapValue.Single(entry => entry.Field.Name == innerMapSetName.FromRiakString());
            var setValues = innerMapSetField.SetValue.Select(v => Deserializer(v)).ToList();

            Assert.AreEqual(2, setValues.Count);
            Assert.Contains("X", setValues);
            Assert.Contains("Y", setValues);

            // Remove nested map, add Z to set
            var innerMapUpdate2 = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = innerMapSetName, type = MapField.MapFieldType.SET
                }
            };

            innerMapUpdate2.set_op.adds.Add(Serializer("Z"));

            var parentMapUpdate2 = new MapUpdate
            {
                field = new MapField {
                    name = innerMapName, type = MapField.MapFieldType.MAP
                },
                map_op = new MapOp()
            };

            parentMapUpdate2.map_op.removes.Add(innerMapUpdate2.field);
            parentMapUpdate2.map_op.updates.Add(innerMapUpdate2);

            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap.Context, NoRemovals,
                                                 new List <MapUpdate> {
                parentMapUpdate2
            });

            Assert.AreEqual(1, updatedMap2.Values.Count);

            var innerMapField2 = updatedMap2.Values.Single(s => s.Field.Name == innerMapName.FromRiakString());

            Assert.AreEqual(1, innerMapField2.MapValue.Count);

            var innerMapSetField2 =
                innerMapField2.MapValue.Single(entry => entry.Field.Name == innerMapSetName.FromRiakString());
            var setValues2 = innerMapSetField2.SetValue.Select(v => Deserializer(v)).ToList();

            Assert.AreEqual(1, setValues2.Count);
            Assert.Contains("Z", setValues2);
        }
コード例 #26
0
        public void TestBasicMapOperations()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);

            // Fetch empty
            // []
            var initialMap = Client.DtFetchMap(id);

            Assert.IsNull(initialMap.Context);
            Assert.IsEmpty(initialMap.Values);

            // Add Counter
            // [ Score => 1 ]
            const string counterName = "Score";

            var counterMapUpdate = new MapUpdate
            {
                counter_op = new CounterOp {
                    increment = 1
                },
                field = new MapField {
                    name = Serializer.Invoke(counterName), type = MapField.MapFieldType.COUNTER
                }
            };

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, initialMap.Context, null,
                                                 new List <MapUpdate> {
                counterMapUpdate
            });

            Assert.IsNotNull(updatedMap1.Context);
            Assert.IsNotEmpty(updatedMap1.Values);
            Assert.AreEqual(1, updatedMap1.Values.Single(s => s.Field.Name == counterName).Counter.Value);


            // Increment Counter
            // [ Score => 5 ]
            counterMapUpdate.counter_op.increment = 4;
            RiakDtMapResult updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                                                             new List <MapUpdate> {
                counterMapUpdate
            });
            var counterMapField = updatedMap2.Values.Single(s => s.Field.Name == counterName);

            Assert.AreEqual(5, counterMapField.Counter.Value);


            // Add an embedded map with new counter
            // decrement "Score" counter by 10
            // [ Score => -5, subMap [ InnerScore => 42 ]]
            const string innerMapName          = "subMap";
            const string innerMapCounterName   = "InnerScore";
            var          innerCounterMapUpdate = new MapUpdate
            {
                counter_op = new CounterOp {
                    increment = 42
                },
                field =
                    new MapField {
                    name = Serializer.Invoke(innerMapCounterName), type = MapField.MapFieldType.COUNTER
                }
            };

            var parentMapUpdate = new MapUpdate
            {
                field = new MapField {
                    name = Serializer.Invoke(innerMapName), type = MapField.MapFieldType.MAP
                },
                map_op = new MapOp()
            };

            parentMapUpdate.map_op.updates.Add(innerCounterMapUpdate);
            counterMapUpdate.counter_op.increment = -10;

            var updatedMap3 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                                                 new List <MapUpdate> {
                parentMapUpdate, counterMapUpdate
            });

            counterMapField = updatedMap3.Values.Single(entry => entry.Field.Name == counterName);
            var innerMapField        = updatedMap3.Values.Single(entry => entry.Field.Name == innerMapName);
            var innerMapCounterField = innerMapField.MapValue.Single(entry => entry.Field.Name == innerMapCounterName);

            Assert.AreEqual(-5, counterMapField.Counter.Value);
            Assert.AreEqual(42, innerMapCounterField.Counter.Value);
            Assert.AreEqual(2, updatedMap3.Values.Count);
            Assert.AreEqual(1, innerMapField.MapValue.Count);


            // Remove Counter from map
            // [ subMap [ InnerScore => 42 ]]
            var removes = new List <RiakDtMapField> {
                new RiakDtMapField(counterMapField.Field.ToMapField())
            };
            var updatedMap4 = Client.DtUpdateMap(id, Serializer, updatedMap3.Context, removes);

            innerMapField        = updatedMap4.Values.Single(entry => entry.Field.Name == innerMapName);
            innerMapCounterField = innerMapField.MapValue.Single(entry => entry.Field.Name == innerMapCounterName);
            Assert.AreEqual(1, updatedMap4.Values.Count);
            Assert.AreEqual(42, innerMapCounterField.Counter.Value);
        }
コード例 #27
0
        public void Test1()
        {
            string key = GetRandomKey();

            var          id      = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string setName = "set";

            // New Map with Set
            var setMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET
                }
            };

            // Add X, Y to set
            var addSet = new List <string> {
                "X", "Y"
            }.Select(s => Serializer.Invoke(s)).ToList();

            setMapUpdate.set_op.adds.AddRange(addSet);

            // Store
            var updatedMap1 = Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals,
                                                 new List <MapUpdate> {
                setMapUpdate
            });

            // Add Z
            var setMapUpdate2 = new MapUpdate
            {
                set_op = new SetOp(),
                field  = new MapField {
                    name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET
                }
            };

            var addSet2 = new List <string> {
                "Z"
            }.Select(s => Serializer.Invoke(s)).ToList();

            setMapUpdate2.set_op.adds.AddRange(addSet2);

            // Remove Set
            var fieldToRemove = new RiakDtMapField(setMapUpdate.field);

            // Store again
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context,
                                                 new List <RiakDtMapField> {
                fieldToRemove
            }, new List <MapUpdate> {
                setMapUpdate2
            });

            Assert.AreEqual(1, updatedMap2.Values.Count);

            var set       = updatedMap2.Values.Single(s => s.Field.Name == setName);
            var setValues = set.SetValue.Select(v => Deserializer.Invoke(v)).ToList();

            Assert.AreEqual(1, setValues.Count);
            Assert.Contains("Z", setValues);
        }
コード例 #28
0
        private static MapUpdate VerifyUpdates(IEnumerable <MapUpdate> updates, bool expectMapUpdate)
        {
            bool      counterIncremented = false;
            bool      setAddedTo         = false;
            bool      setRemovedFrom     = false;
            bool      registerSet        = false;
            bool      flagSet            = false;
            bool      mapAdded           = false;
            MapUpdate mapUpdate          = null;

            foreach (MapUpdate update in updates)
            {
                switch (update.field.type)
                {
                case MapField.MapFieldType.COUNTER:
                    Assert.AreEqual(Encoding.UTF8.GetBytes("counter_1"), update.field.name);
                    Assert.AreEqual(50, update.counter_op.increment);
                    counterIncremented = true;
                    break;

                case MapField.MapFieldType.SET:
                    if (!EnumerableUtil.IsNullOrEmpty(update.set_op.adds))
                    {
                        Assert.AreEqual(Encoding.UTF8.GetBytes("set_1"), update.field.name);
                        Assert.AreEqual(Encoding.UTF8.GetBytes("set_value_1"), update.set_op.adds[0]);
                        setAddedTo = true;
                    }
                    else
                    {
                        Assert.AreEqual(Encoding.UTF8.GetBytes("set_2"), update.field.name);
                        Assert.AreEqual(Encoding.UTF8.GetBytes("set_value_2"), update.set_op.removes[0]);
                        setRemovedFrom = true;
                    }

                    break;

                case MapField.MapFieldType.MAP:
                    if (expectMapUpdate)
                    {
                        Assert.AreEqual(Encoding.UTF8.GetBytes("map_2"), update.field.name);
                        mapAdded  = true;
                        mapUpdate = update;
                    }

                    break;

                case MapField.MapFieldType.REGISTER:
                    Assert.AreEqual(Encoding.UTF8.GetBytes("register_1"), update.field.name);
                    Assert.AreEqual(Encoding.UTF8.GetBytes("register_value_1"), update.register_op);
                    registerSet = true;
                    break;

                case MapField.MapFieldType.FLAG:
                    Assert.AreEqual(Encoding.UTF8.GetBytes("flag_1"), update.field.name);
                    Assert.AreEqual(MapUpdate.FlagOp.ENABLE, update.flag_op);
                    flagSet = true;
                    break;

                default:
                    break;
                }
            }

            Assert.IsTrue(counterIncremented);
            Assert.IsTrue(setAddedTo);
            Assert.IsTrue(setRemovedFrom);
            Assert.IsTrue(registerSet);
            Assert.IsTrue(flagSet);

            if (expectMapUpdate)
            {
                Assert.IsTrue(mapAdded);
            }
            else
            {
                Assert.IsFalse(mapAdded);
            }

            return(mapUpdate);
        }
コード例 #29
0
        private static MapOp Populate(MapOperation mapOperation)
        {
            var mapOp = new MapOp();

            if (mapOperation.HasRemoves)
            {
                foreach (var removeCounter in mapOperation.RemoveCounters)
                {
                    RiakString counterName = removeCounter.Key;
                    var        field       = new MapField
                    {
                        name = counterName,
                        type = MapField.MapFieldType.COUNTER
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeSet in mapOperation.RemoveSets)
                {
                    RiakString setName = removeSet.Key;
                    var        field   = new MapField
                    {
                        name = setName,
                        type = MapField.MapFieldType.SET
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeRegister in mapOperation.RemoveRegisters)
                {
                    RiakString registerName = removeRegister.Key;
                    var        field        = new MapField
                    {
                        name = registerName,
                        type = MapField.MapFieldType.REGISTER
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeFlag in mapOperation.RemoveFlags)
                {
                    RiakString flagName = removeFlag.Key;
                    var        field    = new MapField
                    {
                        name = flagName,
                        type = MapField.MapFieldType.FLAG
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeMap in mapOperation.RemoveMaps)
                {
                    RiakString mapName = removeMap.Key;
                    var        field   = new MapField
                    {
                        name = mapName,
                        type = MapField.MapFieldType.MAP
                    };

                    mapOp.removes.Add(field);
                }
            }

            foreach (var incrementCounter in mapOperation.IncrementCounters)
            {
                RiakString counterName = incrementCounter.Key;
                long       increment   = incrementCounter.Value;

                var field = new MapField
                {
                    name = counterName,
                    type = MapField.MapFieldType.COUNTER
                };

                var counterOp = new CounterOp
                {
                    increment = increment
                };

                var update = new MapUpdate
                {
                    field      = field,
                    counter_op = counterOp
                };

                mapOp.updates.Add(update);
            }

            foreach (var addToSet in mapOperation.AddToSets)
            {
                RiakString         setName = addToSet.Key;
                IList <RiakString> setAdds = addToSet.Value;

                var field = new MapField
                {
                    name = setName,
                    type = MapField.MapFieldType.SET
                };

                var setOp = new SetOp();
                setOp.adds.AddRange(setAdds.Select(v => (byte[])v));

                var update = new MapUpdate
                {
                    field  = field,
                    set_op = setOp
                };

                mapOp.updates.Add(update);
            }

            foreach (var removeFromSet in mapOperation.RemoveFromSets)
            {
                RiakString         setName    = removeFromSet.Key;
                IList <RiakString> setRemoves = removeFromSet.Value;

                var field = new MapField
                {
                    name = setName,
                    type = MapField.MapFieldType.SET
                };

                var setOp = new SetOp();
                setOp.removes.AddRange(setRemoves.Select(v => (byte[])v));

                var update = new MapUpdate
                {
                    field  = field,
                    set_op = setOp
                };

                mapOp.updates.Add(update);
            }

            foreach (var registerToSet in mapOperation.RegistersToSet)
            {
                RiakString registerName  = registerToSet.Key;
                RiakString registerValue = registerToSet.Value;

                var field = new MapField
                {
                    name = registerName,
                    type = MapField.MapFieldType.REGISTER
                };

                var update = new MapUpdate
                {
                    field       = field,
                    register_op = registerValue
                };

                mapOp.updates.Add(update);
            }

            foreach (var flagToSet in mapOperation.FlagsToSet)
            {
                RiakString flagName  = flagToSet.Key;
                bool       flagValue = flagToSet.Value;

                var field = new MapField
                {
                    name = flagName,
                    type = MapField.MapFieldType.FLAG
                };

                var update = new MapUpdate
                {
                    field   = field,
                    flag_op = flagValue ? MapUpdate.FlagOp.ENABLE : MapUpdate.FlagOp.DISABLE
                };

                mapOp.updates.Add(update);
            }

            foreach (var map in mapOperation.Maps)
            {
                RiakString   mapName           = map.Key;
                MapOperation innerMapOperation = map.Value;

                var field = new MapField
                {
                    name = mapName,
                    type = MapField.MapFieldType.MAP
                };

                MapOp innerMapOp = Populate(innerMapOperation);

                var update = new MapUpdate
                {
                    field  = field,
                    map_op = innerMapOp
                };

                mapOp.updates.Add(update);
            }

            return(mapOp);
        }
コード例 #30
0
        private void UpdateMap(MapUpdate mapUpdate)
        {
            Thread t = new Thread(() => editor.UpdateMap(mapUpdate));

            t.Start();
        }