Exemple #1
0
        private void CheckSchedule(IAMDatabase db, Int64 scheduleId, Int64 resourcePluginId, Int64 resourceId, String jSonSchedule, DateTime next)
        {
            DateTime date = DateTime.Now;
            TimeSpan ts   = date - new DateTime(1970, 01, 01);

            Schedule schedule = new Schedule();

            try
            {
                schedule.FromJsonString(jSonSchedule);
                jSonSchedule = null;
            }
            catch
            {
                schedule.Dispose();
                schedule = null;
            }

            if (schedule == null)
            {
                return;
            }

            //Check Start date

            TimeSpan stDateTs = next - new DateTime(1970, 01, 01);

            TextLog.Log("Dispatcher", "[" + resourceId + "] CheckSchedule> next " + next.ToString("yyyy-MM-dd HH:mm:ss"));
            TextLog.Log("Dispatcher", "[" + resourceId + "] CheckSchedule> Executa agora? " + (ts.TotalSeconds >= stDateTs.TotalSeconds));
            if (ts.TotalSeconds >= stDateTs.TotalSeconds) //Data e hora atual maior ou igual a data que se deve iniciar
            {
                TextLog.Log("Dispatcher", "[" + resourceId + "] Starting execution");

                try
                {
                    using (IAMDeploy deploy = new IAMDeploy("Dispatcher", localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword))
                        deploy.DeployResourcePlugin(resourcePluginId);
                }
                catch (Exception ex)
                {
                    TextLog.Log("Dispatcher", "[" + resourceId + "] Error on execution " + ex.Message);
                }
                finally
                {
                    TextLog.Log("Dispatcher", "[" + resourceId + "] Execution completed");

                    //Agenda a próxima execução
                    DateTime nextExecute = schedule.CalcNext();

                    db.ExecuteNonQuery("update resource_plugin_schedule set [next] = '" + nextExecute.ToString("yyyy-MM-dd HH:mm:ss") + "' where id = " + scheduleId, CommandType.Text, null);
                }
            }

            schedule.Dispose();
            schedule = null;
        }