예제 #1
0
        public IInitialSettings GetSettings(IEnumerable <string> args)
        {
            InitialSettings settings = null;

            Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
            {
                if (!File.Exists(o.Input))
                {
                    Console.WriteLine("Input file not exists");
                    return;
                }

                var inputPath  = new FileInfo(o.Input).FullName;
                var outputPath = new FileInfo(o.Output).FullName;
                var imageSize  = new Size(0, 0);
                if (o.Width > 0 && o.Height > 0)
                {
                    imageSize = new Size(o.Width, o.Height);
                }
                settings = new InitialSettings(inputPath, outputPath, imageSize);
            });
            if (settings == null)
            {
                throw new Exception("Cant get settings with these arguments");
            }
            return(settings);
        }
예제 #2
0
        public object Clone()
        {
            var newSettings = new InitialSettings();

            foreach (var propertyInfo in GetType().GetProperties())
            {
                propertyInfo.SetValue(newSettings, propertyInfo.GetValue(this));
            }

            return(newSettings);
        }
예제 #3
0
        public void Run(IEnumerable <string> args)
        {
            Console.WriteLine(helpText);
            IInitialSettings settings = new InitialSettings();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == null)
                {
                    continue;
                }
                if (input.Length == 0)
                {
                    Console.WriteLine("Empty input, please input command");
                    continue;
                }
                if (input == "help")
                {
                    Console.WriteLine(helpText);
                    continue;
                }
                if (input == "exit")
                {
                    break;
                }
                if (input == "draw")
                {
                    if (settings.InputFilePath == null || settings.OutputFilePath == null)
                    {
                        Console.WriteLine("Please enter paths for input and output files");
                    }
                    else
                    {
                        imageCreator.CreateImage(settings);
                        Console.WriteLine("Image saved");
                    }
                    continue;
                }
                var result = TryChangeSettings(input, settings);
                if (result.IsSuccess)
                {
                    settings = result.Value;
                }
                else
                {
                    Console.WriteLine(result.Error);
                }
            }
        }
예제 #4
0
        public void Run(IEnumerable <string> args)
        {
            Console.WriteLine(helpText);
            IInitialSettings settings = new InitialSettings();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == null)
                {
                    continue;
                }
                if (input.Length == 0)
                {
                    Console.WriteLine("Empty input, please input command");
                    continue;
                }
                if (input == "help")
                {
                    Console.WriteLine(helpText);
                    continue;
                }
                if (input == "exit")
                {
                    break;
                }
                if (input == "draw")
                {
                    if (settings.InputFilePath == null || settings.OutputFilePath == null)
                    {
                        Console.WriteLine("Please enter paths for input and output files");
                    }
                    else
                    {
                        imageCreator.CreateImage(settings)
                        .Then(r => Console.WriteLine("Image saved"))
                        .OnFail(Console.WriteLine);
                    }
                    continue;
                }

                TryChangeSettings(input, settings)
                .Then(s => settings = s)
                .OnFail(Console.WriteLine);
            }
        }