Exemplo n.º 1
0
        /// <summary>
        ///  Unit order converter
        /// </summary>
        /// <param name="items"></param>
        /// <param name="unitOrder">0 bytes 1 kbytes 2 Mbytes 3 Gb 4 Lines</param>
        /// <returns></returns>
        public static Int64 unitConverter(Int64 items, OPERATION_SPIT units)
        {
            Int64 result = items;
            Int64 factor = 0;

            switch (units)
            {
            case OPERATION_SPIT.BY_KBYTE:
                factor = 1;
                break;

            case OPERATION_SPIT.BY_MBYTE:
                factor = 2;
                break;

            case OPERATION_SPIT.BY_GBYTE:
                factor = 3;
                break;
            }
            if (factor > 0)
            {
                result = (Int64)Math.Ceiling(items * Math.Pow(1024, factor));
            }
            return(result);
        }
Exemplo 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("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?
            }
        }
Exemplo n.º 3
0
 public ComboboxItem(String text, OPERATION_SPIT key)
 {
     this.Text  = text;
     this.Value = Value;
 }