public BatchManager(bool applicationIsRunningAsService = true) { if (!applicationIsRunningAsService) { string[] args = Environment.GetCommandLineArgs(); // args[0] contains the path to the .exe file if (args.Length > 1) { string batchIdCommandLineArgument = args[1]; // When the application is running from the batch manager, the command line argument starts with -B###, where ### is the decimal batch ID applicationIsRunningFromBatchManager = batchIdCommandLineArgument.StartsWith("-B"); if (applicationIsRunningFromBatchManager) { // Extract the selected Batch ID from -B### string rawBatchId = batchIdCommandLineArgument.Substring(2); selectedBatchId = Convert.ToInt32(rawBatchId); } } } try { sessionManager = new SessionManager(); sessionManager.LoginToRuntimeSession(); batchProcessor = new BatchProcessor(); if (applicationIsRunningFromBatchManager) { // Process the selected batch only IBatch selectedBatch = sessionManager.GetBatchById(selectedBatchId); batchProcessor.ProcessBatch(selectedBatch); KillProcess(); } else { recurringTask = new RecurringTask((taskToExecute) => { taskToExecute.Enabled = false; IBatch nextBatch = sessionManager.GetNextBatch(); if (nextBatch != null) { batchProcessor.ProcessBatch(nextBatch); } taskToExecute.Enabled = true; }, 3000, true); } } catch (Exception exception) { throw exception; } }
/// <summary> /// Tries to retrieve a new batch to process and exits the process if no batch is available /// </summary> public void BatchPolling() { CurrentActiveBatch = sessionManager.GetNextBatch(); if (CurrentActiveBatch != null) { batchProcessor.ProcessBatch(CurrentActiveBatch); } else { sessionManager.Logout(); } }