private List <string> GetTargetUsers(MessageItem item, Participant[] participantsOnOriginalMessage, IWorkingSetPublisherPerformanceTracker performanceTracker)
        {
            List <string> list      = new List <string>(this.groupsCache[item.Session.MailboxGuid].TargetUsers.Count);
            Stopwatch     stopwatch = new Stopwatch();

            stopwatch.Start();
            if (this.groupsCache[item.Session.MailboxGuid].TargetUsers.Count > 0)
            {
                foreach (string text in this.groupsCache[item.Session.MailboxGuid].TargetUsers)
                {
                    Participant participant = new Participant.Builder
                    {
                        EmailAddress = text,
                        RoutingType  = "EX"
                    }.ToParticipant();
                    if (participant.ExistIn(participantsOnOriginalMessage))
                    {
                        performanceTracker.IncrementParticipantsSkippedInPublishedMessage();
                    }
                    else
                    {
                        list.Add(text);
                        performanceTracker.IncrementParticipantsAddedToPublishedMessage();
                    }
                }
            }
            stopwatch.Stop();
            performanceTracker.DedupeParticipantsMilliseconds = stopwatch.ElapsedMilliseconds;
            return(list);
        }
Esempio n. 2
0
        public bool EscalateItem(IMessageItem item, IMailboxSession mailboxSession, out bool isTransientError, bool isFromYammer = false)
        {
            Util.ThrowOnNullArgument(item, "item");
            Util.ThrowOnNullArgument(mailboxSession, "mailboxSession");
            isTransientError = false;
            string        yammerEscalateAddress;
            List <string> escalatedUsersList = this.GetEscalatedUsersList(mailboxSession, out yammerEscalateAddress);
            bool          flag = GroupEscalation.ShouldEscalateToYammer(isFromYammer, yammerEscalateAddress, item.ClassName);

            if (escalatedUsersList.Count < 1 && !flag)
            {
                GroupEscalation.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalation.EscalateItem: Skipping Escalation as there are no users in need to escalate");
                return(true);
            }
            bool result = false;
            IExtensibleLogger logger = GroupEscalateItemDiagnosticsFrameFactory.Default.CreateLogger(mailboxSession.MailboxGuid, mailboxSession.OrganizationId);
            IGroupEscalateItemPerformanceTracker groupEscalateItemPerformanceTracker = GroupEscalateItemDiagnosticsFrameFactory.Default.CreatePerformanceTracker(mailboxSession);

            using (GroupEscalateItemDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("XSO", "EscalateItem", logger, groupEscalateItemPerformanceTracker))
            {
                try
                {
                    if (item.From != null)
                    {
                        groupEscalateItemPerformanceTracker.OriginalMessageSender = (item.From.EmailAddress ?? string.Empty);
                        groupEscalateItemPerformanceTracker.OriginalMessageSenderRecipientType = ((item.From.Origin != null) ? item.From.Origin.ToString() : string.Empty);
                        groupEscalateItemPerformanceTracker.OriginalMessageClass      = (item.ClassName ?? string.Empty);
                        groupEscalateItemPerformanceTracker.OriginalMessageId         = ((item.Id != null) ? item.Id.ToBase64String() : string.Empty);
                        groupEscalateItemPerformanceTracker.OriginalInternetMessageId = (item.InternetMessageId ?? string.Empty);
                    }
                    StoreObjectId escalationFolderId = GroupEscalation.GetEscalationFolderId(mailboxSession);
                    using (IMessageItem messageItem = this.CreateEscalationMessage(mailboxSession, escalationFolderId, item))
                    {
                        ExDateTime?valueOrDefault = item.PropertyBag.GetValueOrDefault <ExDateTime?>(ItemSchema.SentTime);
                        if (valueOrDefault != null)
                        {
                            messageItem[InternalSchema.OriginalSentTimeForEscalation] = valueOrDefault;
                        }
                        else
                        {
                            this.TraceAndLogError(logger, "EscalateItem", "GroupEscalation.EscalateItem: Couldn't find client submit time.");
                        }
                        IExchangePrincipal mailboxOwner = mailboxSession.MailboxOwner;
                        Participant        participant  = new Participant(mailboxOwner);
                        if (!ObjectClass.IsMeetingMessage(messageItem.ClassName))
                        {
                            messageItem.Sender = participant;
                        }
                        messageItem.SuppressAllAutoResponses();
                        messageItem.IsGroupEscalationMessage = true;
                        Participant[] array = new Participant[messageItem.Recipients.Count];
                        int           num   = 0;
                        foreach (Recipient recipient in messageItem.Recipients)
                        {
                            recipient[ItemSchema.Responsibility] = false;
                            array[num] = recipient.Participant;
                            num++;
                        }
                        groupEscalateItemPerformanceTracker.ParticipantsInOriginalMessage = array.Length;
                        List <Participant> list      = new List <Participant>(array);
                        Stopwatch          stopwatch = new Stopwatch();
                        stopwatch.Start();
                        if (!participant.ExistIn(array))
                        {
                            Recipient recipient2 = messageItem.Recipients.Add(participant, RecipientItemType.To);
                            list.Add(participant);
                            recipient2[ItemSchema.Responsibility] = false;
                            groupEscalateItemPerformanceTracker.IsGroupParticipantAddedToParticipants = true;
                        }
                        stopwatch.Stop();
                        groupEscalateItemPerformanceTracker.EnsureGroupParticipantAddedMilliseconds = stopwatch.ElapsedMilliseconds;
                        stopwatch.Reset();
                        stopwatch.Start();
                        bool flag2 = false;
                        foreach (string emailAddress in escalatedUsersList)
                        {
                            Participant participant2 = new Participant.Builder
                            {
                                EmailAddress = emailAddress,
                                RoutingType  = "EX"
                            }.ToParticipant();
                            if (!participant2.ExistIn(array))
                            {
                                Recipient recipient3 = messageItem.Recipients.Add(participant2, RecipientItemType.Bcc);
                                recipient3[ItemSchema.Responsibility] = true;
                                flag2 = true;
                                groupEscalateItemPerformanceTracker.IncrementParticipantsAddedToEscalatedMessage();
                            }
                            else
                            {
                                groupEscalateItemPerformanceTracker.IncrementParticipantsSkippedInEscalatedMessage();
                            }
                        }
                        stopwatch.Stop();
                        groupEscalateItemPerformanceTracker.DedupeParticipantsMilliseconds = stopwatch.ElapsedMilliseconds;
                        groupEscalateItemPerformanceTracker.HasEscalatedUser = flag2;
                        if (!flag2 && !flag)
                        {
                            GroupEscalation.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalation.EscalateItem: Skipping Escalation as there are no additional users in need to escalate");
                            return(true);
                        }
                        messageItem.MarkRecipientAsSubmitted(list.ToArray());
                        if (flag)
                        {
                            this.EscalateMessageToYammer(mailboxSession, logger, groupEscalateItemPerformanceTracker, yammerEscalateAddress, flag2, escalationFolderId, messageItem);
                        }
                        if (flag2)
                        {
                            this.InsertUnsubscribeLinkToBody(groupEscalateItemPerformanceTracker, logger, mailboxOwner, item, messageItem);
                            this.SendEscalateMessage(messageItem);
                        }
                        result = true;
                    }
                }
                catch (StoragePermanentException arg)
                {
                    this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation failed. Got store permanent exception: {0}", arg));
                }
                catch (StorageTransientException arg2)
                {
                    this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation failed. Got store transient exception: {0}", arg2));
                    isTransientError = true;
                }
                catch (Exception arg3)
                {
                    this.TraceAndLogError(logger, "EscalateItem", string.Format("GroupEscalation.EscalateItem: Escalation failed. Got exception: {0}", arg3));
                    throw;
                }
            }
            return(result);
        }