public titan.models.method_results execute(models.lambda _input,bool noLinks,security.titan_token token,bool init) { //actual method execution this.input=_input; query q=new query(); adjust_input_values(); //if a page is set to unlimited rows, adjust the page length q.page=this.input.page; q.pageLength=this.input.pageLength; load_execute(this.input.group,this.input.method,this.input.owner); //load the method q.m=this; q.resultsQuery=strip_comments(this.query); //clean the query of comments. so that it can be simplified in the log. copy/pastable if(init) { get_signature(); q.resultsParameters=execute_load_parameters(token,this.input.parameters,true); //load the parameters q.totalParameters =execute_load_parameters(token,this.input.parameters,true); } else { q.resultsParameters=execute_load_parameters(token,this.input.parameters,false); //load the parameters q.totalParameters =execute_load_parameters(token,this.input.parameters,false); } q.columns=generate_visible_column_list(noLinks); //create a list of available columns for the query. q.orderByString=generate_sort(q); //create the sort q.create_filters(this.input); create_export_link(token); //Create the link for the expot Downoad.. if applicable string temp_q=execute_query(q,noLinks); //This is what does the magic..... if(this.titan_debug) { this.results.executed_query=temp_q; } this.results.success=true; this.results.columns=q.columns; int index=0; foreach (query.column c in q.columns) { this.results.keys[c.name]=index; index++; } return this.results; }//end execute
/*public List<column> get_columns() { //List<string,string> cols=new List<string,string>(); //foreach(column c in columns) cols.Add(c.name,c.display); return cols; }*/ public void create_filters(models.lambda input) { List<string[]> filters=input.filters; if(null==filters) return; //nothing to do here... foreach(string[] d in filters) { int index=m.data_schema.FindIndex(x=>x.display==d[0]); if(index>=0) { addWhere(m.data_schema[index].name,d[1],m.data_schema[index].type); } else { addWhere(d[0],d[1],"number"); } } if(m.combined_search) { //do we combo search? string combined_search=""; if(!input.parameters.ContainsKey("multi_search")) return; if(!String.IsNullOrWhiteSpace(input.parameters["multi_search"])) combined_search=input.parameters["multi_search"]; if(String.IsNullOrWhiteSpace(combined_search)) return; //skip empty searches List<string> multi=new List<string>(); foreach(titan.core.column c in m.data_schema) { if(c.combined_search) multi.Add(create_condition(c.name,combined_search,c.type)); } if(multi.Count>0) { conditions.Add(String.Format("({0})",String.Join(" OR ",multi))); } } //addWhere(multi_search }
public method(models.lambda i, string _group, string _method, string _owner, string _localization, titan.security.titan_token token) { input = i; this.token = token; this.group = _group; this.method = _method; this.owner = _owner; this.configure = _localization; base_init(); }
public static models.json_results wrapper(string JWT,models.lambda i,Func<titan_token,object>func){ models.json_results res=new models.json_results(); if(JWT!=null) { byte[] privateKey=get_certificate_private_key(); titan_token token= JsonWebToken.Decode(JWT,privateKey ,true); if(token.valid) { res.results=func(token); } else { res.results=new error("Failed to validate token"); res.success=false; } } else { res.results=new error("Failed to validate token"); res.success=false; } res.request_for=i.group+"/"+i.method+"/"+i.owner; return res; }
//borrowed from the internet.... stackoverflow /*public void backup_method() { * JavaScriptSerializer jss=new JavaScriptSerializer(); * string method_json=jss.Serialize(this); * db.execute_non_query("titan","INSERT INTO titanDWS_history ([titanDWS_id],[json]) VALUES (@id,@json)",new string[,]{ { "id",this.id.ToString()},{ "json",method_json} } ); * }*/ public parameters execute_load_parameters(security.titan_token token, Dictionary <string, string> form_parameters, bool init) { parameters paramList = new parameters(); if (init) //caching... { get_signature(); get_signature_defaults(); } models.lambda input = new models.lambda(); if (null != token) { input.reference1 = token.r1; //good place for the defaults input.reference2 = token.r2; input.reference3 = token.r3; input.reference4 = token.r4; input.reference5 = token.r5; input.reference6 = token.r6; input.reference7 = token.r7; input.reference8 = token.r8; input.reference9 = token.r9; input.reference10 = token.r10; input.reference11 = token.r11; input.reference12 = token.r12; input.reference13 = token.r13; input.reference14 = token.r14; input.reference15 = token.r15; } input.parameters = new Dictionary <string, string>(); if (init) //testing data? i remember this then i did something { foreach (titan.core.parameter p in this.parameters) //and then im like... important but move? <-Im not sure? { string value = p.test; //Rewrite test data injection (pretty sure I cleaned this up) if (String.IsNullOrWhiteSpace(p.test)) { value = ""; } parameters range = get_parameter_from_html_name(p.htmlName, p.test); if (null != range) { paramList.AddRange(range); } } if (null != this.external_map && null != this.sig_init) { if (!string.IsNullOrWhiteSpace(external_map.reference1)) { paramList.add("@" + external_map.reference1, sig_init.r1); } if (!string.IsNullOrWhiteSpace(external_map.reference2)) { paramList.add("@" + external_map.reference2, sig_init.r2); } if (!string.IsNullOrWhiteSpace(external_map.reference3)) { paramList.add("@" + external_map.reference3, sig_init.r3); } if (!string.IsNullOrWhiteSpace(external_map.reference4)) { paramList.add("@" + external_map.reference4, sig_init.r4); } if (!string.IsNullOrWhiteSpace(external_map.reference5)) { paramList.add("@" + external_map.reference5, sig_init.r5); } if (!string.IsNullOrWhiteSpace(external_map.reference6)) { paramList.add("@" + external_map.reference6, sig_init.r6); } if (!string.IsNullOrWhiteSpace(external_map.reference7)) { paramList.add("@" + external_map.reference7, sig_init.r7); } if (!string.IsNullOrWhiteSpace(external_map.reference8)) { paramList.add("@" + external_map.reference8, sig_init.r8); } if (!string.IsNullOrWhiteSpace(external_map.reference9)) { paramList.add("@" + external_map.reference9, sig_init.r9); } if (!string.IsNullOrWhiteSpace(external_map.reference10)) { paramList.add("@" + external_map.reference10, sig_init.r10); } if (!string.IsNullOrWhiteSpace(external_map.reference11)) { paramList.add("@" + external_map.reference11, sig_init.r11); } if (!string.IsNullOrWhiteSpace(external_map.reference12)) { paramList.add("@" + external_map.reference12, sig_init.r12); } if (!string.IsNullOrWhiteSpace(external_map.reference13)) { paramList.add("@" + external_map.reference13, sig_init.r13); } if (!string.IsNullOrWhiteSpace(external_map.reference14)) { paramList.add("@" + external_map.reference14, sig_init.r14); } if (!string.IsNullOrWhiteSpace(external_map.reference15)) { paramList.add("@" + external_map.reference15, sig_init.r15); } } //end if external_data_maping exists } else //end p1 init { input.parameters = form_parameters; //System variables if (null != this.external_map) { if (!string.IsNullOrWhiteSpace(external_map.reference1)) { paramList.add("@" + external_map.reference1, sig_init.r1); } if (!string.IsNullOrWhiteSpace(external_map.reference2)) { paramList.add("@" + external_map.reference2, sig_init.r2); } if (!string.IsNullOrWhiteSpace(external_map.reference3)) { paramList.add("@" + external_map.reference3, sig_init.r3); } if (!string.IsNullOrWhiteSpace(external_map.reference4)) { paramList.add("@" + external_map.reference4, sig_init.r4); } if (!string.IsNullOrWhiteSpace(external_map.reference5)) { paramList.add("@" + external_map.reference5, sig_init.r5); } if (!string.IsNullOrWhiteSpace(external_map.reference6)) { paramList.add("@" + external_map.reference6, sig_init.r6); } if (!string.IsNullOrWhiteSpace(external_map.reference7)) { paramList.add("@" + external_map.reference7, sig_init.r7); } if (!string.IsNullOrWhiteSpace(external_map.reference8)) { paramList.add("@" + external_map.reference8, sig_init.r8); } if (!string.IsNullOrWhiteSpace(external_map.reference9)) { paramList.add("@" + external_map.reference9, sig_init.r9); } if (!string.IsNullOrWhiteSpace(external_map.reference10)) { paramList.add("@" + external_map.reference10, sig_init.r10); } if (!string.IsNullOrWhiteSpace(external_map.reference11)) { paramList.add("@" + external_map.reference11, sig_init.r11); } if (!string.IsNullOrWhiteSpace(external_map.reference12)) { paramList.add("@" + external_map.reference12, sig_init.r12); } if (!string.IsNullOrWhiteSpace(external_map.reference13)) { paramList.add("@" + external_map.reference13, sig_init.r13); } if (!string.IsNullOrWhiteSpace(external_map.reference14)) { paramList.add("@" + external_map.reference14, sig_init.r14); } if (!string.IsNullOrWhiteSpace(external_map.reference15)) { paramList.add("@" + external_map.reference15, sig_init.r15); } } //end if if (null != input.parameters && 0 < input.parameters.Count) { foreach (KeyValuePair <string, string> p in input.parameters) { core.parameter matchedP = this.parameters.Find(x => x.htmlName == p.Key); //find the parameter in the list with lamba find if (null != matchedP && null != p.Value && null != matchedP.name) //ok we got a match... { if (String.IsNullOrWhiteSpace(matchedP.name)) { continue; } if (matchedP.type == "daterange") { string to = null; string from = null; if (!String.IsNullOrWhiteSpace(p.Value)) { string[] tokens = Regex.Split(p.Value, " - "); if (tokens.Length > 0) { from = tokens[0]; } if (tokens.Length > 1) { to = tokens[1]; } } if (string.IsNullOrWhiteSpace(to)) { paramList.add("@" + matchedP.name + "_from", from); } if (string.IsNullOrWhiteSpace(from)) { paramList.add("@" + matchedP.name + "_to", to); } } else { if (null != p.Value) { paramList.add("@" + matchedP.name, p.Value); } } } //end if matched } //end parameter Loop } //end if params }//end else return(paramList); } //end create parameters