/// <summary>
        /// Reads response elements from Json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal override void ReadElementsFromJson(JsonObject responseObject, ExchangeService service)
        {
            EwsUtilities.Assert(
                this.Results.Conversations != null,
                "FindConversationResponse.ReadElementsFromXml",
                "conversations is null.");

            EwsUtilities.Assert(
                this.Results.HighlightTerms != null,
                "FindConversationResponse.ReadElementsFromXml",
                "highlightTerms is null.");

            foreach (object conversationObject in responseObject.ReadAsArray(XmlElementNames.Conversations))
            {
                JsonObject jsonConversation = conversationObject as JsonObject;

                Conversation item = EwsUtilities.CreateEwsObjectFromXmlElementName <Conversation>(service, XmlElementNames.Conversation);

                if (item != null)
                {
                    item.LoadFromJson(
                        jsonConversation,
                        service,
                        true,
                        null,
                        false);

                    this.Conversations.Add(item);
                }
            }

            Object[] highlightTermObjects = responseObject.ReadAsArray(XmlElementNames.HighlightTerms);
            if (highlightTermObjects != null)
            {
                foreach (object highlightTermObject in highlightTermObjects)
                {
                    JsonObject    jsonHighlightTerm = highlightTermObject as JsonObject;
                    HighlightTerm term = new HighlightTerm();

                    term.LoadFromJson(jsonHighlightTerm, service);
                    this.Results.HighlightTerms.Add(term);
                }
            }

            if (responseObject.ContainsKey(XmlElementNames.TotalConversationsInView))
            {
                this.Results.TotalCount = responseObject.ReadAsInt(XmlElementNames.TotalConversationsInView);
            }

            if (responseObject.ContainsKey(XmlElementNames.IndexedOffset))
            {
                this.Results.IndexedOffset = responseObject.ReadAsInt(XmlElementNames.IndexedOffset);
            }
        }
        /// <summary>
        /// Read Conversations from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            EwsUtilities.Assert(
                   this.Results.Conversations != null,
                   "FindConversationResponse.ReadElementsFromXml",
                   "conversations is null.");

            EwsUtilities.Assert(
                   this.Results.HighlightTerms != null,
                   "FindConversationResponse.ReadElementsFromXml",
                   "highlightTerms is null.");

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

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

                        if (item == null)
                        {
                            reader.SkipCurrentElement();
                        }
                        else
                        {
                            item.LoadFromXml(
                                        reader,
                                        true, /* clearPropertyBag */
                                        null,
                                        false  /* summaryPropertiesOnly */);

                            this.Results.Conversations.Add(item);
                        }
                    }
                }
                while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Conversations));
            }

            reader.Read();

            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms) &&
                !reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        HighlightTerm term = new HighlightTerm();

                        term.LoadFromXml(
                            reader,
                            XmlNamespace.Types,
                            XmlElementNames.HighlightTerm);

                        this.Results.HighlightTerms.Add(term);
                    }
                }
                while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms));
            }

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

                reader.Read();
            }

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

                reader.Read();
            }
        }
Esempio n. 3
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);

            int  totalItemsInView   = reader.ReadAttributeValue <int>(XmlAttributeNames.TotalItemsInView);
            bool moreItemsAvailable = !reader.ReadAttributeValue <bool>(XmlAttributeNames.IncludesLastItemInRange);

            // Ignore IndexedPagingOffset attribute if moreItemsAvailable is false.
            int?nextPageOffset = moreItemsAvailable ? reader.ReadNullableAttributeValue <int>(XmlAttributeNames.IndexedPagingOffset) : null;

            if (!this.isGrouped)
            {
                this.results                = new FindItemsResults <TItem>();
                this.results.TotalCount     = totalItemsInView;
                this.results.NextPageOffset = nextPageOffset;
                this.results.MoreAvailable  = moreItemsAvailable;
                InternalReadItemsFromXml(
                    reader,
                    this.propertySet,
                    this.results.Items);
            }
            else
            {
                this.groupedFindResults                = new GroupedFindItemsResults <TItem>();
                this.groupedFindResults.TotalCount     = totalItemsInView;
                this.groupedFindResults.NextPageOffset = nextPageOffset;
                this.groupedFindResults.MoreAvailable  = moreItemsAvailable;

                reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Groups);

                if (!reader.IsEmptyElement)
                {
                    do
                    {
                        reader.Read();

                        if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.GroupedItems))
                        {
                            string groupIndex = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.GroupIndex);

                            List <TItem> itemList = new List <TItem>();
                            InternalReadItemsFromXml(
                                reader,
                                this.propertySet,
                                itemList);

                            reader.ReadEndElement(XmlNamespace.Types, XmlElementNames.GroupedItems);

                            this.groupedFindResults.ItemGroups.Add(new ItemGroup <TItem>(groupIndex, itemList));
                        }
                    }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.Groups));
                }
            }

            reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.RootFolder);

            reader.Read();

            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms) &&
                !reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        HighlightTerm term = new HighlightTerm();

                        term.LoadFromXml(
                            reader,
                            XmlNamespace.Types,
                            XmlElementNames.HighlightTerm);
                        this.results.HighlightTerms.Add(term);
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms));
            }
        }
        /// <summary>
        /// Read Conversations from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            EwsUtilities.Assert(
                this.Results.Conversations != null,
                "FindConversationResponse.ReadElementsFromXml",
                "conversations is null.");

            EwsUtilities.Assert(
                this.Results.HighlightTerms != null,
                "FindConversationResponse.ReadElementsFromXml",
                "highlightTerms is null.");

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

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

                        if (item == null)
                        {
                            reader.SkipCurrentElement();
                        }
                        else
                        {
                            item.LoadFromXml(
                                reader,
                                true,         /* clearPropertyBag */
                                null,
                                false /* summaryPropertiesOnly */);

                            this.Results.Conversations.Add(item);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Conversations));
            }

            reader.Read();

            if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms) &&
                !reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        HighlightTerm term = new HighlightTerm();

                        term.LoadFromXml(
                            reader,
                            XmlNamespace.Types,
                            XmlElementNames.HighlightTerm);

                        this.Results.HighlightTerms.Add(term);
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms));
            }

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

                reader.Read();
            }

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

                reader.Read();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Reads response elements from Json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal override void ReadElementsFromJson(JsonObject responseObject, ExchangeService service)
        {
            base.ReadElementsFromJson(responseObject, service);

            JsonObject rootFolder         = responseObject.ReadAsJsonObject(XmlElementNames.RootFolder);
            int        totalItemsInView   = rootFolder.ReadAsInt(XmlAttributeNames.TotalItemsInView);
            bool       moreItemsAvailable = !rootFolder.ReadAsBool(XmlAttributeNames.IncludesLastItemInRange);

            // Ignore IndexedPagingOffset attribute if moreItemsAvailable is false.
            int?nextPageOffset = null;

            if (moreItemsAvailable)
            {
                if (rootFolder.ContainsKey(XmlAttributeNames.IndexedPagingOffset))
                {
                    nextPageOffset = rootFolder.ReadAsInt(XmlAttributeNames.IndexedPagingOffset);
                }
            }

            if (!this.isGrouped)
            {
                this.results                = new FindItemsResults <TItem>();
                this.results.TotalCount     = totalItemsInView;
                this.results.NextPageOffset = nextPageOffset;
                this.results.MoreAvailable  = moreItemsAvailable;
                this.InternalReadItemsFromJson(
                    rootFolder,
                    this.propertySet,
                    service,
                    this.results.Items);
            }
            else
            {
                this.groupedFindResults                = new GroupedFindItemsResults <TItem>();
                this.groupedFindResults.TotalCount     = totalItemsInView;
                this.groupedFindResults.NextPageOffset = nextPageOffset;
                this.groupedFindResults.MoreAvailable  = moreItemsAvailable;

                if (rootFolder.ContainsKey(XmlElementNames.Groups))
                {
                    object[] jsGroups = rootFolder.ReadAsArray(XmlElementNames.Groups);

                    foreach (JsonObject jsGroup in jsGroups.OfType <JsonObject>())
                    {
                        if (jsGroup.ContainsKey(XmlElementNames.GroupedItems))
                        {
                            JsonObject jsGroupedItems = jsGroup.ReadAsJsonObject(XmlElementNames.GroupedItems);

                            string groupIndex = jsGroupedItems.ReadAsString(XmlElementNames.GroupIndex);

                            List <TItem> itemList = new List <TItem>();
                            this.InternalReadItemsFromJson(
                                jsGroupedItems,
                                this.propertySet,
                                service,
                                itemList);

                            this.groupedFindResults.ItemGroups.Add(new ItemGroup <TItem>(groupIndex, itemList));
                        }
                    }
                }
            }

            Object[] highlightTermObjects = responseObject.ReadAsArray(XmlElementNames.HighlightTerms);
            if (highlightTermObjects != null)
            {
                foreach (object highlightTermObject in highlightTermObjects)
                {
                    JsonObject    jsonHighlightTerm = highlightTermObject as JsonObject;
                    HighlightTerm term = new HighlightTerm();

                    term.LoadFromJson(jsonHighlightTerm, service);
                    this.results.HighlightTerms.Add(term);
                }
            }
        }