/// <summary>
        /// Swap old id with new one.
        /// </summary>
        /// <param name="oldValue">Old value.</param>
        /// <param name="newValue">New value.</param>
        private void SwapId(MailboxId oldValue, MailboxId newValue)
        {
            string[]      pathSegments = this.requestUriBuilder.Path.Split('/');
            List <string> newSegments  = new List <string>(pathSegments.Length);

            for (int i = 0; i < pathSegments.Length; i++)
            {
                // 'me' id shouldn't contain 'users'
                if (newValue.IdInMeForm &&
                    pathSegments[i].Equals("users", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (pathSegments[i].Equals(oldValue.Id, StringComparison.OrdinalIgnoreCase))
                {
                    if (oldValue.IdInMeForm &&
                        !newValue.IdInMeForm)
                    {
                        newSegments.Add(newValue.MailboxType);
                        newSegments.Add(newValue.Id);
                    }
                    else
                    {
                        newSegments.Add(newValue.Id);
                    }

                    continue;
                }

                newSegments.Add(pathSegments[i]);
            }

            this.requestUriBuilder.Path = string.Join("/", newSegments);
        }
Esempio n. 2
0
        /// <summary>
        /// Create new instance of <see cref="EntityId"/>
        /// </summary>
        /// <param name="entityId">Entity id.</param>
        /// <param name="mailboxId">Mailbox id.</param>
        protected EntityId(string entityId, MailboxId mailboxId, Type idType)
        {
            ArgumentValidator.ThrowIfNullOrEmpty(entityId, nameof(entityId));
            ArgumentValidator.ThrowIfNull(mailboxId, nameof(mailboxId));
            ArgumentValidator.ThrowIfNull(idType, nameof(idType));

            switch (idType.Name)
            {
            case EntityId.MessageTypeName:
                this.RootContainer = "messages";
                break;

            case EntityId.MailFolderTypeName:
                this.RootContainer = "mailfolders";
                break;

            case EntityId.AttachmentTypeName:
                this.RootContainer = "attachments";
                break;

            case EntityId.CalendarFolderTypeName:
                this.RootContainer = "calendars";
                break;

            case EntityId.EventsTypeName:
                this.RootContainer = "events";
                break;

            case EntityId.TaskTypeName:
                this.RootContainer = "tasks";
                break;

            case EntityId.TaskFolderTypeName:
                this.RootContainer = "taskfolders";
                break;

            case EntityId.InferenceClassificationName:
                this.RootContainer = "inferenceClassification";
                break;

            case EntityId.ContactFolderTypeName:
                this.RootContainer = "contactfolders";
                break;

            case EntityId.ContactsTypeName:
                this.RootContainer = "contacts";
                break;

            default:
                throw new NotImplementedException(idType.Name);
            }

            this.MailboxId = mailboxId;
            this.Id        = entityId;
        }
Esempio n. 3
0
 /// <summary>
 /// Register service with objects and reset change tracking.
 /// </summary>
 /// <param name="service"></param>
 internal void RegisterServiceAndResetChangeTracking(ExchangeService service, MailboxId mailboxId)
 {
     if (this.Value != null && this.Value.Count > 0)
     {
         foreach (T entity in this.Value)
         {
             entity.Service   = service;
             entity.MailboxId = mailboxId;
             entity.ResetChangeTracking();
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Create new instance of <see cref="SyncMailFolderHierarchyResponse"/>
 /// </summary>
 /// <param name="entityResponseCollection"></param>
 public SyncMailFolderHierarchyResponse(SyncMailFolderEntityResponseCollection entityResponseCollection, ExchangeService exchangeService, MailboxId mailboxId)
     : base(entityResponseCollection)
 {
     entityResponseCollection.RegisterServiceAndResetChangeTracking(exchangeService, mailboxId);
     byte[] syncStateBytes = Encoding.UTF8.GetBytes(entityResponseCollection.ODataDeltaLink);
     this.SyncState = Convert.ToBase64String(syncStateBytes);
 }
Esempio n. 5
0
 protected ItemId(string entityId, MailboxId mailboxId, Type type)
     : base(entityId, mailboxId, type)
 {
 }
        /// <summary>
        /// Create new instance of <see cref="SyncItemCollection{T}"/>
        /// </summary>
        /// <param name="entityResponseCollection">Response collection.</param>
        internal SyncFolderItemsCollection(SyncEntityResponseCollection <T> entityResponseCollection, ExchangeService exchangeService, MailboxId mailboxId)
            : base(entityResponseCollection)
        {
            if (entityResponseCollection != null)
            {
                // if token isn't delta, then it is skip.
                if (!SyncToken.TryParseFromUrl(entityResponseCollection.ODataDeltaLink, SyncTokenType.DeltaToken, out this.syncToken))
                {
                    SyncToken.TryParseFromUrl(entityResponseCollection.ODataNextLink, SyncTokenType.SkipToken, out this.syncToken);
                }

                // Since property bag will be 'dirty' after loading
                // properties from JSON, reset change tracking since
                // latest version is already in the collection.
                entityResponseCollection.RegisterServiceAndResetChangeTracking(
                    exchangeService,
                    mailboxId);
            }
        }
Esempio n. 7
0
 public MessageId(string entityId, MailboxId mailboxId)
     : base(entityId, mailboxId, typeof(Message))
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Create new instance of <see cref="TaskId"/>
 /// </summary>
 /// <param name="entityId">Entity Id.</param>
 /// <param name="mailboxId">Mailbox id.</param>
 public TaskId(string entityId, MailboxId mailboxId)
     : base(entityId, mailboxId, typeof(Task))
 {
 }
 /// <summary>
 /// Create new instance of <see cref="ContactId"/>
 /// </summary>
 /// <param name="entityId">Entity Id.</param>
 /// <param name="mailboxId">Mailbox Id.</param>
 public ContactId(string entityId, MailboxId mailboxId)
     : base(entityId, mailboxId, typeof(Contact))
 {
 }
Esempio n. 10
0
 public EventId(string entityId, MailboxId mailboxId)
     : base(entityId, mailboxId, typeof(Event))
 {
 }
 /// <summary>
 /// Create new instance of <see cref="FindItemsResults{TItem}"/>.
 /// </summary>
 /// <param name="entityResponseCollection">Response collection.</param>
 internal FindItemsResults(EntityResponseCollection <TItem> entityResponseCollection, ExchangeService exchangeService, MailboxId mailboxId)
     : base(entityResponseCollection)
 {
     if (this.Items != null)
     {
         foreach (TItem item in this.Items)
         {
             item.Service   = exchangeService;
             item.MailboxId = mailboxId;
             item.ResetChangeTracking();
         }
     }
 }