internal static bool CheckArguments( MultilinerBotArguments botArgs, out string errorMessage) { if (!CheckValidArguments(botArgs, out errorMessage)) { errorMessage = string.Format( "multilinerbot can't start without specifying the following arguments:\n{0}", errorMessage); return(false); } if (!File.Exists(botArgs.ConfigFilePath)) { errorMessage = string.Format( "multilinerbot can't start without the JSON config file [{0}]", botArgs.ConfigFilePath); return(false); } if (!TryParseConfigFile(botArgs.ConfigFilePath, out errorMessage)) { errorMessage = string.Format( "multilinerbot can't start without specifying a valid JSON config file [{0}]:\n{1}", botArgs.ConfigFilePath, errorMessage); return(false); } return(true); }
static bool CheckValidArguments( MultilinerBotArguments botArgs, out string errorMessage) { errorMessage = string.Empty; if (string.IsNullOrEmpty(botArgs.WebSocketUrl)) { errorMessage += BuildArgumentError( "Plastic web socket url endpoint", "--websocket wss://blackmore:7111/plug"); } if (string.IsNullOrEmpty(botArgs.RestApiUrl)) { errorMessage += BuildArgumentError( "Plastic REST API url", "--restapi https://blackmore:7178"); } if (string.IsNullOrEmpty(botArgs.BotName)) { errorMessage += BuildArgumentError( "Name for this bot", "--name multiliner-dev-bot"); } if (string.IsNullOrEmpty(botArgs.ApiKey)) { errorMessage += BuildArgumentError( "Connection API key", "--apikey x2fjk28fda"); } if (string.IsNullOrEmpty(botArgs.ConfigFilePath)) { errorMessage += BuildArgumentError( "JSON config file", "--config tunk-dev-bot-config.conf"); } return(string.IsNullOrEmpty(errorMessage)); }
static int Main(string[] args) { string botName = null; try { MultilinerBotArguments botArgs = new MultilinerBotArguments(args); bool bValidArgs = botArgs.Parse(); botName = botArgs.BotName; ConfigureLogging(botName); mLog.InfoFormat("MultilinerBot [{0}] started. Version [{1}]", botName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); string argsStr = args == null ? string.Empty : string.Join(" ", args); mLog.DebugFormat("Args: [{0}]. Are valid args?: [{1}]", argsStr, bValidArgs); if (!bValidArgs || botArgs.ShowUsage) { PrintUsage(); if (botArgs.ShowUsage) { mLog.InfoFormat( "MultilinerBot [{0}] is going to finish: " + "user explicitly requested to show usage.", botName); return(0); } mLog.ErrorFormat( "MultilinerBot [{0}] is going to finish: " + "invalid arguments found in command line.", botName); return(0); } string errorMessage = null; if (!MultilinerBotArgumentsChecker.CheckArguments( botArgs, out errorMessage)) { Console.WriteLine(errorMessage); mLog.ErrorFormat( "MultilinerBot [{0}] is going to finish: error found on arguments check", botName); mLog.Error(errorMessage); return(1); } MultilinerBotConfiguration botConfig = MultilinerBotConfiguration. BuidFromConfigFile(botArgs.ConfigFilePath); errorMessage = null; if (!MultilinerBotConfigurationChecker.CheckConfiguration( botConfig, out errorMessage)) { Console.WriteLine(errorMessage); mLog.ErrorFormat( "MultilinerBot [{0}] is going to finish: error found on configuration check", botName); mLog.Error(errorMessage); return(1); } ConfigureServicePoint(); string escapedBotName = GetEscapedBotName(botName); LaunchMultilinerMergebot( botArgs.WebSocketUrl, botArgs.RestApiUrl, botConfig, ToolConfig.GetBranchesFile(escapedBotName), ToolConfig.GetCodeReviewsFile(escapedBotName), botName, botArgs.ApiKey); mLog.InfoFormat( "MultilinerBot [{0}] is going to finish: orderly shutdown.", botName); return(0); } catch (Exception e) { Console.WriteLine(e.Message); mLog.FatalFormat( "MultilinerBot [{0}] is going to finish: uncaught exception " + "thrown during execution. Message: {1}", botName, e.Message); mLog.DebugFormat("Stack trace:{0}{1}", Environment.NewLine, e.StackTrace); return(1); } }