Пример #1
0
        public static void parseArguments(String[] args, CommandDispatcher cd)
        {
            try
            {
                CommandLineDictionary dict = CommandLineDictionary.FromArguments(args, '-', '=');
                // Shorthand
                Func<string, bool> hasPar = (string key) => hasParameter(dict, key);

                if (hasPar("install"))
                    cd.addCommand(() => RegistryManipulator.install());

                else if (hasPar("uninstall"))
                    cd.addCommand(() => RegistryManipulator.uninstall());

                else if(hasFileParameter(dict)){
                    var filename = dict["file"];
                    if(hasPar("resizePercentage"))
                        cd.addCommand(() => ImageManipulators.setNewSize(filename, Byte.Parse(dict["resizePercentage"])));

                    if (hasPar("resizeSlider"))
                        cd.addCommand(() => {
                            var p = new PercentageSlider();
                            var perc = p.getSelection();
                            return ImageManipulators.setNewSize(filename, perc);
                        });

                    if (hasPar("sepiaPercentage"))
                        cd.addCommand(() => ImageManipulators.setSepiaTone(filename, Byte.Parse(dict["sepiaPercentage"])));

                    if(hasPar("grayScale"))
                        cd.addCommand(() => ImageManipulators.setColorspace(filename, "gray"));

                    if (hasPar("more-contrast"))
                        cd.addCommand(() => ImageManipulators.setContrast(filename, "-contrast"));

                    if (hasPar("less-contrast"))
                        cd.addCommand(() => ImageManipulators.setContrast(filename, "+contrast"));

                    if (hasPar("addBorder") && hasPar("borderColor"))
                        cd.addCommand(() => ImageManipulators.setBorder(filename, dict["borderColor"]));

                    if (hasPar("oilPaint"))
                        cd.addCommand(() => ImageManipulators.oilPaint(filename, dict["oilPaint"]));

                    if (hasPar("signature"))
                        cd.addCommand(() => ImageManipulators.signature(filename, dict["signature"]));

                    if (hasPar("toFileType"))
                        cd.addCommand(() => ImageManipulators.toFileType(filename, dict["toFileType"]));
                }
            }
            catch (System.ArgumentException) { printUsageHelp(); }
            catch (KeyNotFoundException) { /* This is not neccessarily bad */ }
        }