Example #1
0
    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;

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

            return(true);

        default:
            return(false);
        }
    }
    void WriteElementsToXml(EwsServiceXmlWriter writer)
    {
        // Only serialize the TimeZone property against an Exchange 2007 SP1 server.
        // Against Exchange 2010, the time zone is emitted in the request's SOAP header.
        if (writer.Service.RequestedServerVersion == ExchangeVersion.Exchange2007_SP1)
        {
            LegacyAvailabilityTimeZone legacyTimeZone = new LegacyAvailabilityTimeZone(writer.Service.TimeZone);

            legacyTimeZone.WriteToXml(writer, XmlElementNames.TimeZone);
        }

        writer.WriteStartElement(XmlNamespace.Messages, XmlElementNames.MailboxDataArray);

        for (AttendeeInfo attendee in this.Attendees)
        {
            attendee.WriteToXml(writer);
        }

        writer.WriteEndElement();     // MailboxDataArray

        this.Options.WriteToXml(writer, this);
    }