Пример #1
0
        /// <summary>
        /// Gets the data for a row ID.
        /// </summary>
        /// <param name="keyCode"></param>
        /// <param name="rowData"></param>
        /// <returns></returns>
        public int GetRowN(int keyCode, out Span <byte> rowData)
        {
            rowData = default;

            int dataLength = DBT.RowDataLength;
            int entryIndex = DBT.GetIndexOfID(keyCode);

            //if (uVar1 < *(uint *)(file + 8)) {
            if (entryIndex < DBT.EntryCount)
            {
                // ORIGINAL: iVar2 = (int)this->UnkOffset4 + *(int *)(file + uVar1 * 8 + 0x14);
                SpanReader sr = new SpanReader(DBT.Buffer, DBT.Endian);

                // Short version
                sr.Position = DBT.HeaderSize + (8 * entryIndex) + 4;
                int entryOffset = sr.ReadInt32();
                sr.Position = DBT.UnkOffset4 + entryOffset;

                if ((DBT.VersionHigh & 1) == 0)
                {
                    rowData = sr.ReadBytes(dataLength); // memcpy(retSdbIndex,offs,dataLength);
                }
                else
                {
                    rowData = DBT.ExtractRow(ref sr);
                }
            }

            return(dataLength);
        }
Пример #2
0
        /*
         * Copy between the C# byte array and the C library's void * as needed.
         * The library will call this method when it needs data from us or has
         * data to give us.  This prevents us from needing to copy all data in
         * and all data out.  The callback to this method gets set when the
         * DatabaseEnvironment is created (or the Database if created w/o an
         * environment.)
         */
        internal static int dbt_usercopy(IntPtr dbtp, uint offset, IntPtr buf, uint size, uint flags)
        {
            DBT           dbt = new DBT(dbtp, false);
            DatabaseEntry ent = dbt.app_data;

            if (flags == DbConstants.DB_USERCOPY_GETDATA)
            {
                Marshal.Copy(ent.Data, 0, buf, (int)size);
            }
            else
            {
                /*
                 * If the offset is zero, we're writing a new buffer and can
                 * simply allocate byte array.  If the offset is not zero,
                 * however, we are appending to the exisiting array.  Since we
                 * can't extend it, we have to allocate a new one and copy.
                 *
                 * Our caller is setting dbt.size, so set ent._data directly,
                 * since ent.Data would overwrite dbt.size.
                 */
                if (offset != 0)
                {
                    byte[] t = new byte[ent.Data.Length + (int)size];
                    ent.Data.CopyTo(t, 0);
                    ent._data = t;
                }
                else
                {
                    ent._data = new byte[(int)size];
                }

                Marshal.Copy(buf, ent.Data, (int)offset, (int)size);
            }
            return(0);
        }
Пример #3
0
        private static int doCompress(IntPtr dbp, IntPtr prevKeyp,
                                      IntPtr prevDatap, IntPtr keyp, IntPtr datap, IntPtr destp)
        {
            DB            db      = new DB(dbp, false);
            DatabaseEntry prevKey =
                DatabaseEntry.fromDBT(new DBT(prevKeyp, false));
            DatabaseEntry prevData =
                DatabaseEntry.fromDBT(new DBT(prevDatap, false));
            DatabaseEntry key  = DatabaseEntry.fromDBT(new DBT(keyp, false));
            DatabaseEntry data = DatabaseEntry.fromDBT(new DBT(datap, false));
            DBT           dest = new DBT(destp, false);
            BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);

            byte[] arr = new byte[(int)dest.ulen];
            int    len;

            try {
                if (btdb.Compress(prevKey, prevData, key, data, ref arr, out len))
                {
                    Marshal.Copy(arr, 0, dest.dataPtr, len);
                    dest.size = (uint)len;
                    return(0);
                }
                else
                {
                    return(DbConstants.DB_BUFFER_SMALL);
                }
            } catch (Exception) {
                return(-1);
            }
        }
Пример #4
0
        private static int doDecompress(IntPtr dbp, IntPtr prevKeyp,
                                        IntPtr prevDatap, IntPtr cmpp, IntPtr destKeyp, IntPtr destDatap)
        {
            DB            db      = new DB(dbp, false);
            DatabaseEntry prevKey =
                DatabaseEntry.fromDBT(new DBT(prevKeyp, false));
            DatabaseEntry prevData =
                DatabaseEntry.fromDBT(new DBT(prevDatap, false));
            DBT           compressed = new DBT(cmpp, false);
            DBT           destKey    = new DBT(destKeyp, false);
            DBT           destData   = new DBT(destDatap, false);
            BTreeDatabase btdb       = (BTreeDatabase)(db.api_internal);
            uint          size;

            try {
                KeyValuePair <DatabaseEntry, DatabaseEntry> kvp = btdb.Decompress(prevKey, prevData, compressed.data, out size);
                int keylen  = kvp.Key.Data.Length;
                int datalen = kvp.Value.Data.Length;
                destKey.size  = (uint)keylen;
                destData.size = (uint)datalen;
                if (keylen > destKey.ulen ||
                    datalen > destData.ulen)
                {
                    return(DbConstants.DB_BUFFER_SMALL);
                }
                Marshal.Copy(kvp.Key.Data, 0, destKey.dataPtr, keylen);
                Marshal.Copy(kvp.Value.Data, 0, destData.dataPtr, datalen);
                compressed.size = size;
                return(0);
            } catch (Exception) {
                return(-1);
            }
        }
Пример #5
0
        private static void doAppend(IntPtr dbp, IntPtr dbtp1, uint recno)
        {
            DB            db   = new DB(dbp, false);
            DBT           dbt1 = new DBT(dbtp1, false);
            RecnoDatabase rdb  = (RecnoDatabase)(db.api_internal);

            rdb.AppendCallback(DatabaseEntry.fromDBT(dbt1), recno);
        }
Пример #6
0
 /// <summary>
 /// Create a new, empty DatabaseEntry object.
 /// </summary>
 public DatabaseEntry()
 {
     dbt = new DBT();
     if (!this.GetType().IsGenericType)
     {
         dbt.app_data = this;
     }
 }
        private static int doCompare(IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2)
        {
            DB  db   = new DB(dbp, false);
            DBT dbt1 = new DBT(dbtp1, false);
            DBT dbt2 = new DBT(dbtp2, false);

            return(((HashDatabase)(db.api_internal)).compareHandler(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
Пример #8
0
        private static int doCompare(IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2)
        {
            DB            db   = new DB(dbp, false);
            DBT           dbt1 = new DBT(dbtp1, false);
            DBT           dbt2 = new DBT(dbtp2, false);
            BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);

            return(btdb.Compare(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
        private static int doDupCompare(
            IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p)
        {
            DB  db   = new DB(dbp, false);
            DBT dbt1 = new DBT(dbt1p, false);
            DBT dbt2 = new DBT(dbt2p, false);

            return(((HashDatabase)(db.api_internal)).DupCompare(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
Пример #10
0
 internal static DatabaseEntry fromDBT(DBT dbt)
 {
     if (dbt.app_data != null)
     {
         return(dbt.app_data);
     }
     else
     {
         return(new DatabaseEntry(dbt));
     }
 }
Пример #11
0
        /// <summary>
        /// Send a message on the message channel. The message is sent
        /// asynchronously. The method does not wait for a response before
        /// returning. It usually completes quickly because it only waits for
        /// local TCP implementation to accept the bytes into its network data
        /// buffer. However, this message could block briefly for longer
        /// messages, and/or if the network data buffer is nearly full.
        /// It could even block indefinitely if the remote site is slow
        /// to read.
        /// </summary>
        /// <remarks>
        /// <para>
        /// To block while waiting for a response from a remote site, use
        /// <see cref="SendRequest"/> instead of this method.
        /// </para>
        /// <para>
        /// The sent message is received and handled at remote sites using a
        /// message dispatch callback, which is configured using
        /// <see cref="DatabaseEnvironment.RepMessageDispatch"/>. This
        /// method may be used within the message dispatch callback on the
        /// remote site to send a reply or acknowledgement for messages that it
        /// receives and is handling.
        /// </para>
        /// <para>
        /// This method may be used on channels opened to any destination. See
        /// <see cref="DatabaseEnvironment.RepMgrChannel"/> for a list of
        /// potential destinations.
        /// </para>
        /// </remarks>
        /// <param name="msg">
        /// An array of DatabaseEntry objects. Any flags for the DatabaseEntry
        /// objects are ignored.
        /// </param>
        public void SendMessage(DatabaseEntry[] msg)
        {
            int size = msg.Length;

            IntPtr[] dbts = new IntPtr[size];
            for (int i = 0; i < size; i++)
            {
                dbts[i] = DBT.getCPtr(DatabaseEntry.getDBT(msg[i])).Handle;
            }
            channel.send_msg(dbts, (uint)size, 0);
        }
Пример #12
0
        private static int doCompare(IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2)
        {
            DB  db   = new DB(dbp, false);
            DBT dbt1 = new DBT(dbtp1, false);
            DBT dbt2 = new DBT(dbtp2, false);
            SecondaryBTreeDatabase tmp =
                (SecondaryBTreeDatabase)db.api_internal;

            return(tmp.compareHandler(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
        private static int doDupCompare(
            IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p)
        {
            DB  db   = new DB(dbp, false);
            DBT dbt1 = new DBT(dbt1p, false);
            DBT dbt2 = new DBT(dbt2p, false);

            SecondaryHashDatabase tmp = (SecondaryHashDatabase)db.api_internal;

            return(tmp.DupCompare(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
Пример #14
0
        private static int doDupCompare(
            IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p, IntPtr locp)
        {
            DB  db   = new DB(dbp, false);
            DBT dbt1 = new DBT(dbt1p, false);
            DBT dbt2 = new DBT(dbt2p, false);

            if (locp != IntPtr.Zero)
            {
                locp = IntPtr.Zero;
            }

            return(((SecondaryBTreeDatabase)(db.api_internal)).DupCompare(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
Пример #15
0
        /// <summary>
        /// Send a message on the message channel. The message is sent
        /// synchronously. The method blocks waiting for a response before
        /// returning. If a response is not received within the timeout value
        /// configured for this request, this method returns with an error
        /// condition.
        /// </summary>
        /// <remarks>
        /// <para>
        /// To avoid block while waiting for a response from a remote site,
        /// use <see cref="SendMessage"/>
        /// </para>
        /// <para>
        /// The message sent by this method is received and handled at remote
        /// sites using a message dispatch callback, which is configured using
        /// <see cref="DatabaseEnvironment.RepMessageDispatch"/>
        /// </para>
        /// </remarks>
        /// <param name="request">
        /// DatabaseEntry objects array. Any flags for the DatabaseEntry objects
        /// are ignored.
        /// </param>
        /// <param name="timeout">
        /// The amount of time that may elapse while this method waits for a
        /// response from the remote site. The timeout value must be specified
        /// as an unsigned 32-bit number of microseconds, limiting the maximum
        /// timeout to roughly 71 minutes. A timeout value of 0 indicates that
        /// the channel's default timeout value should be used. This default is
        /// configured using <see cref="Timeout"/>.
        /// </param>
        /// <returns>The response from remote site</returns>
        public DatabaseEntry SendRequest(
            DatabaseEntry[] request, uint timeout)
        {
            int size = request.Length;

            IntPtr[] dbts = new IntPtr[size];
            for (int i = 0; i < size; i++)
            {
                dbts[i] = DBT.getCPtr(DatabaseEntry.getDBT(request[i])).Handle;
            }
            DatabaseEntry response = new DatabaseEntry();

            channel.send_request(dbts, (uint)size, response, timeout, 0);
            return(response);
        }
Пример #16
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == 537)
     {
         DBT dBT = (DBT)(int)m.WParam;
         if (!(m.LParam == IntPtr.Zero))
         {
             Marshal.ReadInt32(m.LParam, 4);
         }
         DBT dBT2 = dBT;
         if (dBT2 == DBT.DBT_DEVNODES_CHANGED || dBT2 == DBT.DBT_DEVICEARRIVAL || dBT2 == DBT.DBT_DEVICEREMOVECOMPLETE)
         {
             RefreshPrint = true;
         }
     }
     base.WndProc(ref m);
 }
Пример #17
0
        private static int doCompare(IntPtr dbp,
                                     IntPtr dbtp1, IntPtr dbtp2, IntPtr locp)
        {
            DB  db   = new DB(dbp, false);
            DBT dbt1 = new DBT(dbtp1, false);
            DBT dbt2 = new DBT(dbtp2, false);

            if (locp != IntPtr.Zero)
            {
                locp = IntPtr.Zero;
            }

            SecondaryHashDatabase tmp = (SecondaryHashDatabase)db.api_internal;

            return(tmp.Compare(
                       DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2)));
        }
Пример #18
0
        private void OnDeviceChanged(DBT dbt, DEV_BROADCAST_VOLUME volume)
        {
            if (volume.dbcv_devicetype != DBT_DEVTP.DBT_DEVTYP_VOLUME)
            {
                return;
            }

            switch (dbt)
            {
            case DBT.DBT_DEVICEARRIVAL:
            case DBT.DBT_DEVICEREMOVECOMPLETE:
                DrivesChanged?.Invoke(this, EventArgs.Empty);
                break;

            default:
                break;
            }
        }
Пример #19
0
        /// <summary>
        /// Send a message on the message channel. The message is sent
        /// synchronously. The method blocks waiting for a response before
        /// returning. If a response is not received within the timeout value
        /// configured for this request, this method returns with an error
        /// condition.
        /// </summary>
        /// <remarks>
        /// <para>
        /// To avoid block while waiting for a response from a remote site,
        /// use <see cref="SendMessage"/>
        /// </para>
        /// <para>
        /// The message sent by this method is received and handled at remote
        /// sites using a message dispatch callback, which is configured using
        /// <see cref="DatabaseEnvironment.RepMessageDispatch"/>
        /// </para>
        /// </remarks>
        /// <param name="request">
        /// DatabaseEntry objects array. Any flags for the DatabaseEntry objects
        /// are ignored.
        /// </param>
        /// <param name="bufferSize">Size of bulk buffer</param>
        /// <param name="timeout">
        /// The amount of time that may elapse while this method waits for a
        /// response from the remote site. The timeout value must be specified
        /// as an unsigned 32-bit number of microseconds, limiting the maximum
        /// timeout to roughly 71 minutes. A timeout value of 0 indicates that
        /// the channel's default timeout value should be used. This default is
        /// configured using <see cref="Timeout"/>.
        /// </param>
        /// <returns>Multiple responses from the remote site.</returns>
        public MultipleDatabaseEntry SendRequest(
            DatabaseEntry[] request, int bufferSize, uint timeout)
        {
            int size = request.Length;

            IntPtr[] dbts = new IntPtr[size];
            for (int i = 0; i < size; i++)
            {
                dbts[i] = DBT.getCPtr(DatabaseEntry.getDBT(request[i])).Handle;
            }
            DatabaseEntry data = new DatabaseEntry();

            data.UserData = new byte[bufferSize];
            channel.send_request(dbts, (uint)size, data, timeout,
                                 DbConstants.DB_MULTIPLE);
            MultipleDatabaseEntry response = new MultipleDatabaseEntry(data);

            return(response);
        }
Пример #20
0
        /// <summary>
        /// Protected method to call the key generation function.
        /// </summary>
        /// <param name="dbp">Secondary DB Handle</param>
        /// <param name="keyp">Primary Key</param>
        /// <param name="datap">Primary Data</param>
        /// <param name="skeyp">Scondary Key</param>
        /// <returns>0 on success, !0 on failure</returns>
        protected static int doAssociate(
            IntPtr dbp, IntPtr keyp, IntPtr datap, IntPtr skeyp)
        {
            DB  db   = new DB(dbp, false);
            DBT key  = new DBT(keyp, false);
            DBT data = new DBT(datap, false);
            DBT skey = new DBT(skeyp, false);

            DatabaseEntry s =
                ((SecondaryDatabase)db.api_internal).KeyGen(
                    DatabaseEntry.fromDBT(key), DatabaseEntry.fromDBT(data));

            if (s == null)
            {
                return(DbConstants.DB_DONOTINDEX);
            }

            skey.data = s.Data;
            return(0);
        }
Пример #21
0
        /// <inheritdoc />
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg != Win32.WM_DEVICECHANGE)
            {
                return;
            }

            DBT wParam = (DBT)(int)m.WParam;

            switch (wParam)
            {
            case DBT.DBT_DEVICEARRIVAL:
                lblMessage.Text      = MSG_DETACH;
                lblMessage.ForeColor = Color.Green;
                break;

            case DBT.DBT_DEVICEREMOVECOMPLETE:
                Close();
                break;
            }
        }
Пример #22
0
        /// <summary>
        /// Protected method to nullify a foreign key
        /// </summary>
        /// <param name="dbp">Secondary DB Handle</param>
        /// <param name="keyp">Primary Key</param>
        /// <param name="datap">Primary Data</param>
        /// <param name="fkeyp">Foreign Key</param>
        /// <param name="changed">Whether the foreign key has changed</param>
        /// <returns>0 on success, !0 on failure</returns>
        protected static int doNullify(IntPtr dbp,
                                       IntPtr keyp, IntPtr datap, IntPtr fkeyp, ref int changed)
        {
            DB  db   = new DB(dbp, false);
            DBT key  = new DBT(keyp, false);
            DBT data = new DBT(datap, false);
            DBT fkey = new DBT(fkeyp, false);

            DatabaseEntry d = ((SecondaryDatabase)db.api_internal).Nullifier(
                DatabaseEntry.fromDBT(key),
                DatabaseEntry.fromDBT(data), DatabaseEntry.fromDBT(fkey));

            if (d == null)
            {
                changed = 0;
            }
            else
            {
                changed   = 1;
                data.data = d.Data;
            }

            return(0);
        }
Пример #23
0
        /// <summary>
        /// 查询数据库
        /// </summary>
        /// <returns></returns>
        private DataSet QueryDS(QueryDataSetModel dsm, DBT dbt = DBT.sqllite)
        {
            DataSet ds = new DataSet();

            string sql = string.Empty;

            switch (dbt)
            {
            case DBT.sqllite:
                sql = "SELECT " + dsm.columns + " FROM " + dsm.tableName + " WHERE " + dsm.whereStr + " ORDER BY " + dsm.orderBy + " LIMIT " + dsm.pageSize + " OFFSET " + dsm.pageSize * (dsm.pageIndex - 1);
                if (dsm.total)
                {
                    sql += "; select count(1) AS counts from " + dsm.tableName + " WHERE " + dsm.whereStr;
                    ds   = DB.HelperSQLite.Query(sql);
                }
                else
                {
                    ds = DB.HelperSQLite.Query(sql);
                }
                break;
            }

            return(ds);
        }
Пример #24
0
 static DbRetVal AppRecoverWrapFast(DB_ENV* evp, ref DBT logrec, DB_LSN* lsnp, DB_RECOPS op) {
   Env env = null;
   try {
     env = (Env)((GCHandle)evp->api_internal).Target;
     CallbackStatus cs = env.appRecoverFast(env, ref logrec, lsnp, (RecoveryOps)op);
     return cs == CallbackStatus.Success ? DbRetVal.SUCCESS : DbRetVal.APP_RECOVER_FAILED;
   }
   catch (Exception ex) {
     Trace.WriteLine(ex.Message, "TxnRecover");
     return DbRetVal.APP_RECOVER_FAILED;
   }
 }
Пример #25
0
 static DbRetVal PageOutWrapCLS(DB_ENV* evp, UInt32 pgno, void* pgaddr, ref DBT pgcookie) {
   Env env = null;
   try {
     env = (Env)((GCHandle)evp->api_internal).Target;
     CallbackStatus cs = PageInOutWrapCLS(env, pgno, pgaddr, ref pgcookie, env.pageOutCLS);
     return cs == CallbackStatus.Success ? DbRetVal.SUCCESS : DbRetVal.PAGE_OUT_FAILED;
   }
   catch (Exception ex) {
     Trace.WriteLine(ex.Message, "PageOut");
     return DbRetVal.PAGE_OUT_FAILED;
   }
 }
Пример #26
0
 static CallbackStatus PageInOutWrapCLS(Env env, UInt32 pgno, void* pgaddr, ref DBT pgcookie, PageInOutFcn pgInOut) {
   // construct DbEntry for pgcookie
   int size = unchecked((int)pgcookie.size);
   // we are not using a shared buffer - the call-back might take
   // a long time and we do not want to lock the buffer that long
   byte[] buffer = new byte[size];
   Marshal.Copy((IntPtr)pgcookie.data, buffer, 0, size);
   DbEntry cookieEntry = DbEntry.InOut(buffer, 0, size);
   cookieEntry.dbt.flags = pgcookie.flags;
   cookieEntry.dbt.dlen = pgcookie.dlen;
   cookieEntry.dbt.doff = pgcookie.doff;
   // call CLS compliant delegate - we assume it is not null
   return pgInOut(env, new CachePage(pgno, (IntPtr)pgaddr), ref cookieEntry);
 }
Пример #27
0
 private DatabaseEntry(DBT dbtp)
 {
     dbt  = dbtp;
     Data = (byte[])dbtp.data.Clone();
 }
Пример #28
0
 // constructs a DB_LOCKREQ instance based on this instance and an
 // externally (in unmanaged memory) allocated DBT and byte buffer;
 // bufp *must* point to memory large enough to hold obj.Size bytes
 internal unsafe DB_LOCKREQ PrepareLockReq(DBT* dbt, ref byte* bufp) {
   DB_LOCKREQ dblr = new DB_LOCKREQ((DB_LOCKOP)op, (DB_LOCKMODE)mode, unchecked((uint)timeout),
     (IntPtr)dbt, lck.dblck);
   dbt->data = bufp;
   dbt->size = obj.dbt.size;
   dbt->flags = DBT.DB_DBT_USERMEM;
   if (bufp != null)
     Marshal.Copy(obj.Buffer, obj.Start, (IntPtr)bufp, obj.Size);
   bufp += obj.dbt.size;
   return dblr;
 }
Пример #29
0
 static DbRetVal RepSendWrapFast(
   DB_ENV* evp, 
   ref DBT control,
   ref DBT rec,
   DB_LSN* lsnp,
   int envid,
   uint flags)
 {
   Env env = null;
   try {
     env = Util.GetEnv(evp);
     CallbackStatus cs = env.repSendFast(
       env, ref control, ref rec, lsnp, envid, unchecked((RepSendFlags)flags));
     return cs == CallbackStatus.Success ? DbRetVal.SUCCESS : DbRetVal.REPSEND_FAILED;
   }
   catch (Exception ex) {
     Trace.WriteLine(ex.Message, "RepSend");
     if (env != null)
       env.Error((int)DbRetVal.REPSEND_FAILED, ex.Message);
     else
       evp->Err(evp, (int)DbRetVal.REPSEND_FAILED, null);
     return DbRetVal.REPSEND_FAILED;
   }
 }
Пример #30
0
        private void Config(BTreeDatabaseConfig cfg)
        {
            base.Config(cfg);

            /*
             * Database.Config calls set_flags, but that does not get the BTree
             * specific flags.  No harm in calling it again.
             */
            db.set_flags(cfg.flags);

            if (cfg.BlobDir != null && cfg.Env == null)
            {
                db.set_ext_file_dir(cfg.BlobDir);
            }

            if (cfg.ExternalFileDir != null && cfg.Env == null)
            {
                db.set_ext_file_dir(cfg.ExternalFileDir);
            }

            if (cfg.blobThresholdIsSet)
            {
                db.set_ext_file_threshold(cfg.BlobThreshold, 0);
            }

            if (cfg.BTreeCompare != null)
            {
                Compare = cfg.BTreeCompare;
            }

            if (cfg.BTreePrefixCompare != null)
            {
                PrefixCompare = cfg.BTreePrefixCompare;
            }

            // The duplicate comparison function cannot change.
            if (cfg.DuplicateCompare != null)
            {
                DupCompare = cfg.DuplicateCompare;
            }

            if (cfg.minkeysIsSet)
            {
                db.set_bt_minkey(cfg.MinKeysPerPage);
            }

            if (cfg.compressionIsSet)
            {
                Compress   = cfg.Compress;
                Decompress = cfg.Decompress;
                if (Compress == null)
                {
                    doCompressRef = null;
                }
                else
                {
                    doCompressRef = new BDB_CompressDelegate(doCompress);
                }
                if (Decompress == null)
                {
                    doDecompressRef = null;
                }
                else
                {
                    doDecompressRef = new BDB_DecompressDelegate(doDecompress);
                }
                db.set_bt_compress(doCompressRef, doDecompressRef);
            }

            if (cfg.partitionIsSet)
            {
                nparts    = cfg.NParts;
                Partition = cfg.Partition;
                if (Partition == null)
                {
                    doPartitionRef = null;
                }
                else
                {
                    doPartitionRef = new BDB_PartitionDelegate(doPartition);
                }
                partitionKeys = cfg.PartitionKeys;
                IntPtr[] ptrs = null;
                if (partitionKeys != null)
                {
                    int size = (int)nparts - 1;
                    ptrs = new IntPtr[size];
                    for (int i = 0; i < size; i++)
                    {
                        ptrs[i] = DBT.getCPtr(
                            DatabaseEntry.getDBT(partitionKeys[i])).Handle;
                    }
                }
                db.set_partition(nparts, ptrs, doPartitionRef);
            }
        }
		public DeviceDetectorEventArgs(DBT changeType, DEV_BROADCAST_VOLUME volumeInfo)
		{
			Cancel = false;
			_ChangeType = changeType;
			_VolumeInfo = volumeInfo;
		}
Пример #32
0
 static DbRetVal RepSendWrapCLS(
   DB_ENV* evp,
   ref DBT control,
   ref DBT rec,
   DB_LSN* lsnp,
   int envid,
   uint flags)
 {
   Env env = null;
   try {
     env = Util.GetEnv(evp);
     lock (env.callBackLock) {
       // construct DbEntry for control
       int size = unchecked((int)control.size);
       if (size > env.callBackBuffer1.Length)
         env.callBackBuffer1 = new byte[size];
       Marshal.Copy((IntPtr)control.data, env.callBackBuffer1, 0, size);
       DbEntry ctrlEntry = DbEntry.InOut(env.callBackBuffer1, 0, size);
       // construct DbEntry for rec
       size = unchecked((int)rec.size);
       if (size > env.callBackBuffer2.Length)
         env.callBackBuffer2 = new byte[size];
       Marshal.Copy((IntPtr)rec.data, env.callBackBuffer2, 0, size);
       DbEntry recEntry = DbEntry.InOut(env.callBackBuffer2, 0, size);
       // construct Lsn
       Lsn? lsn;
       if (lsnp == null) lsn = null; else lsn = new Lsn(*lsnp);
       // call CLS compliant delegate - we assume it is not null
       CallbackStatus cs = env.repSendCLS(
         env, ref ctrlEntry, ref recEntry, lsn, envid, unchecked((RepSendFlags)flags));
       return cs == CallbackStatus.Success ? DbRetVal.SUCCESS : DbRetVal.REPSEND_FAILED;
     }
   }
   catch (Exception ex) {
     Trace.WriteLine(ex.Message, "RepSend");
     if (env != null)
       env.Error((int)DbRetVal.REPSEND_FAILED, ex.Message);
     else
       evp->Err(evp, (int)DbRetVal.REPSEND_FAILED, null);
     return DbRetVal.REPSEND_FAILED;
   }
 }
Пример #33
0
 // faster way of getting vendor name, uses "unsafe" techniques
 private unsafe DbRetVal GetVendorNameFast(DbFile secondary, ref DBT key, ref DBT data, ref DBT result)
 {
     // not implemented - would need "UnsafeBufferFormatter"
     return(DbRetVal.DONOTINDEX);
 }
Пример #34
0
 static CallbackStatus PageInOutWrapCLS(Env env, UInt32 pgno, void* pgaddr, ref DBT pgcookie, PageInOutFcn pgInOut) {
   IntPtr cookie = IntPtr.Zero;
   // extract IntPtr from DBT
   int size = unchecked((int)pgcookie.size);
   if (size != 0) {
     if (size != sizeof(IntPtr))
       throw new BdbException("Invalid page cookie.");
     cookie = *(IntPtr*)pgcookie.data;
   }
   // call CLS compliant delegate - we assume it is not null
   return pgInOut(env, new CachePage(pgno, (IntPtr)pgaddr), cookie);
 }
Пример #35
0
        /// <summary>
        /// Protected method to call the key generation function.
        /// </summary>
        /// <param name="dbp">Secondary DB Handle</param>
        /// <param name="keyp">Primary Key</param>
        /// <param name="datap">Primary Data</param>
        /// <param name="skeyp">Scondary Key</param>
        /// <returns>0 on success, !0 on failure</returns>
        protected static int doAssociate(
            IntPtr dbp, IntPtr keyp, IntPtr datap, IntPtr skeyp)
        {
            DB     db = new DB(dbp, false);
            DBT    key = new DBT(keyp, false);
            DBT    data = new DBT(datap, false);
            DBT    skey = new DBT(skeyp, false);
            IntPtr dataPtr, sdataPtr;
            int    nrecs, dbt_sz;

            DatabaseEntry s =
                ((SecondaryDatabase)db.api_internal).KeyGen(
                    DatabaseEntry.fromDBT(key), DatabaseEntry.fromDBT(data));

            if (s == null)
            {
                return(DbConstants.DB_DONOTINDEX);
            }
            if (s is MultipleDatabaseEntry)
            {
                MultipleDatabaseEntry mde = (MultipleDatabaseEntry)s;
                nrecs = mde.nRecs;

                /*
                 * Allocate an array of nrecs DBT in native memory.  The call
                 * returns sizeof(DBT), so that we know where one DBT ends and
                 * the next begins.
                 */
                dbt_sz = (int)libdb_csharp.alloc_dbt_arr(null, nrecs, out sdataPtr);

                /*
                 * We need a managed array to copy each DBT into and then we'll
                 * copy the managed array to the native array we just allocated.
                 * We are not able to copy native -> native.
                 */
                byte[] arr = new byte[nrecs * dbt_sz];
                IntPtr p;
                int    off = 0;
                /* Copy each DBT into the array. */
                foreach (DatabaseEntry dbt in mde)
                {
                    /* Allocate room for the data in native memory. */
                    dataPtr = libdb_csharp.__os_umalloc(null, dbt.size);
                    Marshal.Copy(dbt.Data, 0, dataPtr, (int)dbt.size);
                    dbt.dbt.dataPtr = dataPtr;
                    dbt.flags      |= DbConstants.DB_DBT_APPMALLOC;

                    p = DBT.getCPtr(DatabaseEntry.getDBT(dbt)).Handle;
                    Marshal.Copy(p, arr, off, dbt_sz);
                    off += dbt_sz;
                }
                Marshal.Copy(arr, 0, sdataPtr, nrecs * dbt_sz);
                skey.dataPtr = sdataPtr;
                skey.size    = (uint)mde.nRecs;
                skey.flags   = DbConstants.DB_DBT_MULTIPLE | DbConstants.DB_DBT_APPMALLOC;
            }
            else
            {
                skey.data = s.Data;
            }
            return(0);
        }
Пример #36
0
 public DeviceDetectorEventArgs(DBT changeType, DEV_BROADCAST_VOLUME volumeInfo)
 {
     Cancel      = false;
     _ChangeType = changeType;
     _VolumeInfo = volumeInfo;
 }
Пример #37
0
    static DbRetVal AppRecoverWrapCLS(DB_ENV* evp, ref DBT logrec, DB_LSN* lsnp, DB_RECOPS op) {
      Env env = null;
      try {
        env = (Env)((GCHandle)evp->api_internal).Target;

        // construct DbEntry for log_rec
        int size = unchecked((int)logrec.size);
        // we are not using a shared buffer - the call-back might take
        // a long time and we do not want to lock the buffer that long
        byte[] buffer = new byte[size];
        Marshal.Copy((IntPtr)logrec.data, buffer, 0, size);
        DbEntry logEntry = DbEntry.InOut(buffer, 0, size);
        logEntry.dbt.flags = logrec.flags;
        logEntry.dbt.dlen = logrec.dlen;
        logEntry.dbt.doff = logrec.doff;
        // construct Lsn
        Lsn? lsn;
        if (lsnp == null) lsn = null; else lsn = new Lsn(*lsnp);
        // call CLS compliant delegate - we assume it is not null
        CallbackStatus cs =  env.appRecoverCLS(env, ref logEntry, lsn, (RecoveryOps)op);
        return cs == CallbackStatus.Success ? DbRetVal.SUCCESS : DbRetVal.APP_RECOVER_FAILED;
      }
      catch (Exception ex) {
        Trace.WriteLine(ex.Message, "TxnRecover");
        return DbRetVal.APP_RECOVER_FAILED;
      }
    }
Пример #38
0
 internal static void AddKeys(Dictionary <string, string> db, DBT dbtp)
 {
     try
     {
         if (dbtp == DBT.SDB)
         {
             using (SQLiteTransaction trans = SDB.BeginTransaction())
             {
                 using (SQLiteCommand addKeysCmd = new SQLiteCommand(SDB))
                 {
                     foreach (KeyValuePair <string, string> pair in db)
                     {
                         string sqlIns = "INSERT INTO TEXTDB (hex, virusname) VALUES('" + pair.Key + "', '" + pair.Value + "');";
                         addKeysCmd.CommandText = sqlIns;
                         addKeysCmd.ExecuteNonQuery();
                     }
                 }
                 trans.Commit();
             }
             SetCount(db.Count.ToString());
         }
         else if (dbtp == DBT.HDB)
         {
             using (SQLiteTransaction trans = HADB.BeginTransaction())
             {
                 using (SQLiteCommand addKeysCmd = new SQLiteCommand(HADB))
                 {
                     foreach (KeyValuePair <string, string> pair in db)
                     {
                         string sqlIns = string.Format("INSERT INTO {0} (hash, virusname) VALUES('" + pair.Key + "', '" + pair.Value + "');", FileFormat.GetTable(pair.Key));
                         addKeysCmd.CommandText = sqlIns;
                         addKeysCmd.Transaction = trans;
                         addKeysCmd.ExecuteNonQuery();
                     }
                 }
                 trans.Commit();
             }
             SetCount(db.Count.ToString());
         }
         else if (dbtp == DBT.HEUR)
         {
             using (SQLiteTransaction trans = SDB.BeginTransaction())
             {
                 using (SQLiteCommand addKeysCmd = new SQLiteCommand(SDB))
                 {
                     foreach (KeyValuePair <string, string> pair in db)
                     {
                         string sqlIns = "INSERT INTO HEURISTIC (instruction, rate) VALUES('" + pair.Key + "', '" + pair.Value + "');";
                         addKeysCmd.CommandText = sqlIns;
                         addKeysCmd.Transaction = trans;
                         addKeysCmd.ExecuteNonQuery();
                     }
                 }
                 trans.Commit();
             }
             SetCount(db.Count.ToString());
         }
         else if (dbtp == DBT.WDB)
         {
             using (SQLiteTransaction trans = WDB.BeginTransaction())
             {
                 using (SQLiteCommand addKeysCmd = new SQLiteCommand(WDB))
                 {
                     foreach (KeyValuePair <string, string> pair in db)
                     {
                         string sqlIns = string.Format("INSERT INTO {0} (blacklistid, hash) VALUES('{1}', '{2}');",
                                                       FileFormat.GetTable(pair.Key), pair.Value, pair.Key);
                         addKeysCmd.CommandText = sqlIns;
                         addKeysCmd.Transaction = trans;
                         addKeysCmd.ExecuteNonQuery();
                     }
                 }
                 trans.Commit();
             }
             SetCount(db.Count.ToString());
         }
         else
         {
             using (SQLiteTransaction trans = PEDB.BeginTransaction())
             {
                 using (SQLiteCommand addKeysCmd = new SQLiteCommand(PEDB))
                 {
                     foreach (KeyValuePair <string, string> pair in db)
                     {
                         string sqlIns = string.Format("INSERT INTO {0} (hash, virusname) VALUES('" + pair.Key + "', '" + pair.Value + "');", FileFormat.GetTable(pair.Key));
                         addKeysCmd.CommandText = sqlIns;
                         addKeysCmd.ExecuteNonQuery();
                     }
                 }
                 trans.Commit();
             }
             SetCount(db.Count.ToString());
         }
     }
     catch
     {
     }
     finally
     {
     }
 }
Пример #39
0
        private void Config(HashDatabaseConfig cfg)
        {
            base.Config(cfg);

            /*
             * Database.Config calls set_flags, but that does not get the Hash
             * specific flags.  No harm in calling it again.
             */
            db.set_flags(cfg.flags);

            if (cfg.BlobDir != null && cfg.Env == null)
            {
                db.set_ext_file_dir(cfg.BlobDir);
            }
            if (cfg.ExternalFileDir != null && cfg.Env == null)
            {
                db.set_ext_file_dir(cfg.ExternalFileDir);
            }

            if (cfg.blobThresholdIsSet)
            {
                db.set_ext_file_threshold(cfg.BlobThreshold, 0);
            }

            if (cfg.HashFunction != null)
            {
                HashFunction = cfg.HashFunction;
            }
            // The duplicate comparison function cannot change.
            if (cfg.DuplicateCompare != null)
            {
                DupCompare = cfg.DuplicateCompare;
            }
            if (cfg.fillFactorIsSet)
            {
                db.set_h_ffactor(cfg.FillFactor);
            }
            if (cfg.nelemIsSet)
            {
                db.set_h_nelem(cfg.TableSize);
            }
            if (cfg.HashComparison != null)
            {
                Compare = cfg.HashComparison;
            }

            if (cfg.partitionIsSet)
            {
                nparts    = cfg.NParts;
                Partition = cfg.Partition;
                if (Partition == null)
                {
                    doPartitionRef = null;
                }
                else
                {
                    doPartitionRef = new BDB_PartitionDelegate(doPartition);
                }
                partitionKeys = cfg.PartitionKeys;
                IntPtr[] ptrs = null;
                if (partitionKeys != null)
                {
                    int size = (int)nparts - 1;
                    ptrs = new IntPtr[size];
                    for (int i = 0; i < size; i++)
                    {
                        ptrs[i] = DBT.getCPtr(
                            DatabaseEntry.getDBT(partitionKeys[i])).Handle;
                    }
                }
                db.set_partition(nparts, ptrs, doPartitionRef);
            }
        }