private static int Main(string[] args) { try { // please note that comprehensive logging will be required. Log4net has been added to the solution - but the developer will need to // ensure that it is being used properly everywhere Log.Info("Robot starting"); // if there are any command line options that if (!ConfigOptions.ParseCommandLine(args)) { Console.WriteLine("Unknown command line params. Exiting..."); // todo: log this! MailFunctions.SendErrorEmail("DataRetentionRobot " + ConfigOptions.RobotId + " Error", "Bad command line arguments passed"); // todo - put the list of args into the email body // exit with error code Environment.ExitCode = 1; return(1); } // Instantiate all providers CreateProductionProviders(); // Create the robot - and provide it with implementations of all interfaces it needs (it only deals with abstractions) var robot = new Test1Robot(ConfigOptions.RobotId, _taskServer, _stagingServer, _entity1Provider, _entity2Provider); // these are examples of what command line options *might* do (possible for development/debugging purposes). These are examples only. robot.Verbose = ConfigOptions.Verbose; robot.HealthCheckOnly = ConfigOptions.HealthCheck; robot.StagingDisabled = ConfigOptions.StagingDisabled; // Set the robot running if (!robot.Start()) { Environment.ExitCode = 1; return(1); } } catch (Exception e) { // log this!!!!! Console.WriteLine("Unhandled exception!!!! {0}", e.Message); // email/notify the devs!!!! string emailBody = "An unhandled exception was thrown in Data Retention Robot with ID : " + ConfigOptions.RobotId + Environment.NewLine + Environment.NewLine; emailBody += "Message: " + e.Message + Environment.NewLine + Environment.NewLine; emailBody += "Stack Trace: " + e.StackTrace + Environment.NewLine + Environment.NewLine; MailFunctions.SendErrorEmail("DataRetentionRobot " + ConfigOptions.RobotId + " Unhandled Exception!!!", emailBody); Environment.ExitCode = 1; return(1); } Environment.ExitCode = 0; return(0); }
private void SendErrorEmail(string subject, string message) { var sb = new StringBuilder(); sb.AppendLine(message); if (_robotDiagnostics != null) { sb.AppendLine(); sb.AppendLine(FormatDiagnosticsMessage(_robotDiagnostics)); } MailFunctions.SendErrorEmail("DataRetentionRobot " + ConfigOptions.RobotId + " : " + subject, sb.ToString()); }