Пример #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 IRemovingPresenter.Null();
            var interactor = new RemovingInteractor(repository, presenter);

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

            Console.WriteLine($"Developer=\"{option.Developer}\", Product=\"{option.Product}\", Instrument=\"{option.Instrument}\"");

            var response = interactor.Execute(input);

            if (response.RemovedCount > 0)
            {
                Console.WriteLine($"{response.RemovedCount} records deleted from database({option.DatabasePath})");
                return(0);
            }

            Console.WriteLine("records not found");
            return(0);
        }
Пример #2
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);
        }
Пример #3
0
        public int Execute(ICommandOption opt)
        {
            var option = (CommandOption)opt;

            var translator = new KeySwitchListListToJsonModelList {
                Formatted = true
            };
            var interactor = new ExportingTemplateJsonInteractor(translator);

            var response = interactor.Execute();

            if (StringHelper.IsNullOrTrimEmpty(option.OutputPath))
            {
                Console.Out.WriteLine(response.Text);
            }
            else
            {
                var outputDirectory = Path.GetDirectoryName(option.OutputPath) !;
                PathUtility.CreateDirectory(outputDirectory);

                Console.WriteLine($"generating json to {option.OutputPath}");
                File.WriteAllText(option.OutputPath, response.Text);
            }

            return(0);
        }
Пример #4
0
        private void OutputToJson(IReadOnlyCollection <KeySwitch> entities, CommandOption option)
        {
            var translator = new KeySwitchListListToJsonModelList
            {
                Formatted = true
            };

            var json = translator.Translate(entities);

            if (!string.IsNullOrEmpty(option.LogFilePath))
            {
                File.WriteAllText(option.LogFilePath, json.Value);
            }
        }