Specifies the parameters for an async read request.
Inheritance: ComDaAsnycRequest
Esempio n. 1
0
        /// <summary>
        /// Starts an asynchronous refresh operation.
        /// </summary>
        /// <param name="maxAge">The max age.</param>
        /// <param name="transactionId">The transaction id.</param>
        /// <param name="isFirstUpdate">True if this refresh is the first update after activation.</param>
        /// <param name="cancelId">The cancel id.</param>
        private void Refresh(uint maxAge, int transactionId, bool isFirstUpdate, out int cancelId)
        {
            TraceState("Refresh", maxAge);
            ThrowIfDisposed();

            cancelId = 0;

            lock (m_lock)
            {
                // no refresh in inactive groups.
                if (!m_active)
                {
                    throw ComUtils.CreateComException(ResultIds.E_FAIL);
                }

                // collect active items.
                List<ComDaGroupItem> items = new List<ComDaGroupItem>(m_items.Count);

                for (int ii = 0; ii < m_items.Count; ii++)
                {
                    ComDaGroupItem item = m_items[ii];

                    if (item.Active)
                    {
                        items.Add(item);
                    }
                }

                // no refresh if no active items.
                if (items.Count == 0)
                {
                    throw ComUtils.CreateComException(ResultIds.E_FAIL);
                }

                // create the request.
                ComDaAsnycReadRequest request = new ComDaAsnycReadRequest();

                request.CancelId = ++m_transactionCounter;
                request.TransactionId = transactionId;
                request.IsFirstUpdate = isFirstUpdate;
                request.MaxAge = maxAge;
                request.IsRefresh = true;
                request.ServerHandles = new int[items.Count];
                request.ClientHandles = new int[items.Count];

                for (int ii = 0; ii < items.Count; ii++)
                {
                    request.ServerHandles[ii] = items[ii].ServerHandle;
                    request.ClientHandles[ii] = items[ii].ClientHandle;
                }

                m_requests.Add(request);
                cancelId = request.CancelId;

                // create a thread to process the request.
                Thread thread = new Thread(OnAsyncRead);
                thread.IsBackground = true;
                thread.Start(request);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts an asynchronous read operation.
        /// </summary>
        /// <param name="maxAge">The max age.</param>
        /// <param name="transactionId">The transaction id.</param>
        /// <param name="serverHandles">The server handles.</param>
        /// <param name="cancelId">The cancel id.</param>
        /// <returns>Any errors.</returns>
        public int[] AsyncRead(uint maxAge, int transactionId, int[] serverHandles, out int cancelId)
        {
            TraceState("AsyncRead", maxAge, transactionId, serverHandles.Length);
            ThrowIfDisposed();

            cancelId = 0;

            lock (m_lock)
            {
                int[] results = new int[serverHandles.Length];
                List<ComDaGroupItem> items = new List<ComDaGroupItem>(serverHandles.Length);

                for (int ii = 0; ii < serverHandles.Length; ii++)
                {
                    ComDaGroupItem item = null;

                    if (!m_itemsByHandle.TryGetValue(serverHandles[ii], out item))
                    {
                        results[ii] = ResultIds.E_INVALIDHANDLE;
                        continue;
                    }

                    items.Add(item);
                }

                if (items.Count > 0)
                {
                    ComDaAsnycReadRequest request = new ComDaAsnycReadRequest();

                    request.CancelId = ++m_transactionCounter;
                    request.TransactionId = transactionId;
                    request.MaxAge = maxAge;
                    request.ServerHandles = new int[items.Count];
                    request.ClientHandles = new int[items.Count];

                    for (int ii = 0; ii < items.Count; ii++)
                    {
                        request.ServerHandles[ii] = items[ii].ServerHandle;
                        request.ClientHandles[ii] = items[ii].ClientHandle;
                    }

                    m_requests.Add(request);
                    cancelId = request.CancelId;

                    // create a thread to process the request.
                    Thread thread = new Thread(OnAsyncRead);
                    thread.IsBackground = true;
                    thread.Start(request);
                }

                return results;
            }
        }