Esempio n. 1
0
        public override bool execute( )
        {
            Registry("execute schedule_proc_batch ");

            /// USER [ execute ]

            string dir_watch = new SyCrafEngine.InstallData().pathDir + "\\proc\\";

            I_Batch bat = new I_Batch(this);

            Thread.Sleep(3000);                //  Wait to build valid filelist

            if (bat.select_rows_free(Context.FALSE, Context.FALSE))
            {
                while (bat.fetch())
                {
                    string archive = bat.get_st_archive();

                    #region - SETUP -

                    string path = new InstallData().pathDir + "\\Log_" +
                                  DateTime.Now.Year.ToString() +
                                  DateTime.Now.Month.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Day.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Hour.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Minute.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Second.ToString().PadLeft(2, '0') +
                                  "_batch_" + archive + ".txt.wrk";

                    FileStream   logFile;
                    StreamWriter logStream;

                    if (File.Exists(path))
                    {
                        logFile = new FileStream(path, FileMode.Append, FileAccess.Write);
                    }
                    else
                    {
                        logFile = new FileStream(path, FileMode.Create, FileAccess.Write);
                    }

                    logStream           = new StreamWriter(logFile);
                    logStream.AutoFlush = true;

                    var_Comm.Clear();
                    DB_Access new_access = new DB_Access(ref m_gen_my_access);

                    var_disp.var_Translator = var_Translator;

                    DataPortable port = new DataPortable();

                    port.setValue("archive", archive);

                    new_access.MemorySave("input", ref port);

                    #endregion

                    if (archive.StartsWith("CARGA_EDU_"))
                    {
                        // Runnig in a new thread
                        var_disp.ExecuteThreadTransaction("load_edu",
                                                          Convert.ToInt32(bat.get_identity()),
                                                          ref logStream,
                                                          ref var_Comm,
                                                          ref new_access,
                                                          path);
                    }
                    else if (archive.StartsWith("CARGA_EDUEMPRESASVIRTUAIS"))
                    {
                        // Runnig in a new thread
                        var_disp.ExecuteThreadTransaction("load_edu_emp_virtual",
                                                          Convert.ToInt32(bat.get_identity()),
                                                          ref logStream,
                                                          ref var_Comm,
                                                          ref new_access,
                                                          path);
                    }
                    else if (archive.StartsWith("LEGADO"))
                    {
                        // Runnig in a new thread
                        var_disp.ExecuteThreadTransaction("load_legado",
                                                          Convert.ToInt32(bat.get_identity()),
                                                          ref logStream,
                                                          ref var_Comm,
                                                          ref new_access,
                                                          path);
                    }
                }
            }

            /// USER [ execute ] END

            Registry("execute done schedule_proc_batch ");

            return(true);
        }
        public override bool execute( )
        {
            Registry("execute infra_SchedulerDispatcher ");

            /// USER [ execute ]

            I_Scheduler sch      = new I_Scheduler(this);
            DateTime    time_now = DateTime.Now;

            if (sch.selectAll())
            {
                while (sch.fetch())
                {
                    bool Exec = false;

                    if (sch.get_tg_status() == Context.CLOSED)
                    {
                        continue;
                    }

                    switch (sch.get_tg_type())
                    {
                    case Scheduler.Specific:
                    {
                        DateTime time = Convert.ToDateTime(sch.get_dt_specific());

                        if (time_now.Year == time.Year)
                        {
                            if (time_now.Month == time.Month)
                            {
                                if (time_now.Day == time.Day)
                                {
                                    if (time_now.Hour == time.Hour)
                                    {
                                        if (time_now.Minute == time.Minute)
                                        {
                                            Exec = true;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case Scheduler.Daily:
                    {
                        int daily_hh = Convert.ToInt32(sch.get_st_daily_hhmm().Substring(0, 2));
                        int daily_mm = Convert.ToInt32(sch.get_st_daily_hhmm().Substring(2, 2));

                        if (time_now.Hour == daily_hh)
                        {
                            if (time_now.Minute == daily_mm)
                            {
                                Exec = true;
                            }
                        }

                        break;
                    }

                    case Scheduler.Weekly:
                    {
                        long weekly_dow = sch.get_int_st_weekly_dow();
                        long weekly_hh  = Convert.ToInt64(sch.get_st_daily_hhmm().Substring(0, 2));
                        long weekly_mm  = Convert.ToInt64(sch.get_st_daily_hhmm().Substring(2, 2));

                        switch (weekly_dow)
                        {
                        case 0: if (time_now.DayOfWeek != DayOfWeek.Sunday)
                            {
                                continue;
                            }
                            break;

                        case 1: if (time_now.DayOfWeek != DayOfWeek.Monday)
                            {
                                continue;
                            }
                            break;

                        case 2: if (time_now.DayOfWeek != DayOfWeek.Tuesday)
                            {
                                continue;
                            }
                            break;

                        case 3: if (time_now.DayOfWeek != DayOfWeek.Wednesday)
                            {
                                continue;
                            }
                            break;

                        case 4: if (time_now.DayOfWeek != DayOfWeek.Thursday)
                            {
                                continue;
                            }
                            break;

                        case 5: if (time_now.DayOfWeek != DayOfWeek.Friday)
                            {
                                continue;
                            }
                            break;

                        case 6: if (time_now.DayOfWeek != DayOfWeek.Saturday)
                            {
                                continue;
                            }
                            break;

                        default: break;                                         // 7 is everyday
                        }

                        if (time_now.Hour == weekly_hh)
                        {
                            if (time_now.Minute == weekly_mm)
                            {
                                Exec = true;
                            }
                        }

                        break;
                    }

                    case Scheduler.Monthly:
                    {
                        long monthly_dd = sch.get_int_nu_monthly_day();
                        long monthly_hh = Convert.ToInt64(sch.get_st_monthly_hhmm().Substring(0, 2));
                        long monthly_mm = Convert.ToInt64(sch.get_st_monthly_hhmm().Substring(2, 2));

                        if (time_now.Day == monthly_dd)
                        {
                            if (time_now.Hour == monthly_hh)
                            {
                                if (time_now.Minute == monthly_mm)
                                {
                                    Exec = true;
                                }
                            }
                        }

                        break;
                    }

                    case Scheduler.Minute:
                    {
                        Exec = true;
                        break;
                    }

                    default:
                    {
                        Registry("Unrecognized code! " + sch.get_tg_type());
                        break;
                    }
                    }

                    if (Exec)
                    {
                        Registry(sch.get_st_job() + " >> MATCH!");
                    }

                    Registry(sch.get_st_job());

                    if (!Exec)
                    {
                        Registry(sch.get_st_job() + " >> Checking backlog....");

                        DateTime tim = Convert.ToDateTime(sch.get_dt_prev());

                        Registry(tim.ToString());
                        Registry(time_now.ToString());

                        if (time_now >= tim)
                        {
                            Registry("Back log for: " + sch.get_st_job());
                            Exec = true;
                        }
                    }

                    if (!Exec)
                    {
                        continue;
                    }

                    Registry("Running: " + sch.get_st_job());

                    ApplicationUtil var_util = new ApplicationUtil();

                    int    max_params = var_util.indexCSV(sch.get_st_job(), ';');
                    string job        = var_util.getCSV(0);

                    string path = var_SessionKey +
                                  "\\Log_" +
                                  DateTime.Now.Year.ToString() +
                                  DateTime.Now.Month.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Day.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Hour.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Minute.ToString().PadLeft(2, '0') +
                                  DateTime.Now.Second.ToString().PadLeft(2, '0') +
                                  "_" +
                                  job +
                                  "_" +
                                  sch.get_identity() +
                                  ".txt.wrk";

                    FileStream   logFile;
                    StreamWriter logStream;

                    if (File.Exists(path))
                    {
                        logFile = new FileStream(path, FileMode.Append, FileAccess.Write);
                    }
                    else
                    {
                        logFile = new FileStream(path, FileMode.Create, FileAccess.Write);
                    }

                    logStream           = new StreamWriter(logFile);
                    logStream.AutoFlush = true;

                    var_Comm.Clear();

                    DB_Access new_access = new DB_Access(ref m_gen_my_access);

                    var_disp.var_Translator = var_Translator;

                    if (max_params >= 3)
                    {
                        DataPortable port = new DataPortable();

                        for (int t = 1; t < max_params;)
                        {
                            string ident     = var_util.getCSV(t); ++t;
                            string ident_val = var_util.getCSV(t); ++t;

                            port.setValue(ident, ident_val);
                        }

                        string buffer = "";

                        port.ExportBuffer(ref buffer);

                        Registry(buffer);

                        new_access.MemorySave("input", ref port);
                    }

                    // Runnig in a new thread
                    var_disp.ExecuteThreadTransaction(job,
                                                      Convert.ToInt32(sch.get_identity()),
                                                      ref logStream,
                                                      ref var_Comm,
                                                      ref new_access,
                                                      path);
                }
            }

            /// USER [ execute ] END

            Registry("execute done infra_SchedulerDispatcher ");

            return(true);
        }