/// <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); } }