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