Exemplo n.º 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.IsStartElement())
                    {
                        TEntry entry = this.CreateEntry(reader);

                        if (entry != null)
                        {
                            entry.LoadFromXml(reader, reader.LocalName);
                            this.InternalAdd(entry);
                        }
                        else
                        {
                            reader.SkipCurrentElement();
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, localElementName));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="xmlNamespace">The XML namespace.</param>
        /// <param name="localElementName">Name of the local element.</param>
        internal override void LoadFromXml(
            EwsServiceXmlReader reader,
            XmlNamespace xmlNamespace,
            string localElementName)
        {
            reader.EnsureCurrentNodeIsStartElement(xmlNamespace, localElementName);

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

                    if (reader.IsStartElement())
                    {
                        TComplexProperty complexProperty = this.CreateComplexProperty(reader.LocalName);

                        if (complexProperty != null)
                        {
                            complexProperty.LoadFromXml(reader, reader.LocalName);
                            this.InternalAdd(complexProperty, true);
                        }
                        else
                        {
                            reader.SkipCurrentElement();
                        }
                    }
                }while (!reader.IsEndElement(xmlNamespace, localElementName));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads from XML to update itself.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="xmlNamespace">The XML namespace.</param>
        /// <param name="xmlElementName">Name of the XML element.</param>
        internal override void UpdateFromXml(
            EwsServiceXmlReader reader,
            XmlNamespace xmlNamespace,
            string xmlElementName)
        {
            reader.EnsureCurrentNodeIsStartElement(xmlNamespace, xmlElementName);

            if (!reader.IsEmptyElement)
            {
                int index = 0;
                do
                {
                    reader.Read();

                    if (reader.IsStartElement())
                    {
                        TComplexProperty complexProperty       = this.CreateComplexProperty(reader.LocalName);
                        TComplexProperty actualComplexProperty = this[index++];

                        if (complexProperty == null || !complexProperty.GetType().IsInstanceOfType(actualComplexProperty))
                        {
                            throw new ServiceLocalException(Strings.PropertyTypeIncompatibleWhenUpdatingCollection);
                        }

                        actualComplexProperty.UpdateFromXml(reader, xmlNamespace, reader.LocalName);
                    }
                }while (!reader.IsEndElement(xmlNamespace, xmlElementName));
            }
        }
            /// <summary>
            /// Tries to read element from XML.
            /// </summary>
            /// <param name="reader">The reader.</param>
            /// <returns>True if element was read.</returns>
            internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
            {
                bool result = base.TryReadElementFromXml(reader);

                if (!result)
                {
                    if (reader.LocalName == XmlElementNames.FieldURIOrConstant)
                    {
                        reader.Read();
                        reader.EnsureCurrentNodeIsStartElement();

                        if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Constant))
                        {
                            this.value = reader.ReadAttributeValue(XmlAttributeNames.Value);

                            result = true;
                        }
                        else
                        {
                            result = PropertyDefinitionBase.TryLoadFromXml(reader, ref this.otherPropertyDefinition);
                        }
                    }
                }

                return(result);
            }
        /// <summary>
        /// Loads from XML
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="xmlNamespace">The XML namespace.</param>
        /// <param name="xmlElementName">Name of the XML element.</param>
        /// <param name="readAction"></param>
        private void InternalLoadFromXml(
            EwsServiceXmlReader reader,
            XmlNamespace xmlNamespace,
            string xmlElementName,
            Func <EwsServiceXmlReader, bool> readAction)
        {
            reader.EnsureCurrentNodeIsStartElement(xmlNamespace, xmlElementName);

            this.ReadAttributesFromXml(reader);

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

                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (!readAction(reader))
                        {
                            reader.SkipCurrentElement();
                        }
                        break;

                    case XmlNodeType.Text:
                        this.ReadTextValueFromXml(reader);
                        break;
                    }
                }while (!reader.IsEndElement(xmlNamespace, xmlElementName));
            }
        }
Exemplo n.º 6
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));
            }
        }
        /// <summary>
        /// Load from xml.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Retention policy tag object.</returns>
        internal static RetentionPolicyTag LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.RetentionPolicyTag);

            RetentionPolicyTag retentionPolicyTag = new RetentionPolicyTag();

            retentionPolicyTag.DisplayName     = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.DisplayName);
            retentionPolicyTag.RetentionId     = new Guid(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.RetentionId));
            retentionPolicyTag.RetentionPeriod = reader.ReadElementValue <int>(XmlNamespace.Types, XmlElementNames.RetentionPeriod);
            retentionPolicyTag.Type            = reader.ReadElementValue <ElcFolderType>(XmlNamespace.Types, XmlElementNames.Type);
            retentionPolicyTag.RetentionAction = reader.ReadElementValue <RetentionActionType>(XmlNamespace.Types, XmlElementNames.RetentionAction);

            // Description is not a required property.
            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Description))
            {
                retentionPolicyTag.Description = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Description);
            }

            retentionPolicyTag.IsVisible = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsVisible);
            retentionPolicyTag.OptedInto = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.OptedInto);
            retentionPolicyTag.IsArchive = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsArchive);

            return(retentionPolicyTag);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="allowNoMoreElements">If true the function returns false rather than throw an exception
        /// if the last element has been read.</param>
        internal bool LoadFromXml(EwsServiceXmlReader reader, bool allowNoMoreElements)
        {
            reader.Read();
            if (allowNoMoreElements && reader.NodeType == System.Xml.XmlNodeType.EndElement)
            {
                return(false);
            }

            reader.EnsureCurrentNodeIsStartElement(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);
            }
            return(true);
        }
        /// <summary>
        /// Tries to read element from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>True if element was read.</returns>
        internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement(this.Namespace, XmlElementNames.DictionaryEntry);

            this.LoadEntry(reader);

            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.Duration);

            this.startTime = reader.ReadElementValueAsDateTime(XmlNamespace.Types, XmlElementNames.StartTime).Value;
            this.endTime   = reader.ReadElementValueAsDateTime(XmlNamespace.Types, XmlElementNames.EndTime).Value;

            reader.ReadEndElement(XmlNamespace.Types, XmlElementNames.Duration);
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="xmlElementName">Name of the XML element.</param>
        internal override void LoadFromXml(EwsServiceXmlReader reader, string xmlElementName)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, xmlElementName);

            EwsUtilities.ParseEnumValueList <DayOfTheWeek>(
                this.items,
                reader.ReadElementValue(),
                ' ');
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="propertyBag">The property bag.</param>
        internal override sealed void LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, this.XmlElementName);

            if (!reader.IsEmptyElement || reader.HasAttributes)
            {
                this.InternalLoadFromXml(reader, propertyBag);
            }

            reader.ReadEndElementIfNecessary(XmlNamespace.Types, this.XmlElementName);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Load from xml
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal static MailboxStatisticsItem LoadFromXml(EwsServiceXmlReader reader)
        {
            MailboxStatisticsItem msi = new MailboxStatisticsItem();

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.MailboxStat);
            msi.MailboxId   = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.MailboxId);
            msi.DisplayName = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.DisplayName);
            msi.ItemCount   = reader.ReadElementValue <long>(XmlNamespace.Types, XmlElementNames.ItemCount);
            msi.Size        = reader.ReadElementValue <ulong>(XmlNamespace.Types, XmlElementNames.Size);
            return(msi);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Load from xml
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal static SearchRefinerItem LoadFromXml(EwsServiceXmlReader reader)
        {
            SearchRefinerItem sri = new SearchRefinerItem();

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.Refiner);
            sri.Name  = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Name);
            sri.Value = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Value);
            sri.Count = reader.ReadElementValue <long>(XmlNamespace.Types, XmlElementNames.Count);
            sri.Token = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Token);
            return(sri);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="xmlElementName">Name of the XML element.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader, string xmlElementName)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, xmlElementName);

            if (reader.HasAttributes)
            {
                this.culture = reader.ReadAttributeValue("xml:lang");
            }

            this.message = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Message);

            reader.ReadEndElement(XmlNamespace.Types, xmlElementName);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>SearchFilter.</returns>
        internal static SearchFilter LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement();

            string localName = reader.LocalName;

            SearchFilter searchFilter = GetSearchFilterInstance(localName);

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

            return(searchFilter);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Load extended properties xml
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <returns>Extended properties collection</returns>
        private static ExtendedPropertyCollection LoadExtendedPropertiesXml(EwsServiceXmlReader reader)
        {
            ExtendedPropertyCollection extendedProperties = new ExtendedPropertyCollection();

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.ExtendedProperties);
            do
            {
                reader.Read();
                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ExtendedProperty))
                {
                    extendedProperties.LoadFromXml(reader, XmlElementNames.ExtendedProperty);
                }
            }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.ExtendedProperties));

            return(extendedProperties.Count == 0 ? null : extendedProperties);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Tries to read element from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>True if element was read.</returns>
        internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement();

            TimeZoneTransition transition = TimeZoneTransition.Create(this.timeZoneDefinition, reader.LocalName);

            transition.LoadFromXml(reader);

            EwsUtilities.Assert(
                transition.TargetPeriod != null,
                "TimeZoneTransitionGroup.TryReadElementFromXml",
                "The transition's target period is null.");

            this.transitions.Add(transition);

            return(true);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Load keyword stats xml
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <returns>Array of keyword statistics</returns>
        private static KeywordStatisticsSearchResult[] LoadKeywordStatsXml(EwsServiceXmlReader reader)
        {
            List <KeywordStatisticsSearchResult> keywordStats = new List <KeywordStatisticsSearchResult>();

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.KeywordStats);
            do
            {
                reader.Read();
                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.KeywordStat))
                {
                    KeywordStatisticsSearchResult keywordStat = new KeywordStatisticsSearchResult();
                    keywordStat.Keyword  = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Keyword);
                    keywordStat.ItemHits = int.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ItemHits));
                    keywordStat.Size     = ulong.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Size));
                    keywordStats.Add(keywordStat);
                }
            }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.KeywordStats));

            return(keywordStats.Count == 0 ? null : keywordStats.ToArray());
        }
Exemplo n.º 20
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="propertyBag">The property bag.</param>
        internal override sealed void LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
        {
            ResponseActions value = ResponseActions.None;

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, this.XmlElementName);

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

                    if (reader.IsStartElement())
                    {
                        value |= GetResponseAction(reader.LocalName);
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, this.XmlElementName));
            }

            propertyBag[this] = value;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Load from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void InternalLoadFromXml(EwsServiceXmlReader reader)
        {
            base.InternalLoadFromXml(reader);

            this.folderId = new FolderId();
            this.folderId.LoadFromXml(reader, reader.LocalName);

            reader.Read();

            this.ParentFolderId = new FolderId();
            this.ParentFolderId.LoadFromXml(reader, XmlElementNames.ParentFolderId);

            switch (this.EventType)
            {
            case EventType.Moved:
            case EventType.Copied:
                reader.Read();

                this.oldFolderId = new FolderId();
                this.oldFolderId.LoadFromXml(reader, reader.LocalName);

                reader.Read();

                this.OldParentFolderId = new FolderId();
                this.OldParentFolderId.LoadFromXml(reader, reader.LocalName);
                break;

            case EventType.Modified:
                reader.Read();
                if (reader.IsStartElement())
                {
                    reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.UnreadCount);
                    this.unreadCount = int.Parse(reader.ReadValue());
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Load from xml
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <returns>Searchable mailbox object</returns>
        internal static SearchableMailbox LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.SearchableMailbox);

            SearchableMailbox searchableMailbox = new SearchableMailbox();

            searchableMailbox.Guid        = new Guid(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Guid));
            searchableMailbox.SmtpAddress = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.PrimarySmtpAddress);
            bool isExternalMailbox = false;

            bool.TryParse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.IsExternalMailbox), out isExternalMailbox);
            searchableMailbox.IsExternalMailbox    = isExternalMailbox;
            searchableMailbox.ExternalEmailAddress = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ExternalEmailAddress);
            searchableMailbox.DisplayName          = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.DisplayName);
            bool isMembershipGroup = false;

            bool.TryParse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.IsMembershipGroup), out isMembershipGroup);
            searchableMailbox.IsMembershipGroup = isMembershipGroup;
            searchableMailbox.ReferenceId       = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ReferenceId);

            return(searchableMailbox);
        }
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="propertyBag">The property bag.</param>
        internal override void LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.Recurrence);

            Recurrence recurrence = null;

            reader.Read(XmlNodeType.Element); // This is the pattern element

            recurrence = GetRecurrenceFromString(reader.LocalName);

            recurrence.LoadFromXml(reader, reader.LocalName);

            reader.Read(XmlNodeType.Element); // This is the range element

            RecurrenceRange range = GetRecurrenceRange(reader.LocalName);

            range.LoadFromXml(reader, reader.LocalName);
            range.SetupRecurrence(recurrence);

            reader.ReadEndElementIfNecessary(XmlNamespace.Types, XmlElementNames.Recurrence);

            propertyBag[this] = recurrence;
        }
        /// <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);

            reader.ReadStartElement(XmlNamespace.Types, this.InnerCollectionXmlElementName);
            base.LoadFromXml(reader, this.InnerCollectionXmlElementName);
            reader.ReadEndElementIfNecessary(XmlNamespace.Types, this.InnerCollectionXmlElementName);

            reader.Read();

            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.UnknownEntries))
            {
                do
                {
                    reader.Read();

                    if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.UnknownEntry))
                    {
                        this.unknownEntries.Add(reader.ReadElementValue());
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.UnknownEntries));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Load failed mailboxes xml
        /// </summary>
        /// <param name="rootXmlNamespace">Root xml namespace</param>
        /// <param name="reader">The reader</param>
        /// <returns>Array of failed mailboxes</returns>
        internal static FailedSearchMailbox[] LoadFailedMailboxesXml(XmlNamespace rootXmlNamespace, EwsServiceXmlReader reader)
        {
            List <FailedSearchMailbox> failedMailboxes = new List <FailedSearchMailbox>();

            reader.EnsureCurrentNodeIsStartElement(rootXmlNamespace, XmlElementNames.FailedMailboxes);
            do
            {
                reader.Read();
                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.FailedMailbox))
                {
                    string mailbox   = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Mailbox);
                    int    errorCode = 0;
                    int.TryParse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ErrorCode), out errorCode);
                    string errorMessage = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ErrorMessage);
                    bool   isArchive    = false;
                    bool.TryParse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.IsArchive), out isArchive);

                    failedMailboxes.Add(new FailedSearchMailbox(mailbox, errorCode, errorMessage, isArchive));
                }
            }while (!reader.IsEndElement(rootXmlNamespace, XmlElementNames.FailedMailboxes));

            return(failedMailboxes.Count == 0 ? null : failedMailboxes.ToArray());
        }
Exemplo n.º 26
0
        /// <summary>
        /// Load preview items xml
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <returns>Array of preview items</returns>
        private static SearchPreviewItem[] LoadPreviewItemsXml(EwsServiceXmlReader reader)
        {
            List <SearchPreviewItem> previewItems = new List <SearchPreviewItem>();

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.Items);
            do
            {
                reader.Read();
                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SearchPreviewItem))
                {
                    SearchPreviewItem previewItem = new SearchPreviewItem();
                    do
                    {
                        reader.Read();
                        if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Id))
                        {
                            previewItem.Id = new ItemId();
                            previewItem.Id.ReadAttributesFromXml(reader);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ParentId))
                        {
                            previewItem.ParentId = new ItemId();
                            previewItem.ParentId.ReadAttributesFromXml(reader);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Mailbox))
                        {
                            previewItem.Mailbox                    = new PreviewItemMailbox();
                            previewItem.Mailbox.MailboxId          = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.MailboxId);
                            previewItem.Mailbox.PrimarySmtpAddress = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.PrimarySmtpAddress);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.UniqueHash))
                        {
                            previewItem.UniqueHash = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.UniqueHash);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SortValue))
                        {
                            previewItem.SortValue = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SortValue);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.OwaLink))
                        {
                            previewItem.OwaLink = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.OwaLink);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Sender))
                        {
                            previewItem.Sender = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Sender);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ToRecipients))
                        {
                            previewItem.ToRecipients = GetRecipients(reader, XmlElementNames.ToRecipients);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CcRecipients))
                        {
                            previewItem.CcRecipients = GetRecipients(reader, XmlElementNames.CcRecipients);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.BccRecipients))
                        {
                            previewItem.BccRecipients = GetRecipients(reader, XmlElementNames.BccRecipients);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CreatedTime))
                        {
                            previewItem.CreatedTime = DateTime.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.CreatedTime));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ReceivedTime))
                        {
                            previewItem.ReceivedTime = DateTime.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.ReceivedTime));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.SentTime))
                        {
                            previewItem.SentTime = DateTime.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SentTime));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Subject))
                        {
                            previewItem.Subject = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Subject);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Preview))
                        {
                            previewItem.Preview = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Preview);
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Size))
                        {
                            previewItem.Size = ulong.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Size));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Importance))
                        {
                            previewItem.Importance = (Importance)Enum.Parse(typeof(Importance), reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Importance));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Read))
                        {
                            previewItem.Read = bool.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Read));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.HasAttachment))
                        {
                            previewItem.HasAttachment = bool.Parse(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.HasAttachment));
                        }
                        else if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ExtendedProperties))
                        {
                            previewItem.ExtendedProperties = LoadExtendedPropertiesXml(reader);
                        }
                    }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.SearchPreviewItem));

                    previewItems.Add(previewItem);
                }
            }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.Items));

            return(previewItems.Count == 0 ? null : previewItems.ToArray());
        }
Exemplo n.º 27
0
        /// <summary>
        /// Load from xml
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <returns>Discovery search configuration object</returns>
        internal 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           = string.Empty;
            configuration.InPlaceHoldIdentity   = string.Empty;
            configuration.ManagedByOrganization = string.Empty;
            configuration.Language = string.Empty;

            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);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="propertyBag">The property bag.</param>
        internal override sealed void LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
        {
            EffectiveRights value = EffectiveRights.None;

            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, this.XmlElementName);

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

                    if (reader.IsStartElement())
                    {
                        switch (reader.LocalName)
                        {
                        case XmlElementNames.CreateAssociated:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.CreateAssociated;
                            }
                            break;

                        case XmlElementNames.CreateContents:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.CreateContents;
                            }
                            break;

                        case XmlElementNames.CreateHierarchy:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.CreateHierarchy;
                            }
                            break;

                        case XmlElementNames.Delete:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.Delete;
                            }
                            break;

                        case XmlElementNames.Modify:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.Modify;
                            }
                            break;

                        case XmlElementNames.Read:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.Read;
                            }
                            break;

                        case XmlElementNames.ViewPrivateItems:
                            if (reader.ReadElementValue <bool>())
                            {
                                value |= EffectiveRights.ViewPrivateItems;
                            }
                            break;
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Types, this.XmlElementName));
            }

            propertyBag[this] = value;
        }
Exemplo n.º 29
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));
            }
        }