private Subscription(StoreSession storeSession, StoreObjectId storeObjectId, AdviseFlags flags, NotificationHandler handler, NotificationCallbackMode callbackMode, bool passthruCallback) : this(storeSession, storeObjectId, handler, passthruCallback) { if (passthruCallback) { callbackMode = NotificationCallbackMode.Sync; } try { MapiNotificationHandler mapiNotificationHandler = new MapiNotificationHandler(this.sink.OnNotify); if (callbackMode == NotificationCallbackMode.Async) { mapiNotificationHandler = new MapiNotificationHandler(this.OnNotify); this.waitCallback = new WaitCallback(this.WaitCallbackProc); } this.adviseId = this.storeSession.Mailbox.Advise((storeObjectId == null) ? null : storeObjectId.ProviderLevelItemId, flags, mapiNotificationHandler, callbackMode); this.notificationSource = this.storeSession.Mailbox; } catch { this.Dispose(); throw; } }
internal MapiNotificationHandle Advise(byte[] entryId, AdviseFlags eventMask, MapiNotificationHandler handler, NotificationCallbackMode callbackMode) { StoreSession session = this.CoreObject.Session; object thisObject = null; bool flag = false; MapiNotificationHandle result; try { if (session != null) { session.BeginMapiCall(); session.BeginServerHealthCall(); flag = true; } if (StorageGlobals.MapiTestHookBeforeCall != null) { StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod()); } result = this.MapiStore.Advise(entryId, eventMask, handler, callbackMode, (MapiNotificationClientFlags)0); } catch (MapiPermanentException ex) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotAddNotification, ex, session, thisObject, "{0}. MapiException = {1}.", new object[] { string.Format("Mailbox::Advise.", new object[0]), ex }); } catch (MapiRetryableException ex2) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotAddNotification, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[] { string.Format("Mailbox::Advise.", new object[0]), ex2 }); } finally { try { if (session != null) { session.EndMapiCall(); if (flag) { session.EndServerHealthCall(); } } } finally { if (StorageGlobals.MapiTestHookAfterCall != null) { StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod()); } } } return(result); }