Пример #1
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="localElementName">Name of the local element.</param>
        internal override void LoadFromXml(EwsServiceXmlReader reader, string localElementName)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, localElementName);
            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

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

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

                            this.items.Add(item);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, localElementName));
            }
        }
Пример #2
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();
            }
        }
Пример #3
0
 /// <summary>
 /// Gets the folder instance.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="xmlElementName">Name of the XML element.</param>
 /// <returns>Folder.</returns>
 private Folder GetObjectInstance(ExchangeService service, string xmlElementName)
 {
     if (this.Folder != null)
     {
         return(this.Folder);
     }
     else
     {
         return(EwsUtilities.CreateEwsObjectFromXmlElementName <Folder>(service, xmlElementName));
     }
 }
Пример #4
0
 /// <summary>
 /// Gets Item instance.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="xmlElementName">Name of the XML element.</param>
 /// <returns>Item.</returns>
 private Item GetObjectInstance(ExchangeService service, string xmlElementName)
 {
     if (this.Item != null)
     {
         return(this.Item);
     }
     else
     {
         return(EwsUtilities.CreateEwsObjectFromXmlElementName <Item>(service, xmlElementName));
     }
 }
        /// <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);
            }
        }
Пример #6
0
        /// <summary>
        /// Loads from json collection.
        /// </summary>
        /// <param name="jsonCollection">The json collection.</param>
        /// <param name="service">The service.</param>
        void IJsonCollectionDeserializer.CreateFromJsonCollection(object[] jsonCollection, ExchangeService service)
        {
            foreach (object entry in jsonCollection)
            {
                JsonObject jsonServiceObject = entry as JsonObject;

                TItem item = EwsUtilities.CreateEwsObjectFromXmlElementName <Item>(
                    service,
                    jsonServiceObject.ReadTypeString()) as TItem;

                item.LoadFromJson(jsonServiceObject, service, true);

                this.items.Add(item);
            }
        }
Пример #7
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);
        }
Пример #8
0
        /// <summary>
        /// Read items from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="propertySet">The property set.</param>
        /// <param name="destinationList">The list in which to add the read items.</param>
        private static void InternalReadItemsFromXml(
            EwsServiceXmlReader reader,
            PropertySet propertySet,
            IList <TItem> destinationList)
        {
            EwsUtilities.Assert(
                destinationList != null,
                "FindItemResponse.InternalReadItemsFromXml",
                "destinationList is null.");

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

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

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

                            destinationList.Add(item);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.Items));
            }
        }
Пример #9
0
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.Changes.SyncState            = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.SyncState);
            this.Changes.MoreChangesAvailable = !reader.ReadElementValue <bool>(XmlNamespace.Messages, this.GetIncludesLastInRangeXmlElementName());

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

                    if (reader.IsStartElement())
                    {
                        TChange change = this.CreateChangeInstance();

                        switch (reader.LocalName)
                        {
                        case XmlElementNames.Create:
                            change.ChangeType = ChangeType.Create;
                            break;

                        case XmlElementNames.Update:
                            change.ChangeType = ChangeType.Update;
                            break;

                        case XmlElementNames.Delete:
                            change.ChangeType = ChangeType.Delete;
                            break;

                        case XmlElementNames.ReadFlagChange:
                            change.ChangeType = ChangeType.ReadFlagChange;
                            break;

                        default:
                            reader.SkipCurrentElement();
                            break;
                        }

                        if (change != null)
                        {
                            reader.Read();
                            reader.EnsureCurrentNodeIsStartElement();

                            switch (change.ChangeType)
                            {
                            case ChangeType.Delete:
                            case ChangeType.ReadFlagChange:
                                change.Id = change.CreateId();
                                change.Id.LoadFromXml(reader, change.Id.GetXmlElementName());

                                if (change.ChangeType == ChangeType.ReadFlagChange)
                                {
                                    reader.Read();
                                    reader.EnsureCurrentNodeIsStartElement();

                                    ItemChange itemChange = change as ItemChange;

                                    EwsUtilities.Assert(
                                        itemChange != null,
                                        "SyncResponse.ReadElementsFromXml",
                                        "ReadFlagChange is only valid on ItemChange");

                                    itemChange.IsRead = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsRead);
                                }

                                break;

                            default:
                                change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName <TServiceObject>(
                                    reader.Service,
                                    reader.LocalName);

                                change.ServiceObject.LoadFromXml(
                                    reader,
                                    true,                         /* clearPropertyBag */
                                    this.propertySet,
                                    this.SummaryPropertiesOnly);
                                break;
                            }

                            reader.ReadEndElementIfNecessary(XmlNamespace.Types, change.ChangeType.ToString());

                            this.changes.Add(change);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Changes));
            }
        }
Пример #10
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)
        {
            this.Changes.SyncState            = responseObject.ReadAsString(XmlElementNames.SyncState);
            this.Changes.MoreChangesAvailable = !responseObject.ReadAsBool(this.GetIncludesLastInRangeXmlElementName());

            JsonObject changesElement = responseObject.ReadAsJsonObject(XmlElementNames.Changes);

            foreach (object changeElement in changesElement.ReadAsArray(XmlElementNames.Changes))
            {
                JsonObject jsonChange = changeElement as JsonObject;

                TChange change = this.CreateChangeInstance();

                string changeType = jsonChange.ReadAsString(XmlElementNames.ChangeType);

                switch (changeType)
                {
                case XmlElementNames.Create:
                    change.ChangeType = ChangeType.Create;
                    break;

                case XmlElementNames.Update:
                    change.ChangeType = ChangeType.Update;
                    break;

                case XmlElementNames.Delete:
                    change.ChangeType = ChangeType.Delete;
                    break;

                case XmlElementNames.ReadFlagChange:
                    change.ChangeType = ChangeType.ReadFlagChange;
                    break;

                default:
                    break;
                }

                if (change != null)
                {
                    switch (change.ChangeType)
                    {
                    case ChangeType.Delete:
                    case ChangeType.ReadFlagChange:
                        change.Id = change.CreateId();
                        JsonObject jsonChangeId = jsonChange.ReadAsJsonObject(this.GetChangeIdElementName());
                        change.Id.LoadFromJson(jsonChangeId, service);

                        if (change.ChangeType == ChangeType.ReadFlagChange)
                        {
                            ItemChange itemChange = change as ItemChange;

                            EwsUtilities.Assert(
                                itemChange != null,
                                "SyncResponse.ReadElementsFromJson",
                                "ReadFlagChange is only valid on ItemChange");

                            itemChange.IsRead = jsonChange.ReadAsBool(XmlElementNames.IsRead);
                        }

                        break;

                    default:
                        JsonObject jsonServiceObject = jsonChange.ReadAsJsonObject(this.GetChangeElementName());
                        change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName <TServiceObject>(service, jsonServiceObject.ReadTypeString());

                        change.ServiceObject.LoadFromJson(
                            jsonServiceObject,
                            service,
                            true,                         /* clearPropertyBag */
                            this.propertySet,
                            this.SummaryPropertiesOnly);
                        break;
                    }

                    this.changes.Add(change);
                }
            }
        }
Пример #11
0
 /// <summary>
 /// Creates a folder instance.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="xmlElementName">Name of the XML element.</param>
 /// <returns>Folder</returns>
 private Folder CreateFolderInstance(ExchangeService service, string xmlElementName)
 {
     return(EwsUtilities.CreateEwsObjectFromXmlElementName <Folder>(service, xmlElementName));
 }
Пример #12
0
 /// <summary>
 /// Gets Item instance.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="xmlElementName">Name of the XML element.</param>
 /// <returns>Item.</returns>
 /* private */ Item GetObjectInstance(ExchangeService service, String xmlElementName)
 {
     return(EwsUtilities.CreateEwsObjectFromXmlElementName <Item>(service, xmlElementName));
 }
Пример #13
0
        /// <summary>
        /// Gets Item instance.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="xmlElementName">Name of the XML element.</param>
        /// <returns>Item.</returns>
        private Item GetObjectInstance(ExchangeService service, string xmlElementName)
        {
            this.returnedItem = EwsUtilities.CreateEwsObjectFromXmlElementName <Item>(service, xmlElementName);

            return(this.returnedItem);
        }
Пример #14
0
 /// <summary>
 /// Creates an item instance.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="xmlElementName">Name of the XML element.</param>
 /// <returns>Item</returns>
 private TItem CreateItemInstance(ExchangeService service, string xmlElementName)
 {
     return(EwsUtilities.CreateEwsObjectFromXmlElementName <TItem>(service, xmlElementName));
 }
    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();
        }
    }
 /// <summary>
 /// Gets Item instance.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="xmlElementName">Name of the XML element.</param>
 /// <returns>Item.</returns>
 internal override Item GetObjectInstance(ExchangeService service, string xmlElementName)
 {
     return(EwsUtilities.CreateEwsObjectFromXmlElementName <Item>(service, xmlElementName));
 }