public method fetch_method(lambda i,security.titan_token token) { //for building the method in the report page/editing method m=new method(); m.titan_debug=titan_debug; if(string.IsNullOrWhiteSpace(i.group) || string.IsNullOrWhiteSpace(i.method)) return new method(); bool found=m.load(i.group,i.method,i.owner,i.configure,token); m.base_init(); if(ConfigurationManager.AppSettings["titan_debug"]=="true") { m.titan_debug=true; m.generate_queries(); } return m; }
public int create_export_link_id(string web_token,security.titan_token s_token) { string query=@"INSERT INTO titanDWS_exports ([token],[json],[web_token]) VALUES (@token,@json,@web_token); SELECT CAST(SCOPE_IDENTITY() AS int) AS ProfileKey;"; System.Web.Script.Serialization.JavaScriptSerializer jss=new System.Web.Script.Serialization.JavaScriptSerializer(); string json=jss.Serialize(this.input); string token=jss.Serialize(s_token); if(string.IsNullOrWhiteSpace(web_token)) web_token="error"; parameters param=new parameters(); param.add("@web_token" ,web_token); param.add("@token" ,token); param.add("@json" ,json); column_data res=db.execute_scalar("titan",query,param); int res_id=0; Int32.TryParse((string)res.ToString(),out res_id); return res_id; //return 0; }
public void create_export_link(security.titan_token s_token) { if(!this.export) { this.results.export_id=0; this.results.export_link=""; return; } Guid web_token=Guid.NewGuid(); this.results.export_id=create_export_link_id(web_token.ToString(),s_token); string filename=String.Format("{0}-{1}-{2}.csv", this.input.group,this.input.method,DateTime.Now.ToString("yyyy-MM-dd-HH-mm") ); string href=String.Format("{0}/{1}/{2}", web_token.ToString(), this.results.export_id, System.Net.WebUtility.UrlEncode(filename) ); if(this.export) { this.results.export_link=String.Format("<a class='btn btn-primary' target='_blank' href='{0}/titanDWS/export/{1}'><i class='nc-icon-mini arrows-1_share-66'></i> Export</a>", ConfigurationManager.AppSettings["MangoWebAPI_URL"],href); } }
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 string export(lambda i,string web_token) { string query="SELECT TOP 1 json,token FROM titanDWS_exports WITH (NOLOCK) WHERE [id]=@export_id AND [web_token]=@token"; parameters param=new parameters(); param.add("@token" ,web_token); param.add("@export_id" ,i.export_id); System.Web.Script.Serialization.JavaScriptSerializer jss=new System.Web.Script.Serialization.JavaScriptSerializer(); lambda export_input=null; security.titan_token s_token=null; data_set result=db.fetch("titan",query,param); if(null!=results) { string json= (string)result[0,"json"]; string token=(string)result[0,"token"]; export_input=jss.Deserialize<lambda>(json); s_token=jss.Deserialize<security.titan_token>(token); } else { return null; //nothing... lets exit } if(null==export_input) return null; string name=String.Format("{0}-{1}-{2}.csv",export_input.group,export_input.method,DateTime.Now.ToLongTimeString()); /*HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + name); HttpContext.Current.Response.ContentType = "text/csv"; HttpContext.Current.Response.AddHeader("Pragma", "public"); */ export_input.pageLength=0; export_input.page=0; this.input=export_input; StringBuilder sb=new StringBuilder(); method m=new method(); m.execute(input,true,s_token,false); int index=0; foreach (query.column c in results.columns) { core.column mc=m.data_schema.Find(x=>x.name==c.name); if(null!=mc && mc.export) { if (index!=0) { sb.Append(","); } index++; sb.Append(String.Format("\"{0}\"",c.name)); } } sb.Append("\r\n"); foreach (string[] row in results.rows) { //row index=0; foreach (string column in row) { //column if (index!=0) { sb.Append(","); } index++; sb.Append(String.Format("\"{0}\"",column)); } sb.Append("\r\n"); } return sb.ToString(); //HttpContext.Current.Response.Flush(); //HttpContext.Current.Response.End(); }//end export
public static method from_json(string text, security.titan_token token, bool save = true) { method m = JsonConvert.DeserializeObject <method>(text, new JsonSerializerSettings { Error = delegate(object sender, ErrorEventArgs args){ Console.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }); if (null == m.data_schema) { m.data_schema = new List <titan.core.column>(); } if (null == m.parameters) { m.parameters = new List <titan.core.parameter>(); } m.parameters.RemoveAll(item => item == null); m.parameters.RemoveAll(item => String.IsNullOrWhiteSpace(item.name)); parameters param = m.execute_load_parameters(token, null, true); if (m.regenerate_columns) { m.data_schema.Clear(); data_set row = db.fetch(m.connection_string, strip_comments(m.query), param); //no conn string denotes localhost, aything else is treated as a conn string.. (titan) int index = 0; if (null != row) //only update the titan.core.columns if we have atlest 1 result. { foreach (string key in row.Keys) { index++; titan.core.column c = new titan.core.column(key, "text", index, true); m.data_schema.Add(c); //only add if it doesnt exist... } } // if(null!=titan.core.columns) titan.core.columns.RemoveAll(item=> !row.ContainsKey(item.name) ); } // //global.reload(); if (save) { if (!string.IsNullOrWhiteSpace(m.data_mapping_name)) { if (null == m.sig_init) { m.sig_init = new external_data_defaults(); m.sig_init.group = m.group; m.sig_init.method = m.method; m.sig_init.owner = m.owner; } m.sig_init.save(); } m.save(); m.generate_queries(); } else { m.generate_queries(); } return(m); }
//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