Example #1
0
        public Boolean ParseHTTP(String ParameterName, HTTPRequest HTTPRequest, out String Value, out HTTPResponse HTTPResp, String Context = null, String DefaultValue = null)
        {
            Object JSONToken;

            if (!TryGetValue(ParameterName, out JSONToken))
            {
                Value    = DefaultValue;
                HTTPResp = HTTPExtentions.CreateBadRequest(HTTPRequest, Context, ParameterName);

                return(false);
            }

            if (JSONToken != null)
            {
                Value = JSONToken.ToString();

                if (Value.IsNullOrEmpty())
                {
                    Value    = DefaultValue;
                    HTTPResp = HTTPExtentions.CreateBadRequest(HTTPRequest, Context, ParameterName, JSONToken.ToString());

                    return(false);
                }
            }

            else
            {
                Value    = DefaultValue;
                HTTPResp = null;
                return(false);
            }

            HTTPResp = null;
            return(true);
        }
Example #2
0
        public Boolean ParseHTTP(String ParameterName, HTTPRequest HTTPRequest, out Double Value, out HTTPResponse HTTPResp, String Context = null, Double DefaultValue = 0)
        {
            Object JSONToken;

            if (!TryGetValue(ParameterName, out JSONToken))
            {
                Value    = DefaultValue;
                HTTPResp = HTTPExtentions.CreateBadRequest(HTTPRequest, Context, ParameterName);

                return(false);
            }

            if (JSONToken != null)
            {
                if (!Double.TryParse(JSONToken.ToString(), NumberStyles.Any, CultureInfo.CreateSpecificCulture("en-US"), out Value))
                {
                    Log.Timestamp("Bad request: Invalid \"" + ParameterName + "\" property value!");

                    Value    = DefaultValue;
                    HTTPResp = HTTPExtentions.CreateBadRequest(HTTPRequest, Context, ParameterName, JSONToken.ToString());

                    return(false);
                }
            }

            else
            {
                Value    = 0;
                HTTPResp = null;
                return(false);
            }

            HTTPResp = null;
            return(true);
        }
Example #3
0
        public Boolean ParseHTTP(String ParameterName, HTTPRequest HTTPRequest, out DateTime Value, out HTTPResponse HTTPResp, String Context = null, DateTime DefaultValue = default(DateTime))
        {
            Object JSONToken;

            if (!TryGetValue(ParameterName, out JSONToken))
            {
                Value    = DefaultValue;
                HTTPResp = HTTPExtentions.CreateBadRequest(HTTPRequest, Context, ParameterName);

                return(false);
            }

            if (JSONToken != null)
            {
                try
                {
                    Value = (DateTime)JSONToken;
                }
                catch (Exception)
                {
                    Log.Timestamp("Bad request: Invalid \"" + ParameterName + "\" property value!");

                    Value    = DefaultValue;
                    HTTPResp = HTTPExtentions.CreateBadRequest(HTTPRequest, Context, ParameterName, JSONToken.ToString());

                    return(false);
                }
            }

            else
            {
                Value    = DateTime.Now;
                HTTPResp = null;
                return(false);
            }

            HTTPResp = null;
            return(true);
        }