/// <summary>
 /// Tries to read element from XML.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns>True if appropriate element was read.</returns>
 internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
 {
     switch (reader.LocalName)
     {
         case XmlElementNames.OofState:
             this.state = reader.ReadValue<OofState>();
             return true;
         case XmlElementNames.ExternalAudience:
             this.externalAudience = reader.ReadValue<OofExternalAudience>();
             return true;
         case XmlElementNames.Duration:
             this.duration = new TimeWindow();
             this.duration.LoadFromXml(reader);
             return true;
         case XmlElementNames.InternalReply:
             this.internalReply = new OofReply();
             this.internalReply.LoadFromXml(reader, reader.LocalName);
             return true;
         case XmlElementNames.ExternalReply:
             this.externalReply = new OofReply();
             this.externalReply.LoadFromXml(reader, reader.LocalName);
             return true;
         default:
             return false;
     }
 }
        /// <summary>
        /// Tries to read element from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>True if appropriate element was read.</returns>
        internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
        {
            switch (reader.LocalName)
            {
            case XmlElementNames.OofState:
                this.state = reader.ReadValue <OofState>();
                return(true);

            case XmlElementNames.ExternalAudience:
                this.externalAudience = reader.ReadValue <OofExternalAudience>();
                return(true);

            case XmlElementNames.Duration:
                this.duration = new TimeWindow();
                this.duration.LoadFromXml(reader);
                return(true);

            case XmlElementNames.InternalReply:
                this.internalReply = new OofReply();
                this.internalReply.LoadFromXml(reader, reader.LocalName);
                return(true);

            case XmlElementNames.ExternalReply:
                this.externalReply = new OofReply();
                this.externalReply.LoadFromXml(reader, reader.LocalName);
                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service"></param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlElementNames.OofState:
                    this.state = jsonProperty.ReadEnumValue <OofState>(key);
                    break;

                case XmlElementNames.ExternalAudience:
                    this.externalAudience = jsonProperty.ReadEnumValue <OofExternalAudience>(key);
                    break;

                case XmlElementNames.Duration:
                    this.duration = new TimeWindow();
                    this.duration.LoadFromJson(jsonProperty.ReadAsJsonObject(key), service);
                    break;

                case XmlElementNames.InternalReply:
                    this.internalReply = new OofReply();
                    this.internalReply.LoadFromJson(jsonProperty.ReadAsJsonObject(key), service);
                    break;

                case XmlElementNames.ExternalReply:
                    this.externalReply = new OofReply();
                    this.externalReply.LoadFromJson(jsonProperty.ReadAsJsonObject(key), service);
                    break;

                default:
                    break;
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Certain controls need to be enabled or disabled depending on the
        /// selected OofState.
        /// </summary>
        /// <param name="state">OofState for the form to display</param>
        private void EnableControlsForOofState(OofState state)
        {
            // Both Scheduled and Enabled mean that OOF is enabled
            bool isEnabled = state == OofState.Enabled || state == OofState.Scheduled;

            this.OofScheduledCheck.Enabled         = isEnabled;
            this.InternalReplyText.ReadOnly        = !isEnabled;
            this.InternalReplyCulture.Enabled      = isEnabled;
            this.InternalReplyCultureLabel.Enabled = isEnabled;
            this.ExternalReplyText.ReadOnly        = !isEnabled;
            this.ExternalReplyCulture.Enabled      = isEnabled;
            this.ExternalReplyCultureLabel.Enabled = isEnabled;
            this.externalAudienceCombo.Enabled     = isEnabled;
            this.ExternalAudienceLabel.Enabled     = isEnabled;

            // Greying out the text boxes when ReadOnly is more intuitive
            System.Drawing.Color textBoxColor = isEnabled ?
                                                System.Drawing.Color.FromKnownColor(KnownColor.Window) :
                                                System.Drawing.Color.FromKnownColor(KnownColor.Control);
            this.InternalReplyText.BackColor = textBoxColor;
            this.ExternalReplyText.BackColor = textBoxColor;

            // Set these controls specific to the Scheduled state
            bool isScheduled = state == OofState.Scheduled;

            this.ScheduleStartTimeLabel.Enabled = isScheduled;
            this.ScheduledStartTime.Enabled     = isScheduled;
            this.ScheduleEndTimeLabel.Enabled   = isScheduled;
            this.ScheduledEndTime.Enabled       = isScheduled;
        }
        public static void GetOOF(ExchangeService service)
        {
            // Return the Out Of Office object that contains OOF state for the user whose credendials were supplied at the console.
            // This method will result in a call to the Exchange Server.
            OofSettings userOOFSettings = service.GetUserOofSettings(UserDataFromConsole.GetUserData().EmailAddress);

            // Get the (read-only) audience of email message senders outside a client's organization who will receive automatic Out Of Office replies ("All", "Known", or "None").
            OofExternalAudience allowedExternalAudience = userOOFSettings.AllowExternalOof;

            // Get the duration for a scheduled Out Of Office reply.
            TimeWindow OOFDuration = userOOFSettings.Duration;

            // Get the ExternalAudience of email message senders outside a client's organization who will receive automatic Out OF Office replies (All/Known/None).
            OofExternalAudience externalAudience = userOOFSettings.ExternalAudience;

            // Get the reply to be sent to email message senders outside a client's organization.
            OofReply externalReply = userOOFSettings.ExternalReply;

            // Get the reply to be sent to email message senders inside a client's organization.
            OofReply internalReply = userOOFSettings.InternalReply;

            // Get the (Disabled/Enabled/Scheduled) state of the Out Of Office automatic reply feature.
            OofState userOofState = userOOFSettings.State;

            // Print user status information to the console
            Console.WriteLine("Allowed External Audience: {0}", allowedExternalAudience);
            Console.WriteLine("Out of Office duration: {0}", OOFDuration);
            Console.WriteLine("External Audience: {0}", externalAudience);
            Console.WriteLine("External Reply: {0}", externalReply);
            Console.WriteLine("Internal Reply: {0}", internalReply);
            Console.WriteLine("User OOF state: {0}", userOofState);
        }
Exemple #6
0
        //gavdcodeend 13

        //gavdcodebegin 14
        static void GetOutOfOfficeConfig(ExchangeService ExService)
        {
            OofSettings myOOFConfig = ExService.GetUserOofSettings("*****@*****.**");

            OofExternalAudience myAllowedExternalAudience = myOOFConfig.AllowExternalOof;

            Console.WriteLine(myAllowedExternalAudience.ToString());

            TimeWindow myOOFDuration = myOOFConfig.Duration;

            if (myOOFDuration != null)
            {
                Console.WriteLine(myOOFDuration.StartTime.ToLocalTime() + " - " +
                                  myOOFDuration.EndTime.ToLocalTime());
            }

            OofExternalAudience myExternalAudience = myOOFConfig.ExternalAudience;

            Console.WriteLine(myExternalAudience.ToString());

            OofReply myExternalReply = myOOFConfig.ExternalReply;

            if (myExternalReply != null)
            {
                Console.WriteLine(myExternalReply.ToString());
            }

            OofReply myInternalReply = myOOFConfig.InternalReply;

            if (myInternalReply != null)
            {
                Console.WriteLine(myInternalReply.ToString());
            }

            OofState myOofState = myOOFConfig.State;

            Console.WriteLine(myOofState.ToString());
        }
Exemple #7
0
        private string Write3_OofState(OofState v)
        {
            string result;

            switch (v)
            {
            case OofState.Disabled:
                result = "Disabled";
                break;

            case OofState.Enabled:
                result = "Enabled";
                break;

            case OofState.Scheduled:
                result = "Scheduled";
                break;

            default:
                throw base.CreateInvalidEnumValueException(((long)v).ToString(CultureInfo.InvariantCulture), "Microsoft.Exchange.InfoWorker.Common.OOF.OofState");
            }
            return(result);
        }
Exemple #8
0
        private void UpdateOofRule(Rule rule, ReplyBody reply, string ruleName, string messageClass, OofReplyType oofReplyType, RuleGenerator.ConditionType conditionType, int sequenceNumber, OofState mailboxOofState)
        {
            bool        flag        = false;
            bool        flag2       = false;
            Restriction restriction = this.GetRestriction(conditionType);

            RuleAction.OOFReply ruleAction    = (RuleAction.OOFReply)rule.Actions[0];
            ReplyTemplate       replyTemplate = null;

            try
            {
                replyTemplate = ReplyTemplate.Find(this.itemStore, ruleAction);
                if (replyTemplate != null)
                {
                    RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updating ReplyTemplate to Body: '{1}'", this.itemStore.MailboxOwner, reply.RawMessage);
                    if (this.userOofSettings.SetByLegacyClient)
                    {
                        flag2 = !replyTemplate.PlainTextBody.Equals(reply.RawMessage, StringComparison.Ordinal);
                        replyTemplate.PlainTextBody = reply.RawMessage;
                    }
                    else
                    {
                        string value = TextUtil.ConvertHtmlToPlainText(reply.RawMessage);
                        flag2 = !replyTemplate.PlainTextBody.Equals(value, StringComparison.Ordinal);
                        replyTemplate.CharSet  = this.GetDefaultCharsetForCountryCode(reply.LanguageTag);
                        replyTemplate.HtmlBody = reply.RawMessage;
                    }
                    replyTemplate.OofReplyType = oofReplyType;
                    replyTemplate.ClassName    = messageClass;
                    replyTemplate.SaveChanges();
                    if (flag2)
                    {
                        rule.StateFlags |= RuleStateFlags.ClearOOFHistory;
                        byte[] propValue = this.itemStore.__ContainedMapiStore.GlobalIdFromId(rule.ID);
                        OofHistory.RemoveOofHistoryEntriesWithProperty(this.itemStore, mailboxOofState != OofState.Disabled, OofHistory.PropId.GlobalRuleId, propValue);
                        RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated reply template for global rule '{1}'", this.itemStore.MailboxOwner, ruleName);
                    }
                }
                else
                {
                    Guid   guid = Guid.NewGuid();
                    byte[] replyTemplateMessageEntryID = this.CreateOofReplyTemplate(this.itemStore, guid, reply, messageClass, oofReplyType);
                    rule.Actions = new RuleAction[]
                    {
                        new RuleAction.OOFReply(replyTemplateMessageEntryID, guid)
                    };
                    flag = true;
                    RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Created new reply template and updated global rule '{1}'", this.itemStore.MailboxOwner, ruleName);
                }
                RuleGenerator.TracerPfd.TracePfd <int, string, IExchangePrincipal>((long)this.GetHashCode(), "PFD IWO {0} Updated OOF Rule '{1}' for Mailbox:{2}", 25495, ruleName, this.itemStore.MailboxOwner);
            }
            finally
            {
                if (replyTemplate != null)
                {
                    replyTemplate.Dispose();
                }
            }
            if (!ConditionComparer.Equals(rule.Condition, restriction))
            {
                rule.Condition = restriction;
                flag           = true;
                RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated rule '{1}' with new condition", this.itemStore.MailboxOwner, ruleName);
            }
            if (flag || flag2)
            {
                this.ruleManager.Update(rule);
            }
        }
Exemple #9
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);
                }
            }
        }