public override void AddToQueryOutput(string message, bool includeTrailingLine = true)
 {
     _console.WriteLine(message);
     if (includeTrailingLine)
     {
         _console.WriteLine("");
     }
     AddToOutputStream(message, includeTrailingLine);
 }
Exemplo n.º 2
0
        public void Log(Exception ex)
        {
            _logger.ErrorException("UnhandledException", ex);
            _logManager.Flush();

            var path = Path.Combine(_appPaths.LogDirectoryPath, "unhandled_" + Guid.NewGuid() + ".txt");

            _fileSystem.CreateDirectory(Path.GetDirectoryName(path));

            var builder = LogHelper.GetLogMessage(ex);

            // Write to console just in case file logging fails
            _console.WriteLine("UnhandledException");
            _console.WriteLine(builder.ToString());

            _fileSystem.WriteAllText(path, builder.ToString());
        }
Exemplo n.º 3
0
        void RunPackageUpgrade(PackageManagerUpgradeCommand upgradeCommand)
        {
            InitDiskCache();
            var project = AddProject(PathUtils.Normalize(Environment.CurrentDirectory), false);
            var currentNodePackageManager = new CurrentNodePackageManager(_dc, _logger);
            var before = currentNodePackageManager.GetLockedDependencies(project.Owner.Owner).ToArray();

            if (upgradeCommand.PackageName.Value == null)
            {
                currentNodePackageManager.UpgradeAll(project.Owner.Owner);
            }
            else
            {
                currentNodePackageManager.Upgrade(project.Owner.Owner, upgradeCommand.PackageName.Value);
            }

            _dc.CheckForTrueChange();
            var after = currentNodePackageManager.GetLockedDependencies(project.Owner.Owner).ToArray();
            var lines = new List <string>();

            foreach (var line in new DiffChangeLog(_dc).Generate(before, after))
            {
                lines.Add(line);
                _logger.WriteLine(line);
            }

            if (lines.Count > 0)
            {
                try
                {
                    File.WriteAllText(PathUtils.Join(project.Owner.Owner.FullPath, "DEPSCHANGELOG.md"),
                                      string.Join('\n', lines) + '\n', Encoding.UTF8);
                }
                catch (Exception e)
                {
                    _logger.Error($"Write DEPSCHANGELOG.md failed with {e}");
                }
            }
        }
Exemplo n.º 4
0
        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))
                    {
                        //TODO LOG ERROR
                        _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;
            }
        }