/// <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.timeZone = legacyTimeZone.ToTimeZoneInfo();

                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);
            }
        }
        /// <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.timeZone = legacyTimeZone.ToTimeZoneInfo();
                    
                    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;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service">The service.</param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlElementNames.TimeZone:
                    LegacyAvailabilityTimeZone legacyTimeZone = new LegacyAvailabilityTimeZone();
                    legacyTimeZone.LoadFromJson(jsonProperty.ReadAsJsonObject(key), service);

                    this.timeZone = legacyTimeZone.ToTimeZoneInfo();

                    break;

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

                    object[] workingPeriodsArray = jsonProperty.ReadAsArray(key);

                    foreach (object workingPeriodEntry in workingPeriodsArray)
                    {
                        JsonObject jsonWorkingPeriodEntry = workingPeriodEntry as JsonObject;

                        if (jsonWorkingPeriodEntry != null)
                        {
                            WorkingPeriod workingPeriod = new WorkingPeriod();

                            workingPeriod.LoadFromJson(jsonWorkingPeriodEntry, service);

                            workingPeriods.Add(workingPeriod);
                        }
                    }

                    // 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);
                            }
                        }
                    }

                    break;

                default:
                    break;
                }
            }
        }