Beispiel #1
0
        public int Execute(ICommandOption opt)
        {
            var option = (CommandOption)opt;

            using var repository = new LiteDbKeySwitchRepository(option.DatabasePath);
            var translator = new KeySwitchListListToJsonModelList
            {
                Formatted = true
            };

            var presenter  = new ISearchingPresenter.Console();
            var interactor = new SearchingInteractor(repository, translator, presenter);

            var input = new SearchingRequest(option.Developer, option.Product, option.Instrument);

            var response = interactor.Execute(input);

            if (StringHelper.IsNullOrTrimEmpty(option.OutputPath))
            {
                Console.Out.WriteLine($"{response.Text}");
            }
            else
            {
                File.WriteAllText(option.OutputPath, response.Text.Value, Encoding.UTF8);
                Console.Out.WriteLine($"Output json to {option.OutputPath}");
            }

            Console.Error.WriteLine($"{response.FoundCount} record(s) found");

            return(0);
        }
Beispiel #2
0
        public void ExportTest()
        {
            #region Adding To DB
            var dbRepository = new LiteDbKeySwitchRepository(new MemoryStream());
            var entity       = TestDataGenerator.CreateKeySwitch();
            dbRepository.Save(entity);
            #endregion

            var inputData  = new SearchingRequest(entity.DeveloperName.Value, entity.ProductName.Value);
            var interactor = new SearchingInteractor(
                dbRepository,
                new KeySwitchListListToJsonModelList {
                Formatted = true
            },
                new ISearchingPresenter.Console()
                );

            var response = interactor.Execute(inputData);
            Console.WriteLine(response);
        }