Example #1
0
        public void Test_Parameters_No_filename()
        {
            var parameterParser = new ParameterParser();
            var parameters      = parameterParser.ParseParameters(new string[] { "1000" });

            Assert.Null(parameters);
        }
Example #2
0
        public void Test_Parameters_Wrong_Amount()
        {
            var parameterParser = new ParameterParser();
            var parameters      = parameterParser.ParseParameters(new string[] { "data.csv", "abc" });

            Assert.Null(parameters);
        }
        /// <summary>
        /// Represents the main entry point in the command line tool.
        /// </summary>
        /// <param name="args">
        /// Contains the command line arguments.
        /// For a complete description of the command line arguments see method TypeHelpPage.
        /// </param>
        /// <returns>
        /// 0 - Success.
        /// 1 - Error.
        /// </returns>
        private static int Main(string[] args)
        {
            int result = 1; // Assume error.

            try
            {
                ParameterParser <DatabaseGeneratorParameters> parameterParser = new ParameterParser <DatabaseGeneratorParameters>(DatabaseGeneratorParameters.ParameterListRules);
                DatabaseGeneratorParameters parameters = parameterParser.ParseParameters(args);

                if (parameters.IsHelpSpecified)
                {
                    TypeHelpPage();
                    result = 0; // Success.
                }
                else
                {
                    Console.WriteLine(GetApplicationNameAndVersion());

                    if (parameters.IsShowDbSchemaSpecified)
                    {
                        TypeDbSchema();
                        result = 0; // Success.
                    }
                    else if (parameters.IsRunValidationSpecified)
                    {
                        AutoValidator autoValidator = new AutoValidator(
                            parameters.SqlServerName,
                            parameters.SqlDbName,
                            parameters.SqlUserName,
                            parameters.SqlPassword);

                        result = autoValidator.Validate() ? 0 : 1;
                    }
                    else
                    {
                        Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Active threads: {0}", parameters.Threads));
                        Console.WriteLine();

                        DatabaseConnection databaseConnection = DatabaseConnection.CreateSqlServerConnection(parameters.SqlServerName, parameters.SqlDbName, parameters.SqlUserName, parameters.SqlPassword);
                        DatabaseGenerator  databaseGenerator  = new DatabaseGenerator(parameters, databaseConnection);
                        databaseGenerator.GenerateAndPopulateDatabase().Wait();

                        result = 0; // Success.
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            //// TypePeakMemoryUsage();

            return(result);
        }
        static int Main(string[] args)
        {
            int result = 1; // Assume error.

            try
            {
                ParameterParser <DatabaseGeneratorParameters> parameterParser = new ParameterParser <DatabaseGeneratorParameters>(DatabaseGeneratorParameters.ParameterListRules);
                DatabaseGeneratorParameters parameters = parameterParser.ParseParameters(args);

                if (parameters.IsHelpSpecified)
                {
                    TypeHelpPage();
                    result = 0; // Success.
                }
                else
                {
                    Console.WriteLine(GetApplicationNameAndVersion());

                    if (parameters.IsShowDbSchemaSpecified)
                    {
                        TypeDbSchema();
                        result = 0; // Success.
                    }
                    else
                    {
                        Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Active threads: {0}", parameters.Threads));
                        Console.WriteLine();

                        DatabaseConnection databaseConnection = DatabaseConnection.CreateSqlServerConnection(parameters.SqlServerName, parameters.SqlDbName, parameters.SqlUserName, parameters.SqlPassword);
                        DatabaseGenerator  databaseGenerator  = new DatabaseGenerator(parameters, databaseConnection);
                        databaseGenerator.GenerateAndPopulateDatabase().Wait();

                        //一般情况下,只是调用GenerateAndPopulateDatabase(),将数据存入数据库,
                        //但有时为了做图方便及其他,为每个TX_IN直接添加对应的SourceTranceactionId,则
                        //把UpdateSourceTransactionId()的注释删除。为建立索引,如果数据库已经建好的,一定要
                        //把GenerateAndPopulateDatabase()注释掉,否则会浪费很多时间。
                        //同理UpdateTransactionOutputAddressId()函数是为每个TXOUT的比特币地址设置一个ID值,相同的ADDR具有相同的ID
                        //选择性调用

                        //databaseGenerator.UpdateSourceTransactionId();
                        //databaseGenerator.UpdateTransactionOutputAddressId();

                        result = 0; // Success.
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }

            Console.WriteLine();

            //// TypePeakMemoryUsage();

            return(result);
        }
        /// <summary>
        /// Represents the main entry point in the command line tool.
        /// </summary>
        /// <param name="args">
        /// Contains the command line arguments.
        /// For a complete description of the command line arguments see method TypeHelpPage.
        /// </param>
        /// <returns>
        /// 0 - Success.
        /// 1 - Error.
        /// </returns>
        private static int Main(string[] args)
        {
            int result = 1; // Assume error.

            try
            {
                ParameterParser<DatabaseGeneratorParameters> parameterParser = new ParameterParser<DatabaseGeneratorParameters>(DatabaseGeneratorParameters.ParameterListRules);
                DatabaseGeneratorParameters parameters = parameterParser.ParseParameters(args);

                if (parameters.IsHelpSpecified)
                {
                    TypeHelpPage();
                    result = 0; // Success.
                }
                else
                {
                    Console.WriteLine(GetApplicationNameAndVersion());

                    if (parameters.IsShowDbSchemaSpecified)
                    {
                        TypeDbSchema();
                        result = 0; // Success.
                    }
                    else if (parameters.IsRunValidationSpecified)
                    {
                        AutoValidator autoValidator = new AutoValidator(
                            parameters.SqlServerName,
                            parameters.SqlDbName,
                            parameters.SqlUserName,
                            parameters.SqlPassword);

                        result = autoValidator.Validate() ? 0 : 1;
                    }
                    else
                    {
                        Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Active threads: {0}", parameters.Threads));
                        Console.WriteLine();

                        DatabaseConnection databaseConnection = DatabaseConnection.CreateSqlServerConnection(parameters.SqlServerName, parameters.SqlDbName, parameters.SqlUserName, parameters.SqlPassword);
                        DatabaseGenerator databaseGenerator = new DatabaseGenerator(parameters, databaseConnection);
                        databaseGenerator.GenerateAndPopulateDatabase().Wait();

                        result = 0; // Success.
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }

            Console.WriteLine();

            //// TypePeakMemoryUsage();

            return result;
        }
Example #6
0
        public void GetsNamedPipe(string parameters)
        {
            // Given, When
            KeyValuePair <ParameterParser.ParameterType, string>[] parts = ParameterParser.ParseParameters(parameters);

            // Then
            parts.ShouldBe(new KeyValuePair <ParameterParser.ParameterType, string>[]
            {
                new KeyValuePair <ParameterParser.ParameterType, string>(ParameterParser.ParameterType.Name, "Foo")
            });
        }
Example #7
0
        public void GetsAnonymousPipe(string parameters)
        {
            // Given, When
            KeyValuePair <ParameterParser.ParameterType, string>[] parts = ParameterParser.ParseParameters(parameters);

            // Then
            parts.ShouldBe(new KeyValuePair <ParameterParser.ParameterType, string>[]
            {
                new KeyValuePair <ParameterParser.ParameterType, string>(ParameterParser.ParameterType.Handle, "1234")
            });
        }
Example #8
0
        public void Test_Parameters_OK()
        {
            var parameterParser = new ParameterParser();
            var fileName        = "data.csv";
            var amount          = 1000m;
            var strAmount       = amount.ToString();
            var parameters      = parameterParser.ParseParameters(new string[] { fileName, strAmount });

            Assert.NotNull(parameters);
            Assert.Equal(fileName, parameters.FileName);
            Assert.Equal(amount, parameters.TargetAmount);
        }
Example #9
0
        public void GetsNamedPipeWithServer(string parameters)
        {
            // Given, When
            KeyValuePair <ParameterParser.ParameterType, string>[] parts = ParameterParser.ParseParameters(parameters);

            // Then
            parts.ShouldBe(
                new KeyValuePair <ParameterParser.ParameterType, string>[]
            {
                new KeyValuePair <ParameterParser.ParameterType, string>(ParameterParser.ParameterType.Name, "Foo"),
                new KeyValuePair <ParameterParser.ParameterType, string>(ParameterParser.ParameterType.Server, "Bar")
            },
                true);
        }
Example #10
0
        static void Main(string[] args)
        {
            var parameterParser = new ParameterParser();
            var parameters      = parameterParser.ParseParameters(args);

            if (parameters == null)
            {
                WriteUsage();
                return;
            }

            try
            {
                List <Lender> lenders = null;
                using (IReader reader = new CsvReader())
                {
                    var collector = new DataCollector(reader);
                    lenders = collector.Collect(parameters.FileName);
                }
                var loanCalculator = new LoanCalculator();
                var result         = loanCalculator.CalculateLoan(lenders, parameters.TargetAmount, 3);
                if (result == null)
                {
                    Console.WriteLine("It's not possible to provide a quote");
                }
                else
                {
                    PrintLending(result);
                }
            }
            catch (ReaderException rEx)
            {
                Console.WriteLine("Error during reading input: {0}", rEx.Message);
            }
            catch (DataParsingException dpEx)
            {
                Console.WriteLine("Error during parsing data: {0}", dpEx.Message);
            }
            catch (CalculatorException cEx)
            {
                Console.WriteLine("Error during calculation: {0}", cEx.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Uncategorized error: {0}", ex.Message);
            }
        }