public void OperateMapPut()
        {
            if (!args.ValidateMap())
            {
                return;
            }

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

            client.Delete(null, key);

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

            // Calling put() multiple times performs poorly because the server makes
            // a copy of the map for each call, but we still need to test it.
            // putItems() should be used instead for best performance.
            Record record = client.Operate(null, key,
                                           MapOperation.Put(putMode, binName, Value.Get(11), Value.Get(789)),
                                           MapOperation.Put(putMode, binName, Value.Get(10), Value.Get(999)),
                                           MapOperation.Put(addMode, binName, Value.Get(12), Value.Get(500)),
                                           MapOperation.Put(addMode, binName, Value.Get(15), Value.Get(1000)),
                                           // Ordered type should be ignored since map has already been created in first put().
                                           MapOperation.Put(orderedUpdateMode, binName, Value.Get(10), Value.Get(1)),
                                           MapOperation.Put(updateMode, binName, Value.Get(15), Value.Get(5))
                                           );

            AssertRecordFound(key, record);

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

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

            Assert.AreEqual(1, size);

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

            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);

            record = client.Get(null, key, binName);

            IDictionary map = record.GetMap(binName);

            Assert.AreEqual(4, map.Count);
            Assert.AreEqual(1L, map[10L]);
        }
        public void OperateMapCreateContext()
        {
            Key key = new Key(args.ns, args.set, "opmkey20");

            client.Delete(null, key);

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

            m1[Value.Get("key11")] = Value.Get(9);
            m1[Value.Get("key12")] = Value.Get(4);

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

            m2[Value.Get("key21")] = Value.Get(3);
            m2[Value.Get("key22")] = Value.Get(5);

            IDictionary <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.Create(binName, MapOrder.KEY_ORDERED, CTX.MapKey(Value.Get("key3"))),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("key31"), Value.Get(99), CTX.MapKey(Value.Get("key3"))),
                                           //MapOperation.Put(MapPolicy.Default, binName, Value.Get("key31"), Value.Get(99), CTX.MapKeyCreate(Value.Get("key3"), MapOrder.KEY_ORDERED)),
                                           Operation.Get(binName)
                                           );

            AssertRecordFound(key, record);
            //Console.WriteLine("Record: " + record);

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

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

            Assert.AreEqual(1, count);

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

            Assert.AreEqual(3, map.Count);

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

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

            Assert.AreEqual(99, v);
        }
        public void OperateNestedMap()
        {
            Key key = new Key(args.ns, args.set, "opmkey19");

            client.Delete(null, key);

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

            m1[Value.Get("key11")] = Value.Get(9);
            m1[Value.Get("key12")] = Value.Get(4);

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

            m2[Value.Get("key21")] = Value.Get(3);
            m2[Value.Get("key22")] = Value.Get(5);

            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("key21"), Value.Get(11), CTX.MapKey(Value.Get("key2"))),
                                           Operation.Get(binName)
                                           );

            AssertRecordFound(key, record);

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

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

            Assert.AreEqual(2, count);

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

            Assert.AreEqual(2, map.Count);

            map = (IDictionary)map["key2"];
            long v = (long)map["key21"];

            Assert.AreEqual(11, v);
            v = (long)map["key22"];
            Assert.AreEqual(5, v);
        }
        public void RunNestedMapCreateExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey2");
            string binName = args.GetBinName("mapbin");

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

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

            m1[Value.Get("key21")] = Value.Get(7);
            m1[Value.Get("key22")] = Value.Get(6);

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

            m2[Value.Get("a")] = Value.Get(3);
            m2[Value.Get("c")] = Value.Get(5);

            IDictionary <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(args.writePolicy, key, new Bin(binName, inputMap));

            // Create key ordered map at "key2" only if map does not exist.
            // Set map value to 4 for map key "key21" inside of map key "key2".
            CTX    ctx    = CTX.MapKey(Value.Get("key2"));
            Record record = client.Operate(args.writePolicy, key,
                                           MapOperation.Create(binName, MapOrder.KEY_VALUE_ORDERED, ctx),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("b"), Value.Get(4), ctx),
                                           Operation.Get(binName)
                                           );

            record = client.Get(args.policy, key);
            console.Info("Record: " + record);
        }
        /// <summary>
        /// Operate on a map of maps.
        /// </summary>
        private void RunNestedExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey2");
            string binName = args.GetBinName("mapbin");

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

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

            m1[Value.Get("key11")] = Value.Get(9);
            m1[Value.Get("key12")] = Value.Get(4);

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

            m2[Value.Get("key21")] = Value.Get(3);
            m2[Value.Get("key22")] = Value.Get(5);

            IDictionary <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(args.writePolicy, 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(args.writePolicy, key,
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("key21"), Value.Get(11), CTX.MapKey(Value.Get("key2"))),
                                           Operation.Get(binName)
                                           );

            record = client.Get(args.policy, key);
            console.Info("Record: " + record);
        }
        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);
        }