static int Main(string[] args) { CommandLineParsingResult <Options> parsingResult = CommandLineParser <Options> .Parse(args); CommandLineResult resultCode = CommandLineParser.ValidateOptions(parsingResult); if (resultCode > CommandLineResult.NoErrors) { return((int)resultCode); } if (resultCode == CommandLineResult.EmptyArgs) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new POCOGeneratorForm()); } else if (resultCode == CommandLineResult.NoErrors) { ComandLineWriter writer = new ComandLineWriter(parsingResult.Options); CommandLineResult result = writer.Export(); return((int)result); } return(0); }
/// <summary> /// Start the App, processes command line args and/or launches the UI /// </summary> /// <param name="sender">sender object</param> /// <param name="e">event args</param> private void App_Startup(object sender, StartupEventArgs e) { CommandLineResult commandLineResult = this.ProcessCommandLine(e.Args); switch (commandLineResult) { case CommandLineResult.Failed: this.RunCommandLine(); this.Shutdown(-1); break; case CommandLineResult.Invalid: this.RunCommandLine(); this.ShowCommandLineHelp(); this.Shutdown(-1); break; case CommandLineResult.SucceededExit: this.Shutdown(); break; case CommandLineResult.Succeeded: var main = new MainWindow(); main.WindowStartupLocation = WindowStartupLocation.CenterScreen; main.Show(); break; } }
public void OutputReturnsStandard() { var sut = new CommandLineResult(); sut.StandardOutput = "foo"; Assert.Equal(sut.StandardOutput, sut.Output); }
public void SuccessfulReturnsCorrectValue(bool expected, int exitcode) { var sut = new CommandLineResult(); sut.ExitCode = exitcode; Assert.Equal(expected, sut.Successful); }
private CommandLineResult WritePocoToFiles(List <IDbObjectTraverse> exportObjects) { string folder = options.Folder; bool isSingleFile = options.IsSingleFile; string fileName = options.FileName; if (isSingleFile && string.IsNullOrEmpty(fileName) == false) { StringBuilder sb = new StringBuilder(); IterateDbObjects(exportObjects, sb); if (fileName.EndsWith(".cs") == false) { fileName += ".cs"; } foreach (char c in Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(c.ToString(), string.Empty); } return(WritePocoToFile(folder, fileName, sb.ToString(), true)); } else { CommandLineResult exportResult = CommandLineResult.NoErrors; foreach (var dbObject in exportObjects) { StringBuilder sb = new StringBuilder(); IterateDbObjects(dbObject, sb); fileName = dbObject.ClassName + ".cs"; foreach (char c in Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(c.ToString(), string.Empty); } CommandLineResult result = WritePocoToFile(folder, fileName, sb.ToString(), false); if (result != CommandLineResult.NoErrors && exportResult == CommandLineResult.NoErrors) { exportResult = result; } } return(exportResult); } }
public CommandLineResult Export() { try { SetConnectionString(options.ConnectionString); DbHelper.BuildServerSchema(Server, InitialCatalog, null, null); List <IDbObjectTraverse> exportObjects = GetExportObjects(); if (exportObjects.Count == 0) { return(CommandLineResult.MissingIncludedObjects); } CommandLineResult result = WritePocoToFiles(exportObjects); return(result); } catch { return(CommandLineResult.ExportError); } }
public static async Task <CommandLineResult> Execute( string command, string args, DirectoryInfo workingDir = null) { args = args ?? ""; var stdOut = new StringBuilder(); var stdErr = new StringBuilder(); using (var process = StartProcess( command, args, workingDir, output: data => { stdOut.AppendLine(data); }, error: data => { stdErr.AppendLine(data); })) { var exitCode = await process.Complete(); var output = stdOut.Replace("\r\n", "\n").ToString().Split('\n'); var error = stdErr.Replace("\r\n", "\n").ToString().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); if (error.All(string.IsNullOrWhiteSpace)) { error = null; } var result = new CommandLineResult( exitCode: exitCode, output: output, error: error); return(result); } }
public void NewInstanceReturnsNotSuccessful() { var sut = new CommandLineResult(); Assert.False(sut.Successful); }
internal static CommandLineResult InitRouteTycoon(LogoScene ls = null) { try { if (ls != null) { ls.Text = "Please wait..."; System.Threading.Thread.Sleep(300); } if (!Directory.Exists(Application.StartupPath + @"\data") && File.Exists(Application.StartupPath + @"\data.zip")) { Directory.CreateDirectory(Application.StartupPath + @"\data"); ZipFile.ExtractToDirectory(Application.StartupPath + @"\data.zip", Application.StartupPath + @"\data"); File.Delete(Application.StartupPath + @"\data.zip"); } else if (Directory.Exists(Application.StartupPath + @"\data") && File.Exists(Application.StartupPath + @"\data.zip")) { Directory.Delete(Application.StartupPath + @"\data", true); Directory.CreateDirectory(Application.StartupPath + @"\data"); ZipFile.ExtractToDirectory(Application.StartupPath + @"\data.zip", Application.StartupPath + @"\data"); File.Delete(Application.StartupPath + @"\data.zip"); } else if (!Directory.Exists(Application.StartupPath + @"\\data")) { if (ls != null) { ls.Text = "ERROR!"; } MessageBox.Show("ERROR - 0x000001\nNot exist data folder", "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error); LogManager.Add(new Log() { Message = @"ROUTETYCOON BOOT ERROR\nERRCODE: 0x000001\nERRMESSAGE: Not exist data folder", type = Log.Type.ERROR, evt = Log.Event.MESSAGE }); SceneManager.MainForm.ExitGame(); } if (ls != null) { ls.Text = "Option Loading..."; System.Threading.Thread.Sleep(300); } OptionManager.Get().Load(AccessManager.AccessKey); if (ls != null) { ls.Text = "Font Reading..."; System.Threading.Thread.Sleep(200); } if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\font.otf")) { try { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\font.otf"); } catch (FileNotFoundException) { if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.otf")) { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.otf"); } else if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.ttf")) { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.ttf"); } else { if (ls != null) { ls.Text = "ERROR!"; } MessageBox.Show("ERROR - 0x000002\nNot exist font.otf file", "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error); LogManager.Add(new Log() { Message = @"ROUTETYCOON BOOT ERROR\nERRCODE: 0x000002\nERRMESSAGE: Not exist font.otf file", type = Log.Type.ERROR, evt = Log.Event.MESSAGE }); SceneManager.MainForm.ExitGame(); } } } else if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\font.ttf")) { try { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\font.ttf"); } catch (FileNotFoundException) { if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.otf")) { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.otf"); } else if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.ttf")) { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.ttf"); } else { if (ls != null) { ls.Text = "ERROR!"; } MessageBox.Show("ERROR - 0x000002\nNot exist font.otf file", "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error); LogManager.Add(new Log() { Message = @"ROUTETYCOON BOOT ERROR\nERRCODE: 0x000002\nERRMESSAGE: Not exist font.otf file", type = Log.Type.ERROR, evt = Log.Event.MESSAGE }); SceneManager.MainForm.ExitGame(); } } } else { if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.otf")) { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.otf"); } else if (File.Exists(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.ttf")) { fonts.AddFontFile(Application.StartupPath + $"\\data\\res\\{OptionManager.Get().ResFolder}\\subfont.ttf"); } else { if (ls != null) { ls.Text = "ERROR!"; } MessageBox.Show("ERROR - 0x000002\nNot exist font.otf file", "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error); LogManager.Add(new Log() { Message = @"ROUTETYCOON BOOT ERROR\nERRCODE: 0x000002\nERRMESSAGE: Not exist font.otf file", type = Log.Type.ERROR, evt = Log.Event.MESSAGE }); SceneManager.MainForm.ExitGame(); } } if (ls != null) { ls.Text = "Initialize Managers..."; System.Threading.Thread.Sleep(300); } PluginManager.LoadPlugins(); ResourceManager.Init(); NewsManager.Init(); AccessManager.Init(); AchievementManager.Init(); TrainManager.Init(); Command.Init(); NetworkManager.Init(); //SoundManager.Init(); if (ls != null) { ls.Text = "Checking Event..."; System.Threading.Thread.Sleep(400); } CommandLineResult res = CheckEvent(); if (res == CommandLineResult.DEBUG_MODE) { DebugMode = true; } else if (res == CommandLineResult.ERROR_LIST) { System.Diagnostics.Process.Start("https://docs.google.com/spreadsheets/d/1w513ZXYd-YIZrn9Y9OMI86JGK1Cr3V59YP4wj0kua10/edit?usp=sharing"); } if (DeveloperMode) { DebugMode = true; TextManager.Get().Set(OptionManager.Get().LangURL.Replace(".txf", ".xml")); } else { TextManager.Get().Set(OptionManager.Get().LangURL); } if (ls != null) { ls.Text = "Check SupportVersion..."; } { // 지원 버전 if (!RTAPI.WebAPI.CheckInternetConnection()) { UpdateAccept = false; return(res); } string str = new System.Net.WebClient().DownloadString("https://www.dropbox.com/s/j8gy71f0qyarejy/support.txt?dl=1"); XmlDocument xml = new XmlDocument(); xml.LoadXml(str); XmlNode versions = xml.SelectNodes("versions")[0]; foreach (XmlNode it in versions.SelectNodes("version")) { int code = Convert.ToInt32(it.Attributes["code"].Value); bool update = Convert.ToBoolean(it.Attributes["update"].Value); if (code == VersionInt) { UpdateAccept = update; break; } } } return(res); } catch (Exception e) { ReportError(e, AccessManager.AccessKey); return(CommandLineResult.NONE); } }
private static void HandleCommandLineQuery( string?b64, string?query, string?slappId, bool exactCase, bool exactCharacterRecognition, string?rebuild, string?patch, bool keepOpen, int limit, bool verbose, bool queryIsRegex, bool queryIsClanTag, bool queryIsTeam, bool queryIsPlayer) { try { var options = new MatchOptions { IgnoreCase = !exactCase, NearCharacterRecognition = !exactCharacterRecognition, QueryIsRegex = queryIsRegex, Limit = limit }; if (queryIsPlayer) { options.FilterOptions = FilterOptions.Player; } else if (queryIsTeam) { options.FilterOptions = FilterOptions.Team; } else if (queryIsClanTag) { options.FilterOptions = FilterOptions.ClanTag; } else { options.FilterOptions = FilterOptions.Default; } CommandLineResult result = new CommandLineResult { Message = "OK", Options = options }; string?[] inputs = new string?[] { b64, query, slappId }; SplatTagController.Verbose = verbose; if (rebuild != null) { if (rebuild.Equals(string.Empty)) { SplatTagControllerFactory.GenerateNewDatabase(); result.Message = "Database rebuilt from default sources!"; } else if (File.Exists(rebuild)) { string?saveFolder = Directory.GetParent(rebuild)?.FullName; string sourcesFile = Path.GetFileName(rebuild); SplatTagControllerFactory.GenerateNewDatabase(saveFolder: saveFolder, sourcesFile: sourcesFile); result.Message = $"Database rebuilt from {rebuild}!"; } else { result.Message = $"Rebuild specified but the sources file specified `{rebuild}` from `{Directory.GetCurrentDirectory()}` does not exist. Aborting."; } } else if (patch != null) { if (patch.Equals(string.Empty)) { result.Message = "Patch specified but no patch sources file specified. Aborting."; } else if (File.Exists(patch)) { SplatTagControllerFactory.GenerateDatabasePatch(patchFile: patch); result.Message = $"Database patched from {patch}!"; } else { result.Message = $"Patch specified but the sources file specified `{patch}` from `{Directory.GetCurrentDirectory()}` does not exist. Aborting."; } } else if (inputs.All(s => string.IsNullOrEmpty(s))) { if (keepOpen) { // First run to open result.Message = $"Connection established. {splatTagController.MatchPlayer(null).Length} players and {splatTagController.MatchTeam(null).Length} teams loaded."; } else { result.Message = "Nothing to search!"; } } else { try { if (new[] { b64, query, slappId }.Count(s => !string.IsNullOrEmpty(s)) > 1) { result.Message = "Warning: Multiple inputs defined. YMMV."; } if (!string.IsNullOrEmpty(b64)) { result.Query = query = Encoding.UTF8.GetString(Convert.FromBase64String(b64)); } if (!string.IsNullOrEmpty(slappId)) { result.Query = slappId; options.FilterOptions = FilterOptions.SlappId; result.Players = splatTagController.MatchPlayer(slappId, options); result.Teams = splatTagController.MatchTeam(slappId, options); } else { Console.WriteLine($"Building result for query={query}"); result.Query = query ?? string.Empty; result.Players = splatTagController.MatchPlayer(query, options); result.Teams = splatTagController.MatchTeam(query, options); } if (result.Players.Length > 0 || result.Teams.Length > 0) { result.AdditionalTeams = result.Players .SelectMany(p => p.TeamInformation.GetAllTeamsUnordered().Select(id => splatTagController.GetTeamById(id))) .Distinct() .ToDictionary(t => t.Id, t => t); result.AdditionalTeams[Team.NoTeam.Id] = Team.NoTeam; result.AdditionalTeams[Team.UnlinkedTeam.Id] = Team.UnlinkedTeam; result.PlayersForTeams = result.Teams .ToDictionary(t => t.Id, t => splatTagController.GetPlayersForTeam(t).ToArray()); foreach (var pair in result.PlayersForTeams) { foreach ((Player, bool)tuple in pair.Value) { foreach (Guid t in tuple.Item1.TeamInformation.GetAllTeamsUnordered()) { result.AdditionalTeams.TryAdd(t, splatTagController.GetTeamById(t)); } } } var sources = new HashSet <string>(); foreach (var s in result.Players.SelectMany(p => p.Sources)) { sources.Add(s.Name); } foreach (var s in result.Teams.SelectMany(t => t.Sources)) { sources.Add(s.Name); } foreach (var s in result.AdditionalTeams.Values.SelectMany(t => t.Sources)) { sources.Add(s.Name); } foreach (var s in result.PlayersForTeams.Values.SelectMany(tupleArray => tupleArray.SelectMany(p => p.Item1.Sources))) { sources.Add(s.Name); } sources.Add(Builtins.BuiltinSource.Name); sources.Add(Builtins.ManualSource.Name); result.Sources = sources.ToArray(); try { result.PlacementsForPlayers = new Dictionary <Guid, Dictionary <string, Bracket[]> >(); foreach (var player in result.Players) { result.PlacementsForPlayers[player.Id] = new Dictionary <string, Bracket[]>(); foreach (var source in player.Sources) { result.PlacementsForPlayers[player.Id][source.Name] = source.Brackets; } } } catch (OutOfMemoryException oom) { const string message = "ERROR: OutOfMemoryException on PlacementsForPlayers. Will continue anyway."; Console.WriteLine(message); Console.WriteLine(oom.ToString()); result.PlacementsForPlayers = new Dictionary <Guid, Dictionary <string, Bracket[]> >(); } } } catch (Exception ex) { string message = $"ERROR: {ex.GetType().Name} while compiling data for serialization..."; Console.WriteLine(message); Console.WriteLine(ex.ToString()); string q = result.Query; result = new CommandLineResult { Query = q, Options = options, Message = message, }; } } string messageToSend; try { StringWriter sw = new StringWriter(); serializer.Serialize(sw, result); messageToSend = sw.ToString(); } catch (Exception ex) { string message = $"ERROR: {ex.GetType().Name} while serializing result..."; Console.WriteLine(message); Console.WriteLine(ex.ToString()); string q = result.Query; result = new CommandLineResult { Query = q, Options = options, Message = message }; // Attempt to send the message as a different serialized error StringWriter sw = new StringWriter(); serializer.Serialize(sw, result); messageToSend = sw.ToString(); } // Send back as a b64 string Console.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes(messageToSend))); } catch (Exception ex) { Console.WriteLine($"ERROR: Outer Exception handler, caught a {ex.GetType().Name}..."); Console.WriteLine(ex.ToString()); } finally { errorMessagesReported.Clear(); } }