/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Constructor */ /// <summary> /// Convert an HTTP request submitted by the client-side into a /// DtRequest object /// </summary> /// <param name="rawHttp">Data from the client-side</param> public DtRequest(IEnumerable <KeyValuePair <string, string> > rawHttp) { var http = HttpData(rawHttp); 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"] }; 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 { 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"], } }); } } else { // DataTables get request RequestType = RequestTypes.DataTablesGet; } }
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"] }; 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); } } } } else { // DataTables get request RequestType = RequestTypes.DataTablesGet; } }