示例#1
0
        public override async Task <BerkeleyError> WriteMultipleAsync(BerkeleyDb db, BerkeleyDtoPut data, BerkeleyDbWriteMode writeMode)
        {
            String        requestUri;
            ObjectContent content;

            if (data.Key == null)
            {
                requestUri = "api/database/writemultiplekey/?handle=" + db.Handle.ToString() + "&writemode=" + writeMode.ToStringEx();
                content    = new ObjectContent <Byte[]>(data.Value, _formatter, (String)null);
            }
            else
            {
                requestUri = "api/database/write/?handle=" + db.Handle.ToString() + "&writemode=" + writeMode.ToStringEx();
                content    = new ObjectContent <BerkeleyDtoPut>(data, _formatter, (String)null);
            }

            HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyError(response.StatusCode));
            }

            BerkeleyDbError error = await SerializeHelper.GetErrorAsync(_serializer, response.Content).ConfigureAwait(false);

            return(new BerkeleyError(error));
        }
        private static int GetPageSize(BerkeleyDb bdb)
        {
            BerkeleyResult <int> pageSizeResult = bdb.GetPageSizeAsync().Result;

            pageSizeResult.Error.ThrowIfError();
            return(pageSizeResult.Result);
        }
示例#3
0
        public override async Task <BerkeleyError> WriteDuplicateAsync(BerkeleyDb db, BerkeleyDtoPut data, int bufferSize, BerkeleyDbWriteMode writeMode)
        {
            String         requestUri;
            BerkeleyDtoPut dataPost;

            if (data.Key.Length <= bufferSize && data.Value.Length <= bufferSize)
            {
                requestUri = "api/database/writemultipleduplicate/?handle=" + db.Handle.ToString() + "&writemode=" + writeMode.ToStringEx();
                dataPost   = new BerkeleyDtoPut(data.Key, data.Value);
            }
            else
            {
                requestUri = "api/database/write/?handle=" + db.Handle.ToString() + "&writemode=" + writeMode.ToStringEx();
                dataPost   = data;
            }

            ObjectContent       content  = new ObjectContent <BerkeleyDtoPut>(dataPost, _formatter, (String)null);
            HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyError(response.StatusCode));
            }

            BerkeleyDbError error = await SerializeHelper.GetErrorAsync(_serializer, response.Content).ConfigureAwait(false);

            return(new BerkeleyError(error));
        }
示例#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());
     }
 }
示例#5
0
        public override async Task <BerkeleyError> CloseDbAsync(BerkeleyDb db, BerkeleyDbClose flags)
        {
            String requestUri            = "api/database/close/?handle=" + db.Handle.ToString() + "&flags=" + flags.ToStringEx();
            HttpResponseMessage response = await _httpClient.GetAsync(requestUri).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyError(response.StatusCode));
            }

            BerkeleyDbError error = await SerializeHelper.GetErrorAsync(_serializer, response.Content).ConfigureAwait(false);

            return(new BerkeleyError(error));
        }
示例#6
0
        public override async Task <BerkeleyError> DeleteAsync(BerkeleyDb db, Byte[] key, BerkeleyDbDelete flag, BerkeleyDbMultiple multiple)
        {
            String requestUri            = "api/database/delete/?handle=" + db.Handle.ToString() + "&flag=" + flag.ToStringEx() + "&multiple=" + multiple.ToStringEx();
            var    content               = new ObjectContent <Byte[]>(key, _formatter, (String)null);
            HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyError(response.StatusCode));
            }

            BerkeleyDbError error = await SerializeHelper.GetErrorAsync(_serializer, response.Content).ConfigureAwait(false);

            return(new BerkeleyError(error));
        }
        private static BerkeleyDb CreateDb(BerkeleyDbFlags flags)
        {
            var client = new HttpClient();

            client.BaseAddress = serviceRootUri;
            var methods = new BerkeleyDbWebApiMethods(client, new Newtonsoft.Json.JsonSerializer(), new System.Net.Http.Formatting.JsonMediaTypeFormatter());
            var bdb     = new BerkeleyDb(methods, BerkeleyDbType.DB_BTREE, flags);

            String fileName = Path.Combine(Path.GetTempPath(), "test.bdb");

            File.Delete(fileName);
            BerkeleyError error = bdb.OpenAsync(fileName, BerkeleyDbOpenFlags.DB_CREATE).Result;

            error.ThrowIfError();

            return(bdb);
        }
示例#8
0
        public override async Task <BerkeleyResult <long> > CreateDb(BerkeleyDb berkeleyDb, BerkeleyDbFlags flags)
        {
            String requestUri            = "api/database/create/?type=" + berkeleyDb.DbType.ToStringEx() + "&flags=" + flags.ToStringEx();
            HttpResponseMessage response = await _httpClient.GetAsync(requestUri).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyResult <long>(response.StatusCode));
            }

            BerkeleyDtoResult dtoHandle = await SerializeHelper.GetResultAsync(_serializer, response.Content).ConfigureAwait(false);

            if (dtoHandle.Error != 0)
            {
                return(new BerkeleyResult <long>(dtoHandle.Error));
            }

            return(new BerkeleyResult <long>(0, Int64.Parse(dtoHandle.Result)));
        }
示例#9
0
        public override async Task <BerkeleyResult <long> > OpenCursorAsync(BerkeleyDb db, BerkeleyDbCursorFlags flags)
        {
            String requestUri            = "api/database/opencursor/?handle=" + db.Handle.ToString() + "&flags=" + flags.ToStringEx();
            HttpResponseMessage response = await _httpClient.GetAsync(requestUri).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyResult <long>(response.StatusCode));
            }

            BerkeleyDtoResult result = await SerializeHelper.GetResultAsync(_serializer, response.Content).ConfigureAwait(false);

            if (result.Error != 0)
            {
                return(new BerkeleyResult <long>(result.Error));
            }

            return(new BerkeleyResult <long>(0, Int64.Parse(result.Result)));
        }
示例#10
0
        public override async Task <BerkeleyResult <int> > GetPageSizeAsync(BerkeleyDb db)
        {
            String requestUri            = "api/database/pagesize/?handle=" + db.Handle.ToString();
            HttpResponseMessage response = await _httpClient.GetAsync(requestUri).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new BerkeleyResult <int>(response.StatusCode));
            }

            BerkeleyDtoResult dtoResult = await SerializeHelper.GetResultAsync(_serializer, response.Content).ConfigureAwait(false);

            if (dtoResult.Error != 0)
            {
                return(new BerkeleyResult <int>(dtoResult.Error));
            }

            int pageSize = Int32.Parse(dtoResult.Result);

            return(new BerkeleyResult <int>(pageSize));
        }
示例#11
0
        static void Main(string[] args)
        {
            var serviceRootUri = new Uri("http://*****:*****@"D:\гуманитарий с дипломом менеджера.jpg");
                    //ReadFoto(bdb);
                }
            }
        }
示例#12
0
 private static void WriteFoto(BerkeleyDb bdb, String fileName)
 {
     Byte[] key   = System.Text.Encoding.UTF8.GetBytes(("simple key/value").ToString());
     Byte[] value = File.ReadAllBytes(fileName);
     var    err   = bdb.WriteAsync(key, value, 0).Result;
 }
 public void PrintStats(BerkeleyDb.StatPrintFlags flags) {
   DbRetVal ret;
   lock (rscLock) {
     DB_SEQUENCE* seqp = CheckDisposed();
     ret = seqp->StatPrint(seqp, unchecked((UInt32)flags));
   }
   Util.CheckRetVal(ret);
 }
示例#14
0
 public void PrintTxnStats(BerkeleyDb.StatPrintFlags flags) {
   DbRetVal ret;
   lock (rscLock) {
     DB_ENV* evp = CheckDisposed();
     ret = evp->TxnStatPrint(evp, unchecked((UInt32)flags));
   }
   Util.CheckRetVal(ret);
 }
示例#15
0
 public void MutexStatPrint(BerkeleyDb.StatPrintFlags flags) {
   DbRetVal ret;
   lock (rscLock) {
     DB_ENV* evp = CheckDisposed();
     ret = evp->MutexStatPrint(evp, unchecked((uint)flags));
   }
   Util.CheckRetVal(ret);
 }