示例#1
0
        /// <summary>
        /// Deserializes a Connectivity Response.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <returns>
        /// A PayloadResponse object with the operation id for the data.
        /// </returns>
        public PayloadResponse <Guid> DeserializeConnectivityResponse(string payload)
        {
            XmlDocument doc = new XmlDocument();

            using (var stream = payload.ToUtf8Stream())
                using (var reader = XmlReader.Create(stream))
                {
                    doc.Load(reader);
                }
            var manager = new DynaXmlNamespaceTable(doc);
            PayloadResponse <Guid> result = new PayloadResponse <Guid>();
            var node = doc.SelectSingleNode("/def:PassthroughResponse/def:Data", manager.NamespaceManager);

            if (node.IsNotNull() && node.InnerText.IsNotNullOrEmpty())
            {
                var  text = node.InnerText;
                Guid guid;
                if (!Guid.TryParse(text, out guid))
                {
                    throw new SerializationException("Unable to deserialize the server response.");
                }
                result.Data = guid;
            }
            node = doc.SelectSingleNode("/def:PassthroughResponse/def:Error", manager.NamespaceManager);
            result.ErrorDetails = this.GetErrorDetails(node, manager.NamespaceManager);
            return(result);
        }
示例#2
0
        /// <inheritdoc />
        public PayloadResponse <UserChangeRequestStatus> DeserializeConnectivityStatus(string payload)
        {
            XmlDocument doc = new XmlDocument();

            using (var stream = payload.ToUtf8Stream())
                using (var reader = XmlReader.Create(stream))
                {
                    doc.Load(reader);
                }
            var manager = new DynaXmlNamespaceTable(doc);
            PayloadResponse <UserChangeRequestStatus> result = new PayloadResponse <UserChangeRequestStatus>();
            var node = doc.SelectSingleNode("/def:PassthroughResponse/def:Data", manager.NamespaceManager);

            if (node.IsNotNull())
            {
                result.Data = new UserChangeRequestStatus();
                var data = node;
                node = data.SelectSingleNode("def:State", manager.NamespaceManager);
                UserChangeRequestOperationStatus status;
                if (node.IsNull() || !UserChangeRequestOperationStatus.TryParse(node.InnerText, out status))
                {
                    throw new SerializationException("Unable to deserialize the server response.");
                }
                result.Data.State = status;

                node = data.SelectSingleNode("def:UserType", manager.NamespaceManager);
                UserChangeRequestUserType userType;
                if (node.IsNull() || !UserChangeRequestUserType.TryParse(node.InnerText, out userType))
                {
                    throw new SerializationException("Unable to deserialize the server response.");
                }
                result.Data.UserType = userType;

                node = data.SelectSingleNode("def:OperationType", manager.NamespaceManager);
                UserChangeRequestOperationType operationType;
                if (node.IsNull() || !UserChangeRequestOperationType.TryParse(node.InnerText, out operationType))
                {
                    throw new SerializationException("Unable to deserialize the server response.");
                }
                result.Data.OperationType = operationType;

                node = data.SelectSingleNode("def:RequestIssueDate", manager.NamespaceManager);
                DateTime requestTime;
                if (node.IsNull() || !DateTime.TryParse(node.InnerText, out requestTime))
                {
                    throw new SerializationException("Unable to deserialize the server response.");
                }
                result.Data.RequestIssueDate = requestTime.ToUniversalTime();

                node = data.SelectSingleNode("def:Error", manager.NamespaceManager);
                result.Data.ErrorDetails = this.GetErrorDetails(node, manager.NamespaceManager);
            }
            node = doc.SelectSingleNode("/def:PassthroughResponse/def:Error", manager.NamespaceManager);
            result.ErrorDetails = this.GetErrorDetails(node, manager.NamespaceManager);

            return(result);
        }