Example #1
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);
        }