Exemple #1
0
        /// <summary>
        ///     Execute polling
        /// </summary>
        /// restart
        public static void StartEventEngine(SetEventActionEvent delegateActionEventEmbedded)
        {
            try
            {
                var current = AppDomain.CurrentDomain;
                current.AssemblyResolve += HandleAssemblyResolve;

                LogEngine.Enabled = Configuration.LoggingEngineEnabled();
                LogEngine.ConsoleWriteLine("Load Engine configuration.", ConsoleColor.White);

                //****************************Check for updates
                //Check if need to update files received from partners
                LogEngine.ConsoleWriteLine("Check Engine Syncronization.", ConsoleColor.White);
                EventsEngine.CheckForFileToUpdate();
                //****************************Check for updates

                //Set service states
                LogEngine.ConsoleWriteLine("Initialize Engine Service states.", ConsoleColor.White);
                ServiceStates.RunPolling    = true;
                ServiceStates.RestartNeeded = false;

                LogEngine.ConsoleWriteLine("Initialize Engine.", ConsoleColor.Cyan);
                EventsEngine.InitializeEventEngine(delegateActionEventEmbedded);

                //Init Message ingestor
                MessageIngestor.Init();

                //Create the two sends layers
                // in EventsEngine
                if (!Configuration.DisableExternalEventsStreamEngine())
                {
                    LogEngine.ConsoleWriteLine("Start Internal Event Engine Channel.", ConsoleColor.Yellow);
                    var canStart = EventsEngine.CreateEventUpStream();

                    if (!canStart)
                    {
                        LogEngine.WriteLog(
                            Configuration.EngineName,
                            $"Error during engine service starting. Name: {Configuration.EngineName} - ID: {Configuration.ChannelId()}",
                            Constant.DefconOne,
                            Constant.TaskCategoriesError,
                            null,
                            EventLogEntryType.Error);
                        Thread.Sleep(Configuration.WaitTimeBeforeRestarting());
                        Environment.Exit(0);
                    }

                    //in EventUpStream
                    LogEngine.ConsoleWriteLine("Start External Event Engine Channel.", ConsoleColor.Yellow);
                    //OnRamp start the OnRamp Engine
                    canStart = OffRampEngineSending.Init("MSP Device Component.dll (vNext)");

                    if (!canStart)
                    {
                        LogEngine.WriteLog(
                            Configuration.EngineName,
                            $"Error during engine service starting. Name: {Configuration.ChannelName()} - ID: {Configuration.ChannelId()}",
                            Constant.DefconOne,
                            Constant.TaskCategoriesError,
                            null,
                            EventLogEntryType.Error);
                        Thread.Sleep(Configuration.WaitTimeBeforeRestarting());
                        Environment.Exit(0);
                    }
                }

                //*****************Event object stream area*********************
                //Load the global event and triggers dlls
                var numOfTriggers = 0;
                var numOfEvents   = 0;

                var triggersAndEventsLoaded = EventsEngine.LoadBubblingEventList(ref numOfTriggers, ref numOfEvents);
                if (triggersAndEventsLoaded)
                {
                    LogEngine.ConsoleWriteLine(
                        $"Triggers loaded {numOfTriggers} - Events loaded {numOfEvents}",
                        ConsoleColor.DarkCyan);
                }

                EventsEngine.UpdateAssemblyEventListShared();
                //Load the Active triggers and the active events
                EventsEngine.RefreshBubblingSetting();
                //Start triggers single instances
                EventsEngine.ExecuteBubblingTriggerConfigurationsSingleInstance();
                //Start triggers polling instances
                if (Configuration.EnginePollingTime() > 0)
                {
                    var treadPollingRun = new Thread(StartTriggerPolling);
                    treadPollingRun.Start();
                }
                else
                {
                    LogEngine.WriteLog(Configuration.EngineName,
                                       $"Configuration.EnginePollingTime = {Configuration.EnginePollingTime()}, internal polling system disabled.",
                                       Constant.DefconOne,
                                       Constant.TaskCategoriesError,
                                       null,
                                       EventLogEntryType.Warning);
                }

                //Start Engine Service
                LogEngine.ConsoleWriteLine(
                    "Asyncronous Threading Service state active.",
                    ConsoleColor.DarkCyan);
                var treadEngineStates = new Thread(CheckServiceStates);
                treadEngineStates.Start();

                if (!Configuration.DisableExternalEventsStreamEngine())
                {
                    LogEngine.ConsoleWriteLine("Start On Ramp Engine.", ConsoleColor.Green);
                    var onRampEngineReceiving = new OnRampEngineReceiving();
                    onRampEngineReceiving.Init("component.dll name");
                }
                // Configuration files watcher
                EventsEngine.StartConfigurationSyncEngine();

                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Engine service initialization procedure terminated. Name: {Configuration.ChannelName()} - ID: {Configuration.ChannelId()}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    null,
                    EventLogEntryType.Information);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
            }
        }
Exemple #2
0
        /// <summary>
        ///     Execute polling
        /// </summary>
        /// restart
        public static void StartEventEngine(ActionEvent delegateEmbedded)
        {
            try
            {
                LogEngine.DirectEventViewerLog("Engine starting...", 4);
                var current = AppDomain.CurrentDomain;
                current.AssemblyResolve += HandleAssemblyResolve;

                LogEngine.Enabled = ConfigurationBag.Configuration.LoggingEngineEnabled;
                Debug.WriteLine("Load Engine configuration.");

                //****************************Check for updates
                //Check if need to update files received from partners
                Debug.WriteLine(
                    $"Check Engine Syncronization {ConfigurationBag.Configuration.AutoSyncronizationEnabled}.",
                    ConsoleColor.White);
                if (ConfigurationBag.Configuration.AutoSyncronizationEnabled)
                {
                    EventsEngine.SyncronizePoint();
                }


                //Set service states
                Debug.WriteLine("Initialize Engine Service states.");
                ServiceStates.RunPolling    = ConfigurationBag.Configuration.RunInternalPolling;
                ServiceStates.RestartNeeded = false;

                Debug.WriteLine("Initialize Engine.");
                EventsEngine.InitializeEventEngine(delegateEmbedded);

                //Init Message ingestor
                MessageIngestor.InitSecondaryPersistProvider();

                //Create the two sends layers
                Debug.WriteLine("Start Internal Event Engine Channel.");


                //in EventUpStream
                Debug.WriteLine("Start External Event Engine Channel.");
                //OnRamp start the OnRamp Engine
                var canStart = OffRampEngineSending.Init("MSP Device Component.dll (vNext)");

                if (!canStart)
                {
                    LogEngine.WriteLog(
                        ConfigurationBag.EngineName,
                        $"Error during engine service starting. Name: {ConfigurationBag.Configuration.ChannelName} - ID: {ConfigurationBag.Configuration.ChannelId}",
                        Constant.LogLevelError,
                        Constant.TaskCategoriesError,
                        null,
                        Constant.LogLevelError);
                    Thread.Sleep(ConfigurationBag.Configuration.WaitTimeBeforeRestarting);
                    Environment.Exit(0);
                }


                if (EventsEngine.HAEnabled)
                {
                    Thread haCheck = new Thread(EventsEngine.HAPointsUpdate);
                    haCheck.Start();
                    Thread haClean = new Thread(EventsEngine.HAPointsClean);
                    haClean.Start();
                }


                //*****************Event object stream area*********************
                //Load the global event and triggers dlls
                var numOfTriggers   = 0;
                var numOfEvents     = 0;
                var numOfComponents = 0;

                var triggersAndEventsLoaded = EventsEngine.LoadAssemblyComponents(ref numOfTriggers, ref numOfEvents,
                                                                                  ref numOfComponents);
                if (triggersAndEventsLoaded)
                {
                    Debug.WriteLine(
                        $"Triggers loaded {numOfTriggers} - Events loaded {numOfEvents}",
                        ConsoleColor.DarkCyan);
                }

                //Load the Active triggers and the active events
                EventsEngine.RefreshBubblingSetting(false);
                //Start triggers single instances
                EventsEngine.ExecuteBubblingTriggerConfigurationsSingleInstance();
                //Start triggers polling instances
                if (ConfigurationBag.Configuration.EnginePollingTime > 0)
                {
                    var treadPollingRun = new Thread(StartTriggerPolling);
                    treadPollingRun.Start();
                }
                else
                {
                    LogEngine.WriteLog(ConfigurationBag.EngineName,
                                       $"Configuration.EnginePollingTime = {ConfigurationBag.Configuration.EnginePollingTime}, internal polling system disabled.",
                                       Constant.LogLevelError,
                                       Constant.TaskCategoriesError,
                                       null,
                                       Constant.LogLevelWarning);
                }

                //Start Engine Service
                Debug.WriteLine(
                    "Asyncronous Threading Service state active.",
                    ConsoleColor.DarkCyan);
                var treadEngineStates = new Thread(CheckServiceStates);
                treadEngineStates.Start();

                Debug.WriteLine("Start On Ramp Engine.", ConsoleColor.Green);
                var onRampEngineReceiving = new OnRampEngineReceiving();
                onRampEngineReceiving.Init("component.dll name");

                // Configuration files watcher
                //****************************Start folder whatcher
                EventsEngine.StartFolderWatcherEngine();
                //****************************Start folder whatcher


                LogEngine.WriteLog(
                    ConfigurationBag.EngineName,
                    $"Engine service initialization procedure terminated. Name: {ConfigurationBag.Configuration.ChannelName} - ID: {ConfigurationBag.Configuration.ChannelId}",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesError,
                    null,
                    Constant.LogLevelInformation);
                LogEngine.DirectEventViewerLog("Engine started.", 4);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    ConfigurationBag.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesError,
                    ex,
                    Constant.LogLevelError);
            }
        }