Example #1
0
    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>
    /// Load from xml
    /// </summary>
    /// <param name="reader">The reader</param>
    /// <returns>Discovery search configuration object</returns>
    static DiscoverySearchConfiguration LoadFromXml(EwsServiceXmlReader reader)
    {
        List <SearchableMailbox> mailboxes = new List <SearchableMailbox>();

        reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.DiscoverySearchConfiguration);

        DiscoverySearchConfiguration configuration = new DiscoverySearchConfiguration();

        configuration.SearchId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SearchId);

        // 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 SearchableMailboxes element
        configuration.SearchQuery           = "";
        configuration.InPlaceHoldIdentity   = "";
        configuration.ManagedByOrganization = "";
        configuration.Language = "";

        do
        {
            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SearchQuery))
            {
                configuration.SearchQuery = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SearchQuery);
                reader.ReadEndElementIfNecessary(XmlNamespace.Types, XmlElementNames.SearchQuery);
            }
            else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SearchableMailboxes))
            {
                // search object without any source mailbox is possible, hence need to check if element is empty
                if (!reader.IsEmptyElement)
                {
                    while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.SearchableMailboxes))
                    {
                        reader.Read();

                        if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SearchableMailbox))
                        {
                            mailboxes.Add(SearchableMailbox.LoadFromXml(reader));
                            reader.ReadEndElementIfNecessary(XmlNamespace.Types, XmlElementNames.SearchableMailbox);
                        }
                    }
                }
            }
            else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.InPlaceHoldIdentity))
            {
                configuration.InPlaceHoldIdentity = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.InPlaceHoldIdentity);
                reader.ReadEndElementIfNecessary(XmlNamespace.Types, XmlElementNames.InPlaceHoldIdentity);
            }
            else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ManagedByOrganization))
            {
                configuration.ManagedByOrganization = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ManagedByOrganization);
                reader.ReadEndElementIfNecessary(XmlNamespace.Types, XmlElementNames.ManagedByOrganization);
            }
            else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Language))
            {
                configuration.Language = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Language);
                reader.ReadEndElementIfNecessary(XmlNamespace.Types, XmlElementNames.Language);
            }
            else
            {
                break;
            }
        }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.DiscoverySearchConfiguration));

        configuration.SearchableMailboxes = mailboxes.Count == 0 ? null : mailboxes.ToArray();

        return(configuration);
    }