Ejemplo n.º 1
0
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            try
            {
                //myEventLog.WriteEntry("Timer tick.", EventLogEntryType.Information);
                timer.Stop();

                ConnectionManager connectionManager = new ConnectionManager();
                NpgsqlConnection  conn = connectionManager.getConnection();

                SettingsDAO settingsDAO = new SettingsDAO();
                Settings    set         = settingsDAO.readAll(conn);
                myEventLog.WriteEntry(set.ToString(), EventLogEntryType.Information);
                conn.Close();
                conn.Dispose();

                if (validateSettings(set))
                {
                    if (!DayEnabled(set))
                    {
                        timer.Start();
                        return;
                    }
                    myEventLog.WriteEntry("Inicia Proceso.", EventLogEntryType.Information);

                    resetWeek(set);
                    string   sScheduled = set.todSchedule;
                    string[] scheduled  = sScheduled.Split(';');
                    string   current    = DateTime.Now.ToString("HH:mm");
                    bool     sent       = false;
                    foreach (string sTime in scheduled)
                    {
                        if (current.CompareTo(sTime) >= 0 && !HourExecuted(sTime, set))
                        {
                            if (!sent && InExecutionRange(sTime))
                            {
                                sendSMS(set);
                                //localFiles(set);
                                sent = true;
                            }
                            addExecutionToList(sTime, set);
                        }
                    }
                }
                else
                {
                    myEventLog.WriteEntry("Configuracion incorrecta. Corrija la configuracion de SMS y posteriormente reinicie el servicio.", EventLogEntryType.Error);
                    return;
                }

                timer.Start();
            }
            catch (Exception ex)
            {
                myEventLog.WriteEntry("Ha ocurrido un error: " + ex.Message + " " + ex.StackTrace, EventLogEntryType.Error);
            }
        }