private void LoadModulesFromconfiguration() { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var coreSystemSection = config.GetSection(BillingwareConfigurationSection.SectionName) as BillingwareConfigurationSection; if (coreSystemSection != null) { foreach (ProviderSettings element in coreSystemSection.ServiceModules) { if (Activator.CreateInstance(Type.GetType(element.Type)) is IBillingwareModule notificationModule) { _serviceModules.Add(notificationModule); CommonLogger.Info <BillingwareServiceControl>($"{element.Name} module added."); } else { CommonLogger.Warn <BillingwareServiceControl>($"{element.Name} does not implement IBillingwareModule. Will ignore."); } } } else { CommonLogger.Debug <BillingwareServiceControl>($"{BillingwareConfigurationSection.SectionName} is not defined"); throw new ConfigurationErrorsException($"{BillingwareConfigurationSection.SectionName} is not defined"); } }
private static void StartHttpServer() { var serverUrl = ConfigReader.Settings["Billingware.Api.Public.ListenOn"]; try { _apiListener = WebApp.Start <Startup>(serverUrl); CommonLogger.Info <PublicApiModule>("Public API HTTP Listener started at {0}", serverUrl); CommonLogger.Debug <PublicApiModule>("Waiting for requests..."); } catch (Exception exception) { CommonLogger.Error <PublicApiModule>(exception, exception.Message); throw; } }
/// <summary> /// int method to execute batch /// </summary> /// <param name="batchMain"></param> public void Init(BatchMain batchMain) { //userdata creation UserDataFactory userDataFactory = DefaultBatchUserfactory.GetInstance(); UserData usrdata = userDataFactory.CreateUserData(null); //check the batchmain instance available if (batchMain == null) { MessageData messageData = new MessageData("fbce00023", Properties.Resources.fbce00023); Exception ex = new NullReferenceException(); logger.Error(messageData, ex); ExitApplication(Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_BATCH_MAIN_INSTANCE_NOT_AVAILABLE); } //Get Batch Prameters for batchexecution string batchExecutionTypeParam = BatchConfigurationDataTypeEnum.BATCH_EXECUTION_TYPE.GetValue(); TimeSpan batchExecutionWaitIntervalParam = TimeSpan.Parse(BatchConfigurationDataTypeEnum.BATCH_EXECUTION_WAIT_INTERVAL.GetValue()); //Get Batch Prameters for batchexecution retry on exception int batchExecutionRetryCountParam = Convert.ToInt32(BatchConfigurationDataTypeEnum.BATCH_EXECUTION_RETRY_COUNT_ON_EXCEPTION.GetValue()); TimeSpan batchExecutionRetryWaitIntervalParam = TimeSpan.Parse(BatchConfigurationDataTypeEnum.BATCH_EXECUTION_RETRY_WAIT_INTERVAL_ON_EXCEPTION.GetValue()); //Get Batch Prameters for preventmultipleinvoke bool preventMultipleInvokeParam = Convert.ToBoolean(BatchConfigurationDataTypeEnum.PREVENT_MULTIPLE_INVOKE.GetValue()); TimeSpan preventMultipleInvokeWaitIntervalParam = TimeSpan.Parse(BatchConfigurationDataTypeEnum.PREVENT_MULTIPLE_INVOKE_WAIT_INTERVAL.GetValue()); int preventMultipleInvokeRetryCountParam = Convert.ToInt32(BatchConfigurationDataTypeEnum.PREVENT_MULTIPLE_INVOKE_RETRY_COUNT.GetValue()); //counter to chcek retry count on exception case int exceptionRetryCounter = 0; //to check whether the batch has been started to avoid checking multipleinvoker everytime bool batchStarted = false; //1.start batch process to do continous execution in while loop while (true) { //3.1 prevent multiple invoke based on the settings file value and start the batch program if (preventMultipleInvokeParam && !batchStarted) { //counter to check multipleinvoke retry int preventMultipleInvokeRetryCounter = 0; while (true) { bool continueBatchExecution; try { continueBatchExecution = PreventMultipleInvokeCheckForBatchExecution(batchMain.GetName()); } catch (Exception multipleInvokeEx) { //logging for retry on exception MessageData multipleInvokeExMessageData = new MessageData("fbce00029", Properties.Resources.fbce00029); logger.Error(multipleInvokeExMessageData, multipleInvokeEx); ExitApplication(Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_MULTIPLE_INVOKE_EXCEPTION); return; } //if continuebatchexecution flag is true, exit the loop and do batch execuion if (continueBatchExecution) { //update the flag once batch started batchStarted = true; break; } //if retrycount=0, complete the batch application if (preventMultipleInvokeRetryCountParam == 0) { ExitApplication(Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_MULTIPLE_INVOKE_EXCEPTION_NO_RETRY); return; } //increase the counter to check multipleinvokeretry count preventMultipleInvokeRetryCounter++; //Wait interval for execution retry try { MultipleInvokeExecutionRetryWait(preventMultipleInvokeRetryCounter, preventMultipleInvokeWaitIntervalParam); } catch (Exception ex) { MessageData messagedata = new MessageData("fbce00027", Properties.Resources.fbce00027); logger.Error(messagedata, ex); ExitApplication(Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_MULTIPLE_INVOKE_RETRY_THREAD_WAIT_EXCEPTION); return; } //exception throws after retry counts reached maximum retry count in the settings file if (preventMultipleInvokeRetryCounter >= preventMultipleInvokeRetryCountParam) { MessageData messageData = new MessageData("fbce00022", Properties.Resources.fbce00022); logger.Error(messageData); ExitApplication(Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_MULTIPLE_INVOKE_RETRY_REACHED_MAX_COUNT); return; } } } //1.execute the batch try { logger.Debug(new MessageData("fbcd00001", Properties.Resources.fbcd00001)); batchMain.Execute(); logger.Debug(new MessageData("fbcd00002", Properties.Resources.fbcd00002)); exceptionRetryCounter = 0; } catch (Exception batchExecutionEx) { MessageData batchExceptionMessagedata = new MessageData("fbce00034", Properties.Resources.fbce00034); logger.Error(batchExceptionMessagedata, batchExecutionEx); //if retrycount=0, complete the batch application if (batchExecutionRetryCountParam == 0) { CompleteBatchExecution(batchMain.GetName(), Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_EXECUTION_EXCEPTION_NO_RETRY); return; } //2.1 do retry execution based on settings parameter count exceptionRetryCounter++; //2.2 wait for next execution retry on exception case, if wait interval time specified in settings file try { BatchExecutionRetryWaitOnException(exceptionRetryCounter, batchExecutionRetryWaitIntervalParam); } catch (Exception batchRetryEx) { MessageData messagedata = new MessageData("fbce00026", Properties.Resources.fbce00026); logger.Error(messagedata, batchRetryEx); CompleteBatchExecution(batchMain.GetName(), Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_RETRY_EXECUTION_ON_EXCEPTION_THREAD_WAIT_EXCEPTION); return; } //if the retry count reached the max, exit the batch application if (exceptionRetryCounter >= batchExecutionRetryCountParam) { CompleteBatchExecution(batchMain.GetName(), Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_RETRY_EXECUTION_ON_EXCEPTION_REACHED_MAX_COUNT); return; } continue; } //1.1batch execution stops if batchexecutiontype : 0 - onetime execution / 1 - infinity loop if ("0".Equals(batchExecutionTypeParam)) { //3.update the batch process flag to set '2' as completed CompleteBatchExecution(batchMain.GetName(), Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_BATCH_EXECUTION_SUCCESS); return; } //check isstoprequested flag after each execution //if "1" remove the batchprocessdata and exit the application if (CheckIsStopRequestedForApplication(batchMain.GetName())) { MessageData messagedata = new MessageData("fbci00014", Properties.Resources.fbci00014); logger.Info(messagedata); //complete with success in the taskscheduler after stop requested by administrator CompleteBatchExecution(batchMain.GetName(), Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_BATCH_EXECUTION_SUCCESS); return; } //1.2.wait for next execution, if wait interval time specified in settings file try { BatchExecutionWait(batchExecutionWaitIntervalParam); } catch (Exception batchExecutionWaitEx) { MessageData messagedata = new MessageData("fbce00025", Properties.Resources.fbce00025); logger.Error(messagedata, batchExecutionWaitEx); CompleteBatchExecution(batchMain.GetName(), Properties.Settings.Default.SCHED_RETURN_IN_BATCH_CONTROLLER_EXECUTION_THREAD_WAIT_EXCEPTION); return; } } }