コード例 #1
0
        private void AsyncOperationCallback(Object stateInfo)
        {
            if (IsAsync)
            {
                return;
            }

            IsAsync = true;
            try
            {
                using (ScheduleServicesDS ds = new ScheduleServicesDS())
                {
                    Schedule schedule = new Schedule();
                    LogHelper.LogInfo("inizio attività");
                    schedule.EstraiSchedule(ds);
                    foreach (ScheduleServicesDS.SCHEDULERow riga in ds.SCHEDULE)
                    {
                        string[] elementi = riga.ORAESECUZIONE.Split(':');
                        if (elementi.Length < 2 || elementi.Length > 3)
                        {
                            LogHelper.LogError(string.Format("Errore nella stringa ora {0} del servizio schedulato id: {1} ", riga.ORAESECUZIONE, riga.IDSCHEDULE));
                            return;
                        }

                        int ora     = 0;
                        int minuti  = 0;
                        int secondi = 0;

                        if (!int.TryParse(elementi[0], out ora))
                        {
                            LogHelper.LogError(string.Format("Errore nella conversione della stringa ora {0} del servizio schedulato id: {1} ", riga.ORAESECUZIONE, riga.IDSCHEDULE));
                            return;
                        }
                        if (!int.TryParse(elementi[1], out minuti))
                        {
                            LogHelper.LogError(string.Format("Errore nella conversione della stringa ora {0} del servizio schedulato id: {1} ", riga.ORAESECUZIONE, riga.IDSCHEDULE));
                            return;
                        }
                        if (elementi.Length == 3)
                        {
                            if (!int.TryParse(elementi[2], out secondi))
                            {
                                LogHelper.LogError(string.Format("Errore nella conversione della stringa ora {0} del servizio schedulato id: {1} ", riga.ORAESECUZIONE, riga.IDSCHEDULE));
                                return;
                            }
                        }

                        DateTime oraSchedulata = new DateTime(riga.DATAESECUZIONE.Year, riga.DATAESECUZIONE.Month, riga.DATAESECUZIONE.Day, ora, minuti, secondi);
                        if (oraSchedulata < DateTime.Now)
                        {
                            riga.ESEGUITA = SiNo.Si;
                            schedule.RischedulaServizio(riga, ds);
                            schedule.SalvaModificheSchedulazione(ds);

                            IScheduledTask task = schedule.EstraiScheduledTask(riga);
                            try
                            {
                                task.Esegui();
                            }
                            catch (Exception exc)
                            {
                                LogHelper.LogError("Errore in task.esegui", exc);
                            }
                        }
                    }
                }
                //using (GestioneOrdiniCliente gos = new GestioneOrdiniCliente())
                //{
                //    LogHelper.LogInfo("Inizio attivita");
                //    gos.DoIt();
                //    LogHelper.LogInfo("Fine attivita");
                //}
            }
            catch (Exception ex)
            {
                LogHelper.LogError("Errore in AsyncOperationCallback", ex);
            }
            finally
            {
                IsAsync = false;
            }
        }
コード例 #2
0
 protected override void OnStop()
 {
     LogHelper.LogInfo("#### SCHEDULED SERVICE FERMATO ####");
 }