示例#1
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());
        }
        /// <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();
        }