Exemplo n.º 1
0
        public int FunctionByte(string[] args)
        {
            CLI options = new CLI();
            CommandLineParser parser = new CommandLineParser(options);

            parser.Parse();

            if (options.Byte)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].ToLower() == "-b" | args[i].ToLower() == "--byte")
                    {
                        int iByte = 0;

                        bool booleanByte = int.TryParse(args[i + 1], out iByte);

                        if (booleanByte == false)
                        {
                            Console.WriteLine("\nThe value entered with the -b option is incorrect\n");
                            Environment.Exit(0);
                        }
                        else
                        {
                            if (args[i + 2].ToLower() == "kib")
                            {
                                iByte *= 1024;
                            }
                            else if (args[i + 2].ToLower() == "mib")
                            {
                                iByte *= 1048576;
                            }
                            else if (args[i + 2].ToLower() == "gib")
                            {
                                iByte *= 1073741824;
                            }

                            //Statistical.DefaultSizeFileInOctet = iByte;
                            Statistical obj = new Statistical();
                            Parameter.NumberLine = obj.CalculSizeFile(iByte, Parameter.NumberOfChar, Parameter.TypesAtGenerate, Parameter.NumberOfAllCombination);
                        }
                    }
                }
            }
            else if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.ToString(78, true));
                return(-1);
            }
            // No errors present and all arguments correct
            // Do work according to arguments
            return(0);
        }
Exemplo n.º 2
0
        public int FunctionByte(string[] args)
        {
            CLI options = new CLI();
            CommandLineParser parser = new CommandLineParser(options);
            parser.Parse();

            if (options.Byte)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].ToLower() == "-b" | args[i].ToLower() == "--byte")
                    {
                        int iByte = 0;

                        bool booleanByte = int.TryParse(args[i + 1], out iByte);

                        if (booleanByte == false)
                        {
                            Console.WriteLine("\nThe value entered with the -b option is incorrect\n");
                            Environment.Exit(0);
                        }
                        else
                        {
                            if (args[i + 2].ToLower() == "kib")
                            {
                                iByte *= 1024;
                            }
                            else if (args[i + 2].ToLower() == "mib")
                            {
                                iByte *= 1048576;

                            }
                            else if (args[i + 2].ToLower() == "gib")
                            {
                                iByte *= 1073741824;
                            }

                            //Statistical.DefaultSizeFileInOctet = iByte;
                            Statistical obj = new Statistical();
                            Parameter.NumberLine = obj.CalculSizeFile(iByte,Parameter.NumberOfChar,Parameter.TypesAtGenerate,Parameter.NumberOfAllCombination);
                        }
                    }

                }
            }
            else if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.ToString(78, true));
                return -1;
            }
            // No errors present and all arguments correct
            // Do work according to arguments
            return 0;
        }
        } // End Fonction 


        internal BigInteger SizeFile(bool saveFile, int numberOfChar, int typesAtGenerate, BigInteger numberOfAllCombination)
        {
            Statistical info = new Statistical();
            bool b = true;
            string sizeFiles = null;
            BigInteger numberLine = 0;

            if (saveFile)
            {
                while (b)
                {
                    try
                    {
                        SetColorThemes();
                        Console.Write(lang.GetString("SizeFile"));
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        sizeFiles = Console.ReadLine();                        
                        Console.ResetColor();
                        
                        int sizFilesInMB = 0;

                        if (Int32.TryParse(sizeFiles, out sizFilesInMB))
                        {
                            sizFilesInMB *= 1048576;
                            numberLine = info.CalculSizeFile(sizFilesInMB,numberOfChar, typesAtGenerate, numberOfAllCombination);
                            b = false;
                        }

                    }
                    catch (Exception e)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n {0} \n", e.Message);
                        Console.ResetColor();
                    }
                }
            }
            return numberLine;
        }