Example #1
0
 protected override void InternalDispose(bool isExplicitDispose)
 {
     if (isExplicitDispose && !this.isDisposing && this.pgEventDataDictionary != null)
     {
         lock (this.pgEventDataDictionary)
         {
             this.isDisposing = true;
             foreach (string key in this.pgEventDataDictionary.Keys)
             {
                 PendingRequestEventData pendingRequestEventData = this.pgEventDataDictionary[key];
                 if (pendingRequestEventData != null)
                 {
                     if (pendingRequestEventData.AsyncResult != null)
                     {
                         lock (pendingRequestEventData.AsyncResult)
                         {
                             if (!pendingRequestEventData.AsyncResult.IsCompleted)
                             {
                                 pendingRequestEventData.AsyncResult.CompleteRequest(false);
                             }
                         }
                     }
                     if (pendingRequestEventData.Response != null)
                     {
                         pendingRequestEventData.Response.Dispose();
                     }
                 }
             }
         }
     }
 }
Example #2
0
        public IAsyncResult BeginUseNotificationPipe(AsyncCallback callback, object extraData)
        {
            ExTraceGlobals.NotificationsCallTracer.TraceDebug((long)this.GetHashCode(), "[PendingRequestEventHandler.BeginUseNotificationPipe] called from the client");
            string                  text                    = (string)base.GetParameter("cid");
            OwaAsyncResult          owaAsyncResult          = new OwaAsyncResult(callback, extraData, text);
            PendingRequestEventData pendingRequestEventData = null;

            this.pgEventDataDictionary.TryGetValue(text, out pendingRequestEventData);
            UserContext userContext = UserContextManager.GetUserContext(HttpContext.Current);

            if (userContext == null || (pendingRequestEventData != null && !pendingRequestEventData.AsyncResult.IsCompleted))
            {
                owaAsyncResult.CompleteRequest(true);
                return(owaAsyncResult);
            }
            HttpResponse response = HttpContext.Current.Response;

            response.AppendHeader("X-NoCompression", "1");
            response.AppendHeader("X-NoBuffering", "1");
            response.AddHeader("Content-Encoding", "none");
            try
            {
                if (!userContext.GetPendingGetManagerLock())
                {
                    owaAsyncResult.CompleteRequest(true);
                    return(owaAsyncResult);
                }
                if (this.pendingRequestManager == null)
                {
                    this.pendingRequestManager = userContext.PendingRequestManager;
                }
                if (this.pendingRequestManager == null)
                {
                    owaAsyncResult.CompleteRequest(true);
                    return(owaAsyncResult);
                }
                PendingRequestChannel pendingRequestChannel = null;
                if (this.pendingRequestManager != null)
                {
                    pendingRequestChannel = this.pendingRequestManager.GetPendingGetChannel(text);
                }
                if (pendingRequestChannel == null)
                {
                    pendingRequestChannel = this.pendingRequestManager.AddPendingGetChannel(text);
                }
                object parameter = base.GetParameter("A");
                if (parameter != null)
                {
                    pendingRequestChannel.MaxTicksPerPendingRequest = (long)parameter * 10000L;
                }
                pendingRequestEventData = new PendingRequestEventData(owaAsyncResult, new ChunkedHttpResponse(this.HttpContext));
                this.pgEventDataDictionary.Add(text, pendingRequestEventData);
                try
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceDebug <bool, string>((long)this.GetHashCode(), "[PendingRequestEventHandler.BeginUseNotificationPipe] calling pendingGetChannel.BeginSendNotification. userContext.HasActiveHierarchySubscription: {0}. ChannelId: {1}", userContext.HasActiveHierarchySubscription, text);
                    pendingRequestChannel.BeginSendNotification(new AsyncCallback(this.UseNotificationPipeCallback), this.pgEventDataDictionary[text].Response, this, userContext.HasActiveHierarchySubscription, text);
                }
                catch (Exception ex)
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceError <Exception>((long)this.GetHashCode(), "An exception happened while executing BeginUseNotificationPipe. Exception:{0}", ex);
                    lock (this.pgEventDataDictionary[text].AsyncResult)
                    {
                        if (!this.pgEventDataDictionary[text].AsyncResult.IsCompleted)
                        {
                            this.pgEventDataDictionary[text].AsyncResult.CompleteRequest(true, ex);
                        }
                    }
                }
            }
            finally
            {
                if (userContext.PendingRequestManager != null && userContext.PendingRequestManager.ShouldDispose)
                {
                    userContext.PendingRequestManager.Dispose();
                }
                userContext.ReleasePendingGetManagerLock();
            }
            return(owaAsyncResult);
        }