예제 #1
0
        /// <summary>
        ///
        /// </summary>
        private void StartupNotificationEngine()
        {
            logger.Debug("Start Mainthread.. waiting 5 seconds to allow debug to attach");
            System.Threading.Thread.Sleep(5000);
            logger.Info("Started");
            int sleep = @Configurazione.getSleepServiceValue();

            // start an endless loop; loop will abort only when serviceStarted == false
            while (serviceStarted)
            {
                EventProcessingEngine engineEvent = new EventProcessingEngine();
                try
                {
                    Thread.Sleep(sleep);
                    logger.Debug("Start Cycle");
                    engineEvent.ListToBeProcessed();
                    engineEvent.BuildRecipientsOfEvents();
                    engineEvent.FilterByAssertions();
                    engineEvent.FilterByFollowDomainObject();
                    engineEvent.CreatesEventNotifications();
                    engineEvent.WriteEventsNotifications();
                    engineEvent.UnlockEventQueue();
                    logger.Debug("End Cycle");
                }
                catch (Exception exc)
                {
                    engineEvent.UnlockEventQueue();
                    logger.Error(exc);
                    EventLog.WriteEntry(exc.Message + exc.Data + exc.InnerException + exc.StackTrace + "\n");
                }
            }
            // time to end the thread
            Thread.CurrentThread.Abort();
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        private void StartupLibroFirmaEngine()
        {
            int sleep = 4000;

            try
            {
                if (System.Configuration.ConfigurationManager.AppSettings["sleep_service"] != null)
                {
                    sleep = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["sleep_service"]);
                }

                if (System.Configuration.ConfigurationManager.AppSettings["logFilePath"] != null)
                {
                    logWriter.logSourcePath = System.Configuration.ConfigurationManager.AppSettings["logFilePath"].ToString();

                    if (!System.IO.File.Exists(logWriter.logSourcePath))
                    {
                        System.IO.File.CreateText(logWriter.logSourcePath);
                    }
                }

                if (System.Configuration.ConfigurationManager.AppSettings["logAttivo"] != null)
                {
                    string strlogAttivo = System.Configuration.ConfigurationManager.AppSettings["logAttivo"];
                    string strloglevel  = System.Configuration.ConfigurationManager.AppSettings["logLevel"];

                    if (strlogAttivo.ToUpper().Trim() == "NO" || strlogAttivo.ToUpper().Trim() == "FALSE" || strlogAttivo.Trim() == "0")
                    {
                        logWriter.logAttive = false;
                    }
                    else
                    {
                        logWriter.logAttive = true;
                    }

                    if (!string.IsNullOrEmpty(strloglevel))
                    {
                        int logLevel;
                        try
                        {
                            int.TryParse(strloglevel, out logLevel);
                            if (logLevel < 1)
                            {
                                logLevel = 1;
                            }
                            else if (logLevel > 3)
                            {
                                logLevel = 3;
                            }
                        }
                        catch
                        {
                            logLevel = 1;
                        }

                        logWriter.loglevel = logLevel;
                    }

                    logWriter.addLog(logWriter.INIT, "ATTESA: " + (sleep / 1000).ToString() + " SECONDI");
                    logWriter.addLog(logWriter.INIT, "LOG ATTIVO, LIVELLO " + logWriter.loglevel + (logWriter.loglevel == 1 ? " (ERRORI)" : (logWriter.loglevel == 2 ? " (ERRORI e INFO)" : " (ERRORI, INFO e DEBUG)")));
                }
                else
                {
                    logWriter.logAttive = false;
                }
            }
            catch (Exception exc)
            {
                EventLog.WriteEntry(exc.Message + exc.InnerException + exc.Source + exc.StackTrace + exc.Data);
            }

            string[] listOfEventType = null;
            if (System.Configuration.ConfigurationManager.AppSettings["SignificativeEvent"] != null)
            {
                string tempList = System.Configuration.ConfigurationManager.AppSettings["SignificativeEvent"];
                listOfEventType = tempList.Split('|');
            }

            string eventWithoutActor = null;

            if (System.Configuration.ConfigurationManager.AppSettings["EventWithoutActor"] != null)
            {
                eventWithoutActor = System.Configuration.ConfigurationManager.AppSettings["EventWithoutActor"];
            }

            // start an endless loop; loop will abort only when serviceStarted == false
            while (serviceStarted)
            {
                EventProcessingEngine engineEvent = new EventProcessingEngine();

                try
                {
                    Thread.Sleep(sleep);
                    engineEvent.ListToBeProcessed(listOfEventType);
                    engineEvent.ElaborateListOfEvents(eventWithoutActor);
                    engineEvent.CloseManualProcess();
                    //engineEvent.ClearDatabase();
                }
                catch (Exception exc)
                {
                    logWriter.addLog(logWriter.ERRORE, exc.Message);
                    //if (exc.InnerException!=null)
                    //    EventLog.WriteEntry(exc.Message + exc.Data.ToString() + exc.InnerException.Message  + exc.StackTrace + "\n");
                    //else
                    //    EventLog.WriteEntry(exc.Message + exc.Data.ToString() + exc.StackTrace + "\n");
                }
            }

            // time to end the thread
            Thread.CurrentThread.Abort();
        }