コード例 #1
0
        public ODataParameterCollection(JObject body, IQueryCollection query)
        {
            var names = query?.Keys.Except(ODataRequest.WellKnownQueryStringParameterNames) ?? Array.Empty <string>();

            if (body != null)
            {
                names = names
                        .Union(body.Properties().Select(p => p.Name))
                        .Distinct();
            }

            var allParams = new Dictionary <string, ODataParameterValue>();

            foreach (var name in names)
            {
                if (query?.ContainsKey(name) ?? false)
                {
                    allParams.Add(name, new ODataParameterValue(query[name]));
                }
                else
                {
                    // ReSharper disable once PossibleNullReferenceException
                    allParams.Add(name, new ODataParameterValue(body[name]));
                }
            }
            _allParameters          = allParams;
            _allParametersLowercase = _allParameters.ToDictionary(x => x.Key.ToLowerInvariant(), x => x.Value);
        }
コード例 #2
0
        public async Task <IPagedResult <T> > GetPage(IQueryCollection query, IQueryable <T> results)
        {
            var pageSize = 10;

            if (query.ContainsKey("max"))
            {
                pageSize = int.Parse(query["max"]);
            }
            var offset = 0;

            if (query.ContainsKey("offset"))
            {
                offset = int.Parse(query["offset"]);
            }

            var pageNumber = (offset / pageSize) + 1;

            return(await PagedResult <T> .ToPagedResult(results, pageNumber, pageSize));
        }
コード例 #3
0
        public static void GamesFiltersBuilder(IQueryCollection parameters, out string search, out int offset, out int take)
        {
            search = "";
            offset = 0;
            take   = 5;

            if (parameters.ContainsKey(nameof(search)))
            {
                search = parameters[nameof(search)].ToString().ToLower();
            }
            if (parameters.ContainsKey(nameof(offset)))
            {
                int.TryParse(parameters[nameof(offset)], out offset);
            }
            if (parameters.ContainsKey(nameof(take)))
            {
                int.TryParse(parameters[nameof(take)], out take);
            }
        }
コード例 #4
0
 public DataShell Validate(IQueryCollection requestParams)
 {
     if (!requestParams.ContainsKey("commentId") ||
         !Int32.TryParse(requestParams["commentId"], out int outInt))
     {
         var result = new DataShell("invalid query parametrs");
         return(result);
     }
     return(new DataShell());
 }
コード例 #5
0
        public Dictionary <string, object> QueryToDic(string tableKey)
        {
            if (!Query.ContainsKey(tableKey))
            {
                return(new Dictionary <string, object>());
            }
            var tablename = Query[tableKey];
            var cols      = DB.UniClient.DbMaintenance.GetColumnInfosByTableName(tablename);
            Dictionary <string, object> dic = new Dictionary <string, object>();

            foreach (var cinfo in cols)
            {
                if (Query.ContainsKey(cinfo.DbColumnName))
                {
                    dic.Add(cinfo.DbColumnName, Query[cinfo.DbColumnName]);
                }
            }
            return(dic);
        }
コード例 #6
0
        /// <summary>
        /// Serializes the object into a string. In particular, this will check to see if we need to prettify the
        /// output string.
        /// </summary>
        /// <param name="queryCollection">The query collection.</param>
        /// <param name="resp">The response object.</param>
        /// <returns>The resultant string.</returns>
        private string ProcessJsonSerialization <T>(IQueryCollection queryCollection, T resp)
            where T : notnull, RealmEyePlayerResponse
        {
            var res = queryCollection.ContainsKey("prettify")
                                ? JsonSerializer.Serialize(resp, _prettifySerializationOption)
                                : JsonSerializer.Serialize(resp, _defaultSerializationOption);

            // This is needed since the serializer will encode some characters.
            return(Regex.Unescape(res));
        }
コード例 #7
0
        /// <summary>
        /// validate query string parameters common between Actors and Movies
        /// </summary>
        /// <param name="query">IQueryCollection</param>
        /// <param name="q">search</param>
        /// <param name="pageNumber">Page Number</param>
        /// <param name="pageSize">Page Size</param>
        /// <param name="message">error message</param>
        /// <returns></returns>
        public static bool Common(IQueryCollection query, string q, int pageNumber, int pageSize, out string message)
        {
            message = string.Empty;

            // no query string
            if (query == null)
            {
                return(true);
            }

            // validate q (search)
            if (query.ContainsKey("q"))
            {
                if (q == null || q.Length < 2 || q.Length > 20)
                {
                    message = "Invalid q (search) parameter";
                    return(false);
                }
            }

            // validate page number
            if (query.ContainsKey("pageNumber"))
            {
                if (!int.TryParse(query["pageNumber"], out int val) || val != pageNumber || pageNumber < 1 || pageNumber > 10000)
                {
                    message = "Invalid PageNumber parameter";
                    return(false);
                }
            }

            // validate page size
            if (query.ContainsKey("pageSize"))
            {
                if (!int.TryParse(query["pageSize"], out int val) || val != pageSize || pageSize < 1 || pageSize > 1000)
                {
                    message = "Invalid PageSize parameter";
                    return(false);
                }
            }

            return(true);
        }
コード例 #8
0
 private static int GetDepth(IQueryCollection query)
 {
     if (query.ContainsKey("depth"))
     {
         if (int.TryParse(query["depth"], out int queryDepth))
         {
             return(queryDepth);
         }
     }
     return(0);
 }
コード例 #9
0
        public static T SafeGetValue <T>(this IQueryCollection collection, string key)
        {
            if (!collection.ContainsKey(key))
            {
                return(default(T));
            }

            var value = collection[key][0];

            return((T)Convert.ChangeType(value, typeof(T)));
        }
コード例 #10
0
        /// <summary>
        /// Retrieves value as an integer
        /// </summary>
        /// <param name="qc"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        //============================================================
        //Revision History
        //Date        Author          Description
        //06/28/2017  TB               Created
        //============================================================
        public static int GetAsInt(this IQueryCollection qc, string fieldName)
        {
            int retVal = 0;

            if (qc.ContainsKey(fieldName))
            {
                Int32.TryParse(qc[fieldName], out retVal);
            }

            return(retVal);
        }
コード例 #11
0
        public static string GetQueryParamValue(this IQueryCollection collection, string key)
        {
            string value = null;

            if (collection.ContainsKey(key))
            {
                value = collection[key];
            }

            return(value);
        }
コード例 #12
0
        /// <summary>
        /// Retrieves value as a boolean
        /// </summary>
        /// <param name="qc"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        //============================================================
        //Revision History
        //Date        Author          Description
        //06/28/2017  TB               Created
        //============================================================
        public static bool GetAsBool(this IQueryCollection qc, string fieldName)
        {
            bool retVal = false;

            if (qc.ContainsKey(fieldName))
            {
                bool.TryParse(qc[fieldName], out retVal);
            }

            return(retVal);
        }
コード例 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="query"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static T TryGet <T>(this IQueryCollection query, string key)
 {
     if (query.ContainsKey(key))
     {
         if (query.TryGetValue(key, out Microsoft.Extensions.Primitives.StringValues keyValue))
         {
             return((T)Convert.ChangeType(keyValue.ToString(), typeof(T)));
         }
     }
     throw new ArgumentNullException();
 }
コード例 #14
0
        /// <summary>
        /// Gets a string value from the <paramref name="query"/> by the specified <paramref name="key"/>.
        /// </summary>
        /// <param name="query">The query to retrieve a string value from.</param>
        /// <param name="key">The key associated with the parameter to retrieve.</param>
        /// <param name="defaultValue">The default value if the value does not exist.</param>
        /// <returns>The string value for the specified <paramref name="key"/>.</returns>
        public static string GetStringValueOrDefault(this IQueryCollection query, string key, string defaultValue = null)
        {
            string value = null;

            if (query.ContainsKey(key))
            {
                value = query[key].ToString();
            }

            return(string.IsNullOrWhiteSpace(value) ? defaultValue : value);
        }
コード例 #15
0
ファイル: GridFilter.cs プロジェクト: orville-zc/hager-crm
        public Dictionary <string, string> ExtractSorts(IQueryCollection getQuery)
        {
            var types  = config.GetActions();
            var result = new Dictionary <string, string>
            {
                { "OrderField", "ID" },
                { "OrderDir", "ASC" },
            };

            if (getQuery.ContainsKey("OrderField") && types.ContainsKey(getQuery["OrderField"]))
            {
                result["OrderField"] = getQuery["OrderField"];
            }

            if (getQuery.ContainsKey("OrderDir") && orderDirs.Any(i => i == getQuery["OrderDir"].ToString().ToUpper()))
            {
                result["OrderDir"] = getQuery["OrderDir"].ToString().ToUpper();
            }

            return(result);
        }
コード例 #16
0
        private async Task <ConcurrentDictionary <string, object> > GetData(IQueryCollection lookupTypes)
        {
            ConcurrentDictionary <string, object> lookupData = new ConcurrentDictionary <string, object>();

            if (lookupTypes.ContainsKey("makes"))
            {
                await GetMakes(lookupData);
            }

            if (lookupTypes.ContainsKey("models"))
            {
                await GetModels(lookupData);
            }

            if (lookupTypes.ContainsKey("states"))
            {
                await GetStates(lookupData);
            }

            return(lookupData);
        }
コード例 #17
0
        public static bool GetOrDefaultBool(this IQueryCollection queryCollection, string key, bool defaultValue)
        {
            if (queryCollection.ContainsKey(key))
            {
                if (bool.TryParse(queryCollection[key], out var result))
                {
                    return(result);
                }
            }

            return(defaultValue);
        }
コード例 #18
0
        public static int GetOrDefaultInt(this IQueryCollection queryCollection, string key, int defaultValue)
        {
            if (queryCollection.ContainsKey(key))
            {
                if (int.TryParse(queryCollection[key], out var result))
                {
                    return(result);
                }
            }

            return(defaultValue);
        }
コード例 #19
0
        private string GetDecodedQueryValue(IQueryCollection query, string key)
        {
            string value = null;

            if (query.ContainsKey(key))
            {
                value = query[key].ToString();
                value = WebUtility.UrlDecode(value).Trim();
            }

            return(value);
        }
コード例 #20
0
 public static int?TryExtractFromQuery(this IQueryCollection query)
 {
     if (query.ContainsKey(Constants.ProjectIdName) &&
         int.TryParse(query[Constants.ProjectIdName], out var projectId))
     {
         return(projectId);
     }
     else
     {
         return(null);
     }
 }
コード例 #21
0
        internal void InitializeQuery(IQueryCollection query)
        {
            StringBuilder q = new StringBuilder("?");

            if (query.ContainsKey("level"))
            {
                _logLevel = ToLogLevel(query["level"]);
                q.Append($"level={query["level"]}&");
            }

            if (query.ContainsKey("my"))
            {
                _key = _myHttpLoggerKey;
            }

            if (query.ContainsKey("key"))
            {
                if (query["key"].ToString().ToLower() == "my")
                {
                    _key = _myHttpLoggerKey;
                }
                else
                {
                    _key = query["key"];
                }
            }

            if (!string.IsNullOrEmpty(_key))
            {
                q.Append($"key={_key}&");
            }

            if (query.ContainsKey("user"))
            {
                _user = query["user"];
                q.Append($"user={_user}&");
            }

            _query = q.ToString();
        }
コード例 #22
0
        private ExpandoObject ToExpando(IQueryCollection query, string viewComponentType)
        {
            ViewComponentDescriptor vcDescriptor = _selector.SelectComponent(viewComponentType);

            if (vcDescriptor == null)
            {
                throw new Exception($"Unable to find definition of ViewComponent ({viewComponentType})");
            }
            MethodBase invokeMethod = vcDescriptor.TypeInfo.GetMethod("InvokeAsync");

            if (invokeMethod == null)
            {
                throw new Exception($"InvokeAsync method not found in ViewComponent ({viewComponentType})");
            }
            ParameterInfo[] paramInfo = invokeMethod.GetParameters();

            var expando = new ExpandoObject() as IDictionary <string, object>;

            foreach (var param in paramInfo)
            {
                if (query.ContainsKey(param.Name))
                {
                    if (param.ParameterType == typeof(string))
                    {
                        expando.Add(param.Name, query[param.Name].ToString());
                    }

                    else if (param.ParameterType == typeof(bool))
                    {
                        expando.Add(param.Name, Convert.ToBoolean(query[param.Name]));
                    }

                    else if (param.ParameterType == typeof(int))
                    {
                        expando.Add(param.Name, Convert.ToInt32(query[param.Name]));
                    }

                    else if (param.ParameterType == typeof(double))
                    {
                        expando.Add(param.Name, Convert.ToDouble(query[param.Name]));
                    }

                    else if (param.ParameterType == typeof(DateTime))
                    {
                        expando.Add(param.Name, Convert.ToDateTime(query[param.Name]));
                    }

                    // TO DO: Add conversions for arrays, collections, and classes
                }
            }
            return((ExpandoObject)expando);
        }
コード例 #23
0
        protected void GetQueryParameters(out int page, out int start, out int limit, out string filterStr)
        {
            page  = -1;
            start = -1;
            limit = -1;
            IQueryCollection query = this.HttpContext.Request.Query;

            if (query.ContainsKey("page"))
            {
                int.TryParse(query["page"][0], out page);
            }
            if (query.ContainsKey("start"))
            {
                int.TryParse(query["start"][0], out start);
            }
            if (query.ContainsKey("limit"))
            {
                int.TryParse(query["limit"][0], out limit);
            }

            filterStr = this.GetFilterString();
        }
コード例 #24
0
        private static string GetCode(IQueryCollection queryStringParameters)
        {
            if (queryStringParameters == null || !queryStringParameters.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(queryStringParameters));
            }

            // Maybe we have an error?
            if (queryStringParameters.ContainsKey("error"))
            {
                var errorMessage = $"{queryStringParameters["error"]}: {queryStringParameters["error_description"]}";

                throw new NogginNetCoreAuthException(errorMessage);
            }

            if (!queryStringParameters.ContainsKey("code"))
            {
                throw new NogginNetCoreAuthException("No auth code returned by GitHub");
            }

            return(queryStringParameters["code"].ToString());
        }
コード例 #25
0
ファイル: GridFilter.cs プロジェクト: orville-zc/hager-crm
        public Dictionary <string, string> ExtractFields(IQueryCollection getQuery)
        {
            var result = new Dictionary <string, string>();

            foreach (var rule in config.GetActions().Keys)
            {
                if (getQuery.ContainsKey(rule))
                {
                    result[rule] = getQuery[rule];
                }
            }
            return(result);
        }
コード例 #26
0
        protected virtual string GetFilterString()
        {
            IQueryCollection query     = this.HttpContext.Request.Query;
            string           filterStr = "";

            if (query.ContainsKey("filterExpr"))
            {
                filterStr = query["filterExpr"][0];
                byte[] bytes = Convert.FromBase64String(filterStr);
                filterStr = Encoding.UTF8.GetString(bytes);
            }
            return(filterStr);
        }
コード例 #27
0
        public string ParseTokenFromQuery(IQueryCollection queryCollection)
        {
            if (queryCollection.ContainsKey(TOKEN_PARAM_NAME))
            {
                var result = Uri.UnescapeDataString(queryCollection[TOKEN_PARAM_NAME]);

                if (!string.IsNullOrWhiteSpace(result))
                {
                    return(result);
                }
            }

            return(null);
        }
コード例 #28
0
        static string GetKey(string key, IQueryCollection qs)
        {
            if (!qs.ContainsKey(key))
            {
                return(null);
            }
            var v = qs[key].ToArray();

            if (v.Length == 0)
            {
                return(null);
            }
            return(v[0]);
        }
コード例 #29
0
        public IQueryable ApplyQuery <T>(IQueryable <T> items, IQueryCollection query = null) where T : class
        {
            if (query != null)
            {
                var filter = query.ContainsKey("$filter") ? query["$filter"].ToString().Replace("i =>", "") : null;
                if (!string.IsNullOrEmpty(filter))
                {
                    items = items.Where(filter);
                }

                if (query.ContainsKey("$orderBy"))
                {
                    items = items.OrderBy(query["$orderBy"].ToString());
                }

                if (query.ContainsKey("$expand"))
                {
                    var propertiesToExpand = query["$expand"].ToString().Split(',');
                    foreach (var p in propertiesToExpand)
                    {
                        items = items.Include(p);
                    }
                }

                if (query.ContainsKey("$skip"))
                {
                    items = items.Skip(int.Parse(query["$skip"].ToString()));
                }

                if (query.ContainsKey("$top"))
                {
                    items = items.Take(int.Parse(query["$top"].ToString()));
                }
            }

            return(items);
        }
コード例 #30
0
        /// <summary>
        /// validate query string parameters common between Actors and Movies
        /// </summary>
        /// <param name="query">IQueryCollection</param>
        /// <param name="q">search</param>
        /// <param name="pageNumber">Page Number</param>
        /// <param name="pageSize">Page Size</param>
        /// <param name="method">current method</param>
        /// <param name="logger">ILogger</param>
        /// <returns></returns>
        public static JsonResult Common(IQueryCollection query, string q, int pageNumber, int pageSize, string method, ILogger logger)
        {
            // no query string
            if (query == null)
            {
                return(null);
            }

            // validate q (search)
            if (query.ContainsKey("q"))
            {
                if (q == null || q.Length < 2 || q.Length > 20)
                {
                    return(GetAndLogBadParam("Invalid q (search) parameter", method, logger));
                }
            }

            // validate page number
            if (query.ContainsKey("pageNumber"))
            {
                if (!int.TryParse(query["pageNumber"], out int val) || val != pageNumber || pageNumber < 1 || pageNumber > 10000)
                {
                    return(GetAndLogBadParam("Invalid PageNumber parameter", method, logger));
                }
            }

            // validate page size
            if (query.ContainsKey("pageSize"))
            {
                if (!int.TryParse(query["pageSize"], out int val) || val != pageSize || pageSize < 1 || pageSize > 1000)
                {
                    return(GetAndLogBadParam("Invalid PageSize parameter", method, logger));
                }
            }

            return(null);
        }