protected virtual MessageStatus RunUnderStorageExceptionHandler(StoreDriverDelegate action) { return(StorageExceptionHandler.RunUnderExceptionHandler(this.mailItemDeliver, action)); }
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); }