Example #1
0
        /// <summary>
        /// Get the request body.
        /// </summary>
        /// <typeparam name="T">The data type.</typeparam>
        /// <param name="body">The body containg the data.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="queryBody">The query body.</param>
        /// <param name="bodyOriginal">The original body.</param>
        /// <returns>The new type.</returns>
        /// <exception cref="System.Exception"></exception>
        public static T RequestBody <T>(string body, NameValueCollection queryString, NameValueCollection queryBody, byte[] bodyOriginal)
        {
            T requestBody = default(T);

            // If the data format key query exists.
            if (queryString[DataFormatQueryStringKey] != null)
            {
                // Select the data format.
                switch (queryString[DataFormatQueryStringKey].ToLower())
                {
                case "query":
                    // Query data format.
                    requestBody = Nequeo.Serialisation.NameValue.Deserializer <T>(queryBody);
                    break;

                case "xml":
                    // Xml data format.
                    requestBody = RequestDeserialiseAction <T>(queryString, bodyOriginal).Body;
                    break;

                case "json":
                    // Json data format.
                    requestBody = JavaObjectNotation.JavaScriptDeserializer <T>(body);
                    break;

                default:
                    break;
                }
            }

            // Return the body data.
            return(requestBody);
        }
Example #2
0
        /// <summary>
        /// Parse the data according to the format.
        /// </summary>
        /// <param name="queryString">The query string.</param>
        /// <param name="queryBody">The query body.</param>
        /// <param name="bodyString">The body string.</param>
        /// <returns>The web request.</returns>
        /// <exception cref="System.Exception"></exception>
        public static WebRequest Request(NameValueCollection queryString, NameValueCollection queryBody, string bodyString)
        {
            WebRequest request = null;

            // If the data format key query exists.
            if (queryString[DataFormatQueryStringKey] != null)
            {
                // Select the data format.
                switch (queryString[DataFormatQueryStringKey].ToLower())
                {
                case "query":
                    // Query data format.
                    string requestName = (queryBody["name"] != null ? queryBody["name"] : "");
                    request = new WebRequest()
                    {
                        Name = requestName, Body = bodyString
                    };
                    break;

                case "xml":
                    // Deserialise the data.
                    XDocument xml  = Document.LoadDocumentParseXmlString(bodyString);
                    string    name = xml.Element("WebRequest").Element("Name").Value;
                    request = new WebRequest()
                    {
                        Name = name
                    };
                    break;

                case "json":
                    // Json data format.
                    request = JavaObjectNotation.JavaScriptDeserializer <WebRequest>(bodyString);
                    break;

                default:
                    // Create an empty request.
                    request = new WebRequest();
                    break;
                }
            }
            else
            {
                // Create an empty request.
                request = new WebRequest();
            }

            // Return the request.
            return(request);
        }
Example #3
0
 /// <summary>
 /// Deserialise the current object type.
 /// </summary>
 /// <typeparam name="T">The type to examine.</typeparam>
 /// <param name="source">The current source object type.</param>
 /// <returns>The deserialised obejct type.</returns>
 public static T DeserialiseJson <T>(this string source)
 {
     return(JavaObjectNotation.JavaScriptDeserializer <T>(source));
 }
Example #4
0
        /// <summary>
        /// Deserialise the current object type.
        /// </summary>
        /// <typeparam name="T">The type to examine.</typeparam>
        /// <param name="source">The current source object type.</param>
        /// <returns>The deserialised obejct type.</returns>
        public static T DeserialiseJson <T>(this byte[] source)
        {
            string json = Encoding.Default.GetString(source);

            return(JavaObjectNotation.JavaScriptDeserializer <T>(json));
        }