doSplit() public method

Do split operation
public doSplit ( ) : void
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Common Split test
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="size"></param>
        private void sizeTest(SplitUnit unit,int size)
        {
            String tempPath = Path.GetTempPath() + @"fSplitTest\";
            String fileName = tempPath +"file" + size + unit + "F.txt";
            System.IO.Directory.CreateDirectory(tempPath);
            Debug.WriteLine("Split " + fileName + " to " + tempPath);

            TestUtils.createFile(fileName, TestUtils.SIZE_2MB);

            FileSplitWorker worker = new FileSplitWorker();

            worker.DeleteOriginalFile = true;
            worker.DestinationFolder = tempPath;
            worker.FileName = fileName;

            worker.OperationMode = unit;
            worker.PartSize = Utils.unitConverter(size, unit);

            worker.doSplit();
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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(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);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Start Splitting operation
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lbStart_Click(object sender, EventArgs e)
 {
     fileSplitter.doSplit();
 }