public static BerkeleyDbFlags Flags(String flags)
        {
            BerkeleyDbFlags value = 0;

            foreach (String flag in flags.Split(','))
            {
                value |= (BerkeleyDbFlags)Enum.Parse(typeof(BerkeleyDbFlags), flags, true);
            }
            return(value);
        }
        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));
        }
        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);
        }
Example #4
0
        public static String ToStringEx(this BerkeleyDbFlags flag)
        {
            switch (flag)
            {
            case 0:
                return("0");

            case BerkeleyDbFlags.DB_CHKSUM:
                return("db_chksum");

            case BerkeleyDbFlags.DB_DUP:
                return("db_dup");

            case BerkeleyDbFlags.DB_DUPSORT:
                return("db_dupsort");

            case BerkeleyDbFlags.DB_ENCRYPT:
                return("db_encrypt");

            case BerkeleyDbFlags.DB_INORDER:
                return("db_inorder");

            case BerkeleyDbFlags.DB_TXN_NOT_DURABLE:
                return("db_txn_not_durable");

            case BerkeleyDbFlags.DB_RECNUM:
                return("db_recnum");

            case BerkeleyDbFlags.DB_RENUMBER:
                return("db_renumber");

            case BerkeleyDbFlags.DB_REVSPLITOFF:
                return("db_revsplitoff");

            case BerkeleyDbFlags.DB_SNAPSHOT:
                return("db_snapshot");

            default:
                throw new ArgumentOutOfRangeException(flag.ToString());
            }
        }
Example #5
0
        public BerkeleyDtoResult Create([FromUri] BerkeleyDbType type, [FromUri] String flags)
        {
            ulong           handle   = 0;
            BerkeleyDbFlags bdbFlags = BerkeleyEnumParser.Flags(flags);

            IntPtr          pdb;
            IntPtr          penv  = DbenvInstance.Instance.Handle;
            BerkeleyDbError error = BDbMethods.Create(BDbOffsetOfInstance.Instance, penv, type, bdbFlags, out pdb);

            if (error == 0)
            {
                BDbMethods dbMethods = BDbMethods.GetMethods(type);
                var        db        = new DbHandle(pdb, dbMethods);
                handle = DbInstance.AddDb(db);
                if (handle == 0)
                {
                    dbMethods.Close(pdb, 0);
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }

            return(new BerkeleyDtoResult(error, handle.ToString()));
        }
Example #6
0
 public BerkeleyDbError SetFlags(IntPtr pdb, BerkeleyDbFlags flags)
 {
     return (BerkeleyDbError)_set_flags(pdb, (uint)flags);
 }
Example #7
0
        public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr penv, BerkeleyDbType dbType, BerkeleyDbFlags flags, out IntPtr pdb)
        {
            var error = (BerkeleyDbError)db_create(out pdb, penv, 0);
            if (error != 0)
                return error;

            BDbMethods methods = CreateMethods(dbType, pdb, offsetOf);
            error = (BerkeleyDbError)methods.SetFlags(pdb, flags);
            if (error != 0 && pdb != IntPtr.Zero)
            {
                methods.Close(pdb, 0);
                pdb = IntPtr.Zero;
            }
            return 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;
        }
Example #9
0
 public BerkeleyDb(BerkeleyDbMethodsAsync methods, BerkeleyDbType dbType, BerkeleyDbFlags flags)
 {
     _methods = methods;
     _dbType = dbType;
     _flags = flags;
 }
 public abstract Task <BerkeleyResult <long> > CreateDb(BerkeleyDb berkeleyDb, BerkeleyDbFlags flags);
 public abstract Task<BerkeleyResult<long>> CreateDb(BerkeleyDb berkeleyDb, BerkeleyDbFlags flags);
Example #12
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)));
        }
Example #13
0
 public BerkeleyDb(BerkeleyDbMethodsAsync methods, BerkeleyDbType dbType, BerkeleyDbFlags flags)
 {
     _methods = methods;
     _dbType  = dbType;
     _flags   = flags;
 }
Example #14
0
 public BerkeleyDbError SetFlags(IntPtr pdb, BerkeleyDbFlags flags)
 {
     return((BerkeleyDbError)_set_flags(pdb, (uint)flags));
 }
Example #15
0
        public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr penv, BerkeleyDbType dbType, BerkeleyDbFlags flags, out IntPtr pdb)
        {
            var error = (BerkeleyDbError)db_create(out pdb, penv, 0);

            if (error != 0)
            {
                return(error);
            }

            BDbMethods methods = CreateMethods(dbType, pdb, offsetOf);

            error = (BerkeleyDbError)methods.SetFlags(pdb, flags);
            if (error != 0 && pdb != IntPtr.Zero)
            {
                methods.Close(pdb, 0);
                pdb = IntPtr.Zero;
            }
            return(error);
        }