示例#1
0
 private void HandleResults(ApprovalEngine.ApprovalProcessResults resultInfo, MessageItem messageItem, MbxTransportMailItem rmi, MailRecipient recipient)
 {
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationMessageOk)
     {
         messageItem.VotingInfo.MessageCorrelationBlob              = resultInfo.ApprovalTrackingBlob;
         messageItem[MessageItemSchema.ApprovalRequestMessageId]    = resultInfo.ApprovalRequestMessageId;
         messageItem[MessageItemSchema.ApprovalDecisionMakersNdred] = NdrOofHandler.FormatNdrOofProperty(resultInfo.TotalDecisionMakers, 0, 0);
         messageItem[MessageItemSchema.ApprovalStatus]              = ApprovalStatus.Unhandled;
         this.perfCounter.InitiationMessages.Increment();
         return;
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.UnauthorizedMessage)
     {
         throw new SmtpResponseException(AckReason.ApprovalUnAuthorizedMessage);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationMessageDuplicate)
     {
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalDuplicateInitiation, base.Name);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.DecisionMarked)
     {
         this.perfCounter.DecisionUsed.Increment();
         this.perfCounter.DecisionMessages.Increment();
         this.perfCounter.DecisionInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds);
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalDecisionSuccsess, base.Name);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationNotFoundForDecision || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.DecisionAlreadyMade)
     {
         byte[] conversationIndex = messageItem.ConversationIndex;
         string threadIndex       = Convert.ToBase64String(ConversationIndex.CreateFromParent(conversationIndex).ToByteArray());
         this.SendNotifications(recipient.Email, (RoutingAddress)rmi.Message.Sender.SmtpAddress, rmi, threadIndex, messageItem.ConversationTopic, resultInfo.ExistingDecisionMakerAddress, resultInfo.ExistingApprovalStatus, resultInfo.ExistingDecisionTime);
         this.perfCounter.DecisionMessages.Increment();
         this.perfCounter.DecisionInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds);
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalDecisionSuccsess, base.Name);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdated || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdateSkipped || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationNotFoundForNdrOrOof || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofInvalid)
     {
         this.perfCounter.TotalNdrOofHandled.Increment();
         if (resultInfo.ProcessResults != ApprovalEngine.ProcessResult.NdrOrOofInvalid)
         {
             this.perfCounter.TotalSearchesForInitiationBasedOnNdrAndOof.Increment();
             this.perfCounter.NdrOofInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds);
         }
         if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdated)
         {
             this.perfCounter.TotalNdrOofUpdated.Increment();
         }
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalNdrOofUpdateSuccess, base.Name);
     }
     throw new SmtpResponseException(AckReason.ApprovalInvalidMessage);
 }
示例#2
0
        private bool WriteToInitiationMessage(MailboxSession session, StoreObjectId storeId, string initMessageId)
        {
            ConflictResolutionResult conflictResolutionResult = null;

            try
            {
                for (int i = 0; i < 5; i++)
                {
                    using (MessageItem messageItem = MessageItem.Bind(session, storeId, NdrOofHandler.PropertiesNeededToUpdateInitiation))
                    {
                        messageItem.OpenAsReadWrite();
                        string         ndrOofValue     = (string)messageItem[MessageItemSchema.ApprovalDecisionMakersNdred];
                        ApprovalStatus?valueAsNullable = messageItem.GetValueAsNullable <ApprovalStatus>(MessageItemSchema.ApprovalStatus);
                        if (valueAsNullable == null)
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Invalid approval status property in initation message {0}. Ignored", initMessageId);
                            return(false);
                        }
                        if ((valueAsNullable & (ApprovalStatus.Approved | ApprovalStatus.Rejected)) != (ApprovalStatus)0)
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "There is already a decision for {0}, there is no need to handle NDR or OOF", initMessageId);
                            return(false);
                        }
                        int num;
                        int num2;
                        int num3;
                        if (!NdrOofHandler.TryParseNdrOofProperty(ndrOofValue, out num, out num2, out num3))
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Invalid ndr/oof property in initation message {0}. Ignored", initMessageId);
                            return(false);
                        }
                        int num4;
                        int num5;
                        this.GetNdrOrOofCountInMessage(out num4, out num5);
                        num2 += num4;
                        num3 += num5;
                        messageItem[MessageItemSchema.ApprovalDecisionMakersNdred] = NdrOofHandler.FormatNdrOofProperty(num, num2, num3);
                        if (num3 + num2 == num)
                        {
                            if (num3 == 0)
                            {
                                messageItem[MessageItemSchema.ApprovalStatus] = (valueAsNullable.Value | ApprovalStatus.Ndred);
                            }
                            else
                            {
                                messageItem[MessageItemSchema.ApprovalStatus] = (valueAsNullable.Value | ApprovalStatus.Oofed);
                            }
                        }
                        conflictResolutionResult = messageItem.Save(SaveMode.ResolveConflicts);
                        if (SaveResult.IrresolvableConflict != conflictResolutionResult.SaveStatus)
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Saved initiation message '{0}' successfully.", initMessageId);
                            return(true);
                        }
                        NdrOofHandler.diag.TraceDebug <string, int, SaveResult>((long)this.GetHashCode(), "Saving message: '{0}' try {1}, resulted in an update conflict ({2}).", initMessageId, i, conflictResolutionResult.SaveStatus);
                    }
                }
            }
            catch (ObjectNotFoundException arg)
            {
                NdrOofHandler.diag.TraceDebug <string, ObjectNotFoundException>((long)this.GetHashCode(), "Initiation Message '{0}' is no longer there {1}", initMessageId, arg);
                return(false);
            }
            NdrOofHandler.diag.TraceDebug <string, SaveResult>((long)this.GetHashCode(), "Saving message failed after all retries. Init MessageId={0}, Save status={1}", initMessageId, conflictResolutionResult.SaveStatus);
            return(false);
        }