private void SubscribeForSearchComplete(OwaSearchContext searchContext)
 {
     ExTraceGlobals.NotificationsCallTracer.TraceDebug((long)this.GetHashCode(), "SearchNotificationHandler.SubscribeForSearchComplete Start");
     if (base.IsDisposed)
     {
         return;
     }
     try
     {
         StoreObjectId storeObjectId = StoreId.GetStoreObjectId(searchContext.SearchFolderId);
         base.UserContext.LockAndReconnectMailboxSession(3000);
         if (base.Subscription != null)
         {
             MapiNotificationHandlerBase.DisposeXSOObjects(base.Subscription, base.UserContext);
             base.Subscription = null;
         }
         this.currentSearchContext = searchContext;
         base.Subscription         = Subscription.Create(base.UserContext.MailboxSession, this.GetDefaultNotificationHandler(this.currentSearchContext), NotificationType.SearchComplete, storeObjectId);
     }
     catch (OwaLockTimeoutException ex)
     {
         ExTraceGlobals.CoreCallTracer.TraceError <string>((long)this.GetHashCode(), "User context lock timed out in SubscribeForSearchComplete. Exception: {0}", ex.Message);
     }
     finally
     {
         if (base.UserContext.MailboxSessionLockedByCurrentThread())
         {
             base.UserContext.UnlockAndDisconnectMailboxSession();
         }
     }
 }
 internal virtual void DisposeSubscriptions(bool disposeQueryResult)
 {
     try
     {
         OwaDiagnostics.SendWatsonReportsForGrayExceptions(delegate()
         {
             try
             {
                 ExTraceGlobals.NotificationsCallTracer.TraceDebug <bool, Type>((long)this.GetHashCode(), "MapiNotificationHandlerBase.DisposeInternal. doNotDisposeQueryResult: {0}, Type: {1}", disposeQueryResult, this.GetType());
                 if (disposeQueryResult && this.result != null)
                 {
                     MapiNotificationHandlerBase.DisposeXSOObjects(this.result, this.UserContext);
                     this.result = null;
                 }
                 if (this.mapiSubscription != null)
                 {
                     MapiNotificationHandlerBase.DisposeXSOObjects(this.mapiSubscription, this.UserContext);
                     this.mapiSubscription = null;
                 }
             }
             catch (StoragePermanentException ex2)
             {
                 ExTraceGlobals.NotificationsCallTracer.TraceError <string, SmtpAddress, Type>((long)this.GetHashCode(), "Unexpected exception in MapiNotificationHandlerBase Dispose. User: {1}. Exception: {0}, type: {2}", ex2.Message, this.UserContext.PrimarySmtpAddress, this.GetType());
             }
             catch (StorageTransientException ex3)
             {
                 ExTraceGlobals.NotificationsCallTracer.TraceError <string, SmtpAddress, Type>((long)this.GetHashCode(), "Unexpected exception in MapiNotificationHandlerBase Dispose. User: {1}. Exception: {0}, type: {2}", ex3.Message, this.UserContext.PrimarySmtpAddress, this.GetType());
             }
         });
     }
     catch (GrayException ex)
     {
         ExTraceGlobals.NotificationsCallTracer.TraceError <string>(0L, "MapiNotificationHandlerBase.Dispose Unable to dispose object.  exception {0}", ex.Message);
     }
 }
 protected override void InternalDispose(bool isDisposing)
 {
     ExTraceGlobals.NotificationsCallTracer.TraceDebug <bool, SmtpAddress, Type>((long)this.GetHashCode(), "UnseenItemNotificationHandler.Dispose. IsDisposing: {0}, User: {1}, Type: {2}", isDisposing, base.UserContext.PrimarySmtpAddress, base.GetType());
     lock (base.SyncRoot)
     {
         if (isDisposing && this.unseenItemsReader != null)
         {
             MapiNotificationHandlerBase.DisposeXSOObjects(this.unseenItemsReader, base.UserContext);
             this.unseenItemsReader = null;
         }
         base.InternalDispose(isDisposing);
     }
 }
 private void CleanupSubscriptions()
 {
     if (this.Subscription != null)
     {
         MapiNotificationHandlerBase.DisposeXSOObjects(this.Subscription, this.UserContext);
     }
     this.Subscription = null;
     if (this.QueryResult != null)
     {
         MapiNotificationHandlerBase.DisposeXSOObjects(this.QueryResult, this.UserContext);
     }
     this.QueryResult = null;
 }
        protected void InitSubscription()
        {
            MapiNotificationsLogEvent logEvent = new MapiNotificationsLogEvent(this.UserContext.ExchangePrincipal, this.UserContext.Key.ToString(), this, this.EventPrefix + "InitSubscription");

            if (this.IsDisposed_Reentrant)
            {
                return;
            }
            try
            {
                this.userContext.LockAndReconnectMailboxSession(3000);
                this.NeedRefreshPayload = false;
                if (this.NeedToReinitSubscriptions)
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceDebug <Type>((long)this.GetHashCode(), "MapiNotificationHandlerBase.InitSubscription need to cleanup subscription before reinit for type: {0}", base.GetType());
                    this.CleanupSubscriptions();
                    this.NeedRefreshPayload = true;
                }
                if (this.Subscription == null)
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceDebug <Type, SmtpAddress>((long)this.GetHashCode(), "Notification Handler type: {0} needs to init subscriptions. User: {1}", base.GetType(), this.UserContext.PrimarySmtpAddress);
                    if (this.QueryResult != null)
                    {
                        MapiNotificationHandlerBase.DisposeXSOObjects(this.QueryResult, this.UserContext);
                    }
                    this.QueryResult = null;
                    this.InitSubscriptionInternal();
                    ExTraceGlobals.NotificationsCallTracer.TraceDebug <Type>((long)this.GetHashCode(), "MapiNotificationHandlerBase.InitSubscription subscription successfully initialized for type: {0}", base.GetType());
                }
                this.NeedToReinitSubscriptions = false;
            }
            finally
            {
                if (this.userContext.MailboxSessionLockedByCurrentThread())
                {
                    this.userContext.UnlockAndDisconnectMailboxSession();
                }
                if (this.ShouldLog(logEvent))
                {
                    OwaServerTraceLogger.AppendToLog(logEvent);
                }
            }
        }
 internal MapiNotificationsLogEvent(ExchangePrincipal exchangePrincipal, string userContext, MapiNotificationHandlerBase notificationHandler, string methodName)
 {
     if (!Globals.Owa2ServerUnitTestsHook && exchangePrincipal == null)
     {
         throw new ArgumentNullException("exchangePrincipal");
     }
     if (notificationHandler == null)
     {
         throw new ArgumentNullException("notificationHandler");
     }
     this.exchangePrincipal   = exchangePrincipal;
     this.userContext         = (userContext ?? string.Empty);
     this.notificationHandler = notificationHandler;
     this.MethodName          = (methodName ?? string.Empty);
 }
 // Token: 0x06000E95 RID: 3733 RVA: 0x00037AA3 File Offset: 0x00035CA3
 private void WireConnectionDroppedHandler(MapiNotificationHandlerBase handler)
 {
     this.InitializeConnectionDroppedHandler();
     this.connectionDroppedNotificationHandler.OnConnectionDropped += handler.HandleConnectionDroppedNotification;
 }
 public SubscriptionContextHolder(MapiNotificationHandlerBase parent, object context)
 {
     this.parent  = parent;
     this.context = context;
 }