public static void SaveUserOofSettings(MailboxSession itemStore, UserOofSettings userOofSettings)
        {
            UserOofSettingsSerializer o = UserOofSettingsSerializer.Serialize(userOofSettings);

            using (StringWriter stringWriter = new StringWriter())
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings
                {
                    CheckCharacters = false
                }))
                {
                    UserOofSettingsSerializer.Serializer.Serialize(xmlWriter, o);
                    string      body        = stringWriter.ToString();
                    VersionedId versionedId = UserOofSettingsStorage.settingsStorageHandler.SetItemContent(itemStore, body);
                    itemStore.Mailbox[MailboxSchema.UserOofSettingsItemId] = versionedId.ObjectId.ProviderLevelItemId;
                }
            }
            UserOofSettingsStorage.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0}: Adding OOF rules", itemStore.MailboxOwner);
            using (RuleGenerator ruleGenerator = new RuleGenerator(itemStore, userOofSettings))
            {
                ruleGenerator.OnUserOofSettingsChanges();
            }
            UserOofSettingsStorage.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0}: OOF rules added, setting OOF mailbox table properties.", itemStore.MailboxOwner);
            OofStateHandler.Set(itemStore, userOofSettings.OofState == OofState.Enabled, (userOofSettings.UserChangeTime != null) ? userOofSettings.UserChangeTime.Value : DateTime.UtcNow);
            itemStore.Mailbox[MailboxSchema.OofScheduleStart] = ((userOofSettings.OofState == OofState.Scheduled) ? ((ExDateTime)userOofSettings.StartTime) : UserOofSettingsStorage.Date1601Utc);
            itemStore.Mailbox[MailboxSchema.OofScheduleEnd]   = ((userOofSettings.OofState == OofState.Scheduled) ? ((ExDateTime)userOofSettings.EndTime) : UserOofSettingsStorage.Date1601Utc);
            itemStore.Mailbox.Save();
            itemStore.Mailbox.Load();
        }
Esempio n. 2
0
        private void HandleSenderGroupRule(Rule rule, bool senderGroupEnabled, ReplyBody reply, string ruleName, string messageClass, OofReplyType oofReplyType, RuleGenerator.ConditionType conditionType, int sequenceNumber, OofState mailboxOofState)
        {
            int i = 0;

            while (i < 5)
            {
                i++;
                try
                {
                    if (rule == null)
                    {
                        if (senderGroupEnabled && !RuleGenerator.IsEmptyString(reply.RawMessage))
                        {
                            this.CreateOofRule(reply, ruleName, messageClass, oofReplyType, conditionType, sequenceNumber);
                        }
                        else
                        {
                            RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Sender group '{1}' and rule doesn't exist. Nothing to do.", this.itemStore.MailboxOwner, ruleName);
                        }
                    }
                    else if (senderGroupEnabled && !RuleGenerator.IsEmptyString(reply.RawMessage))
                    {
                        this.UpdateOofRule(rule, reply, ruleName, messageClass, oofReplyType, conditionType, sequenceNumber, mailboxOofState);
                    }
                    else
                    {
                        this.ruleManager.Remove(rule);
                    }
                    break;
                }
                catch (SaveConflictException ex)
                {
                    if (i == 5)
                    {
                        RuleGenerator.Tracer.TraceError <IExchangePrincipal, int, SaveConflictException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retried {2} times, rethrowing", this.itemStore.MailboxOwner, 5, ex);
                        throw;
                    }
                    RuleGenerator.Tracer.TraceError <IExchangePrincipal, SaveConflictException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retrying", this.itemStore.MailboxOwner, ex);
                }
                catch (ObjectNotFoundException ex2)
                {
                    if (i == 5)
                    {
                        RuleGenerator.Tracer.TraceError <IExchangePrincipal, int, ObjectNotFoundException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retried {2} times, rethrowing", this.itemStore.MailboxOwner, 5, ex2);
                        throw;
                    }
                    RuleGenerator.Tracer.TraceError <IExchangePrincipal, ObjectNotFoundException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retrying", this.itemStore.MailboxOwner, ex2);
                }
            }
        }