Exemple #1
0
            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);
                }
            }
Exemple #2
0
 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;
 }
Exemple #3
0
            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
Exemple #4
0
        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);
        }