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); } } }
internal void RemovePendingGetChannel(string channelId) { if (this.pendingRequestChannels != null) { lock (this.pendingRequestChannels) { PendingRequestChannel pendingGetChannel = this.GetPendingGetChannel(channelId); if (pendingGetChannel != null) { this.pendingRequestChannels.Remove(channelId); pendingGetChannel.Dispose(); } this.listenerChannelsManager.RemovePendingGetChannel(channelId); } } ExTraceGlobals.NotificationsCallTracer.TraceDebug <string>((long)this.GetHashCode(), "[PendingRequestManager::RemovePendingGetChannel] ChannelId: {0}", channelId); try { OwaDiagnostics.SendWatsonReportsForGrayExceptions(delegate() { if (this.userContext.NotificationManager != null) { this.userContext.NotificationManager.ReleaseSubscriptionsForChannelId(channelId); } }); } catch (GrayException ex) { ExTraceGlobals.NotificationsCallTracer.TraceError <string>(0L, "MapiNotificationHandlerBase.DisposeXSOObjects Unable to dispose object. exception {0}", ex.Message); } }
internal PendingRequestChannel GetPendingGetChannel(string channelId) { PendingRequestChannel result = null; if (this.pendingRequestChannels != null) { this.pendingRequestChannels.TryGetValue(channelId, out result); } return(result); }
public void DisposePendingNotificationClientRequest() { IMailboxContext mailboxContext = UserContextManager.GetMailboxContext(HttpContext.Current, null, false); HttpResponse response = HttpContext.Current.Response; object parameter = base.GetParameter("Fn"); bool flag = false; if (parameter != null) { flag = (bool)parameter; } bool flag2 = false; string text = (string)base.GetParameter("cid"); text = this.ProcessChannelIdOnRequestAndGenerateIfNeeded(text, flag); if (mailboxContext != null && text != null) { PendingRequestChannel pendingGetChannel = mailboxContext.PendingRequestManager.GetPendingGetChannel(text); if (pendingGetChannel != null) { flag2 = pendingGetChannel.HandleFinishRequestFromClient(); if (flag) { ExTraceGlobals.NotificationsCallTracer.TraceDebug <string>((long)this.GetHashCode(), "[PendingRequestEventHandler::DisposePendingNotificationClientRequest] userContext.PendingRequestManager.RemovePendingGetChannel. ChannelId: {0}", text); mailboxContext.PendingRequestManager.RemovePendingGetChannel(text); } } else { mailboxContext.PendingRequestManager.AddPendingGetChannel(text); } } response.AppendHeader("X-OWA-EventResult", "0"); response.Write("{"); if (text != null) { response.Write("cid:\""); response.Write(text); response.Write("\","); } response.Write("syncFnshRq:"); response.Write(flag2 ? "1}" : "0}"); HttpUtilities.MakePageNoCacheNoStore(response); response.ContentType = HttpUtilities.GetContentTypeString(base.ResponseContentType); }
internal PendingRequestChannel AddPendingGetChannel(string channelId) { if (this.pendingRequestChannels != null) { lock (this.pendingRequestChannels) { if (this.pendingRequestChannels != null && this.pendingRequestChannels.Count <= 10 && !this.pendingRequestChannels.ContainsKey(channelId)) { PendingRequestChannel pendingRequestChannel = new PendingRequestChannel(this, channelId); this.pendingRequestChannels.Add(channelId, pendingRequestChannel); this.listenerChannelsManager.AddPendingGetChannel(channelId, this); if (this.userContext.ExchangePrincipal != null && !string.IsNullOrEmpty(this.userContext.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString())) { OwaServerLogger.AppendToLog(new PendingRequestChannelLogEvent(this.userContext.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), channelId)); } return(pendingRequestChannel); } } } return(null); }
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); }
protected override void InternalDispose(bool isDisposing) { if (!this.disposed && isDisposing) { try { OwaDiagnostics.SendWatsonReportsForGrayExceptions(delegate() { try { bool flag = false; try { flag = this.notifiersStateLock.LockWriterElastic(5000); } catch (OwaLockTimeoutException) { ExTraceGlobals.NotificationsCallTracer.TraceDebug((long)this.GetHashCode(), "Dispose was called but the writer lock is not available:"); return; } if (!flag) { ExTraceGlobals.NotificationsCallTracer.TraceDebug((long)this.GetHashCode(), "Dispose was called but the writer lock is not available:"); return; } foreach (KeyValuePair <IPendingRequestNotifier, PendingRequestManager.PendingNotifierState> keyValuePair in this.notifierDataAvailableState) { keyValuePair.Value.Dispose(); } this.notifierDataAvailableState = null; } finally { if (this.notifiersStateLock.IsWriterLockHeld) { this.notifiersStateLock.ReleaseWriterLock(); } } lock (this.pendingRequestChannels) { if (this.pendingRequestChannels != null) { foreach (string channelId in this.pendingRequestChannels.Keys) { PendingRequestChannel pendingGetChannel = this.GetPendingGetChannel(channelId); if (pendingGetChannel != null) { pendingGetChannel.Dispose(); } this.listenerChannelsManager.RemovePendingGetChannel(channelId); } } this.pendingRequestChannels.Clear(); this.pendingRequestChannels = null; } if (this.budget != null) { this.budget.Dispose(); this.budget = null; } }); } catch (GrayException ex) { ExTraceGlobals.NotificationsCallTracer.TraceError <string>(0L, "MapiNotificationHandlerBase.DisposeXSOObjects Unable to dispose object. exception {0}", ex.Message); } this.disposed = true; } }