Beispiel #1
0
        /// <summary>
        /// This method is used to check the Add element in Sync response.
        /// </summary>
        /// <param name="syncKey">The sync key</param>
        /// <param name="collectionId">Folder's collectionID</param>
        /// <param name="subject">The subject of item which is expected to add</param>
        /// <returns>The boolean value which indicates the Add element is found in Sync response or not</returns>
        private bool CheckAddInSyncResponse(string syncKey, string collectionId, string subject)
        {
            SyncResponse syncResponse = syncKey != null
                ? this.SyncChanges(syncKey, collectionId)
                : this.SyncChanges(collectionId);

            Response.SyncCollectionsCollectionCommands commands = this.GetCommandsFromSyncResponse(syncResponse);

            if (commands == null || commands.Add == null)
            {
                return(false);
            }
            else
            {
                Site.Assert.IsNotNull(commands.Add, "The Add element in Sync response for collection ID: {0} should not be null", collectionId);
            }

            foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
            {
                Site.Assert.IsNotNull(add, "The Add element in Sync response for collection ID: {0} should not be null", collectionId);
                for (int i = 0; i < add.ApplicationData.Items.Length; i++)
                {
                    if (add.ApplicationData.ItemsElementName[i] == Response.ItemsChoiceType8.Subject1)
                    {
                        if (subject.Equals(add.ApplicationData.Items[i].ToString()))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Load sync response to sync store.
        /// </summary>
        /// <param name="response">The response of Sync command.</param>
        /// <returns>The sync store instance.</returns>
        public static SyncStore LoadSyncResponse(ActiveSyncResponseBase <Response.Sync> response)
        {
            if (response.ResponseData.Item == null)
            {
                return(null);
            }

            SyncStore result = new SyncStore();

            Response.SyncCollectionsCollection collection = ((Response.SyncCollections)response.ResponseData.Item).Collection[0];
            for (int i = 0; i < collection.ItemsElementName.Length; i++)
            {
                switch (collection.ItemsElementName[i])
                {
                case Response.ItemsChoiceType10.CollectionId:
                    result.CollectionId = collection.Items[i].ToString();
                    break;

                case Response.ItemsChoiceType10.SyncKey:
                    result.SyncKey = collection.Items[i].ToString();
                    break;

                case Response.ItemsChoiceType10.Status:
                    result.Status = Convert.ToByte(collection.Items[i]);
                    break;

                case Response.ItemsChoiceType10.Commands:
                    Response.SyncCollectionsCollectionCommands commands = collection.Items[i] as Response.SyncCollectionsCollectionCommands;
                    if (commands != null)
                    {
                        foreach (SyncItem item in LoadAddCommands(commands))
                        {
                            result.AddCommands.Add(item);
                        }
                    }

                    break;

                case Response.ItemsChoiceType10.Responses:
                    Response.SyncCollectionsCollectionResponses responses = collection.Items[i] as Response.SyncCollectionsCollectionResponses;
                    if (responses != null)
                    {
                        if (responses.Add != null)
                        {
                            foreach (Response.SyncCollectionsCollectionResponsesAdd add in responses.Add)
                            {
                                result.AddResponses.Add(add);
                            }
                        }
                    }

                    break;
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// This method is used to check the Delete element in Sync response.
        /// </summary>
        /// <param name="syncKey">The sync key</param>
        /// <param name="collectionId">Folder's collectionID</param>
        /// <param name="serverId">The ServerId of item which is expected to delete</param>
        /// <returns>The boolean value which indicates the Delete element is found in Sync response or not</returns>
        private bool CheckDeleteInSyncResponse(string syncKey, string collectionId, string serverId)
        {
            SyncResponse syncResponse = this.SyncChanges(syncKey, collectionId);

            Response.SyncCollectionsCollectionCommands commands = this.GetCommandsFromSyncResponse(syncResponse);

            Site.Assert.IsNotNull(commands.Delete, "The Delete elements in Sync response for collection ID: {0} should not be null.", collectionId);
            foreach (Response.SyncCollectionsCollectionCommandsDelete delete in commands.Delete)
            {
                Site.Assert.IsNotNull(delete, "The Delete element in Sync response for collection ID: {0} should not be null.", collectionId);
                if (serverId.Equals(delete.ServerId))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Load add commands in sync response.
        /// </summary>
        /// <param name="collectionCommands">The add commands response.</param>
        /// <returns>The list of SyncItem in add commands.</returns>
        public static Collection <SyncItem> LoadAddCommands(Response.SyncCollectionsCollectionCommands collectionCommands)
        {
            if (collectionCommands.Add != null)
            {
                Collection <SyncItem> commands = new Collection <SyncItem>();
                if (collectionCommands.Add.Length > 0)
                {
                    foreach (Response.SyncCollectionsCollectionCommandsAdd addCommand in collectionCommands.Add)
                    {
                        SyncItem syncItem = new SyncItem {
                            ServerId = addCommand.ServerId
                        };
                        for (int i = 0; i < addCommand.ApplicationData.ItemsElementName.Length; i++)
                        {
                            switch (addCommand.ApplicationData.ItemsElementName[i])
                            {
                            case Response.ItemsChoiceType8.Subject1:
                                syncItem.Subject = addCommand.ApplicationData.Items[i].ToString();
                                break;

                            case Response.ItemsChoiceType8.Subject:
                                syncItem.Subject = addCommand.ApplicationData.Items[i].ToString();
                                break;
                            }
                        }

                        commands.Add(syncItem);
                    }
                }

                return(commands);
            }
            else
            {
                return(null);
            }
        }