Пример #1
0
        /// <summary>
        /// Get policies from Provision command response.
        /// </summary>
        /// <param name="provisionResponse">The response of Provision command.</param>
        /// <returns>The dictionary of policies gotten from Provision command response.</returns>
        public static Dictionary<string, string> GetPoliciesFromProvisionResponse(ActiveSyncResponseBase<Response.Provision> provisionResponse)
        {
            Dictionary<string, string> policiesSetting = new Dictionary<string, string>();
            if (null == provisionResponse || string.IsNullOrEmpty(provisionResponse.ResponseDataXML))
            {
                return policiesSetting;
            }

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(provisionResponse.ResponseDataXML);
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
            namespaceManager.AddNamespace("prov", "Provision");
            XmlNode provisionDocNode = xmlDoc.SelectSingleNode(@"//prov:EASProvisionDoc", namespaceManager);

            if (provisionDocNode != null && provisionDocNode.HasChildNodes)
            {
                foreach (XmlNode policySetting in provisionDocNode.ChildNodes)
                {
                    string policyValue = string.IsNullOrEmpty(policySetting.InnerText) ? string.Empty : policySetting.InnerText;
                    string policyName = string.IsNullOrEmpty(policySetting.LocalName) ? string.Empty : policySetting.LocalName;
                    policiesSetting.Add(policyName, policyValue);
                }
            }

            return policiesSetting;
        }
Пример #2
0
        /// <summary>
        /// Get policies from Provision command response.
        /// </summary>
        /// <param name="provisionResponse">The response of Provision command.</param>
        /// <returns>The dictionary of policies gotten from Provision command response.</returns>
        public static Dictionary <string, string> GetPoliciesFromProvisionResponse(ActiveSyncResponseBase <Response.Provision> provisionResponse)
        {
            Dictionary <string, string> policiesSetting = new Dictionary <string, string>();

            if (null == provisionResponse || string.IsNullOrEmpty(provisionResponse.ResponseDataXML))
            {
                return(policiesSetting);
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(provisionResponse.ResponseDataXML);
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);

            namespaceManager.AddNamespace("prov", "Provision");
            XmlNode provisionDocNode = xmlDoc.SelectSingleNode(@"//prov:EASProvisionDoc", namespaceManager);

            if (provisionDocNode != null && provisionDocNode.HasChildNodes)
            {
                foreach (XmlNode policySetting in provisionDocNode.ChildNodes)
                {
                    string policyValue = string.IsNullOrEmpty(policySetting.InnerText) ? string.Empty : policySetting.InnerText;
                    string policyName  = string.IsNullOrEmpty(policySetting.LocalName) ? string.Empty : policySetting.LocalName;
                    policiesSetting.Add(policyName, policyValue);
                }
            }

            return(policiesSetting);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Convert the instance of SendStringResponse to SyncResponse.
        /// </summary>
        /// <param name="syncResponseString">The SendStringResponse instance to convert.</param>
        /// <returns>The instance of SyncResponse.</returns>
        public static SyncResponse ConvertSyncResponseFromSendString(ActiveSyncResponseBase <object> syncResponseString)
        {
            SyncResponse syncResponse = new SyncResponse
            {
                ResponseDataXML = syncResponseString.ResponseDataXML,
                Headers         = syncResponseString.Headers
            };

            syncResponse.DeserializeResponseData();

            return(syncResponse);
        }
        /// <summary>
        /// Convert the instance of SendStringResponse to SyncResponse.
        /// </summary>
        /// <param name="syncResponseString">The SendStringResponse instance to convert.</param>
        /// <returns>The instance of SyncResponse.</returns>
        public static SyncResponse ConvertSyncResponseFromSendString(ActiveSyncResponseBase<object> syncResponseString)
        {
            SyncResponse syncResponse = new SyncResponse
            {
                ResponseDataXML = syncResponseString.ResponseDataXML,
                Headers = syncResponseString.Headers
            };

            syncResponse.DeserializeResponseData();

            return syncResponse;
        }
Пример #6
0
        /// <summary>
        /// Get policy key from Provision string response.
        /// </summary>
        /// <param name="provisionResponseString">The SendStringResponse instance of Provision command.</param>
        /// <returns>The policy key of the policy.</returns>
        public static string GetPolicyKeyFromSendString(ActiveSyncResponseBase <object> provisionResponseString)
        {
            ProvisionResponse provisionResponse = new ProvisionResponse
            {
                ResponseDataXML = provisionResponseString.ResponseDataXML
            };

            if (!string.IsNullOrEmpty(provisionResponse.ResponseDataXML))
            {
                provisionResponse.DeserializeResponseData();

                if (provisionResponse.ResponseData.Policies != null)
                {
                    Response.ProvisionPoliciesPolicy policyInResponse = provisionResponse.ResponseData.Policies.Policy;
                    if (policyInResponse != null)
                    {
                        return(policyInResponse.PolicyKey);
                    }
                }
            }

            return(string.Empty);
        }
        /// <summary>
        /// Get policy key from Provision string response.
        /// </summary>
        /// <param name="provisionResponseString">The SendStringResponse instance of Provision command.</param>
        /// <returns>The policy key of the policy.</returns>
        public static string GetPolicyKeyFromSendString(ActiveSyncResponseBase<object> provisionResponseString)
        {
            ProvisionResponse provisionResponse = new ProvisionResponse
            {
                ResponseDataXML = provisionResponseString.ResponseDataXML
            };

            if (!string.IsNullOrEmpty(provisionResponse.ResponseDataXML))
            {
                provisionResponse.DeserializeResponseData();

                if (provisionResponse.ResponseData.Policies != null)
                {
                    Response.ProvisionPoliciesPolicy policyInResponse = provisionResponse.ResponseData.Policies.Policy;
                    if (policyInResponse != null)
                    {
                        return policyInResponse.PolicyKey;
                    }
                }
            }

            return string.Empty;
        }
Пример #8
0
        /// <summary>
        /// Get the DisplayName or ParentId of the specified folder from FolderSync response.
        /// </summary>
        /// <param name="folderSyncResponse">The FolderSync response.</param>
        /// <param name="folderServerId">The ServerId of the folder to get.</param>
        /// <param name="elementName">The element name of the folder to get, it should be DisplayName or ParentId.</param>
        /// <returns>The value of DisplayName or ParentId.</returns>
        protected string GetFolderFromFolderSyncResponse(ActiveSyncResponseBase<Response.FolderSync> folderSyncResponse, string folderServerId, string elementName)
        {
            Site.Assert.IsNotNull(folderSyncResponse, "The FolderSyncResponse should not be null.");
            Site.Assert.IsNotNull(folderSyncResponse.ResponseData, "The FolderSyncResponse.ResponseData should not be null.");
            Site.Assert.IsNotNull(folderSyncResponse.ResponseData.Changes, "The FolderSyncResponse.ResponseData.Changes should not be null.");
            Site.Assert.IsNotNull(folderSyncResponse.ResponseData.Changes.Add, "The FolderSyncResponse.ResponseData.Changes.Add should not be null.");

            foreach (Response.FolderSyncChangesAdd add in folderSyncResponse.ResponseData.Changes.Add)
            {
                if (add.ServerId == folderServerId)
                {
                    if (elementName == "DisplayName")
                    {
                        return add.DisplayName;
                    }
                    else if (elementName == "ParentId")
                    {
                        return add.ParentId;
                    }
                }
            }

            return null;
        }
        /// <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;
        }