Ejemplo n.º 1
0
        /// <summary>
        /// Download all the starships from the API
        /// </summary>
        /// <returns></returns>
        private async Task <List <Starship> > DownloadStarships()
        {
            _logger.Message("Downloading starships from API..");
            List <Starship> _starships = await _download.GetStarships();

            if (_starships == null || _starships.Count == 0)
            {
                _logger.Error("Was not possible to get the starthips from the API.");
            }
            else
            {
                _logger.Message($"Found {_starships.Count} starships");
            }

            return(_starships);
        }
        public void SetValue(string keyName, string valueName, object value)
        {
            var registryValueKind = value.GetType() switch
            {
                { } x when x == typeof(uint) => RegistryValueKind.DWord,
                { } x when x == typeof(string) => RegistryValueKind.String,
                _ => throw new Exception(
                          $"{nameof(RegistrySetting)}.{nameof(RegistrySetting.ValueData)} only supports types: string and uint32")
            };

            if (value is uint)
            {
                value = unchecked ((int)(uint)value);
            }

            try
            {
                Registry.SetValue(keyName, valueName, value, registryValueKind);
            }
            catch (Exception e)
            {
                logger.Error(
                    $"Error setting value in registry >> {nameof(keyName)}: {keyName}; {nameof(valueName)}: {valueName}; {nameof(RegistryValueKind)}: {registryValueKind}",
                    e);
                throw;
            }
        }
    }
Ejemplo n.º 3
0
        public ActionResult <IEnumerable <string> > Get()
        {
            System.Console.WriteLine("Teste novamente");
            _consoleLogger.Information("Logger gerado");
            _consoleLogger.Error("Opps! An Error has occurred");

            return(new string[] { "value1", "value2" });
        }
Ejemplo n.º 4
0
 public async Task ExecuteAsync()
 {
     try
     {
         await ExecuteInternalAsync();
     }
     catch (Exception e)
     {
         consoleLogger.Error(e.ToString());
     }
 }
Ejemplo n.º 5
0
        private void ErrorDataAdded(object?sender, System.Management.Automation.DataAddedEventArgs e)
        {
            var data = powershell.Streams.Error[e.Index];

            consoleLogger.Error(data.ToString());
        }
Ejemplo n.º 6
0
        void RunPackageAdd(PackageManagerAddCommand addCommand)
        {
            InitDiskCache();
            var project = AddProject(PathUtils.Normalize(Environment.CurrentDirectory), false);
            var currentNodePackageManager = new CurrentNodePackageManager(_dc, _logger);

            if (addCommand.PackageName.Value == null)
            {
                _logger.Error("Didn't specified name of package to add");
            }
            else
            {
                currentNodePackageManager.Add(project.Owner.Owner, addCommand.PackageName.Value, addCommand.Dev.Value);
            }
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
0
        public void Resolve(IResult result)
        {
            _consoleLogger.Error(result.Message);

            Environment.Exit((int)result.Code);
        }