private void SendApprovalRequest(ApprovalRequestWriter writer, ICollection <RoutingAddress> p1DecisionMakers, CultureInfo cultureInfo, string messageId, byte[] corelationBlob)
        {
            IList <RoutingAddress> decisionMakers = this.initiationMessage.DecisionMakers;

            byte[] conversationIndex = this.initiationMessageItem.ConversationIndex;
            (string)this.initiationMessage.Requestor;
            using (MessageItemApprovalRequest messageItemApprovalRequest = this.requestCreate(this.mbxTransportMailItem))
            {
                messageItemApprovalRequest.SetSender(this.approvalRequestSender);
                foreach (RoutingAddress routingAddress in decisionMakers)
                {
                    bool flag = p1DecisionMakers == null || p1DecisionMakers.Contains(routingAddress);
                    messageItemApprovalRequest.AddRecipient(routingAddress, flag);
                    InitiationProcessor.diag.TraceDebug <RoutingAddress, bool>(0L, "Added recipient '{0}' with promote to P1={1}.", routingAddress, flag);
                }
                CultureInfo cultureInfo2;
                if (!writer.WriteSubjectAndBody(messageItemApprovalRequest, cultureInfo, out cultureInfo2))
                {
                    InitiationProcessor.diag.TraceError <ApprovalRequestWriter>(0L, "Approval request body cannot be written with writer {0}", writer);
                }
                messageItemApprovalRequest.ApprovalRequestor = this.initiationMessage.Requestor;
                messageItemApprovalRequest.MessageItem[ItemSchema.NormalizedSubject] = this.initiationMessageItem.ConversationTopic;
                messageItemApprovalRequest.MessageItem.Importance = this.initiationMessageItem.Importance;
                messageItemApprovalRequest.MessageItem.References = InitiationProcessor.ConstructApprovalRequestReferences(this.initiationMessageItem);
                ConversationIndex o = ConversationIndex.CreateFromParent(conversationIndex);
                if (!ConversationIndex.Empty.Equals(o))
                {
                    messageItemApprovalRequest.MessageItem.ConversationIndex = o.ToByteArray();
                }
                if (cultureInfo2 != null)
                {
                    InitiationProcessor.diag.TraceDebug <CultureInfo>(0L, "Approval request written in {0}", cultureInfo2);
                    messageItemApprovalRequest.MessageItem[MessageItemSchema.MessageLocaleId] = cultureInfo2.LCID;
                }
                foreach (Attachment attachment in this.initiationMessage.EmailMessage.Attachments)
                {
                    messageItemApprovalRequest.AddAttachment(attachment, this.mbxTransportMailItem.ADRecipientCache.ADSession);
                }
                if (this.initiationMessage.EmailMessage.RootPart != null && this.initiationMessage.EmailMessage.RootPart.Headers != null)
                {
                    HeaderList headers = this.initiationMessage.EmailMessage.RootPart.Headers;
                    Header[]   array   = headers.FindAll("X-MS-Exchange-Inbox-Rules-Loop");
                    if (array != null && array.Length > 0)
                    {
                        string[] array2 = new string[array.Length];
                        for (int i = 0; i < array.Length; i++)
                        {
                            array2[i] = array[i].Value;
                        }
                        messageItemApprovalRequest.MessageItem.SafeSetProperty(MessageItemSchema.XLoop, array2);
                    }
                }
                InitiationProcessor.AddVotingToApprovalRequest(messageItemApprovalRequest, this.initiationMessage.VotingActions, cultureInfo2);
                messageItemApprovalRequest.Send(messageId, corelationBlob, this.mbxTransportMailItem);
            }
        }
        internal ApprovalEngine.ApprovalProcessResults PrepareApprovalRequestData()
        {
            this.initiationMessageItem.Load(InitiationProcessor.PropertiesFromInitiationForApprovalRequestCreation);
            this.CopyPropertiesToInitiationMessageFromMessageItem();
            string local = Guid.NewGuid().ToString();

            byte[] approvalTrackingBlob = Guid.NewGuid().ToByteArray();
            string domainPart           = this.approvalRequestSender.DomainPart;

            return(new ApprovalEngine.ApprovalProcessResults(ApprovalEngine.ProcessResult.InitiationMessageOk)
            {
                ApprovalTrackingBlob = approvalTrackingBlob,
                ApprovalRequestMessageId = ApprovalRequestWriter.FormatStoredApprovalRequestMessageId(local, domainPart),
                TotalDecisionMakers = this.initiationMessage.DecisionMakers.Count
            });
        }
        internal ApprovalEngine.ProcessResult CreateAndSubmitApprovalRequests(int?messageLocaleId)
        {
            this.initiationMessageItem.Load(InitiationProcessor.PropertiesFromInitiationForApprovalRequestCreation);
            this.CopyPropertiesToInitiationMessageFromMessageItem();
            this.initiationMessage.MessageItemLocale = messageLocaleId;
            ApprovalApplicationId?valueAsNullable = this.initiationMessageItem.GetValueAsNullable <ApprovalApplicationId>(MessageItemSchema.ApprovalApplicationId);
            string valueOrDefault = this.initiationMessageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalRequestMessageId);

            if (string.IsNullOrEmpty(valueOrDefault) || this.initiationMessageItem.VotingInfo == null)
            {
                return(ApprovalEngine.ProcessResult.Invalid);
            }
            string local;
            string domain;

            if (!FindMessageUtils.TryParseMessageId(valueOrDefault, out local, out domain))
            {
                return(ApprovalEngine.ProcessResult.Invalid);
            }
            byte[] messageCorrelationBlob = this.initiationMessageItem.VotingInfo.MessageCorrelationBlob;
            using (ApprovalRequestWriter instance = ApprovalRequestWriter.GetInstance(valueAsNullable, this.mbxTransportMailItem.OrganizationId, this.initiationMessage))
            {
                Dictionary <CultureInfo, List <RoutingAddress> > dictionary = null;
                if (instance.SupportMultipleRequestsForDifferentCultures && ApprovalProcessor.TryGetCulturesForDecisionMakers(this.initiationMessage.DecisionMakers, this.mbxTransportMailItem.ADRecipientCache.ADSession, this.organizationFallbackCulture, out dictionary))
                {
                    int num = 0;
                    using (Dictionary <CultureInfo, List <RoutingAddress> > .KeyCollection.Enumerator enumerator = dictionary.Keys.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            CultureInfo            cultureInfo = enumerator.Current;
                            IList <RoutingAddress> list        = dictionary[cultureInfo];
                            string text = ApprovalRequestWriter.FormatApprovalRequestMessageId(local, num++, domain, false);
                            this.SendApprovalRequest(instance, list, cultureInfo, text, messageCorrelationBlob);
                            InitiationProcessor.diag.TraceDebug <string, int, long>((long)this.GetHashCode(), "Approval request '{0}' submitted for {1} decision makers, init message internal id '{2}'", text, list.Count, this.mbxTransportMailItem.RecordId);
                        }
                        goto IL_19C;
                    }
                }
                string text2 = ApprovalRequestWriter.FormatApprovalRequestMessageId(local, 0, domain, false);
                this.SendApprovalRequest(instance, null, this.organizationFallbackCulture, text2, messageCorrelationBlob);
                InitiationProcessor.diag.TraceDebug <string, long>((long)this.GetHashCode(), "Approval request '{0}' submitted for all decision makers for init message with internal id '{1}'", text2, this.mbxTransportMailItem.RecordId);
                IL_19C :;
            }
            return(ApprovalEngine.ProcessResult.InitiationMessageOk);
        }
Exemple #4
0
        private static ApprovalRequestUpdater.Result FindAndUpdateExistingApprovalRequest(MessageItem updateMessage, int decision, string decisionMaker, ExDateTime decisionTime, string messageId)
        {
            bool   updated = false;
            string local;
            string domain;

            if (!FindMessageUtils.TryParseMessageId(messageId, out local, out domain))
            {
                return(ApprovalRequestUpdater.Result.InvalidUpdateMessage);
            }
            ApprovalRequestUpdater.diag.TraceDebug <string>(0L, "Update approval request: messageid={0}", messageId);
            MessageStatus messageStatus = StorageExceptionHandler.RunUnderExceptionHandler(ApprovalRequestUpdater.MessageConverterInstance, delegate
            {
                MailboxSession mailboxSession = (MailboxSession)updateMessage.Session;
                StoreObjectId storeObjectId   = null;
                for (int i = 0; i < 25; i++)
                {
                    string internetMessageId  = ApprovalRequestWriter.FormatApprovalRequestMessageId(local, i, domain, false);
                    IStorePropertyBag[] array = AllItemsFolderHelper.FindItemsFromInternetId(mailboxSession, internetMessageId, new PropertyDefinition[]
                    {
                        ItemSchema.Id
                    });
                    if (array != null && array.Length > 0)
                    {
                        ApprovalRequestUpdater.diag.TraceDebug <int>(0L, "Found {0} to update, picking the first.", array.Length);
                        storeObjectId = ((VersionedId)array[0][ItemSchema.Id]).ObjectId;
                        break;
                    }
                }
                if (storeObjectId != null)
                {
                    using (MessageItem messageItem = MessageItem.Bind(mailboxSession, storeObjectId))
                    {
                        if (ApprovalRequestUpdater.VerifyAndUpdateApprovalRequest(mailboxSession, updateMessage.Sender, decision, decisionMaker, decisionTime, messageItem))
                        {
                            ConflictResolutionResult conflictResolutionResult = messageItem.Save(SaveMode.ResolveConflicts);
                            if (conflictResolutionResult.SaveStatus != SaveResult.Success)
                            {
                                ApprovalRequestUpdater.diag.TraceDebug <string, SaveResult>(0L, "Saving message: {0}, resulted in an update conflict ({1}). Ignored", messageId, conflictResolutionResult.SaveStatus);
                            }
                            AggregateOperationResult aggregateOperationResult = mailboxSession.Delete(DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                            {
                                storeObjectId
                            });
                            if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
                            {
                                ApprovalRequestUpdater.diag.TraceDebug <string, OperationResult>(0L, "Delete message: {0}, resulted in failure {1} Ignored", messageId, aggregateOperationResult.OperationResult);
                            }
                            updated = true;
                        }
                    }
                }
            });

            if (!updated)
            {
                ApprovalRequestUpdater.diag.TraceDebug <string>(0L, "Couldn't find message: {0}, ignored", messageId);
                return(ApprovalRequestUpdater.Result.NotFound);
            }
            if (MessageStatus.Success != messageStatus)
            {
                ApprovalRequestUpdater.diag.TraceDebug <string, string>(0L, "Message ({0}) processing was not successful ({1}), ignoring..", messageId, (messageStatus.Exception == null) ? "NULL exception" : messageStatus.Exception.Message);
                return(ApprovalRequestUpdater.Result.SaveConflict);
            }
            return(ApprovalRequestUpdater.Result.UpdatedSucessfully);
        }