예제 #1
0
            /// <summary>
            /// Dequeue messages from a persistent message queue file at server side in batch
            /// </summary>
            /// <param name="key">An ASCII string for identifying a queue at server side</param>
            /// <param name="d">A callback for tracking data like remaining message count within a server queue file, queue file size in bytes, message dequeued within this batch and bytes dequeued within this batch</param>
            /// <param name="timeout">A time-out number in milliseconds</param>
            /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
            /// <returns>true for sending the request successfully, and false for failure</returns>
            public virtual bool Dequeue(byte[] key, DDequeue d, uint timeout, DDiscarded discarded)
            {
                DAsyncResultHandler rh = null;

                lock (m_csQ)
                {
                    m_keyDequeue = key;
                    if (d != null)
                    {
                        rh = (ar) =>
                        {
                            ulong messageCount, fileSize, ret;
                            ar.UQueue.Load(out messageCount).Load(out fileSize).Load(out ret);
                            uint messages = (uint)ret;
                            uint bytes    = (uint)(ret >> 32);
                            d((CAsyncQueue)ar.AsyncServiceHandler, messageCount, fileSize, messages, bytes);
                        };
                        m_dDequeue = d;
                    }
                    else
                    {
                        m_dDequeue = null;
                    }
                }
                using (CScopeUQueue sb = new CScopeUQueue())
                {
                    CUQueue q = sb.UQueue;
                    q.Save(key).Save(timeout);
                    return(SendRequest(idDequeue, q, rh, discarded, (DOnExceptionFromServer)null));
                }
            }
예제 #2
0
            public static DDiscarded get_aborted <R>(TaskCompletionSource <R> tcs, ushort req_id)
            {
                DDiscarded aborted = (h, canceled) =>
                {
                    if (canceled)
                    {
                        tcs.TrySetException(new CSocketError(REQUEST_CANCELED, REQUEST_CANCELED_ERR_MSG, req_id, false));
                    }
                    else
                    {
                        CClientSocket cs = h.Socket;
                        int           ec = cs.ErrorCode;
                        if (ec != 0)
                        {
                            string em = cs.ErrorMsg;
                            tcs.TrySetException(new CSocketError(ec, em, req_id, false));
                        }
                        else
                        {
                            tcs.TrySetException(new CSocketError(SESSION_CLOSED_AFTER, SESSION_CLOSED_AFTER_ERR_MSG, req_id, false));
                        }
                    }
                };

                return(aborted);
            }
예제 #3
0
            /// <summary>
            /// End enqueuing messages with transaction style. Currently, total size of queued messages must be less than 4 G bytes
            /// </summary>
            /// <param name="rollback">true for rollback, and false for committing</param>
            /// <param name="qt">A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_TRANS_NOT_STARTED_YET, and so on</param>
            /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
            /// <returns>true for sending the request successfully, and false for failure</returns>
            public virtual bool EndQueueTrans(bool rollback, DQueueTrans qt, DDiscarded discarded)
            {
                bool ok = SendRequest(idEndTrans, rollback, (ar) =>
                {
                    if (qt != null)
                    {
                        int errCode;
                        ar.UQueue.Load(out errCode);
                        qt((CAsyncQueue)ar.AsyncServiceHandler, errCode);
                    }
                    else
                    {
                        ar.UQueue.SetSize(0);
                    }
                }, discarded, (DOnExceptionFromServer)null);
                IClientQueue cq = AttachedClientSocket.ClientQueue;

                if (cq.Available)
                {
                    if (rollback)
                    {
                        cq.AbortJob();
                    }
                    else
                    {
                        cq.EndJob();
                    }
                }
                return(ok);
            }
예제 #4
0
 /// <summary>
 /// Query queue keys opened at server side
 /// </summary>
 /// <param name="gk">A callback for tracking a list of key names</param>
 /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
 /// <returns>true for sending the request successfully, and false for failure</returns>
 public virtual bool GetKeys(DGetKeys gk, DDiscarded discarded)
 {
     return(SendRequest(idGetKeys, (ar) =>
     {
         CUQueue q = ar.UQueue;
         if (gk != null)
         {
             uint size;
             q.Load(out size);
             string[] v = new string[size];
             for (uint n = 0; n < size; ++n)
             {
                 byte[] bytes;
                 q.Load(out bytes);
                 if (bytes != null)
                 {
                     v[n] = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                 }
             }
             gk((CAsyncQueue)ar.AsyncServiceHandler, v);
         }
         else
         {
             q.SetSize(0);
         }
     }, discarded, (DOnExceptionFromServer)null));
 }
예제 #5
0
    public bool GetMasterSlaveConnectedSessions(DConnectedSessions cs, DDiscarded discarded = null)
    {
        DAsyncResultHandler arh = (ar) => {
            uint master_connections, slave_conenctions;
            ar.Load(out master_connections).Load(out slave_conenctions);
            if (cs != null)
            {
                cs(master_connections, slave_conenctions);
            }
        };

        return(SendRequest(ss.Consts.idGetMasterSlaveConnectedSessions, arh, discarded, (DOnExceptionFromServer)null));
    }
예제 #6
0
            public virtual bool EnqueueBatch(byte[] key, CUQueue q, DEnqueue e, DDiscarded discarded)
            {
                if (q == null || q.GetSize() < 2 * sizeof(uint))
                {
                    throw new InvalidOperationException("Bad operation");
                }
                CUQueue sb = CScopeUQueue.Lock();

                sb.Save(key).Push(q.IntenalBuffer, q.HeadPosition, q.Size);
                q.SetSize(0);
                bool ok = SendRequest(idEnqueueBatch, sb, GetRH(e), discarded, (DOnExceptionFromServer)null);

                CScopeUQueue.Unlock(sb);
                return(ok);
            }
예제 #7
0
    public bool GetRentalDateTimes(long rentalId, DRentalDateTimes rdt, DDiscarded discarded = null)
    {
        DAsyncResultHandler arh = (ar) => {
            int    errCode;
            string errMsg;
            ss.CRentalDateTimes dates;
            ar.Load(out dates).Load(out errCode).Load(out errMsg);
            if (rdt != null)
            {
                rdt(dates, errCode, errMsg);
            }
        };

        return(SendRequest(ss.Consts.idGetRentalDateTimes, rentalId, arh, discarded, (DOnExceptionFromServer)null));
    }
예제 #8
0
    public bool QueryPaymentMaxMinAvgs(string filter, DMaxMinAvg mma, DDiscarded discarded = null)
    {
        DAsyncResultHandler arh = (ar) => {
            int           res;
            string        errMsg;
            ss.CMaxMinAvg m_m_a;
            ar.Load(out res).Load(out errMsg).Load(out m_m_a);
            if (mma != null)
            {
                mma(m_m_a, res, errMsg);
            }
        };

        return(SendRequest(ss.Consts.idQueryMaxMinAvgs, filter, arh, discarded, (DOnExceptionFromServer)null));
    }
예제 #9
0
 /// <summary>
 /// Try to close or delete a persistent queue opened at server side
 /// </summary>
 /// <param name="key">An ASCII string for identifying a queue at server side</param>
 /// <param name="c">A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_DEQUEUING, and so on</param>
 /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
 /// <param name="permanent">true for deleting a queue file, and false for closing a queue file</param>
 /// <returns>true for sending the request successfully, and false for failure</returns>
 public virtual bool CloseQueue(byte[] key, DClose c, DDiscarded discarded, bool permanent)
 {
     return(SendRequest(idClose, key, permanent, (ar) =>
     {
         if (c != null)
         {
             int errCode;
             ar.UQueue.Load(out errCode);
             c((CAsyncQueue)ar.AsyncServiceHandler, errCode);
         }
         else
         {
             ar.UQueue.SetSize(0);
         }
     }, discarded, (DOnExceptionFromServer)null));
 }
예제 #10
0
 /// <summary>
 /// Try to close or delete a persistent queue opened at server side
 /// </summary>
 /// <param name="key">An ASCII string for identifying a queue at server side</param>
 /// <param name="c">A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_DEQUEUING, and so on</param>
 /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
 /// <param name="permanent">true for deleting a queue file, and false for closing a queue file</param>
 /// <returns>true for sending the request successfully, and false for failure</returns>
 public virtual bool CloseQueue(byte[] key, DClose c, DDiscarded discarded, bool permanent)
 {
     if (key == null)
     {
         key = new byte[0];
     }
     return(SendRequest(idClose, key, permanent, (ar) =>
     {
         if (c != null)
         {
             int errCode;
             ar.Load(out errCode);
             c(errCode);
         }
         else
         {
             ar.UQueue.SetSize(0);
         }
     }, discarded, (DOnExceptionFromServer)null));
 }
예제 #11
0
 public bool ForeignKeys(string PKCatalogName, string PKSchemaName, string PKTableName, string FKCatalogName, string FKSchemaName, string FKTableName, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
 {
     return(DoMeta(idSQLForeignKeys, PKCatalogName, PKSchemaName, PKTableName, FKCatalogName, FKSchemaName, FKTableName, handler, row, rh, discarded));
 }
예제 #12
0
 public bool SpecialColumns(short identifierType, string CatalogName, string SchemaName, string TableName, short scope, short nullable, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
 {
     return(DoMeta(idSQLSpecialColumns, identifierType, CatalogName, SchemaName, TableName, scope, nullable, handler, row, rh, discarded));
 }
예제 #13
0
            public bool Statistics(string CatalogName, string SchemaName, string TableName, ushort unique, ushort reserved, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
            {
                ulong index = GetCallIndex();

                //don't make m_csDB locked across calling SendRequest, which may lead to client dead-lock
                //in case a client asynchronously sends lots of requests without use of client side queue.
                lock (m_csDB) {
                    m_mapRowset[index] = new KeyValuePair <DRowsetHeader, DRows>(rh, row);
                }
                if (!SendRequest(idSQLStatistics, CatalogName, SchemaName, TableName, unique, reserved, index, (ar) => {
                    ProcessODBC(handler, ar, idSQLStatistics, index);
                }, discarded, null))
                {
                    lock (m_csDB) {
                        m_mapRowset.Remove(index);
                    }
                    return(false);
                }
                return(true);
            }
예제 #14
0
 public bool Download(string localFile, string remoteFile, DDownload dl, DTransferring trans, DDiscarded discarded)
 {
     return(Download(localFile, remoteFile, dl, trans, discarded, FILE_OPEN_TRUNCACTED));
 }
예제 #15
0
        public virtual bool Download(string localFile, string remoteFile, DDownload dl, DTransferring trans, DDiscarded discarded, uint flags)
        {
            if (localFile == null || localFile.Length == 0)
            {
                return(false);
            }
            if (remoteFile == null || remoteFile.Length == 0)
            {
                return(false);
            }
            CContext context = new CContext(false, flags);

            context.Download     = dl;
            context.Transferring = trans;
            context.Discarded    = discarded;
            context.FilePath     = remoteFile;
            context.LocalFile    = localFile;
            lock (m_csFile)
            {
                m_vContext.AddToBack(context);
                return(Transfer());
            }
        }
예제 #16
0
 /// <summary>
 /// Try to close or delete a persistent queue opened at server side
 /// </summary>
 /// <param name="key">An ASCII string for identifying a queue at server side</param>
 /// <param name="c">A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_DEQUEUING, and so on</param>
 /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
 /// <returns>true for sending the request successfully, and false for failure</returns>
 public bool CloseQueue(byte[] key, DClose c, DDiscarded discarded)
 {
     return(CloseQueue(key, c, discarded, false));
 }
예제 #17
0
 public bool Upload(string localFile, string remoteFile, DUpload up, DTransferring trans, DDiscarded discarded)
 {
     return(Upload(localFile, remoteFile, up, trans, discarded, FILE_OPEN_TRUNCACTED));
 }
예제 #18
0
 public bool Download(string localFile, string remoteFile, DDownload dl, DTransferring trans, DDiscarded discarded, uint flags)
 {
     return(Download(localFile, remoteFile, dl, trans, discarded, flags, null));
 }
예제 #19
0
        public virtual bool Download(string localFile, string remoteFile, DDownload dl, DTransferring trans, DDiscarded discarded, uint flags, DOnExceptionFromServer se)
        {
            if (localFile == null || localFile.Length == 0)
            {
                throw new ArgumentException("localFile cannot be empty");
            }
            if (remoteFile == null || remoteFile.Length == 0)
            {
                throw new ArgumentException("remoteFile cannot be empty");
            }
            CContext context = new CContext(false, flags);

            context.Download     = dl;
            context.Transferring = trans;
            context.Discarded    = discarded;
            context.FilePath     = remoteFile;
            context.LocalFile    = localFile;
            context.Se           = se;
            lock (m_csFile)
            {
                m_vContext.AddToBack(context);
                uint filesOpened = GetFilesOpened();
                if (m_MaxDownloading > filesOpened)
                {
                    ClientCoreLoader.PostProcessing(Socket.Handle, 0, 0);
                    if (filesOpened == 0)
                    {
                        Socket.DoEcho(); //make sure WaitAll works correctly
                    }
                }
            }
            return(true);
        }
예제 #20
0
 public bool Enqueue <T0>(byte[] key, ushort idMessage, T0 t0, DEnqueue e, DDiscarded discarded)
 {
     using (CScopeUQueue sb = new CScopeUQueue())
     {
         sb.Save(t0);
         return(Enqueue(key, idMessage, sb.UQueue, e, discarded));
     }
 }
예제 #21
0
 public bool Upload(string localFile, string remoteFile, DUpload up, DTransferring trans, DDiscarded discarded, uint flags)
 {
     return(Upload(localFile, remoteFile, up, trans, discarded, flags, null));
 }
예제 #22
0
 public bool ProcedureColumns(string CatalogName, string SchemaName, string ProcName, string ColumnName, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
 {
     return(DoMeta(idSQLProcedureColumns, CatalogName, SchemaName, ProcName, ColumnName, handler, row, rh, discarded));
 }
예제 #23
0
 /// <summary>
 /// May flush memory data into either operation system memory or hard disk, and return message count and queue file size in bytes. Note the method only returns message count and queue file size in bytes if the option is oMemoryCached
 /// </summary>
 /// <param name="key">An ASCII string for identifying a queue at server side</param>
 /// <param name="f">A callback for tracking returning message count and queue file size in bytes</param>
 /// <param name="option">one of options, oMemoryCached, oSystemMemoryCached and oDiskCommitted</param>
 /// <param name="discarded">a callback for tracking cancel or socket closed event</param>
 /// <returns>true for sending the request successfully, and false for failure</returns>
 public virtual bool FlushQueue(byte[] key, DFlush f, tagOptimistic option, DDiscarded discarded)
 {
     return(SendRequest(idFlush, key, (int)option, (ar) =>
     {
         if (f != null)
         {
             ulong messageCount, fileSize;
             ar.UQueue.Load(out messageCount).Load(out fileSize);
             f((CAsyncQueue)ar.AsyncServiceHandler, messageCount, fileSize);
         }
         else
         {
             ar.UQueue.SetSize(0);
         }
     }, discarded, (DOnExceptionFromServer)null));
 }
예제 #24
0
 public bool Enqueue <T0, T1, T2, T3, T4>(byte[] key, ushort idMessage, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, DEnqueue e, DDiscarded discarded)
 {
     using (CScopeUQueue sb = new CScopeUQueue())
     {
         sb.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4);
         return(Enqueue(key, idMessage, sb.UQueue, e, discarded));
     }
 }
예제 #25
0
            private bool DoMeta <T0, T1, T2>(ushort id, T0 t0, string s0, string s1, string s2, T1 t1, T2 t2, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
            {
                ulong index = GetCallIndex();

                //don't make m_csDB locked across calling SendRequest, which may lead to client dead-lock
                //in case a client asynchronously sends lots of requests without use of client side queue.
                lock (m_csDB) {
                    m_mapRowset[index] = new KeyValuePair <DRowsetHeader, DRows>(rh, row);
                }
                if (!SendRequest(id, t0, s0, s1, s2, t1, t2, index, (ar) => {
                    ProcessODBC(handler, ar, id, index);
                }, discarded, null))
                {
                    lock (m_csDB) {
                        m_mapRowset.Remove(index);
                    }
                    return(false);
                }
                return(true);
            }
예제 #26
0
    public bool UploadEmployees(SocketProAdapter.UDB.CDBVariantArray vData, DUploadEmployees res, DDiscarded discarded = null)
    {
        DAsyncResultHandler arh = (ar) =>
        {
            int            errCode;
            string         errMsg;
            ss.CInt64Array vId;
            ar.Load(out errCode).Load(out errMsg).Load(out vId);
            if (res != null)
            {
                res(errCode, errMsg, vId);
            }
        };

        return(SendRequest(ss.Consts.idUploadEmployees, vData, arh, discarded, (DOnExceptionFromServer)null));
    }
예제 #27
0
 public bool ColumnPrivileges(string CatalogName, string SchemaName, string TableName, string ColumnName, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
 {
     return(DoMeta(idSQLColumnPrivileges, CatalogName, SchemaName, TableName, ColumnName, handler, row, rh, discarded));
 }
예제 #28
0
 public bool Enqueue <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(byte[] key, ushort idMessage, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, DEnqueue e, DDiscarded discarded)
 {
     using (CScopeUQueue sb = new CScopeUQueue())
     {
         sb.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5).Save(t6).Save(t7).Save(t8).Save(t9);
         return(Enqueue(key, idMessage, sb.UQueue, e, discarded));
     }
 }
예제 #29
0
 public bool PrimaryKeys(string CatalogName, string SchemaName, string TableName, DExecuteResult handler, DRows row, DRowsetHeader rh, DDiscarded discarded)
 {
     return(DoMeta(idSQLPrimaryKeys, CatalogName, SchemaName, TableName, handler, row, rh, discarded));
 }
예제 #30
0
        public virtual bool Download(string localFile, string remoteFile, DDownload dl, DTransferring trans, DDiscarded discarded, uint flags)
        {
            if (localFile == null || localFile.Length == 0)
            {
                return(false);
            }
            if (remoteFile == null || remoteFile.Length == 0)
            {
                return(false);
            }
            CContext context = new CContext(false, flags);

            context.Download     = dl;
            context.Transferring = trans;
            context.Discarded    = discarded;
            context.FilePath     = remoteFile;
            context.LocalFile    = localFile;
            lock (m_csFile) {
                m_vContext.AddToBack(context);
                if (m_vContext.Count == 1)
                {
                    ClientCoreLoader.PostProcessing(AttachedClientSocket.Handle, 0, 0);
                    AttachedClientSocket.DoEcho(); //make sure WaitAll works correctly
                }
            }
            return(true);
        }