예제 #1
0
 private static void ReadAll(BerkeleyKeyValueCursor cursor)
 {
     for (BerkeleyResult<BerkeleyKeyValue> result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_FIRST).Result;
         result.Error.BerkeleyDbError != BerkeleyDbError.DB_NOTFOUND;
         result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_NEXT).Result)
     {
         result.Error.ThrowIfError();
         WriteLine(result.Result.Key, result.Result.Value);
     }
 }
예제 #2
0
        private static bool Check(BerkeleyKeyValueCursor cursor, List<int> keys)
        {
            var readKeys = new List<int>();
            for (BerkeleyResult<BerkeleyKeyValue> result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_FIRST).Result;
                result.Error.BerkeleyDbError != BerkeleyDbError.DB_NOTFOUND;
                result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_NEXT).Result)
            {
                result.Error.ThrowIfError();

                String skey = Encoding.UTF8.GetString(result.Result.Key);
                int ikey = int.Parse(skey.Replace("key", ""));

                String svalue = Encoding.UTF8.GetString(result.Result.Value);
                int ivalue = int.Parse(svalue.Replace("value", ""));

                if (ikey != ivalue)
                    throw new InvalidOperationException();

                readKeys.Add(ikey);
            }

            return keys.SequenceEqual(readKeys);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var serviceRootUri = new Uri("http://*****:*****@"D:\гуманитарий с дипломом менеджера.jpg");
                    //ReadFoto(bdb);
                }
            }
        }
예제 #4
0
 private static void ReadFoto(BerkeleyDb bdb)
 {
     Byte[] key = System.Text.Encoding.UTF8.GetBytes("simple key/value");
     using (var reader = new BerkeleyKeyValueCursor(bdb))
     {
         var result = reader.ReadAsync(key, BerkeleyDbOperation.DB_SET).Result;
         File.WriteAllBytes(@"D:\zzz.jpg", result.Result.Value.ToArray());
     }
 }
        public void KeyValueTest()
        {
            using (var bdb = CreateDb())
            {
                var keys = new List<int>();
                for (int i = 0; i < 6; i++)
                {
                    keys.Add(i);
                    var key = Encoding.UTF8.GetBytes("key" + i.ToString());
                    var value = Encoding.UTF8.GetBytes("value" + i.ToString());
                    BerkeleyError error = bdb.WriteAsync(key, value, 0).Result;
                    error.ThrowIfError();
                }

                using (var cursor = new BerkeleyKeyValueCursor(bdb))
                {
                    KeyValueCheck(cursor, keys);

                    BerkeleyError error = cursor.DeleteCurrentAsync().Result;
                    error.ThrowIfError();

                    keys.Remove(keys.Last());
                    KeyValueCheck(cursor, keys);

                    var key = Encoding.UTF8.GetBytes("key3");
                    error = cursor.DeleteAsync(key, 0).Result;
                    error.ThrowIfError();

                    keys.Remove(3);
                    KeyValueCheck(cursor, keys);
                }
            }
        }
        private static void KeyValueCheck(BerkeleyKeyValueCursor cursor, List<int> keys)
        {
            var readKeys = new List<int>();
            for (BerkeleyResult<BerkeleyKeyValue> result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_FIRST).Result;
                result.Error.BerkeleyDbError != BerkeleyDbError.DB_NOTFOUND;
                result = cursor.ReadAsync(null, BerkeleyDbOperation.DB_NEXT).Result)
            {
                result.Error.ThrowIfError();

                String skey = Encoding.UTF8.GetString(result.Result.Key);
                int ikey = int.Parse(skey.Replace("key", ""));

                String svalue = Encoding.UTF8.GetString(result.Result.Value);
                int ivalue = int.Parse(svalue.Replace("value", ""));

                Assert.IsTrue(ikey == ivalue, "read error");

                readKeys.Add(ikey);
            }

            Assert.IsTrue(keys.SequenceEqual(readKeys), "delete error");
        }