public void run_crons() { string query="SELECT * FROM titanDWS WITH (NOLOCK) WHERE cron=cast(1 as bit)"; //get all methods that are cron's data_set rows=db.fetch_all("titan",query); foreach(row row in rows) { lambda i=new lambda(); i.group =(string)row["group"]; i.method=(string)row["method"]; string cron=(string)row["schedule"]; string[] tokens=cron.Split(' '); if(tokens.Length!=5) continue; //we need 5 pieces. string minute =tokens[0]; string hour =tokens[1]; string day =tokens[2]; string month =tokens[3]; string day_of_week =tokens[4]; DateTime time=DateTime.Now; if(minute !="*" && time.Minute.ToString() !=minute) continue; if(hour !="*" && time.Hour.ToString() !=hour) continue; if(day !="*" && time.Day.ToString() !=day) continue; if(month !="*" && time.Month.ToString() !=month) continue; if(day_of_week !="*" && time.DayOfWeek.ToString() !=day_of_week) continue; //we only get here if we have passed all the checks. //web_service w=new web_service(); method m=new method(); m.execute(i,true,null,true); } }
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