public object GetParameter(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (!this.values.ContainsKey(key))
            {
                throw new InvalidOperationException(MissingKeyInCookies);
            }

            return(this.values[key]);
        }
예제 #2
0
        public HttpCookie(string key, string value, int expires = HttpCookieDefaulExpirationDate, string path = HttpCookieDefaultPath)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));
            CoreValidator.ThrowIfNullOrEmpty(value, nameof(value));

            Key     = key;
            Value   = value;
            Expires = DateTime.UtcNow.AddDays(3);
            Path    = path;
            IsNew   = true;
        }
        public HttpHeader GetHeader(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (!ContainsHeader(key))
            {
                return(null);
            }

            return(this.headers[key]);
        }
예제 #4
0
        public HttpRequest(string requestString)
        {
            CoreValidator.ThrowIfNullOrEmpty(requestString, nameof(requestString));

            this.FormData  = new Dictionary <string, object>();
            this.QueryData = new Dictionary <string, object>();
            this.Headers   = new HttpHeaderCollection();
            //TODO:this.Cookies = new HttpCookieCollection();

            this.ParseRequest(requestString);
        }
        public HttpRequest(string requestText)
        {
            CoreValidator.ThrowIfNullOrEmpty(requestText, nameof(requestText));

            this.Headers         = new HttpHeaderCollection();
            this.UrlParameters   = new Dictionary <string, string>();
            this.QueryParameters = new Dictionary <string, string>();
            this.FormData        = new Dictionary <string, string>();

            this.ParseRequest(requestText);
        }
예제 #6
0
        private bool IsValidRequestQueryString(string queryString, string[] queryParameters)
        {
            CoreValidator.ThrowIfNullOrEmpty(queryString, nameof(queryString));

            if (queryParameters.Length < 1)
            {
                return(false);
            }

            return(true);
        }
예제 #7
0
        public void Add(string key, string value)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));
            CoreValidator.ThrowIfNullOrEmpty(value, nameof(value));

            if (!this.headers.ContainsKey(key))
            {
                this.headers[key] = new List <HttpHeader>();
            }
            this.headers[key].Add(new HttpHeader(key, value));
        }
        public HttpCookie GetHttpCookie(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (this.ContainsCookie(key) == false)
            {
                throw new ArgumentException("Doesnt exist cookie with given name");
            }

            return(this.httpCookies[key]);
        }
예제 #9
0
        public ICollection <HttpHeader> Get(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (!this.headers.ContainsKey(key))
            {
                throw new InvalidOperationException($"The given key {key} is not present in the headers collection!");
            }

            return(this.headers[key]);
        }
예제 #10
0
        public HttpCookie(string key, string value, int expires = HttpCookieDefaultExpirationDays, string path = HttpCookieDefaultPath)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));
            CoreValidator.ThrowIfNullOrEmpty(value, nameof(value));

            this.Key     = key;
            this.Value   = value;
            this.IsNew   = true;
            this.Path    = path;
            this.Expires = DateTime.UtcNow.AddDays(expires);
        }
        public HttpRequest(string requestString)
        {
            CoreValidator.ThrowIfNullOrEmpty(requestString, nameof(requestString));

            this.FormData  = new Dictionary <string, ISet <string> >(new StringCaseInsensitiveEqualityComaparer());
            this.QueryData = new Dictionary <string, ISet <string> >(new StringCaseInsensitiveEqualityComaparer());
            this.Headers   = new HttpHeaderCollection();
            this.Cookies   = new HttpCookieCollection();

            this.ParseRequest(requestString);
        }
        public HttpCookie Get(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (!this.cookies.ContainsKey(key))
            {
                throw new InvalidOperationException($"The given key '{key}' is not present in the cookies collection.");
            }

            return(this.cookies[key]);
        }
예제 #13
0
        public object GetParameter(string name)
        {
            CoreValidator.ThrowIfNullOrEmpty(name, nameof(name));

            if (this.HttpSesionParameters.ContainsKey(name))
            {
                return(this.HttpSesionParameters[name]);
            }

            return(null);
        }
예제 #14
0
        public HttpRequest(string requestString)
        {
            CoreValidator.ThrowIfNullOrEmpty(requestString, nameof(requestString));

            this.FormData  = new Dictionary <string, ISet <string> >();
            this.QueryData = new Dictionary <string, ISet <string> >();
            this.Headers   = new HttpHeaderCollection();
            this.Cookies   = new HttpCookieCollection();

            this.ParseRequest(WebUtility.UrlDecode(requestString));
        }
예제 #15
0
        public object GetParameter(string parameterName)
        {
            CoreValidator.ThrowIfNullOrEmpty(parameterName, nameof(parameterName));

            if (!this.ContainsParameter(parameterName))
            {
                return(null);
            }

            return(this.sessionParameters[parameterName]);
        }
        public HttpCookie GetCookie(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (!this.httpCookies.ContainsKey(key))
            {
                throw new ArgumentException(string.Format(GlobalConstants.InvalidCookieKey, key));
            }

            return(this.httpCookies[key]);
        }
        public object Get(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (!this.values.ContainsKey(key))
            {
                return(null);
            }

            return(this.values[key]);
        }
예제 #18
0
        public bool ContainsHeader(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));
            bool contains = false;

            if (headers.Keys.Contains(key))
            {
                contains = true;
            }

            return(contains);
        }
예제 #19
0
        public void Add(string name, string price)
        {
            CoreValidator.ThrowIfNullOrEmpty(name, nameof(name));
            CoreValidator.ThrowIfNullOrEmpty(price, nameof(price));

            var id = File.ReadAllLines(DefaultDataFilePath).Length;

            using (var streamWriter = new StreamWriter(DefaultDataFilePath, true))
            {
                streamWriter.WriteLine($"{id + 1},{name},{price}");
            }
        }
        public HttpCookie GetCookie(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (this.ContainsCookie(key))
            {
                return(this.cookies[key]);
            }

            // throw exception vs return null;
            return(null);
        }
예제 #21
0
        public object GetParameter(string name)
        {
            CoreValidator.ThrowIfNullOrEmpty(name, nameof(name));

            if (this.ContainsParameter(name))
            {
                return(this.sessionParameters[name]);
            }

            // throw exception vs return null;
            return(null);
        }
예제 #22
0
        public HttpHeader GetHeader(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            if (this.ContainsHeader(key))
            {
                return(this.headers[key]);
            }

            // throw exception vs return null;
            return(null);
        }
예제 #23
0
        public Product GetProductByName(string name)
        {
            CoreValidator.ThrowIfNullOrEmpty(name, nameof(name));

            using (var db = dbContext)
            {
                var product = db.Products.Include("Bids").FirstOrDefault(p => p.Name == name);

                CoreValidator.ThrowIfNull(product, nameof(product));

                return(product);
            }
        }
        public HttpRequest(string requestAsString)
        {
            CoreValidator.ThrowIfNullOrEmpty(requestAsString, nameof(requestAsString));

            this.requestAsString = requestAsString;

            this.Headers       = new HttpHeaderCollection();
            this.Cookies       = new HttpCookieCollection();
            this.FormData      = new Dictionary <string, string>();
            this.UrlParameters = new Dictionary <string, string>();

            this.ParseRequest(requestAsString);
        }
        public bool?Contains(HttpRequestMethod requestMethod, string path)
        {
            CoreValidator.ThrowIfNull(requestMethod, nameof(requestMethod));
            CoreValidator.ThrowIfNullOrEmpty(path, nameof(path));


            if (!this.routes.ContainsKey(requestMethod))
            {
                return(null);
            }

            return(this.routes[requestMethod].ContainsKey(path));
        }
예제 #26
0
        public HttpRequest(string requestText)
        {
            CoreValidator.ThrowIfNullOrEmpty(requestText, nameof(requestText));

            this.requestText   = requestText;
            this.FormData      = new Dictionary <string, string>();
            this.Headers       = new HttpHeaderCollection();
            this.Cookies       = new HttpCookieCollection();
            this.UrlParameters = new Dictionary <string, string>();
            this.Session       = new HttpSession(Guid.NewGuid().ToString());

            this.ParseRequest(requestText);
        }
예제 #27
0
        public User GetUserByUsername(string username)
        {
            CoreValidator.ThrowIfNullOrEmpty(username, nameof(username));

            using (var db = new AuctionContext())
            {
                var currentUser = db.Users.FirstOrDefault(u => u.Username == username);

                CoreValidator.ThrowIfNull(currentUser, nameof(currentUser));

                return(currentUser);
            }
        }
예제 #28
0
        public HttpHeader GetHeader(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            HttpHeader header = null;

            if (ContainsHeader(key))
            {
                header = this.httpHeaders[key];
            }

            return(header);
        }
예제 #29
0
        public User GetUserByUsername(string username)
        {
            CoreValidator.ThrowIfNullOrEmpty(username, nameof(username));

            using (this.dbContext)
            {
                var currentUser = this.dbContext.Users.FirstOrDefault(u => u.Username == username);

                CoreValidator.ThrowIfNull(currentUser, nameof(currentUser));

                return(currentUser);
            }
        }
        public object Get(string key)
        {
            CoreValidator.ThrowIfNullOrEmpty(key, nameof(key));

            object result = null;

            if (_parameters.ContainsKey(key))
            {
                result = _parameters[key];
            }

            return(result);
        }