/// <summary> /// Calculates the distance for each starship /// </summary> /// <param name="starships"></param> private void CalculateStops(long distance, List <Starship> starships) { foreach (Starship starship in starships) { if (starship.MGLT.ToLower().Equals("unknown")) { _logger.Error($"Unknown MGLT for {starship.name}"); continue; } Consumable consumable = _function.SeparateConsumable(starship.consumables); long hours = _function.CalculateHours(consumable); long stops = _function.CalculateStops(distance, starship.MGLT.ToInt64(), hours); _logger.Success($"The starship {starship.name} needs {stops} stop(s)"); } }
void RunTranslation(TranslationCommand tCommand) { InitDiskCache(); var project = AddProject(PathUtils.Normalize(Environment.CurrentDirectory), false); TranslationDb trDb; var addLanguage = tCommand.AddLang.Value; if (addLanguage != null) { project.InitializeTranslationDb(); trDb = project.TranslationDb; addLanguage = addLanguage.ToLowerInvariant(); if (trDb.HasLanguage(addLanguage)) { _logger.WriteLine($"Cannot add language {addLanguage} because it already exists. Doing nothing."); } else { _logger.WriteLine($"Adding language {addLanguage}"); trDb.AddLanguage(addLanguage); trDb.SaveLangDb(PathToTranslations(project), addLanguage); _logger.WriteLine($"Added language {addLanguage}"); } return; } var removeLanguage = tCommand.RemoveLang.Value; if (removeLanguage != null) { project.InitializeTranslationDb(); trDb = project.TranslationDb; if (!trDb.HasLanguage(removeLanguage)) { _logger.Warn($"Cannot remove language {removeLanguage} because it does not exist. Doing nothing."); } else { _logger.WriteLine($"Removing language {removeLanguage}"); File.Delete(PathUtils.Join(PathToTranslations(project), $"{removeLanguage}.json")); _logger.WriteLine($"Removed language {removeLanguage}"); } return; } var export = tCommand.Export.Value; var exportAll = tCommand.ExportAll.Value; var lang = tCommand.Lang.Value; var specificPath = tCommand.SpecificPath.Value; if (export != null || exportAll != null) { project.InitializeTranslationDb(specificPath); trDb = project.TranslationDb; if (lang != null && !trDb.HasLanguage(lang)) { _logger.Error( $"You have entered unsupported language '{lang}'. Please enter one of {string.Join(',', trDb.GetLanguages())}"); return; } var destinationFile = export; var exportOnlyUntranslated = true; if (exportAll != null) { destinationFile = exportAll; exportOnlyUntranslated = false; } if (!trDb.ExportLanguages(destinationFile, exportOnlyUntranslated, lang, specificPath)) { _logger.Warn("Nothing to export. No export file created."); } else { if (specificPath == null) { _logger.WriteLine(lang != null ? $"Exported {(exportOnlyUntranslated ? "untranslated " : string.Empty)}language '{lang}' to {destinationFile}." : $"Exported {(exportOnlyUntranslated ? "untranslated " : string.Empty)}languages to {destinationFile}."); } else { _logger.WriteLine($"Exported file from {specificPath} into file {destinationFile}"); } } return; } var import = tCommand.Import.Value; if (import != null) { project.InitializeTranslationDb(specificPath); trDb = project.TranslationDb; if (specificPath == null) { if (!trDb.ImportTranslatedLanguage(import, specificPath)) { _logger.Error("Import failed. See output for more information."); return; } var importedLang = Path.GetFileNameWithoutExtension(PathUtils.Normalize(import)); trDb.SaveLangDb(PathToTranslations(project), importedLang); _logger.WriteLine($"Translated language from file {import} successfully imported."); } else { if (!trDb.ImportTranslatedLanguage(import, specificPath)) { _logger.Error("Import failed. See output for more information."); return; } var language = trDb.GetLanguageFromSpecificFile(specificPath); var dir = Path.GetDirectoryName(specificPath); trDb.SaveLangDb(dir, language); _logger.WriteLine( $"Translated language from file {import} successfully imported to file {specificPath}."); } return; } var union = tCommand.Union.Value; if (union != null && union.All(x => x != null)) { if (union.Length != 3) { _logger.Error("Incorrect count of parameters."); return; } project.InitializeTranslationDb(); trDb = project.TranslationDb; if (trDb.UnionExportedLanguage(union[0], union[1], union[2])) { _logger.Success($"Union of {union[0]} with {union[1]} successfully saved to {union[2]}"); } return; } var subtract = tCommand.Subtract.Value; if (subtract != null && subtract.All(x => x != null)) { if (subtract.Length != 3) { _logger.Error("Incorrect count of parameters."); return; } project.InitializeTranslationDb(); trDb = project.TranslationDb; if (trDb.SubtractExportedLanguage(subtract[0], subtract[1], subtract[2])) { _logger.Success( $"Subtract of {subtract[0]} with {subtract[1]} successfully saved to {subtract[2]}"); } return; } }
void RunTest(TestCommand testCommand) { InitDiskCache(); InitTestServer(); InitMainServer(); AddProject(PathUtils.Normalize(Environment.CurrentDirectory), testCommand.Sprite.Value); int port = 0; if (int.TryParse(testCommand.Port.Value, out var portInInt)) { port = portInInt; } StartWebServer(port, false); DateTime start = DateTime.UtcNow; int errors = 0; int testFailures = 0; int warnings = 0; var messages = new List <CompilationResultMessage>(); var messagesFromFiles = new HashSet <string>(); var totalFiles = 0; foreach (var proj in _projects) { try { _logger.WriteLine("Test build started " + proj.Owner.Owner.FullPath, ConsoleColor.Blue); TestResultsHolder testResults = new TestResultsHolder(); proj.Owner.LoadProjectJson(true); proj.Owner.InitializeOnce(); proj.StyleDefNaming = StyleDefNamingStyle.AddNames; proj.GenerateCode(); proj.SpriterInitialization(); proj.RefreshMainFile(); proj.DetectBobrilJsxDts(); proj.RefreshTestSources(); if (proj.TestSources != null && proj.TestSources.Count > 0) { var ctx = new BuildCtx(_compilerPool, _verbose, ShowTsVersion); ctx.TSCompilerOptions = proj.GetDefaultTSCompilerOptions(); ctx.Sources = new HashSet <string>(); ctx.Sources.Add(proj.JasmineDts); proj.TestSources.ForEach(s => ctx.Sources.Add(s)); if (proj.BobrilJsxDts != null) { ctx.Sources.Add(proj.BobrilJsxDts); } proj.Owner.Build(ctx); var testBuildResult = ctx.BuildResult; var fastBundle = new FastBundleBundler(_tools); var filesContent = new Dictionary <string, object>(); proj.FillOutputByAdditionalResourcesDirectory(filesContent); fastBundle.FilesContent = filesContent; fastBundle.Project = proj; fastBundle.BuildResult = testBuildResult; fastBundle.Build("bb/base", "testbundle.js.map", true); proj.TestProjFastBundle = fastBundle; proj.FilesContent = filesContent; IncludeMessages(proj.TestProjFastBundle, ref errors, ref warnings, messages, messagesFromFiles, proj.Owner.Owner.FullPath); if (errors == 0) { var wait = new Semaphore(0, 1); _testServer.OnTestResults.Subscribe((results) => { testFailures = results.TestsFailed; testResults = results; wait.Release(); }); var durationb = DateTime.UtcNow - start; _logger.Success("Build successful. Starting Chrome to run tests in " + durationb.TotalSeconds.ToString("F1", CultureInfo.InvariantCulture) + "s"); _testServer.StartTest("/test.html", new Dictionary <string, SourceMap> { { "testbundle.js", testBuildResult.SourceMap } }); StartChromeTest(); wait.WaitOne(); StopChromeTest(); } } if (testCommand.Out.Value != null) { File.WriteAllText(testCommand.Out.Value, testResults.ToJUnitXml(testCommand.FlatTestSuites.Value), new UTF8Encoding(false)); } } catch (Exception ex) { _logger.Error("Fatal Error: " + ex); errors++; } } var duration = DateTime.UtcNow - start; var color = (errors + testFailures) != 0 ? ConsoleColor.Red : warnings != 0 ? ConsoleColor.Yellow : ConsoleColor.Green; _logger.WriteLine("Test done in " + duration.TotalSeconds.ToString("F1", CultureInfo.InvariantCulture) + " with " + Plural(errors, "error") + " and " + Plural(warnings, "warning") + " and has " + Plural(totalFiles, "file") + " and " + Plural(testFailures, "failure"), color); Environment.ExitCode = (errors + testFailures) != 0 ? 1 : 0; }