Example #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);
        }
        public SearchingResponse Execute(SearchingRequest request)
        {
            var developerName  = request.DeveloperName;
            var productName    = request.ProductName;
            var instrumentName = request.InstrumentName;

            #region By Developer, Product, Instrument
            if (!StringHelper.IsNullOrTrimEmpty(developerName, productName, instrumentName))
            {
                var keySwitches = Repository.Find(
                    new DeveloperName(request.DeveloperName),
                    new ProductName(request.ProductName),
                    new InstrumentName(request.InstrumentName)
                    );

                return(CreateResponse(keySwitches));
            }
            #endregion

            #region By Developer, Product
            if (!StringHelper.IsNullOrTrimEmpty(developerName, productName))
            {
                var keySwitches = Repository.Find(
                    new DeveloperName(request.DeveloperName),
                    new ProductName(request.ProductName)
                    );

                return(CreateResponse(keySwitches));
            }
            #endregion

            #region By Developer
            if (!StringHelper.IsNullOrTrimEmpty(developerName))
            {
                var keySwitches = Repository.Find(
                    new DeveloperName(request.DeveloperName)
                    );

                return(CreateResponse(keySwitches));
            }
            #endregion

            return(new SearchingResponse(new List <KeySwitch>(), PlainText.Empty));
        }
Example #3
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);
        }