示例#1
0
        public static Subscription Create(StoreSession session, NotificationHandler handler, NotificationType notificationType, StoreId id, bool isSyncCallback, bool passthruCallback)
        {
            EnumValidator.ThrowIfInvalid <NotificationType>(notificationType, "notificationType");
            if (session == null)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>(0L, "Subscription::Create. {0} should not be null.", "session");
                throw new ArgumentNullException("session");
            }
            if (handler == null)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>(0L, "Subscription::Create. {0} should not be null.", "handler");
                throw new ArgumentNullException("handler");
            }
            if (id == null)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>(0L, "Subscription::Create. {0} should not be null.", "id");
                throw new ArgumentNullException("id");
            }
            if ((notificationType & NotificationType.ConnectionDropped) == NotificationType.ConnectionDropped)
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "Subscription::Create. ConnectionDropped not valid on object notifications.");
                throw new InvalidOperationException("ConnectionDropped not valid on object notifications.");
            }
            StoreObjectId            storeObjectId = StoreId.GetStoreObjectId(id);
            NotificationCallbackMode callbackMode  = isSyncCallback ? NotificationCallbackMode.Sync : NotificationCallbackMode.Async;

            return(Subscription.InternalCreate(session, handler, notificationType, storeObjectId, callbackMode, passthruCallback));
        }
示例#2
0
 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;
     }
 }
示例#3
0
        private static Subscription InternalCreate(StoreSession session, NotificationHandler handler, NotificationType notificationType, StoreObjectId storeObjectId, NotificationCallbackMode callbackMode, bool passthruCallback)
        {
            Subscription.CheckSubscriptionLimit(session);
            AdviseFlags adviseFlags = (AdviseFlags)0;

            if ((notificationType & NotificationType.NewMail) == NotificationType.NewMail)
            {
                adviseFlags |= AdviseFlags.NewMail;
            }
            if ((notificationType & NotificationType.Created) == NotificationType.Created)
            {
                adviseFlags |= AdviseFlags.ObjectCreated;
            }
            if ((notificationType & NotificationType.Deleted) == NotificationType.Deleted)
            {
                adviseFlags |= AdviseFlags.ObjectDeleted;
            }
            if ((notificationType & NotificationType.Modified) == NotificationType.Modified)
            {
                adviseFlags |= AdviseFlags.ObjectModified;
            }
            if ((notificationType & NotificationType.Moved) == NotificationType.Moved)
            {
                adviseFlags |= AdviseFlags.ObjectMoved;
            }
            if ((notificationType & NotificationType.Copied) == NotificationType.Copied)
            {
                adviseFlags |= AdviseFlags.ObjectCopied;
            }
            if ((notificationType & NotificationType.SearchComplete) == NotificationType.SearchComplete)
            {
                adviseFlags |= AdviseFlags.SearchComplete;
            }
            if ((notificationType & NotificationType.ConnectionDropped) == NotificationType.ConnectionDropped)
            {
                adviseFlags |= AdviseFlags.ConnectionDropped;
            }
            return(new Subscription(session, storeObjectId, adviseFlags, handler, callbackMode, passthruCallback));
        }
示例#4
0
        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);
        }