Ejemplo n.º 1
0
        private SearchBuilderDetails searchBuilderParse(Dictionary <String, object> data)
        {
            var sb = new SearchBuilderDetails();

            // If the logic key is present then it must be a group and different parsing needs to occur
            if (data.ContainsKey("logic"))
            {
                sb.logic = (string)data["logic"];
                var criteria = (Dictionary <string, object>)data["criteria"];
                var keyList  = new List <string>(criteria.Keys);

                foreach (var key in keyList)
                {
                    // Specifically the items in this group also need to be parsed
                    sb.criteria.Add(searchBuilderParse((Dictionary <string, object>)criteria[key]));
                }
            }
            // Otherwise if all of the values required to cause a search are present then make a criteria
            else if (data.ContainsKey("condition") && data.ContainsKey("origData"))
            {
                sb.condition = (String)data["condition"];
                sb.data      = (String)data["data"];
                sb.origData  = (String)data["origData"];
                sb.value1    = data.ContainsKey("value1") ? (String)data["value1"].ToString() : "";
                sb.value2    = data.ContainsKey("value2") ? (String)data["value2"].ToString() : "";
                sb.type      = (String)data["type"];
            }

            return(sb);
        }
Ejemplo n.º 2
0
        private void _Build(IEnumerable <KeyValuePair <string, string> > rawHttp, string culture)
        {
            var http = HttpData(rawHttp, culture);

            if (http.ContainsKey("action"))
            {
                // Editor request
                Action = http["action"] as string;

                if (Action == "create")
                {
                    RequestType = RequestTypes.EditorCreate;
                    Data        = http["data"] as Dictionary <string, object>;
                }
                else if (Action == "edit")
                {
                    RequestType = RequestTypes.EditorEdit;
                    Data        = http["data"] as Dictionary <string, object>;
                }
                else if (Action == "remove")
                {
                    RequestType = RequestTypes.EditorRemove;
                    Data        = http["data"] as Dictionary <string, object>;
                }
                else if (Action == "upload")
                {
                    RequestType = RequestTypes.EditorUpload;

                    UploadField = http["uploadField"] as string;
                }
            }
            else if (http.ContainsKey("draw"))
            {
                // DataTables server-side processing get request
                RequestType = RequestTypes.DataTablesSsp;

                var search = http["search"] as Dictionary <string, object>;

                Draw   = (int)http["draw"];
                Start  = (int)http["start"];
                Length = (int)http["length"];
                Search = new SearchT
                {
                    Value = search["value"].ToString(),
                    Regex = (Boolean)search["regex"]
                };

                if (http.ContainsKey("order"))
                {
                    foreach (var item in http["order"] as Dictionary <string, object> )
                    {
                        var order = item.Value as Dictionary <string, object>;

                        Order.Add(new OrderT
                        {
                            Column = (int)order["column"],
                            Dir    = order["dir"].ToString()
                        });
                    }
                }

                foreach (var item in http["columns"] as Dictionary <string, object> )
                {
                    var column    = item.Value as Dictionary <string, object>;
                    var colSearch = column["search"] as Dictionary <string, object>;
                    Columns.Add(new ColumnT
                    {
                        // TODO
                        Name       = column["name"].ToString(),
                        Data       = column["data"].ToString(),
                        Searchable = (Boolean)column["searchable"],
                        Orderable  = (Boolean)column["orderable"],
                        Search     = new SearchT
                        {
                            Value = colSearch["value"].ToString(),
                            Regex = (Boolean)colSearch["regex"],
                        }
                    });
                }

                // SearchPanes
                if (http.ContainsKey("searchPanes"))
                {
                    // Get the column names
                    Dictionary <string, object> httpSP = (Dictionary <string, object>)http["searchPanes"];
                    List <string> keyList = new List <string>(httpSP.Keys);

                    foreach (var key in keyList)
                    {
                        Dictionary <string, object> httpSPKey = (Dictionary <string, object>)httpSP[key];
                        List <string> keykeyList = new List <string>(httpSPKey.Keys);
                        string[]      values     = new string[keykeyList.Count()];
                        int           count      = 0;
                        foreach (var keykey in keykeyList)
                        {
                            values[count] = httpSPKey[keykey].ToString();
                            count++;
                        }

                        // Don't add multiple selections for one column
                        if (!searchPanes.ContainsKey(key))
                        {
                            searchPanes.Add(key, values);
                        }
                    }
                }

                // SearchPanes_null
                if (http.ContainsKey("searchPanes_null"))
                {
                    // Get the column names
                    Dictionary <string, object> httpSP = (Dictionary <string, object>)http["searchPanes_null"];
                    List <string> keyList = new List <string>(httpSP.Keys);

                    foreach (var key in keyList)
                    {
                        Dictionary <string, object> httpSPKey = (Dictionary <string, object>)httpSP[key];
                        List <string> keykeyList = new List <string>(httpSPKey.Keys);
                        bool[]        values     = new bool[keykeyList.Count()];
                        int           count      = 0;
                        foreach (var keykey in keykeyList)
                        {
                            if (httpSPKey[keykey] is bool)
                            {
                                values[count] = (bool)httpSPKey[keykey];
                                count++;
                            }
                        }

                        // Don't add multiple selections for one column
                        if (!searchPanes_null.ContainsKey(key))
                        {
                            searchPanes_null.Add(key, values);
                        }
                    }
                }
                // searchPanesLast
                if (http.ContainsKey("searchPanesLast"))
                {
                    searchPanesLast = (string)http["searchPanesLast"];
                }
                //SearchBuilder
                if (http.ContainsKey("searchBuilder") && !(http["searchBuilder"] is String))
                {
                    searchBuilder = searchBuilderParse((Dictionary <String, object>)http["searchBuilder"]);
                }
            }
            else
            {
                // DataTables get request
                RequestType = RequestTypes.DataTablesGet;
            }
        }