Пример #1
0
        private void UseNotificationPipeCallback(IAsyncResult async)
        {
            OwaAsyncResult        owaAsyncResult        = (OwaAsyncResult)async;
            PendingRequestChannel pendingRequestChannel = null;

            if (this.pendingRequestManager == null)
            {
                return;
            }
            pendingRequestChannel = this.pendingRequestManager.GetPendingGetChannel(owaAsyncResult.PendingGetId);
            if (pendingRequestChannel == null)
            {
                return;
            }
            try
            {
                pendingRequestChannel.EndSendNotification(owaAsyncResult);
            }
            catch (Exception exception)
            {
                if (this.pgEventDataDictionary.ContainsKey(owaAsyncResult.PendingGetId))
                {
                    lock (this.pgEventDataDictionary[owaAsyncResult.PendingGetId].AsyncResult)
                    {
                        if (!this.pgEventDataDictionary[owaAsyncResult.PendingGetId].AsyncResult.IsCompleted)
                        {
                            this.pgEventDataDictionary[owaAsyncResult.PendingGetId].AsyncResult.Exception = exception;
                        }
                    }
                }
            }
            try
            {
                lock (this.pgEventDataDictionary)
                {
                    if (this.pgEventDataDictionary.ContainsKey(owaAsyncResult.PendingGetId))
                    {
                        lock (this.pgEventDataDictionary[owaAsyncResult.PendingGetId].AsyncResult)
                        {
                            if (!this.pgEventDataDictionary[owaAsyncResult.PendingGetId].AsyncResult.IsCompleted)
                            {
                                this.pgEventDataDictionary[owaAsyncResult.PendingGetId].AsyncResult.CompleteRequest(owaAsyncResult.CompletedSynchronously);
                            }
                        }
                        this.pgEventDataDictionary.Remove(owaAsyncResult.PendingGetId);
                    }
                }
            }
            finally
            {
                try
                {
                    pendingRequestChannel.RecordFinishPendingRequest();
                }
                catch (OwaOperationNotSupportedException ex)
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceDebug <string>((long)this.GetHashCode(), "An exception was thrown during the processing of the async callback: {0}", ex.Message);
                }
            }
        }
Пример #2
0
        internal void EndSendNotification(IAsyncResult async)
        {
            OwaAsyncResult owaAsyncResult = (OwaAsyncResult)async;

            if (!this.lockTracker.IsLockOwner())
            {
                throw new OwaInvalidOperationException("A thread that is not the owner of the lock can't call WriteNotification!", owaAsyncResult.Exception, this);
            }
            this.disposePendingRequest = false;
            this.WriteIsRequestAlive(false);
            if (owaAsyncResult.Exception != null)
            {
                throw new OwaNotificationPipeException("An exception happened while handling the pending connection asynchronously", owaAsyncResult.Exception);
            }
        }
Пример #3
0
        public void EndUseNotificationPipe(IAsyncResult async)
        {
            if (this.isDisposing)
            {
                return;
            }
            OwaAsyncResult owaAsyncResult = (OwaAsyncResult)async;

            try
            {
                string pendingGetId = owaAsyncResult.PendingGetId;
                PendingRequestEventData pendingRequestEventData;
                if (!this.pgEventDataDictionary.TryGetValue(pendingGetId, out pendingRequestEventData))
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceWarning <string>((long)this.GetHashCode(), "There is no PendingRequestEventData for PendingGetId {0}", pendingGetId);
                }
                else
                {
                    if (owaAsyncResult.Exception != null)
                    {
                        Exception ex = (owaAsyncResult.Exception.InnerException == null) ? owaAsyncResult.Exception : owaAsyncResult.Exception.InnerException;
                        ExTraceGlobals.NotificationsCallTracer.TraceDebug <string>((long)this.GetHashCode(), "An exception was thrown during the processing of the async request: {0}", ex.Message);
                        if (pendingRequestEventData.Response != null)
                        {
                            StringBuilder stringBuilder = new StringBuilder(500);
                            stringBuilder.Append(ex.Message);
                            stringBuilder.Append(":").Append(ex.StackTrace);
                            pendingRequestEventData.Response.WriteError(PendingRequestUtilities.JavascriptEncode(stringBuilder.ToString()));
                        }
                    }
                    if (pendingRequestEventData.Response != null)
                    {
                        pendingRequestEventData.Response.WriteLastChunk();
                    }
                }
            }
            catch (OwaPermanentException)
            {
            }
        }
 // Token: 0x06000ED1 RID: 3793 RVA: 0x0003914E File Offset: 0x0003734E
 internal PendingRequestEventData(OwaAsyncResult asyncResult, ChunkedHttpResponse response)
 {
     this.asyncResult = asyncResult;
     this.response    = response;
 }
Пример #5
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);
        }
Пример #6
0
        private void ElapsedConnectionAliveTimeout(object state)
        {
            bool           requestRestart = false;
            OwaAsyncResult owaAsyncResult = this.asyncResult;

            this.pendingRequestManager.FireKeepAlive();
            if (DateTime.UtcNow.Ticks - this.startPendingRequestTime > this.MaxTicksPerPendingRequest)
            {
                this.disposePendingRequest = true;
                requestRestart             = true;
            }
            try
            {
                if (this.lockTracker.TryAcquireLockOnlyIfSucceed())
                {
                    try
                    {
                        if (DateTime.UtcNow.Ticks - this.lastWriteTime >= 100000000L)
                        {
                            if (this.disposePendingRequest)
                            {
                                this.CloseCurrentPendingRequest(false, requestRestart);
                                this.lockTracker.TryReleaseLock(owaAsyncResult.IsCompleted);
                                return;
                            }
                            this.WriteEmptyNotification();
                        }
                    }
                    catch (Exception e)
                    {
                        this.HandleException(e, false);
                        this.lockTracker.TryReleaseLock(owaAsyncResult.IsCompleted);
                        return;
                    }
                    if (!this.lockTracker.TryReleaseLock(owaAsyncResult.IsCompleted))
                    {
                        try
                        {
                            this.WriteNotification(false);
                        }
                        catch (Exception e2)
                        {
                            this.HandleException(e2, false);
                        }
                    }
                }
            }
            finally
            {
                if (this.IsActive)
                {
                    this.checkClientInactiveCounter = 0;
                }
                else
                {
                    this.checkClientInactiveCounter++;
                }
                if (this.ShouldBeFinalized)
                {
                    this.pendingRequestManager.RemovePendingGetChannel(this.channelId);
                }
                if (!this.pendingRequestManager.HasAnyActivePendingGetChannel())
                {
                    if (this.lastDisconnectedTime == 0L)
                    {
                        this.lastDisconnectedTime = DateTime.UtcNow.Ticks;
                        goto IL_1A9;
                    }
                    if (DateTime.UtcNow.Ticks - this.lastDisconnectedTime <= 700000000L)
                    {
                        goto IL_1A9;
                    }
                    this.lastDisconnectedTime = 0L;
                    try
                    {
                        this.pendingRequestManager.FireClientDisconnect();
                        goto IL_1A9;
                    }
                    catch (Exception ex)
                    {
                        ExTraceGlobals.NotificationsCallTracer.TraceDebug <string>((long)this.GetHashCode(), "Exception during ClientDisconnected event: {0}", ex.ToString());
                        goto IL_1A9;
                    }
                }
                this.lastDisconnectedTime = 0L;
                IL_1A9 :;
            }
        }