コード例 #1
0
        /// <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.TimeZone:
                LegacyAvailabilityTimeZone legacyTimeZone = new LegacyAvailabilityTimeZone();
                legacyTimeZone.LoadFromXml(reader, reader.LocalName);

                this.customTimeZone = legacyTimeZone.ToCustomTimeZoneInfo();

                return(true);

            case XmlElementNames.WorkingPeriodArray:
                List <WorkingPeriod> workingPeriods = new List <WorkingPeriod>();

                do
                {
                    reader.Read();

                    if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.WorkingPeriod))
                    {
                        WorkingPeriod workingPeriod = new WorkingPeriod();

                        workingPeriod.LoadFromXml(reader, reader.LocalName);

                        workingPeriods.Add(workingPeriod);
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.WorkingPeriodArray));

                // Availability supports a structure that can technically represent different working
                // times for each day of the week. This is apparently how the information is stored in
                // Exchange. However, no client (Outlook, OWA) either will let you specify different
                // working times for each day of the week, and Outlook won't either honor that complex
                // structure if it happens to be in Exchange.
                // So here we'll do what Outlook and OWA do: we'll use the start and end times of the
                // first working period, but we'll use the week days of all the periods.
                this.startTime = workingPeriods[0].StartTime;
                this.endTime   = workingPeriods[0].EndTime;

                foreach (WorkingPeriod workingPeriod in workingPeriods)
                {
                    foreach (DayOfTheWeek dayOfWeek in workingPeriods[0].DaysOfWeek)
                    {
                        if (!this.daysOfTheWeek.Contains(dayOfWeek))
                        {
                            this.daysOfTheWeek.Add(dayOfWeek);
                        }
                    }
                }

                return(true);

            default:
                return(false);
            }
        }
コード例 #2
0
        public static CustomTimeZoneInfo CreateCustomTimeZone(
            string id,
            TimeSpan baseUtcOffset,
            string displayName,
            string standardDisplayName)
        {
            CustomTimeZoneInfo customTimeZoneInfo = new CustomTimeZoneInfo();

            customTimeZoneInfo.Id            = id;
            customTimeZoneInfo.BaseUtcOffset = baseUtcOffset;
            customTimeZoneInfo.DisplayName   = displayName;
            customTimeZoneInfo.StandardName  = standardDisplayName;
            customTimeZoneInfo.SupportsDaylightSavingTime = false;
            return(customTimeZoneInfo);
        }
コード例 #3
0
        public static CustomTimeZoneInfo CreateCustomTimeZone(
            TimeZoneInfo timeZoneInfo
            )
        {
            CustomTimeZoneInfo customTimeZoneInfo = new CustomTimeZoneInfo();

            customTimeZoneInfo.Id            = timeZoneInfo.Id;
            customTimeZoneInfo.BaseUtcOffset = timeZoneInfo.BaseUtcOffset;
            customTimeZoneInfo.DisplayName   = timeZoneInfo.DisplayName;
            customTimeZoneInfo.StandardName  = timeZoneInfo.StandardName;
            customTimeZoneInfo.DaylightName  = timeZoneInfo.DaylightName;
            customTimeZoneInfo.SupportsDaylightSavingTime = timeZoneInfo.SupportsDaylightSavingTime;
            // NOTE: Time Zone Info doesn't support adjustment rules
            // customTimeZoneInfo.adjustmentRules = timeZoneInfo.getAdjustRules();
            return(customTimeZoneInfo);
        }
コード例 #4
0
        public static CustomTimeZoneInfo CreateCustomTimeZone(
            string id,
            TimeSpan baseUtcOffset,
            string displayName,
            string standardDisplayName,
            string daylightDisplayName,
            AdjustmentRule[] adjustmentRules
            )
        {
            CustomTimeZoneInfo customTimeZoneInfo = new CustomTimeZoneInfo();

            customTimeZoneInfo.Id            = id;
            customTimeZoneInfo.BaseUtcOffset = baseUtcOffset;
            customTimeZoneInfo.DisplayName   = displayName;
            customTimeZoneInfo.StandardName  = standardDisplayName;
            customTimeZoneInfo.DaylightName  = daylightDisplayName;
            customTimeZoneInfo.SupportsDaylightSavingTime = adjustmentRules.Length > 0 ? true : false;
            customTimeZoneInfo.adjustmentRules            = adjustmentRules;
            return(customTimeZoneInfo);
        }
コード例 #5
0
        /// <summary>
        /// Writes to XML.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <param name="isUpdateOperation">Indicates whether the context is an update operation.</param>
        internal override void WritePropertyValueToXml(
            EwsServiceXmlWriter writer,
            PropertyBag propertyBag,
            bool isUpdateOperation)
        {
            Misc.CustomTimeZoneInfo value = (Misc.CustomTimeZoneInfo)propertyBag[this];

            if (value != null)
            {
                // We emit time zone properties only if we have not emitted the time zone SOAP header
                // or if this time zone is different from that of the service through which the request
                // is being emitted.
                if (!writer.IsTimeZoneHeaderEmitted || /*value != writer.Service.TimeZone*/ !value.Equals(writer.Service.TimeZone))
                {
                    TimeZoneDefinition timeZoneDefinition = new TimeZoneDefinition(value);

                    timeZoneDefinition.WriteToXml(writer, this.XmlElementName);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeZoneDefinition"/> class.
        /// </summary>
        /// <param name="timeZoneInfo">The time zone info used to initialize this definition.</param>
        internal TimeZoneDefinition(Misc.CustomTimeZoneInfo customTimeZoneInfo)
            : this()
        {
            this.Id   = customTimeZoneInfo.Id;
            this.Name = customTimeZoneInfo.DisplayName;

            // TimeZoneInfo only supports one standard period, which bias is the time zone's base
            // offset to UTC.
            TimeZonePeriod standardPeriod = new TimeZonePeriod();

            standardPeriod.Id   = TimeZonePeriod.StandardPeriodId;
            standardPeriod.Name = TimeZonePeriod.StandardPeriodName;
            standardPeriod.Bias = -customTimeZoneInfo.BaseUtcOffset;

            Misc.AdjustmentRule[] adjustmentRules = customTimeZoneInfo.GetAdjustmentRules();

            TimeZoneTransition transitionToStandardPeriod = new TimeZoneTransition(this, standardPeriod);

            if (adjustmentRules.Length == 0)
            {
                this.periods.Add(standardPeriod.Id, standardPeriod);

                // If the time zone info doesn't support Daylight Saving Time, we just need to
                // create one transition to one group with one transition to the standard period.
                TimeZoneTransitionGroup transitionGroup = new TimeZoneTransitionGroup(this, "0");
                transitionGroup.Transitions.Add(transitionToStandardPeriod);

                this.transitionGroups.Add(transitionGroup.Id, transitionGroup);

                TimeZoneTransition initialTransition = new TimeZoneTransition(this, transitionGroup);

                this.transitions.Add(initialTransition);
            }
            else
            {
                for (int i = 0; i < adjustmentRules.Length; i++)
                {
                    TimeZoneTransitionGroup transitionGroup = new TimeZoneTransitionGroup(this, this.transitionGroups.Count.ToString());
                    transitionGroup.InitializeFromAdjustmentRule(adjustmentRules[i], standardPeriod);

                    this.transitionGroups.Add(transitionGroup.Id, transitionGroup);

                    TimeZoneTransition transition;

                    if (i == 0)
                    {
                        // If the first adjustment rule's start date in not undefined (DateTime.MinValue)
                        // we need to add a dummy group with a single, simple transition to the Standard
                        // period and a group containing the transitions mapping to the adjustment rule.
                        if (adjustmentRules[i].DateStart > DateTime.MinValue.Date)
                        {
                            TimeZoneTransition transitionToDummyGroup = new TimeZoneTransition(
                                this,
                                this.CreateTransitionGroupToPeriod(standardPeriod));

                            this.transitions.Add(transitionToDummyGroup);

                            AbsoluteDateTransition absoluteDateTransition = new AbsoluteDateTransition(this, transitionGroup);
                            absoluteDateTransition.DateTime = adjustmentRules[i].DateStart;

                            transition = absoluteDateTransition;
                            this.periods.Add(standardPeriod.Id, standardPeriod);
                        }
                        else
                        {
                            transition = new TimeZoneTransition(this, transitionGroup);
                        }
                    }
                    else
                    {
                        AbsoluteDateTransition absoluteDateTransition = new AbsoluteDateTransition(this, transitionGroup);
                        absoluteDateTransition.DateTime = adjustmentRules[i].DateStart;

                        transition = absoluteDateTransition;
                    }

                    this.transitions.Add(transition);
                }

                // If the last adjustment rule's end date is not undefined (DateTime.MaxValue),
                // we need to create another absolute date transition that occurs the date after
                // the last rule's end date. We target this additional transition to a group that
                // contains a single simple transition to the Standard period.
                DateTime lastAdjustmentRuleEndDate = adjustmentRules[adjustmentRules.Length - 1].DateEnd;

                if (lastAdjustmentRuleEndDate < DateTime.MaxValue.Date)
                {
                    AbsoluteDateTransition transitionToDummyGroup = new AbsoluteDateTransition(
                        this,
                        this.CreateTransitionGroupToPeriod(standardPeriod));
                    transitionToDummyGroup.DateTime = lastAdjustmentRuleEndDate.AddDays(1);

                    this.transitions.Add(transitionToDummyGroup);
                }
            }
        }