internal override void HandleNotificationInternal(Notification notif, MapiNotificationsLogEvent logEvent, object context)
        {
            NewMailNotification newMailNotification = notif as NewMailNotification;

            if (newMailNotification == null)
            {
                return;
            }
            if (newMailNotification.NewMailItemId == null || newMailNotification.ParentFolderId == null)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug((long)this.GetHashCode(), "notification has a null notifying item id");
                return;
            }
            StoreObjectId parentFolderId = newMailNotification.ParentFolderId;

            if (parentFolderId == null || newMailNotification.NewMailItemId == null)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug((long)this.GetHashCode(), "notification has a null notifying item id");
                return;
            }
            if (!parentFolderId.Equals(this.InboxFolderId))
            {
                return;
            }
            NewMailNotificationPayload newMailNotificationPayload = this.BindToItemAndCreatePayload(newMailNotification);

            if (newMailNotificationPayload != null)
            {
                this.newMailNotifier.Payload = newMailNotificationPayload;
                this.newMailNotifier.PickupData();
            }
        }
Ejemplo n.º 2
0
        protected override void HandleNotificatonInternal(BrokerNotification notification)
        {
            NewMailNotification newMailNotification = notification.Payload as NewMailNotification;

            if (newMailNotification == null)
            {
                return;
            }
            this.newMailNotifier.Payload = new NewMailNotificationPayload
            {
                SubscriptionId = newMailNotification.ConsumerSubscriptionId,
                ConversationId = newMailNotification.ConversationId,
                ItemId         = newMailNotification.ItemId,
                Sender         = newMailNotification.Sender,
                Subject        = newMailNotification.Subject,
                PreviewText    = newMailNotification.PreviewText,
                EventType      = newMailNotification.EventType
            };
            this.newMailNotifier.PickupData();
        }
Ejemplo n.º 3
0
        internal void HandleNewMailNotification(Notification notif)
        {
            if (Globals.ArePerfCountersEnabled)
            {
                OwaSingleCounters.TotalMailboxNotifications.Increment();
            }
            NewMailNotification newMailNotification = notif as NewMailNotification;

            if (newMailNotification == null)
            {
                return;
            }
            bool          flag          = false;
            StringBuilder stringBuilder = null;
            bool          flag2         = false;
            bool          flag3         = false;
            bool          flag4         = false;

            if (newMailNotification.NewMailItemId == null || newMailNotification.ParentFolderId == null)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug((long)this.GetHashCode(), "notification has a null notifying item id");
                return;
            }
            lock (this)
            {
                if (this.isDisposed || this.missedNotifications || this.needReinitSubscriptions)
                {
                    return;
                }
            }
            try
            {
                this.userContext.Lock();
                OwaMapiNotificationHandler.UpdateMailboxSessionBeforeAccessing(this.mailboxSession, this.userContext);
                lock (this)
                {
                    if ((this.flags & ClientSubscriptionFlags.NewMail) != ClientSubscriptionFlags.NewMail)
                    {
                        return;
                    }
                    if (newMailNotification.ParentFolderId == null || !newMailNotification.ParentFolderId.Equals(this.userContext.InboxFolderId))
                    {
                        return;
                    }
                    stringBuilder = new StringBuilder();
                    using (StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.InvariantCulture))
                    {
                        bool flag7 = false;
                        if (ObjectClass.IsVoiceMessage(newMailNotification.MessageClass))
                        {
                            flag3 = true;
                        }
                        else if (ObjectClass.IsOfClass(newMailNotification.MessageClass, "IPM.Note.Microsoft.Fax.CA"))
                        {
                            flag4 = true;
                        }
                        else
                        {
                            flag2 = true;
                        }
                        if (flag4)
                        {
                            flag7 = true;
                            if ((this.userContext.UserOptions.NewItemNotify & NewNotification.FaxToast) == NewNotification.FaxToast)
                            {
                                stringWriter.Write("shwNF(1);");
                                stringWriter.Write("g_sFId=\"");
                                Utilities.JavascriptEncode(newMailNotification.NewMailItemId.ToBase64String(), stringWriter);
                                stringWriter.Write("\";");
                                flag7 = this.BindItemAndShowDialog(newMailNotification.NewMailItemId, "lnkNwFx", stringWriter);
                            }
                            else
                            {
                                flag4 = false;
                            }
                        }
                        if (flag3)
                        {
                            flag7 = true;
                            if ((this.userContext.UserOptions.NewItemNotify & NewNotification.VoiceMailToast) == NewNotification.VoiceMailToast)
                            {
                                stringWriter.Write("shwNVM(1);");
                                stringWriter.Write("g_sVMId=\"");
                                Utilities.JavascriptEncode(newMailNotification.NewMailItemId.ToBase64String(), stringWriter);
                                stringWriter.Write("\";");
                                flag7 = this.BindItemAndShowDialog(newMailNotification.NewMailItemId, "lnkNwVMl", stringWriter);
                            }
                            else
                            {
                                flag3 = false;
                            }
                        }
                        if (flag2)
                        {
                            flag7 = true;
                            if ((this.userContext.UserOptions.NewItemNotify & NewNotification.EMailToast) == NewNotification.EMailToast)
                            {
                                stringWriter.Write("shwNM(1);");
                                stringWriter.Write("g_sMId=\"");
                                Utilities.JavascriptEncode(newMailNotification.NewMailItemId.ToBase64String(), stringWriter);
                                stringWriter.Write("\";");
                                flag7 = this.BindItemAndShowDialog(newMailNotification.NewMailItemId, "lnkNwMl", stringWriter);
                            }
                            else
                            {
                                flag2 = false;
                            }
                        }
                        if ((this.userContext.UserOptions.NewItemNotify & NewNotification.Sound) == NewNotification.Sound && flag7)
                        {
                            stringWriter.Write("plySnd();");
                        }
                    }
                }
                if (this.userContext.LockedByCurrentThread())
                {
                    Utilities.DisconnectStoreSession(this.mailboxSession);
                    this.userContext.Unlock();
                }
                if (flag4 || flag3 || flag2)
                {
                    this.emailPayload.AddNewMailPayload(stringBuilder);
                    this.emailPayload.PickupData();
                }
            }
            catch (OwaLockTimeoutException ex)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>((long)this.GetHashCode(), "User context lock timed out for notification thread. Exception: {0}", ex.Message);
                flag = true;
            }
            catch (Exception ex2)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>((long)this.GetHashCode(), "Unexpected exception in HandleNewMailNotification on the notification thread. Exception: {0}", ex2.Message);
                flag = true;
            }
            finally
            {
                if (flag)
                {
                    lock (this)
                    {
                        this.missedNotifications = true;
                    }
                }
                if (this.userContext.LockedByCurrentThread())
                {
                    Utilities.DisconnectStoreSessionSafe(this.mailboxSession);
                    this.userContext.Unlock();
                }
            }
        }
        protected NewMailNotificationPayload BindToItemAndCreatePayload(NewMailNotification notification)
        {
            NewMailNotificationPayload result;

            try
            {
                base.UserContext.LockAndReconnectMailboxSession(3000);
                MessageItem newMessage             = null;
                NewMailNotificationPayload payload = new NewMailNotificationPayload();
                payload.Source         = MailboxLocation.FromMailboxContext(base.UserContext);
                payload.SubscriptionId = base.SubscriptionId;
                try
                {
                    newMessage = Item.BindAsMessage(base.UserContext.MailboxSession, notification.NewMailItemId, this.GetAdditionalPropsToLoad());
                    ExchangeVersion.ExecuteWithSpecifiedVersion(ExchangeVersion.Exchange2012, delegate
                    {
                        payload.ItemId         = IdConverter.ConvertStoreItemIdToItemId(newMessage.Id, this.UserContext.MailboxSession).Id;
                        payload.ConversationId = IdConverter.ConversationIdToEwsId(this.UserContext.MailboxSession.MailboxGuid, newMessage.GetConversation(new PropertyDefinition[0]).ConversationId);
                    });
                    if (newMessage != null)
                    {
                        if (newMessage.From != null && newMessage.From.DisplayName != null)
                        {
                            payload.Sender = newMessage.From.DisplayName;
                        }
                        if (newMessage.Subject != null)
                        {
                            payload.Subject = newMessage.Subject;
                        }
                        string previewText = newMessage.Body.PreviewText;
                        if (previewText != null)
                        {
                            payload.PreviewText = previewText;
                        }
                        this.OnPayloadCreated(newMessage, payload);
                        result = payload;
                    }
                    else
                    {
                        result = null;
                    }
                }
                catch (ObjectNotFoundException)
                {
                    result = null;
                }
                finally
                {
                    if (newMessage != null)
                    {
                        newMessage.Dispose();
                    }
                }
            }
            finally
            {
                if (base.UserContext.MailboxSessionLockedByCurrentThread())
                {
                    base.UserContext.UnlockAndDisconnectMailboxSession();
                }
            }
            return(result);
        }