Esempio n. 1
0
 private void ReturnResult(CallContext context, Response response)
 {
     if (context != null && context.CompletedAction != null)
     {
         // Deployment.Current.Dispatcher.BeginInvoke(() => context.CompletedAction(response, context.UserContext));
         context.CompletedAction(response, context.UserContext);
     }
 }
Esempio n. 2
0
 private void ReturnError(CallContext context, ErrorCode errorCode)
 {
     if (context != null && context.ErrorAction != null)
     {
         // Deployment.Current.Dispatcher.BeginInvoke(() => context.ErrorAction(errorCode, context.UserContext));
         context.ErrorAction(errorCode, context.UserContext);
     }
 }
Esempio n. 3
0
        private void AddQueue(CallContext callContext)
        {
            lock (CallQueue)
            {
                callContext.ID = Interlocked.Increment(ref NextID);

                int queueCount = CallQueue.Count;

                CallQueue.Enqueue(callContext);

                // if there was nothing in the queue, then the queue processing thread is not running
                // so start it now; otherwise, it's already running, so don't need to do anything
                if (queueCount == 0)
                    ProcessQueueAsync();
            }
        }
Esempio n. 4
0
 private void RemoveQueue(CallContext callContext)
 {
     lock (CallQueue)
     {
         CallContext cc = CallQueue.Dequeue();
         if (callContext.ID != cc.ID)
         {
             throw new Exception(
                 "The dequeued CallContext did not match the supplied (expected) CallContext. Responses are being handled out of the expected order.");
         }
     }
 }
Esempio n. 5
0
        public void SendRequest(
			Request request,
			Action<Response, object> completed,
			Action<ErrorCode, object> error,
			object context)
        {
            lock (CallQueue)
            {
                var callContext = new CallContext
                {
                    CompletedAction = completed,
                    ErrorAction = error,
                    Request = request,
                    UserContext = context,
                    Operation = SocketAsyncOperation.Send,
                };

                AddQueue(callContext);
            }
        }