Esempio n. 1
0
        /// <summary>
        /// Reads the response.
        /// </summary>
        /// <param name="ewsXmlReader">The XML reader.</param>
        /// <param name="responseHeaders">HTTP response headers</param>
        /// <returns>Service response.</returns>
        protected object ReadResponse(EwsServiceXmlReader ewsXmlReader, WebHeaderCollection responseHeaders)
        {
            object serviceResponse;

            this.ReadPreamble(ewsXmlReader);
            ewsXmlReader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPEnvelopeElementName);
            this.ReadSoapHeader(ewsXmlReader);
            ewsXmlReader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPBodyElementName);

            ewsXmlReader.ReadStartElement(XmlNamespace.Messages, this.GetResponseXmlElementName());

            if (responseHeaders != null)
            {
                serviceResponse = this.ParseResponse(ewsXmlReader, responseHeaders);
            }
            else
            {
                serviceResponse = this.ParseResponse(ewsXmlReader);
            }

            ewsXmlReader.ReadEndElementIfNecessary(XmlNamespace.Messages, this.GetResponseXmlElementName());

            ewsXmlReader.ReadEndElement(XmlNamespace.Soap, XmlElementNames.SOAPBodyElementName);
            ewsXmlReader.ReadEndElement(XmlNamespace.Soap, XmlElementNames.SOAPEnvelopeElementName);
            return(serviceResponse);
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Resolution);

            reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Mailbox);
            this.mailbox.LoadFromXml(reader, XmlElementNames.Mailbox);

            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Contact))
            {
                this.contact = new Contact(this.owner.Session);

                // Contacts returned by ResolveNames should behave like Contact.Load with FirstClassPropertySet specified.
                this.contact.LoadFromXml(
                    reader,
                    true,                                               /* clearPropertyBag */
                    PropertySet.FirstClassProperties,
                    false);                                             /* summaryPropertiesOnly */

                reader.ReadEndElement(XmlNamespace.Types, XmlElementNames.Resolution);
            }
            else
            {
                reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.Resolution);
            }
        }
        /// <summary>
        /// Loads an entry, consisting of a key value pair, into this dictionary from the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void LoadEntry(EwsServiceXmlReader reader)
        {
            EwsUtilities.Assert(
                reader != null,
                "UserConfigurationDictionary.LoadEntry",
                "reader is null");

            object key;
            object value = null;

            // Position at DictionaryKey
            reader.ReadStartElement(this.Namespace, XmlElementNames.DictionaryKey);

            key = this.GetDictionaryObject(reader);

            // Position at DictionaryValue
            reader.ReadStartElement(this.Namespace, XmlElementNames.DictionaryValue);

            string nil      = reader.ReadAttributeValue(XmlNamespace.XmlSchemaInstance, XmlAttributeNames.Nil);
            bool   hasValue = (nil == null) || (!Convert.ToBoolean(nil));

            if (hasValue)
            {
                value = this.GetDictionaryObject(reader);
            }

            this.dictionary.Add(key, value);
        }
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Response object.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            GetUserAvailabilityResults serviceResponse = new GetUserAvailabilityResults();

            if (this.IsFreeBusyViewRequested)
            {
                serviceResponse.AttendeesAvailability = new ServiceResponseCollection <AttendeeAvailability>();

                reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray);

                do
                {
                    reader.Read();

                    if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponse))
                    {
                        AttendeeAvailability freeBusyResponse = new AttendeeAvailability();

                        freeBusyResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage);

                        if (freeBusyResponse.ErrorCode == ServiceError.NoError)
                        {
                            freeBusyResponse.LoadFreeBusyViewFromXml(reader, this.Options.RequestedFreeBusyView);
                        }

                        serviceResponse.AttendeesAvailability.Add(freeBusyResponse);
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray));
            }

            if (this.IsSuggestionsViewRequested)
            {
                serviceResponse.SuggestionsResponse = new SuggestionsResponse();

                reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse);

                serviceResponse.SuggestionsResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage);

                if (serviceResponse.SuggestionsResponse.ErrorCode == ServiceError.NoError)
                {
                    serviceResponse.SuggestionsResponse.LoadSuggestedDaysFromXml(reader);
                }

                reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse);
            }

            return(serviceResponse);
        }
Esempio n. 5
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.ClientExtensions.Clear();
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ClientExtensions);

            if (!reader.IsEmptyElement)
            {
                // Because we don't have an element for count of returned object,
                // we have to test the element to determine if it is StartElement of return object or EndElement
                reader.Read();

                while (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ClientExtension))
                {
                    ClientExtension clientExtension = new ClientExtension();
                    clientExtension.LoadFromXml(reader, XmlNamespace.Types, XmlElementNames.ClientExtension);
                    this.ClientExtensions.Add(clientExtension);

                    reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.ClientExtension);
                    reader.Read();
                }

                reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Messages, XmlElementNames.ClientExtensions);
            }

            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.ClientExtensionRawMasterTableXml))
            {
                this.rawMasterTableXml = reader.ReadElementValue();
            }
        }
        /// <summary>
        /// Read Conversations from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.Conversation = new ConversationResponse(this.propertySet);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Conversation);
            this.Conversation.LoadFromXml(reader, XmlNamespace.Messages, XmlElementNames.Conversation);
        }
Esempio n. 7
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Attachments);
            if (!reader.IsEmptyElement)
            {
                reader.Read(XmlNodeType.Element);

                if (this.attachment == null)
                {
                    if (string.Equals(reader.LocalName, XmlElementNames.FileAttachment, StringComparison.OrdinalIgnoreCase))
                    {
                        this.attachment = new FileAttachment(reader.Service);
                    }
                    else if (string.Equals(reader.LocalName, XmlElementNames.ItemAttachment, StringComparison.OrdinalIgnoreCase))
                    {
                        this.attachment = new ItemAttachment(reader.Service);
                    }
                }

                if (this.attachment != null)
                {
                    this.attachment.LoadFromXml(reader, reader.LocalName);
                }

                reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.Attachments);
            }
        }
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.Rooms.Clear();
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Rooms);

            if (!reader.IsEmptyElement)
            {
                // Because we don't have an element for count of returned object,
                // we have to test the element to determine if it is StartElement of return object or EndElement
                reader.Read();
                while (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Room))
                {
                    reader.Read(); // skip the start <Room>

                    EmailAddress emailAddress = new EmailAddress();
                    emailAddress.LoadFromXml(reader, XmlElementNames.RoomId);
                    this.Rooms.Add(emailAddress);

                    reader.ReadEndElement(XmlNamespace.Types, XmlElementNames.Room);
                    reader.Read();
                }

                reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Messages, XmlElementNames.Rooms);
            }
        }
        /// <summary>
        /// Read Photo results from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            bool hasChanged = reader.ReadElementValue <bool>(XmlNamespace.Messages, XmlElementNames.HasChanged);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.PictureData);
            byte[] photoData = reader.ReadBase64ElementValue();

            // We only get a content type if we get a photo
            if (photoData.Length > 0)
            {
                this.Results.Photo       = photoData;
                this.Results.ContentType = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.ContentType);
            }

            if (hasChanged)
            {
                if (this.Results.Photo.Length == 0)
                {
                    this.Results.Status = GetUserPhotoStatus.PhotoOrUserNotFound;
                }
                else
                {
                    this.Results.Status = GetUserPhotoStatus.PhotoReturned;
                }
            }
            else
            {
                this.Results.Status = GetUserPhotoStatus.PhotoUnchanged;
            }
        }
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.searchableMailboxes.Clear();

            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.SearchableMailboxes);
            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();
                    if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SearchableMailbox))
                    {
                        this.searchableMailboxes.Add(SearchableMailbox.LoadFromXml(reader));
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.SearchableMailboxes));
            }

            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FailedMailboxes))
            {
                this.FailedMailboxes = FailedSearchMailbox.LoadFailedMailboxesXml(XmlNamespace.Messages, reader);
            }
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            EwsUtilities.Assert(
                reader != null,
                "UserConfiguration.LoadFromXml",
                "reader is null");

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.UserConfiguration);
            reader.Read(); // Position at first property element

            do
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                    case XmlElementNames.UserConfigurationName:
                        string responseName = reader.ReadAttributeValue(XmlAttributeNames.Name);

                        EwsUtilities.Assert(
                            string.Compare(this.name, responseName, StringComparison.Ordinal) == 0,
                            "UserConfiguration.LoadFromXml",
                            "UserConfigurationName does not match: Expected: " + this.name + " Name in response: " + responseName);

                        reader.SkipCurrentElement();
                        break;

                    case XmlElementNames.ItemId:
                        this.itemId = new ItemId();
                        this.itemId.LoadFromXml(reader, XmlElementNames.ItemId);
                        break;

                    case XmlElementNames.Dictionary:
                        this.dictionary.LoadFromXml(reader, XmlElementNames.Dictionary);
                        break;

                    case XmlElementNames.XmlData:
                        this.xmlData = Convert.FromBase64String(reader.ReadElementValue());
                        break;

                    case XmlElementNames.BinaryData:
                        this.binaryData = Convert.FromBase64String(reader.ReadElementValue());
                        break;

                    default:
                        EwsUtilities.Assert(
                            false,
                            "UserConfiguration.LoadFromXml",
                            "Xml element not supported: " + reader.LocalName);
                        break;
                    }
                }

                // If XmlData was loaded, read is skipped because GetXmlData positions the reader at the next property.
                reader.Read();
            }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.UserConfiguration));
        }
        /// <summary>
        /// Reads the response.
        /// </summary>
        /// <param name="ewsXmlReader">The XML reader.</param>
        /// <returns>Service response.</returns>
        protected object ReadResponse(EwsServiceXmlReader ewsXmlReader)
        {
            object serviceResponse;

            this.ReadPreamble(ewsXmlReader);
            ewsXmlReader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPEnvelopeElementName);
            this.ReadSoapHeader(ewsXmlReader);
            ewsXmlReader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPBodyElementName);

            ewsXmlReader.ReadStartElement(XmlNamespace.Messages, this.GetResponseXmlElementName());

            serviceResponse = this.ParseResponse(ewsXmlReader);

            ewsXmlReader.ReadEndElementIfNecessary(XmlNamespace.Messages, this.GetResponseXmlElementName());

            ewsXmlReader.ReadEndElement(XmlNamespace.Soap, XmlElementNames.SOAPBodyElementName);
            ewsXmlReader.ReadEndElement(XmlNamespace.Soap, XmlElementNames.SOAPEnvelopeElementName);
            return(serviceResponse);
        }
Esempio n. 13
0
        /// <summary>
        /// Read Personas from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            EwsUtilities.Assert(
                this.Results.Personas != null,
                "FindPeopleResponse.ReadElementsFromXml",
                "Personas is null.");

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.People);
            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        Persona item = EwsUtilities.CreateEwsObjectFromXmlElementName <Persona>(reader.Service, reader.LocalName);

                        if (item == null)
                        {
                            reader.SkipCurrentElement();
                        }
                        else
                        {
                            // Don't clear propertyBag because all properties have been initialized in the persona constructor.
                            item.LoadFromXml(reader, false, null, false);
                            this.Results.Personas.Add(item);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.People));
            }

            reader.Read();

            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.TotalNumberOfPeopleInView) && !reader.IsEmptyElement)
            {
                this.Results.TotalCount = reader.ReadElementValue <int>();

                reader.Read();
            }

            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FirstMatchingRowIndex) && !reader.IsEmptyElement)
            {
                this.Results.FirstMatchingRowIndex = reader.ReadElementValue <int>();

                reader.Read();
            }

            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FirstLoadedRowIndex) && !reader.IsEmptyElement)
            {
                this.Results.FirstLoadedRowIndex = reader.ReadElementValue <int>();

                reader.Read();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Attachments);

            reader.Read(XmlNodeType.Element);
            this.attachment.LoadFromXml(reader, reader.LocalName);

            reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.Attachments);
        }
Esempio n. 15
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Token);
            this.Id         = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Id);
            this.TokenType  = (ClientAccessTokenType)Enum.Parse(typeof(ClientAccessTokenType), reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.TokenType));
            this.TokenValue = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.TokenValue);
            this.TTL        = int.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.TTL));
            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.Token);
        }
Esempio n. 16
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.RootFolder);

            this.results.TotalCount    = reader.ReadAttributeValue <int>(XmlAttributeNames.TotalItemsInView);
            this.results.MoreAvailable = !reader.ReadAttributeValue <bool>(XmlAttributeNames.IncludesLastItemInRange);

            // Ignore IndexedPagingOffset attribute if MoreAvailable is false.
            this.results.NextPageOffset = results.MoreAvailable ? reader.ReadNullableAttributeValue <int>(XmlAttributeNames.IndexedPagingOffset) : null;

            reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Folders);
            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        Folder folder = EwsUtilities.CreateEwsObjectFromXmlElementName <Folder>(reader.Service, reader.LocalName);

                        if (folder == null)
                        {
                            reader.SkipCurrentElement();
                        }
                        else
                        {
                            folder.LoadFromXml(
                                reader,
                                true,         /* clearPropertyBag */
                                this.propertySet,
                                true /* summaryPropertiesOnly */);

                            this.results.Folders.Add(folder);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.Folders));
            }

            reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.RootFolder);
        }
Esempio n. 17
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.DLExpansion);
            if (!reader.IsEmptyElement)
            {
                int totalItemsInView = reader.ReadAttributeValue <int>(XmlAttributeNames.TotalItemsInView);
                this.includesAllMembers = reader.ReadAttributeValue <bool>(XmlAttributeNames.IncludesLastItemInRange);

                for (int i = 0; i < totalItemsInView; i++)
                {
                    EmailAddress emailAddress = new EmailAddress();

                    reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Mailbox);
                    emailAddress.LoadFromXml(reader, XmlElementNames.Mailbox);

                    this.members.Add(emailAddress);
                }

                reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.DLExpansion);
            }
        }
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Response object.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            GetStreamingEventsResponse response = new GetStreamingEventsResponse(this);

            response.LoadFromXml(reader, XmlElementNames.GetStreamingEventsResponseMessage);

            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            return(response);
        }
        /// <summary>
        /// Loads the free busy view from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="viewType">Type of free/busy view.</param>
        internal void LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView);

            string viewTypeString = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.FreeBusyViewType);

            this.viewType = (FreeBusyViewType)Enum.Parse(typeof(FreeBusyViewType), viewTypeString, false);

            do
            {
                reader.Read();

                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case XmlElementNames.MergedFreeBusy:
                        string mergedFreeBusy = reader.ReadElementValue();

                        for (int i = 0; i < mergedFreeBusy.Length; i++)
                        {
                            this.mergedFreeBusyStatus.Add((LegacyFreeBusyStatus)Byte.Parse(mergedFreeBusy[i].ToString()));
                        }

                        break;

                    case XmlElementNames.CalendarEventArray:
                        do
                        {
                            reader.Read();

                            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CalendarEvent))
                            {
                                CalendarEvent calendarEvent = new CalendarEvent();

                                calendarEvent.LoadFromXml(reader, XmlElementNames.CalendarEvent);

                                this.calendarEvents.Add(calendarEvent);
                            }
                        }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.CalendarEventArray));

                        break;

                    case XmlElementNames.WorkingHours:
                        this.workingHours = new WorkingHours();
                        this.workingHours.LoadFromXml(reader, reader.LocalName);

                        break;
                    }
                }
            }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView));
        }
        /// <summary>
        /// Extracts the dictionary object (key or entry value) type from the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Dictionary object type.</returns>
        private UserConfigurationDictionaryObjectType GetObjectType(EwsServiceXmlReader reader)
        {
            EwsUtilities.Assert(
                reader != null,
                "UserConfigurationDictionary.LoadFromXml",
                "reader is null");

            reader.ReadStartElement(this.Namespace, XmlElementNames.Type);

            string type = reader.ReadElementValue();

            return(GetObjectType(type));
        }
Esempio n. 21
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ReturnValue);

            using (XmlReader returnValueReader = reader.GetXmlReaderForNode())
            {
                this.ReturnValue = new SafeXmlDocument();
                this.ReturnValue.Load(returnValueReader);
            }

            reader.SkipCurrentElement();
            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.ReturnValue);
        }
Esempio n. 22
0
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Service response collection.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            ServiceResponseCollection <TResponse> serviceResponses = new ServiceResponseCollection <TResponse>();

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            for (int i = 0; i < this.GetExpectedResponseMessageCount(); i++)
            {
                // Read ahead to see if we've reached the end of the response messages early.
                reader.Read();
                if (reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages))
                {
                    break;
                }

                TResponse response = this.CreateServiceResponse(reader.Service, i);

                response.LoadFromXml(reader, this.GetResponseMessageXmlElementName());

                // Add the response to the list after it has been deserialized because the response
                // list updates an overall result as individual responses are added to it.
                serviceResponses.Add(response);
            }

            // If there's a general error in batch processing,
            // the server will return a single response message containing the error
            // (for example, if the SavedItemFolderId is bogus in a batch CreateItem
            // call). In this case, throw a ServiceResponsException. Otherwise this
            // is an unexpected server error.
            if (serviceResponses.Count < this.GetExpectedResponseMessageCount())
            {
                if ((serviceResponses.Count == 1) && (serviceResponses[0].Result == ServiceResult.Error))
                {
                    throw new ServiceResponseException(serviceResponses[0]);
                }
                else
                {
                    throw new ServiceXmlDeserializationException(
                              string.Format(
                                  Strings.TooFewServiceReponsesReturned,
                                  this.GetResponseMessageXmlElementName(),
                                  this.GetExpectedResponseMessageCount(),
                                  serviceResponses.Count));
                }
            }

            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            return(serviceResponses);
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Notification);

            do
            {
                NotificationGroup notifications = new NotificationGroup();
                notifications.SubscriptionId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SubscriptionId);
                notifications.Events         = new Collection <NotificationEvent>();

                lock (this)
                {
                    this.events.Add(notifications);
                }

                do
                {
                    reader.Read();

                    if (reader.IsStartElement())
                    {
                        string    eventElementName = reader.LocalName;
                        EventType eventType;

                        if (GetEventsResults.XmlElementNameToEventTypeMap.TryGetValue(eventElementName, out eventType))
                        {
                            if (eventType == EventType.Status)
                            {
                                // We don't need to return status events
                                reader.ReadEndElementIfNecessary(XmlNamespace.Types, eventElementName);
                            }
                            else
                            {
                                this.LoadNotificationEventFromXml(
                                    reader,
                                    eventElementName,
                                    eventType,
                                    notifications);
                            }
                        }
                        else
                        {
                            reader.SkipCurrentElement();
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notification));

                reader.Read();
            }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notifications));
        }
Esempio n. 24
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.RootItemId);

            string changeKey = reader.ReadAttributeValue(XmlAttributeNames.RootItemChangeKey);

            if (!string.IsNullOrEmpty(changeKey) && this.attachment.Owner != null)
            {
                this.attachment.Owner.RootItemId.ChangeKey = changeKey;
            }

            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.RootItemId);
        }
        /// <summary>
        /// Load from xml
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <returns>Mailbox hold object</returns>
        internal static MailboxHoldResult LoadFromXml(EwsServiceXmlReader reader)
        {
            List <MailboxHoldStatus> statuses = new List <MailboxHoldStatus>();

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.MailboxHoldResult);

            MailboxHoldResult holdResult = new MailboxHoldResult();

            holdResult.HoldId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.HoldId);

            // the query could be empty means there won't be Query element, hence needs to read and check
            // if the next element is not Query, then it means already read MailboxHoldStatuses element
            reader.Read();
            holdResult.Query = string.Empty;
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Query))
            {
                holdResult.Query = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Query);
                reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.MailboxHoldStatuses);
            }

            do
            {
                reader.Read();
                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.MailboxHoldStatus))
                {
                    string     mailbox        = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Mailbox);
                    HoldStatus status         = (HoldStatus)Enum.Parse(typeof(HoldStatus), reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Status));
                    string     additionalInfo = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.AdditionalInfo);
                    statuses.Add(new MailboxHoldStatus(mailbox, status, additionalInfo));
                }
            }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.MailboxHoldResult));

            holdResult.Statuses = statuses.Count == 0 ? null : statuses.ToArray();

            return(holdResult);
        }
Esempio n. 26
0
        /// <summary>
        /// Read SOAP header and extract server version
        /// </summary>
        /// <param name="reader">EwsServiceXmlReader</param>
        private void ReadSoapHeader(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPHeaderElementName);
            do
            {
                reader.Read();

                // Is this the ServerVersionInfo?
                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ServerVersionInfo))
                {
                    this.Service.ServerInfo = ExchangeServerInfo.Parse(reader);
                }

                // Ignore anything else inside the SOAP header
            }while (!reader.IsEndElement(XmlNamespace.Soap, XmlElementNames.SOAPHeaderElementName));
        }
        /// <summary>
        /// Extracts a dictionary object (key or entry value) as a string list from the
        /// specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="type">The object type.</param>
        /// <returns>String list representing a dictionary object.</returns>
        private List <string> GetObjectValue(EwsServiceXmlReader reader, UserConfigurationDictionaryObjectType type)
        {
            EwsUtilities.Assert(
                reader != null,
                "UserConfigurationDictionary.LoadFromXml",
                "reader is null");

            List <string> values = new List <string>();

            reader.ReadStartElement(this.Namespace, XmlElementNames.Value);

            do
            {
                string value = null;

                if (reader.IsEmptyElement)
                {
                    // Only string types can be represented with empty values.
                    switch (type)
                    {
                    case UserConfigurationDictionaryObjectType.String:
                    case UserConfigurationDictionaryObjectType.StringArray:
                        value = string.Empty;
                        break;

                    default:
                        EwsUtilities.Assert(
                            false,
                            "UserConfigurationDictionary.GetObjectValue",
                            "Empty element passed for type: " + type.ToString());
                        break;
                    }
                }
                else
                {
                    value = reader.ReadElementValue();
                }

                values.Add(value);

                reader.Read(); // Position at next element or DictionaryKey/DictionaryValue end element
            }while (reader.IsStartElement(this.Namespace, XmlElementNames.Value));

            return(values);
        }
        /// <summary>
        /// Loads the suggested days from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadSuggestedDaysFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.SuggestionDayResultArray);

            do
            {
                reader.Read();

                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SuggestionDayResult))
                {
                    Suggestion daySuggestion = new Suggestion();

                    daySuggestion.LoadFromXml(reader, reader.LocalName);

                    this.daySuggestions.Add(daySuggestion);
                }
            }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.SuggestionDayResultArray));
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResolutionSet);

            int totalItemsInView = reader.ReadAttributeValue <int>(XmlAttributeNames.TotalItemsInView);

            this.includesAllResolutions = reader.ReadAttributeValue <bool>(XmlAttributeNames.IncludesLastItemInRange);

            for (int i = 0; i < totalItemsInView; i++)
            {
                NameResolution nameResolution = new NameResolution(this);

                nameResolution.LoadFromXml(reader);

                this.items.Add(nameResolution);
            }

            reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.ResolutionSet);
        }
Esempio n. 30
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.AlternateId);

            string alternateIdClass = reader.ReadAttributeValue(XmlNamespace.XmlSchemaInstance, XmlAttributeNames.Type);

            int aliasSeparatorIndex = alternateIdClass.IndexOf(':');

            if (aliasSeparatorIndex > -1)
            {
                alternateIdClass = alternateIdClass.Substring(aliasSeparatorIndex + 1);
            }

            // Alternate Id classes are responsible fro reading the AlternateId end element when necessary
            switch (alternateIdClass)
            {
            case AlternateId.SchemaTypeName:
                this.convertedId = new AlternateId();
                break;

            case AlternatePublicFolderId.SchemaTypeName:
                this.convertedId = new AlternatePublicFolderId();
                break;

            case AlternatePublicFolderItemId.SchemaTypeName:
                this.convertedId = new AlternatePublicFolderItemId();
                break;

            default:
                EwsUtilities.Assert(
                    false,
                    "ConvertIdResponse.ReadElementsFromXml",
                    string.Format("Unknown alternate Id class: {0}", alternateIdClass));
                break;
            }

            this.convertedId.LoadAttributesFromXml(reader);

            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.AlternateId);
        }