private void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            IDictionary inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get(1)] = Value.Get(55);
            inputMap[Value.Get(2)] = Value.Get(33);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            console.Info("Record: " + record);

            // Pop value from map and also return new size of map.
            record = client.Operate(args.writePolicy, key, MapOperation.RemoveByKey(binName, Value.Get(1), MapReturnType.VALUE), MapOperation.Size(binName));

            console.Info("Record: " + record);

            // There should be one result for each map operation on the same map bin.
            // In this case, there are two map operations (pop and size), so there
            // should be two results.
            IList results = record.GetList(binName);

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
        public void OperateMapSwitch()
        {
            // Switch from unordered map to a key ordered map.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey4");

            client.Delete(null, key);

            Record record = client.Operate(null, key,
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(4), Value.Get(4)),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(3), Value.Get(3)),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(2), Value.Get(2)),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(1), Value.Get(1)),
                                           MapOperation.GetByIndex(binName, 2, MapReturnType.KEY_VALUE),
                                           MapOperation.GetByIndexRange(binName, 0, 10, MapReturnType.KEY_VALUE)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 3;

            long size = (long)results[i++];

            Assert.AreEqual(4, size);

            IList list = (IList)results[i++];

            Assert.AreEqual(1, list.Count);

            list = (IList)results[i++];
            Assert.AreEqual(4, list.Count);

            record = client.Operate(null, key,
                                    MapOperation.SetMapPolicy(new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE), binName),
                                    MapOperation.GetByKeyRange(binName, Value.Get(3), Value.Get(5), MapReturnType.COUNT),
                                    MapOperation.GetByKeyRange(binName, Value.Get(-5), Value.Get(2), MapReturnType.KEY_VALUE),
                                    MapOperation.GetByIndexRange(binName, 0, 10, MapReturnType.KEY_VALUE));

            AssertRecordFound(key, record);

            results = record.GetList(binName);
            i       = 0;

            object obj = results[i++];

            Assert.IsNull(obj);

            long val = (long)results[i++];

            Assert.AreEqual(2, val);

            list = (IList)results[i++];
            Assert.AreEqual(1, list.Count);
            KeyValuePair <object, object> entry = (KeyValuePair <object, object>)list[0];

            Assert.AreEqual(1L, entry.Value);

            list  = (IList)results[i++];
            entry = (KeyValuePair <object, object>)list[3];
            Assert.AreEqual(4L, entry.Key);
        }
 public Builder WithMapOperation(MapOperation mapOp)
 {
     this.mapOp = mapOp;
     return(this);
 }
        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);
        }
        public void OperateMapPutItems()
        {
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey2");

            client.Delete(null, key);

            Dictionary <Value, Value> addMap = new Dictionary <Value, Value>();

            addMap[Value.Get(12)]    = Value.Get("myval");
            addMap[Value.Get(-8734)] = Value.Get("str2");
            addMap[Value.Get(1)]     = Value.Get("my default");

            Dictionary <Value, Value> putMap = new Dictionary <Value, Value>();

            putMap[Value.Get(12)] = Value.Get("myval12222");
            putMap[Value.Get(13)] = Value.Get("str13");

            Dictionary <Value, Value> updateMap = new Dictionary <Value, Value>();

            updateMap[Value.Get(13)] = Value.Get("myval2");

            Dictionary <Value, Value> replaceMap = new Dictionary <Value, Value>();

            replaceMap[Value.Get(12)]    = Value.Get(23);
            replaceMap[Value.Get(-8734)] = Value.Get("changed");

            MapPolicy putMode    = MapPolicy.Default;
            MapPolicy addMode    = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.CREATE_ONLY);
            MapPolicy updateMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE_ONLY);

            Record record = client.Operate(null, key,
                                           MapOperation.PutItems(addMode, binName, addMap),
                                           MapOperation.PutItems(putMode, binName, putMap),
                                           MapOperation.PutItems(updateMode, binName, updateMap),
                                           MapOperation.PutItems(updateMode, binName, replaceMap),
                                           MapOperation.GetByKey(binName, Value.Get(1), MapReturnType.VALUE),
                                           MapOperation.GetByKey(binName, Value.Get(-8734), MapReturnType.VALUE),
                                           MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.KEY_VALUE)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long size = (long)results[i++];

            Assert.AreEqual(3, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            string str = (string)results[i++];

            Assert.AreEqual("my default", str);

            str = (string)results[i++];
            Assert.AreEqual("changed", str);

            IList list = (IList)results[i++];

            Assert.AreEqual(2, list.Count);
        }
Exemple #6
0
 /// <summary>
 /// 使地图面板进入ZoomOut模式
 /// </summary>
 public void ZoomOutMode()
 {
     operationType    = MapOperation.ZoomOut;
     picBoxMap.Cursor = cursorZoomOut;
 }
        public void OperateDoubleNestedMap()
        {
            Key key = new Key(args.ns, args.set, "opmkey19");

            client.Delete(null, key);

            IDictionary <Value, Value> m11 = new Dictionary <Value, Value>();

            m11[Value.Get("key111")] = Value.Get(1);

            IDictionary <Value, Value> m12 = new Dictionary <Value, Value>();

            m12[Value.Get("key121")] = Value.Get(5);

            IDictionary <Value, Value> m1 = new Dictionary <Value, Value>();

            m1[Value.Get("key11")] = Value.Get(m11);
            m1[Value.Get("key12")] = Value.Get(m12);

            IDictionary <Value, Value> m21 = new Dictionary <Value, Value>();

            m21[Value.Get("key211")] = Value.Get(7);

            IDictionary <Value, Value> m2 = new Dictionary <Value, Value>();

            m2[Value.Get("key21")] = Value.Get(m21);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("key1")] = Value.Get(m1);
            inputMap[Value.Get("key2")] = Value.Get(m2);

            // Create maps.
            client.Put(null, key, new Bin(binName, inputMap));

            // Set map value to 11 for map key "key21" inside of map key "key2"
            // and retrieve all maps.
            Record record = client.Operate(null, key,
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("key121"), Value.Get(11), CTX.MapKey(Value.Get("key1")), CTX.MapRank(-1)),
                                           Operation.Get(binName)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long count = (long)results[i++];

            Assert.AreEqual(1, count);

            IDictionary map = (IDictionary)results[i++];

            Assert.AreEqual(2, map.Count);

            map = (IDictionary)map["key1"];
            Assert.AreEqual(2, map.Count);

            map = (IDictionary)map["key12"];
            Assert.AreEqual(1, map.Count);

            long v = (long)map["key121"];

            Assert.AreEqual(11, v);
        }
        public void OperateMapScore()
        {
            // Test score.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey10");

            client.Delete(null, key);

            MapPolicy mapPolicy = new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("weiling")] = Value.Get(0);
            inputMap[Value.Get("briann")]  = Value.Get(0);
            inputMap[Value.Get("brianb")]  = Value.Get(0);
            inputMap[Value.Get("meher")]   = Value.Get(0);

            // Create map.
            Record record = client.Operate(null, key, MapOperation.PutItems(mapPolicy, binName, inputMap));

            AssertRecordFound(key, record);

            // Change scores
            record = client.Operate(null, key,
                                    MapOperation.Increment(mapPolicy, binName, Value.Get("weiling"), Value.Get(10)),
                                    MapOperation.Increment(mapPolicy, binName, Value.Get("briann"), Value.Get(20)),
                                    MapOperation.Increment(mapPolicy, binName, Value.Get("brianb"), Value.Get(1)),
                                    MapOperation.Increment(mapPolicy, binName, Value.Get("meher"), Value.Get(20))
                                    );

            AssertRecordFound(key, record);

            // Query top 3 scores
            record = client.Operate(null, key, MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY));

            AssertRecordFound(key, record);

            // Remove people with score 10 and display top 3 again
            record = client.Operate(null, key,
                                    MapOperation.RemoveByValue(binName, Value.Get(10), MapReturnType.KEY),
                                    MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY)
                                    );

            AssertRecordFound(key, record);

            IList  results = record.GetList(binName);
            int    i       = 0;
            IList  list    = (IList)results[i++];
            string s       = (string)list[0];

            Assert.AreEqual("weiling", s);

            list = (IList)results[i++];
            s    = (string)list[0];
            Assert.AreEqual("brianb", s);
            s = (string)list[1];
            Assert.AreEqual("briann", s);
            s = (string)list[2];
            Assert.AreEqual("meher", s);
        }
Exemple #9
0
 /// <summary>
 /// 使地图进入编辑节点模式
 /// </summary>
 internal void EditVerticesMode()
 {
     operationType    = MapOperation.EditVertices;
     picBoxMap.Cursor = Cursors.Arrow;
 }
Exemple #10
0
 /// <summary>
 /// 使地图面板进入Identify模式
 /// </summary>
 internal void IdentifyMode()
 {
     operationType    = MapOperation.Identify;
     picBoxMap.Cursor = Cursors.Help;
 }
Exemple #11
0
 /// <summary>
 /// 使地图面板进入编辑要素模式
 /// </summary>
 public void EditMode(int index)
 {
     operationType    = MapOperation.Edit;
     picBoxMap.Cursor = Cursors.Arrow;
     EditingIndex     = index;
 }
Exemple #12
0
 /// <summary>
 /// 使地图面板进入选择要素模式
 /// </summary>
 public void SelectFeaturesMode()
 {
     operationType    = MapOperation.SelectFeatures;
     picBoxMap.Cursor = Cursors.Arrow;
 }
Exemple #13
0
 /// <summary>
 /// 使地图面板进入漫游模式
 /// </summary>
 public void PanMode()
 {
     operationType    = MapOperation.Pan;
     picBoxMap.Cursor = Cursors.Hand;
 }
        public void OperateMapRank()
        {
            // Test rank.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey6");

            client.Delete(null, key);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("Charlie")] = Value.Get(55);
            inputMap[Value.Get("Jim")]     = Value.Get(98);
            inputMap[Value.Get("John")]    = Value.Get(76);
            inputMap[Value.Get("Harry")]   = Value.Get(82);

            // Write values to empty map.
            Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            AssertRecordFound(key, record);

            // Increment some user scores.
            record = client.Operate(null, key,
                                    MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)),
                                    MapOperation.Decrement(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(4))
                                    );

            AssertRecordFound(key, record);

            // Get scores.
            record = client.Operate(null, key,
                                    MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY),
                                    MapOperation.GetByRankRange(binName, 0, 2, MapReturnType.KEY_VALUE),
                                    MapOperation.GetByRank(binName, 0, MapReturnType.VALUE),
                                    MapOperation.GetByRank(binName, 2, MapReturnType.KEY),
                                    MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.RANK),
                                    MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.COUNT),
                                    MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.KEY_VALUE),
                                    MapOperation.GetByValueRange(binName, Value.Get(81), Value.Get(82), MapReturnType.KEY),
                                    MapOperation.GetByValue(binName, Value.Get(77), MapReturnType.KEY),
                                    MapOperation.GetByValue(binName, Value.Get(81), MapReturnType.RANK),
                                    MapOperation.GetByKey(binName, Value.Get("Charlie"), MapReturnType.RANK),
                                    MapOperation.GetByKey(binName, Value.Get("Charlie"), MapReturnType.REVERSE_RANK)
                                    );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            IList  list = (IList)results[i++];
            string str;
            long   val;

            str = (string)list[0];
            Assert.AreEqual("Harry", str);
            str = (string)list[1];
            Assert.AreEqual("Jim", str);

            list = (IList)results[i++];
            KeyValuePair <object, object> entry = (KeyValuePair <object, object>)list[0];

            Assert.AreEqual("Charlie", entry.Key);
            Assert.AreEqual(55L, entry.Value);
            entry = (KeyValuePair <object, object>)list[1];
            Assert.AreEqual("John", entry.Key);
            Assert.AreEqual(81L, entry.Value);

            val = (long)results[i++];
            Assert.AreEqual(55, val);

            str = (string)results[i++];
            Assert.AreEqual("Harry", str);

            list = (IList)results[i++];
            val  = (long)list[0];
            Assert.AreEqual(3, val);

            val = (long)results[i++];
            Assert.AreEqual(1, val);

            list  = (IList)results[i++];
            entry = (KeyValuePair <object, object>)list[0];
            Assert.AreEqual("Jim", entry.Key);
            Assert.AreEqual(94L, entry.Value);

            list = (IList)results[i++];
            str  = (string)list[0];
            Assert.AreEqual("John", str);

            list = (IList)results[i++];
            Assert.AreEqual(0, list.Count);

            list = (IList)results[i++];
            val  = (long)list[0];
            Assert.AreEqual(1, val);

            val = (long)results[i++];
            Assert.AreEqual(0, val);

            val = (long)results[i++];
            Assert.AreEqual(3, val);
        }
Exemple #15
0
        public void OperateMapRemoveRelative()
        {
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey15");

            client.Delete(null, key);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get(0)] = Value.Get(17);
            inputMap[Value.Get(4)] = Value.Get(2);
            inputMap[Value.Get(5)] = Value.Get(15);
            inputMap[Value.Get(9)] = Value.Get(10);

            // Write values to empty map.
            Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            AssertRecordFound(key, record);

            record = client.Operate(null, key,
                                    MapOperation.RemoveByKeyRelativeIndexRange(binName, Value.Get(5), 0, MapReturnType.VALUE),
                                    MapOperation.RemoveByKeyRelativeIndexRange(binName, Value.Get(5), 1, MapReturnType.VALUE),
                                    MapOperation.RemoveByKeyRelativeIndexRange(binName, Value.Get(5), -1, 1, MapReturnType.VALUE)
                                    );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            IList list = (IList)results[i++];

            Assert.AreEqual(2L, list.Count);
            Assert.AreEqual(15L, list[0]);
            Assert.AreEqual(10L, list[1]);

            list = (IList)results[i++];
            Assert.AreEqual(0L, list.Count);

            list = (IList)results[i++];
            Assert.AreEqual(1L, list.Count);
            Assert.AreEqual(2L, list[0]);

            // Write values to empty map.
            client.Delete(null, key);

            record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            AssertRecordFound(key, record);

            record = client.Operate(null, key,
                                    MapOperation.RemoveByValueRelativeRankRange(binName, Value.Get(11), 1, MapReturnType.VALUE),
                                    MapOperation.RemoveByValueRelativeRankRange(binName, Value.Get(11), -1, 1, MapReturnType.VALUE)
                                    );

            AssertRecordFound(key, record);

            results = record.GetList(binName);
            i       = 0;

            list = (IList)results[i++];
            Assert.AreEqual(1L, list.Count);
            Assert.AreEqual(17L, list[0]);

            list = (IList)results[i++];
            Assert.AreEqual(1L, list.Count);
            Assert.AreEqual(10L, list[0]);
        }
        public void OperateMapRemove()
        {
            // Test remove.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey7");

            client.Delete(null, key);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("Charlie")] = Value.Get(55);
            inputMap[Value.Get("Jim")]     = Value.Get(98);
            inputMap[Value.Get("John")]    = Value.Get(76);
            inputMap[Value.Get("Harry")]   = Value.Get(82);
            inputMap[Value.Get("Sally")]   = Value.Get(79);
            inputMap[Value.Get("Lenny")]   = Value.Get(84);
            inputMap[Value.Get("Abe")]     = Value.Get(88);

            List <Value> removeItems = new List <Value>();

            removeItems.Add(Value.Get("Sally"));
            removeItems.Add(Value.Get("UNKNOWN"));
            removeItems.Add(Value.Get("Lenny"));

            Record record = client.Operate(null, key,
                                           MapOperation.PutItems(MapPolicy.Default, binName, inputMap),
                                           MapOperation.RemoveByKey(binName, Value.Get("NOTFOUND"), MapReturnType.VALUE),
                                           MapOperation.RemoveByKey(binName, Value.Get("Jim"), MapReturnType.VALUE),
                                           MapOperation.RemoveByKeyList(binName, removeItems, MapReturnType.COUNT),
                                           MapOperation.RemoveByValue(binName, Value.Get(55), MapReturnType.KEY),
                                           MapOperation.Size(binName));

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long val = (long)results[i++];

            Assert.AreEqual(7, val);

            object obj = results[i++];

            Assert.IsNull(obj);

            val = (long)results[i++];
            Assert.AreEqual(98, val);

            val = (long)results[i++];
            Assert.AreEqual(2, val);

            IList list = (IList)results[i++];

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("Charlie", (string)list[0]);

            val = (long)results[i++];
            Assert.AreEqual(3, val);
        }
 public Builder(MapOperation mapOp)
 {
     InitMapOp(mapOp);
 }
        public void OperateMapInverted()
        {
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey12");

            client.Delete(null, key);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("Charlie")] = Value.Get(55);
            inputMap[Value.Get("Jim")]     = Value.Get(98);
            inputMap[Value.Get("John")]    = Value.Get(76);
            inputMap[Value.Get("Harry")]   = Value.Get(82);

            // Write values to empty map.
            Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            AssertRecordFound(key, record);

            List <string> keyList = new List <string>();

            keyList.Add("Harry");
            keyList.Add("Jim");

            List <int> valueList = new List <int>();

            valueList.Add(76);
            valueList.Add(55);
            valueList.Add(98);
            valueList.Add(50);

            record = client.Operate(null, key,
                                    MapOperation.GetByValue(binName, Value.Get(81), MapReturnType.RANK | MapReturnType.INVERTED),
                                    MapOperation.GetByValue(binName, Value.Get(82), MapReturnType.RANK | MapReturnType.INVERTED),
                                    MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.RANK | MapReturnType.INVERTED),
                                    MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(100), MapReturnType.RANK | MapReturnType.INVERTED),
                                    MapOperation.GetByValueList(binName, valueList, MapReturnType.KEY_VALUE | MapReturnType.INVERTED),
                                    MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY | MapReturnType.INVERTED),
                                    MapOperation.GetByRankRange(binName, 0, 3, MapReturnType.KEY_VALUE | MapReturnType.INVERTED)
                                    );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            IList list = (IList)results[i++];

            Assert.AreEqual(4, list.Count);

            list = (IList)results[i++];
            Assert.AreEqual(3, list.Count);

            list = (IList)results[i++];
            Assert.AreEqual(4, list.Count);

            list = (IList)results[i++];
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(0L, list[0]);
            Assert.AreEqual(1L, list[1]);
            Assert.AreEqual(2L, list[2]);

            list = (IList)results[i++];
            Assert.AreEqual(1, list.Count);
            KeyValuePair <object, object> entry = (KeyValuePair <object, object>)list[0];

            Assert.AreEqual("Harry", entry.Key);
            Assert.AreEqual(82L, entry.Value);

            list = (IList)results[i++];
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("Charlie", list[0]);
            Assert.AreEqual("John", list[1]);

            list = (IList)results[i++];
            Assert.AreEqual(1, list.Count);
            entry = (KeyValuePair <object, object>)list[0];
            Assert.AreEqual("Jim", entry.Key);
            Assert.AreEqual(98L, entry.Value);
        }
 public Builder(MapOperation mapOp, Builder source)
     : base(source)
 {
     InitMapOp(mapOp);
 }
Exemple #20
0
        /// <summary>
        /// 進行方向に対する操作をおこないます。
        /// </summary>
        /// <param name="direction">現在の進行方向を指定します。</param>
        /// <param name="operation">進行方向に対する操作を指定します。</param>
        /// <returns>操作後の進行方向を返します。</returns>
        public Direction OperateDirection(Direction direction, MapOperation operation)
        {
            switch (operation)
            {
            case MapOperation.TurnLeft:
                if (direction == Direction.Left)
                {
                    return(Direction.Down);
                }
                else if (direction == Direction.Up)
                {
                    return(Direction.Left);
                }
                else if (direction == Direction.Right)
                {
                    return(Direction.Up);
                }
                else
                {
                    return(Direction.Right);
                }

            case MapOperation.TurnRight:
                if (direction == Direction.Left)
                {
                    return(Direction.Up);
                }
                else if (direction == Direction.Up)
                {
                    return(Direction.Right);
                }
                else if (direction == Direction.Right)
                {
                    return(Direction.Down);
                }
                else
                {
                    return(Direction.Left);
                }

            case MapOperation.TurnAround:
                if (direction == Direction.Left)
                {
                    return(Direction.Right);
                }
                else if (direction == Direction.Up)
                {
                    return(Direction.Down);
                }
                else if (direction == Direction.Right)
                {
                    return(Direction.Left);
                }
                else
                {
                    return(Direction.Up);
                }
            }

            return(direction);
        }
Exemple #21
0
 /// <summary>
 /// 使地图面板进入正常鼠标模式
 /// </summary>
 public void SelectElementMode()
 {
     operationType    = MapOperation.SelectElement;
     picBoxMap.Cursor = Cursors.Hand;
 }