hasKey() public method

Check for key
public hasKey ( string key ) : System.Boolean
key string
return System.Boolean
コード例 #1
0
ファイル: Program.cs プロジェクト: dubasdey/File-Splitter
        static void Main(String[] args)
        {
            Console.Title = Application.ProductName +  " " + Application.ProductVersion + " Console Window";
            CommandLine cmd = new CommandLine();
            if (args != null && args.Length > 1) {
                cmd.parseArguments(args);
                if (cmd.hasKey(global::FileSplitter.CommandLine.SplitParameterCmd)) {
                    List<string> splitParams = cmd.getParamsOfKey(CommandLine.SplitParameterCmd);
                    if (splitParams.Count < 3) {
                        Console.WriteLine("Missing parameter");
                        cmd.printUsageHelp();

                        // return an ErrorLevel in case it is processed in a Batch file
                        Environment.Exit(EXIT_CODE_FAIL );
                    } else {
                        // check size
                        Int64 size = 0;
                        bool delete = false;
                        string format, destinationFolder, outLogFile;
                        SplitUnit mode = SplitUnit.Bytes;
                        string sizeParameter = splitParams[CommandLine.SizeParameterIndex];
                        string unitParameterLowered = args[CommandLine.UnitParameterIndex].ToLower();

                        // Check size
                        if (!Int64.TryParse(sizeParameter, out size)) {
                            Console.WriteLine("Invalid size");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }

                        mode = UnitAttribute.Parse<SplitUnit>(unitParameterLowered);

                        if (mode == SplitUnit.Incorrect) {
                            Console.WriteLine("Invalid size unit");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }

                        size = Utils.unitConverter(size, mode);

                        // check delete original
                        if (cmd.hasKey(CommandLine.DeleteParameterCmd)) {
                            delete = true;
                        }

                        Func<string, string, string> extractKeyWhenSet = (string parameter, string errorMessage) => {
                            string result = null;
                            if (cmd.hasKey(parameter)) {
                                if (cmd.hasParams(parameter)) {
                                    result = cmd.getParamsOfKeyAsString(parameter);
                                } else {
                                    Console.WriteLine(errorMessage);
                                    cmd.printUsageHelp();
                                    Environment.Exit(EXIT_CODE_FAIL);
                                }
                            }
                            return result;
                        };

                        // Check format
                        format = extractKeyWhenSet(CommandLine.FormatParameterCmd, "Invalid format");

                        // Check destination Folder
                        destinationFolder = extractKeyWhenSet(CommandLine.DestinationFolderParameterCmd, "Invalid destination");

                        // Check file to save names
                        outLogFile = extractKeyWhenSet(CommandLine.LogFileParameterCmd, "Invalid file");

                        // check file exists
                        String fileName = args[3];
                        if (File.Exists(fileName)) {
                            FileSplitWorker fs = new FileSplitWorker();
                            fs.start += new FileSplitWorker.StartHandler(fs_splitStart);
                            fs.finish += new FileSplitWorker.FinishHandler(fs_splitEnd);
                            fs.processing += new FileSplitWorker.ProcessHandler(fs_splitProcess);
                            fs.message += new FileSplitWorker.MessageHandler(fs_message);
                            fs.FileName = fileName;
                            fs.PartSize = size;
                            fs.OperationMode = mode;
                            fs.DeleteOriginalFile = delete;
                            fs.DestinationFolder = destinationFolder;
                            fs.GenerationLogFile = outLogFile;
                            if (format != null) {
                                fs.FileFormatPattern = format;
                            }
                            fs.doSplit();

                            Environment.Exit(EXIT_CODE_OK);
                        } else {
                            Console.WriteLine("File does not exist");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }
                    }

                /* TODO JOIN */
                } else {
                    Console.WriteLine("Unrecognized Command");
                    cmd.printUsageHelp();
                    Environment.Exit(EXIT_CODE_FAIL);
                }

            } else {
                setConsoleWindowVisibility(false);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmSplitter());

                Environment.Exit(EXIT_CODE_OK);
            }
        }
コード例 #2
0
        static void Main(String[] args)
        {
            Console.Title = Application.ProductName + " " + Application.ProductVersion + " Console Window";
            CommandLine cmd = new CommandLine();

            if (args != null && args.Length > 1)
            {
                cmd.parseArguments(args);
                if (cmd.hasKey(global::FileSplitter.CommandLine.SplitParameterCmd))
                {
                    List <string> splitParams = cmd.getParamsOfKey(CommandLine.SplitParameterCmd);
                    if (splitParams.Count < 3)
                    {
                        Console.WriteLine("Missing parameter");
                        cmd.printUsageHelp();

                        // return an ErrorLevel in case it is processed in a Batch file
                        Environment.Exit(EXIT_CODE_FAIL);
                    }
                    else
                    {
                        // check size
                        Int64     size = 0;
                        bool      delete = false;
                        string    format, destinationFolder, outLogFile;
                        SplitUnit mode = SplitUnit.Bytes;
                        string    sizeParameter = splitParams[CommandLine.SizeParameterIndex], unitParameter = args[CommandLine.UnitParameterIndex], unitParameterLowered = unitParameter.ToLower();

                        // Check size
                        if (!Int64.TryParse(sizeParameter, out size))
                        {
                            Console.WriteLine("Invalid size");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }

                        mode = UnitAttribute.Parse <SplitUnit>(unitParameterLowered);

                        if (mode == SplitUnit.Incorrect)
                        {
                            Console.WriteLine("Invalid size unit");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }

                        size = Utils.unitConverter(size, mode);

                        // check delete original
                        if (cmd.hasKey(CommandLine.DeleteParameterCmd))
                        {
                            delete = true;
                        }

                        Func <string, string, string> extractKeyWhenSet = (string parameter, string errorMessage) => {
                            string result = null;
                            if (cmd.hasKey(parameter))
                            {
                                if (cmd.hasParams(parameter))
                                {
                                    result = cmd.getParamsOfKeyAsString(parameter);
                                }
                                else
                                {
                                    Console.WriteLine(errorMessage);
                                    cmd.printUsageHelp();
                                    Environment.Exit(EXIT_CODE_FAIL);
                                }
                            }
                            return(result);
                        };

                        // Check format
                        format = extractKeyWhenSet(CommandLine.FormatParameterCmd, "Invalid format");
                        // Check destination Folder
                        destinationFolder = extractKeyWhenSet(CommandLine.DestinationFolderParameterCmd, "Invalid destination");
                        // Check file to save names
                        outLogFile = extractKeyWhenSet(CommandLine.LogFileParameterCmd, "Invalid file");

                        // check file exists
                        String fileName = args[3];
                        if (File.Exists(fileName))
                        {
                            FileSplitWorker fs = new FileSplitWorker();
                            fs.start             += new FileSplitWorker.StartHandler(fs_splitStart);
                            fs.finish            += new FileSplitWorker.FinishHandler(fs_splitEnd);
                            fs.processing        += new FileSplitWorker.ProcessHandler(fs_splitProcess);
                            fs.message           += new FileSplitWorker.MessageHandler(fs_message);
                            fs.FileName           = fileName;
                            fs.PartSize           = size;
                            fs.OperationMode      = mode;
                            fs.DeleteOriginalFile = delete;
                            fs.DestinationFolder  = destinationFolder;
                            fs.GenerationLogFile  = outLogFile;
                            if (format != null)
                            {
                                fs.FileFormatPattern = format;
                            }
                            fs.doSplit();

                            Environment.Exit(EXIT_CODE_OK);
                        }
                        else
                        {
                            Console.WriteLine("File does not exist");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }
                    }

                    /* TODO JOIN */
                }
                else
                {
                    Console.WriteLine("Unrecognized Command");
                    cmd.printUsageHelp();
                    Environment.Exit(EXIT_CODE_FAIL);
                }
            }
            else
            {
                setConsoleWindowVisibility(false);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmSplitter());

                Environment.Exit(EXIT_CODE_OK);
            }
        }
コード例 #3
0
        static void Main(String[] args)
        {
            Console.Title = Application.ProductName + " " + Application.ProductVersion + " Console Window";
            CommandLine cmd = new CommandLine();

            if (args != null && args.Length > 1)
            {
                cmd.parseArguments(args);

                if (cmd.hasKey("split"))
                {
                    List <string> splitParams = cmd.getParamsOfKey("split");
                    if (splitParams.Count < 3)
                    {
                        Console.WriteLine("Missing parameter");
                        cmd.printUsageHelp();
                        Environment.Exit(1);  // return an ErrorLevel in case it is processed in a Batch file
                    }
                    else
                    {
                        // check size
                        Int64          size              = 0;
                        Boolean        delete            = false;
                        string         format            = null;
                        String         destinationFolder = null;
                        String         outLogFile        = null;
                        OPERATION_SPIT mode              = OPERATION_SPIT.BY_BYTE;

                        // Check size
                        try {
                            size = Convert.ToInt64(splitParams[0]);
                        } catch {
                            Console.WriteLine("Invalid size");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }


                        // check units
                        if (args[2].ToLower() == "b")
                        {
                            mode = OPERATION_SPIT.BY_BYTE;
                        }
                        else if (args[2].ToLower() == "kb")
                        {
                            mode = OPERATION_SPIT.BY_KBYTE;
                        }
                        else if (args[2].ToLower() == "mb")
                        {
                            mode = OPERATION_SPIT.BY_MBYTE;
                        }
                        else if (args[2].ToLower() == "gb")
                        {
                            mode = OPERATION_SPIT.BY_GBYTE;
                        }
                        else if (args[2].ToLower() == "l")
                        {
                            mode = OPERATION_SPIT.BY_LINES;
                        }
                        else
                        {
                            Console.WriteLine("Invalid size unit");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }
                        size = Utils.unitConverter(size, mode);

                        // check delete original
                        if (cmd.hasKey("d"))
                        {
                            delete = true;
                        }

                        // check format
                        if (cmd.hasKey("f"))
                        {
                            if (cmd.hasParams("f"))
                            {
                                format = cmd.getParamsOfKeyAsString("f");
                            }
                            else
                            {
                                Console.WriteLine("Invalid format");
                                cmd.printUsageHelp();
                                Environment.Exit(EXIT_CODE_FAIL);
                            }
                        }

                        // Check destination Folder
                        if (cmd.hasKey("df"))
                        {
                            if (cmd.hasParams("df"))
                            {
                                destinationFolder = cmd.getParamsOfKeyAsString("df");
                            }
                            else
                            {
                                Console.WriteLine("Invalid destination");
                                cmd.printUsageHelp();
                                Environment.Exit(EXIT_CODE_FAIL);
                            }
                        }

                        // Check file to save names
                        if (cmd.hasKey("lf"))
                        {
                            if (cmd.hasParams("lf"))
                            {
                                outLogFile = cmd.getParamsOfKeyAsString("lf");
                            }
                            else
                            {
                                Console.WriteLine("Invalid file");
                                cmd.printUsageHelp();
                                Environment.Exit(EXIT_CODE_FAIL);
                            }
                        }

                        // check file exists
                        String fileName = args[3];
                        if (File.Exists(fileName))
                        {
                            FileSplitter fs = new FileSplitter();
                            fs.start             += new FileSplitter.StartHandler(fs_splitStart);
                            fs.finish            += new FileSplitter.FinishHandler(fs_splitEnd);
                            fs.processing        += new FileSplitter.ProcessHandler(fs_splitProcess);
                            fs.message           += new FileSplitter.MessageHandler(fs_message);
                            fs.FileName           = fileName;
                            fs.PartSize           = size;
                            fs.OperationMode      = mode;
                            fs.DeleteOriginalFile = delete;
                            fs.DestinationFolder  = destinationFolder;
                            fs.GenerationLogFile  = outLogFile;

                            if (format != null)
                            {
                                fs.FileFormatPattern = format;
                            }
                            fs.doSplit();
                            Environment.Exit(EXIT_CODE_OK);       // return an ErrorLevel indicating successful launch
                        }
                        else
                        {
                            Console.WriteLine("File does not exist");
                            cmd.printUsageHelp();
                            Environment.Exit(EXIT_CODE_FAIL);
                        }
                    }
                    /* TODO JOIN */
                }
                else
                {
                    Console.WriteLine("Unrecognized Command");
                    cmd.printUsageHelp();
                    Environment.Exit(EXIT_CODE_FAIL);
                }
            }
            else
            {
                setConsoleWindowVisibility(false);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmSplitter());
                Environment.Exit(EXIT_CODE_OK);     // although there's not much point - the console window is no longer visible.  Does it need to be closed?
            }
        }