Ejemplo n.º 1
0
        public override bool authenticate( )
        {
            Registry("authenticate schedule_base ");

            /// USER [ authenticate ]

            sch = new I_Scheduler(this);

            sch.ExclusiveAccess();

            if (!sch.selectIdentity(var_iPid.ToString()))
            {
                return(false);
            }

            sch.set_tg_status(Context.CLOSED);

            if (!sch.synchronize_I_Scheduler())
            {
                return(false);
            }

            sch.ReleaseExclusive();

            /// USER [ authenticate ] END

            Registry("authenticate done schedule_base ");

            return(true);
        }
Ejemplo n.º 2
0
 public void copy(ref I_Scheduler cpy)
 {
     st_job          = cpy.st_job;
     tg_type         = cpy.tg_type;
     dt_specific     = cpy.dt_specific;
     st_daily_hhmm   = cpy.st_daily_hhmm;
     st_weekly_dow   = cpy.st_weekly_dow;
     st_weekly_hhmm  = cpy.st_weekly_hhmm;
     nu_monthly_day  = cpy.nu_monthly_day;
     st_monthly_hhmm = cpy.st_monthly_hhmm;
     dt_last         = cpy.dt_last;
     tg_status       = cpy.tg_status;
     dt_prev         = cpy.dt_prev;
 }
Ejemplo n.º 3
0
        public override bool authenticate( )
        {
            if (base.authenticate() == false)
            {
                return(false);
            }

            Registry("authenticate del_agenda ");

            /// USER [ authenticate ]

            LINK_Agenda la = new LINK_Agenda(this);

            if (!la.selectIdentity(input_fk_agenda))
            {
                PublishError("Agenda não encontrada");
                return(false);
            }

            I_Scheduler sch = new I_Scheduler(this);

            if (!sch.selectIdentity(la.get_fk_schedule()))
            {
                return(false);
            }

            if (!sch.delete())
            {
                return(false);
            }

            if (!la.delete())
            {
                return(false);
            }

            /// USER [ authenticate ] END

            Registry("authenticate done del_agenda ");

            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);
        }
Ejemplo n.º 5
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_agenda ");

            /// USER [ execute ]

            LINK_Agenda l_a = new LINK_Agenda(this);

            // ## Busca todos os registros de agendamento

            if (l_a.selectAll())
            {
                StringBuilder sb = new StringBuilder();

                T_Empresa   emp = new T_Empresa(this);
                I_Scheduler sch = new I_Scheduler(this);

                ApplicationUtil var_util = new ApplicationUtil();

                while (l_a.fetch())
                {
                    // ## Cria container de dados

                    DadosAgenda da = new DadosAgenda();

                    // ## Valida links para outras tabelas

                    if (!emp.selectIdentity(l_a.get_fk_empresa()))
                    {
                        continue;
                    }

                    if (!sch.selectIdentity(l_a.get_fk_schedule()))
                    {
                        continue;
                    }

                    var_util.indexCSV(sch.get_st_job(), ';');

                    string aff = "";
                    string job = var_util.getCSV(0);

                    if (sch.get_st_job().IndexOf("afiliada") > 0)
                    {
                        if (job == "schedule_fech_mensal")
                        {
                            aff = " - " + var_util.getCSV(4);
                        }
                    }

                    // ## Copia dados

                    da.set_fk_agenda(l_a.get_identity());
                    da.set_st_empresa(emp.get_st_empresa() + aff);
                    da.set_st_nome_empresa(emp.get_st_fantasia());
                    da.set_en_atividade(l_a.get_en_atividade());
                    da.set_dt_ultima(sch.get_dt_last());

                    // ## Formata

                    switch (sch.get_tg_type())
                    {
                        #region - Monthly -

                    case Scheduler.Monthly:
                    {
                        da.set_st_info("Mensal, Dia " +
                                       sch.get_nu_monthly_day() +
                                       ", Hora " +
                                       sch.get_st_monthly_hhmm().Substring(0, 2) +
                                       ":" +
                                       sch.get_st_monthly_hhmm().Substring(2, 2));

                        break;
                    }

                        #endregion

                        #region - Weekly -

                    case Scheduler.Weekly:
                    {
                        string dia = "";

                        switch (sch.get_st_weekly_dow())
                        {
                        case "0": dia = "Domingo";      break;

                        case "1": dia = "Segunda";      break;

                        case "2": dia = "Terça";                break;

                        case "3": dia = "Quarta";       break;

                        case "4": dia = "Quinta";       break;

                        case "5": dia = "Sexta";                break;

                        case "6": dia = "Sábado";       break;
                        }

                        da.set_st_info("Semanal, Dia " +
                                       dia +
                                       ", Hora " +
                                       sch.get_st_weekly_hhmm().Substring(0, 2) +
                                       ":" +
                                       sch.get_st_weekly_hhmm().Substring(2, 2));

                        break;
                    }

                        #endregion

                        #region - Daily -

                    case Scheduler.Daily:
                    {
                        da.set_st_info("Diariamente " +
                                       sch.get_st_daily_hhmm().Substring(0, 2) +
                                       ":" +
                                       sch.get_st_daily_hhmm().Substring(2, 2));

                        break;
                    }

                        #endregion
                    }

                    // ## Guarda em memória

                    DataPortable mem_rtc = da as DataPortable;

                    sb.Append(MemorySave(ref mem_rtc));
                    sb.Append(",");
                }

                // ## Guarda todos os identificadores em um bloco

                string list_ids = sb.ToString().TrimEnd(',');

                DataPortable dp = new DataPortable();

                dp.setValue("ids", list_ids);

                // ## Envia para client a identificação do bloco

                output_st_csv = MemorySave(ref dp);
            }

            /// USER [ execute ] END

            Registry("execute done fetch_agenda ");

            return(true);
        }
Ejemplo n.º 6
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute ins_agenda ");

            /// USER [ execute ]

            I_Scheduler schel = new I_Scheduler(this);

            if (input_en_atividade == TipoAtividade.FechMensal)
            {
                string job = "schedule_fech_mensal;empresa;" +
                             input_st_empresa + ";afiliada;" +
                             input_st_afiliada;

                schel.set_st_job(job);
            }

            schel.set_tg_type(input_en_tipo_schedule);
            schel.set_dt_specific(GetDataBaseTime());
            schel.set_tg_status(Context.OPEN);

            switch (input_en_tipo_schedule)
            {
            case Scheduler.Daily:
            {
                schel.set_st_daily_hhmm(input_st_horario);

                schel.set_dt_last(GetDataBaseTime(DateTime.Now.AddDays(1)));
                schel.set_dt_prev(GetDataBaseTime(DateTime.Now.AddDays(1)));

                break;
            }

            case Scheduler.Weekly:
            {
                schel.set_st_weekly_dow(input_st_aux);
                schel.set_st_weekly_hhmm(input_st_horario);

                schel.set_dt_last(GetDataBaseTime(DateTime.Now.AddDays(7)));
                schel.set_dt_prev(GetDataBaseTime(DateTime.Now.AddDays(7)));

                break;
            }

            case Scheduler.Monthly:
            {
                schel.set_nu_monthly_day(input_st_aux);
                schel.set_st_monthly_hhmm(input_st_horario);

                schel.set_dt_last(GetDataBaseTime(DateTime.Now.AddMonths(1)));
                schel.set_dt_prev(GetDataBaseTime(DateTime.Now.AddMonths(1)));

                break;
            }
            }

            if (!schel.create_I_Scheduler())
            {
                return(false);
            }

            l_a = new LINK_Agenda(this);

            l_a.set_en_atividade(input_en_atividade);
            l_a.set_fk_schedule(schel.get_identity());
            l_a.set_fk_empresa(emp.get_identity());
            l_a.set_st_emp_afiliada(input_st_afiliada);

            if (!l_a.create_LINK_Agenda())
            {
                return(false);
            }

            PublishNote("Agendamento criado com sucesso");

            /// USER [ execute ] END

            Registry("execute done ins_agenda ");

            return(true);
        }