Ejemplo n.º 1
0
        public static void Configure(CommandLineApplication app, CommandLineOptions options, IConsole console)
        {
            // description
            app.Description      = "Modifies existing asset account";
            app.ExtendedHelpText = $"{Environment.NewLine}Use 'accounts modify -i' to enter interactive mode{Environment.NewLine}";

            // arguments
            var argumentAssetAccountId = app.Argument("account", "The asset account id", false);

            // options
            var optionType   = app.Option("-t|--type", string.Concat("The asset account type (", string.Join(" | ", Enum.GetNames(typeof(AssetAccountType))), ")"), CommandOptionType.SingleValue);
            var optionStatus = app.Option("-s|--status", $"The asset account status ({string.Join(" | ", Enum.GetNames(typeof(AssetAccountStatus)))})", CommandOptionType.SingleValue);

            var optionMarginAccount               = app.Option("-m|--margin_account <margin_account>", "The margin account id", CommandOptionType.SingleValue);
            var optionReferenceAccount            = app.Option("-r|--reference_account <reference_account>", "The reference account id", CommandOptionType.SingleValue);
            var optionBankIdentificationMargin    = app.Option("-b|--bank_ident_margin <bank_identification_margin>", "The bank identification margin", CommandOptionType.SingleValue);
            var optionBankIdentificationReference = app.Option("-i|--bank_ident_reference <bank_identification_reference>", "The bank identification reference", CommandOptionType.SingleValue);
            var optionWithdrawalAllowed           = app.Option("-a|--withdrawal_allowed", "withdrawal allowed", CommandOptionType.NoValue);
            var optionInteractive = app.Option("-i|--interactive", "Enters interactive mode", CommandOptionType.NoValue);

            // action (for this command)
            app.OnExecute(
                () =>
            {
                AssetAccountType type     = default;
                AssetAccountStatus status = default;
                if ((string.IsNullOrWhiteSpace(argumentAssetAccountId.Value) &&
                     (string.IsNullOrWhiteSpace(optionType.Value()) || !Enum.TryParse(optionType.Value(), out type)) &&
                     (string.IsNullOrWhiteSpace(optionStatus.Value()) || !Enum.TryParse(optionStatus.Value(), out status))) &&
                    string.IsNullOrWhiteSpace(optionMarginAccount.Value()) &&
                    string.IsNullOrWhiteSpace(optionReferenceAccount.Value()) &&
                    string.IsNullOrWhiteSpace(optionBankIdentificationMargin.Value()) &&
                    string.IsNullOrWhiteSpace(optionBankIdentificationReference.Value()) &&
                    string.IsNullOrWhiteSpace(optionMarginAccount.Value()) &&
                    !optionInteractive.HasValue())
                {
                    app.ShowVersionAndHelp();
                    return;
                }

                var withdrawalAllowed = optionWithdrawalAllowed.HasValue();

                var reporter = new ConsoleReporter(console, options.Verbose.HasValue(), false);
                var helper   = new AccountHelper();

                var account = new InvestorAssetAccountBasicInfo
                {
                    AssetAccountId              = argumentAssetAccountId.Value,
                    MarginAccount               = optionMarginAccount.Value(),
                    ReferenceAccount            = optionReferenceAccount.Value(),
                    BankIdentificationMargin    = optionBankIdentificationMargin.Value(),
                    BankIdentificationReference = optionBankIdentificationReference.Value(),
                    WithdrawalAllowed           = withdrawalAllowed,
                };

                if (Enum.TryParse(optionType.Value(), out type))
                {
                    account.Type = type;
                }

                if (Enum.TryParse(optionStatus.Value(), out status))
                {
                    account.Status = status;
                }

                reporter.Verbose("Prototype account (from command line arguments):");
                reporter.Verbose(JsonConvert.SerializeObject(account));

                if (!(helper.IsValid(account) || optionWithdrawalAllowed.HasValue()) ||
                    optionInteractive.HasValue())
                {
                    try
                    {
                        account = helper.GetValid(account);

                        if (!helper.IsValid(account) && !account.WithdrawalAllowed.HasValue)
                        {
                            throw new CommandParsingException(app, "Operation Aborted. please provide atleast one argument to modify.");
                        }
                    }
                    catch (NotSupportedException ex)
                    {
                        throw new CommandParsingException(app, $"Operation Aborted. {ex.Message}", ex);
                    }

                    reporter.Verbose("Validated account (from interactive console):");
                    reporter.Verbose(JsonConvert.SerializeObject(account));
                }

                options.Command = new ModifyInvestorAssetAccountCommand {
                    accountBasicInfo = account
                };
            });
        }
        public static void Configure(CommandLineApplication app, CommandLineOptions options, IConsole console)
        {
            // description
            app.Description      = "Creates a new asset account";
            app.ExtendedHelpText = $"{Environment.NewLine}Use 'accounts add -i' to enter interactive mode{Environment.NewLine}";

            // arguments
            var argumentAssetAccountId = app.Argument("account", "The asset account id", false);
            var argumentOwnerId        = app.Argument("id", "The user subject identifier of the owner user", false);
            var argumentIntermediaryId = app.Argument("intermediary", "The intermediary asset account id", false);
            var argumentType           = app.Argument("type", string.Concat("The asset account type (", string.Join(" | ", Enum.GetNames(typeof(AssetAccountType))), ")"), false);

            // options
            var optionSettlementCurrency          = app.Option("-c|--currency <currency_code>", "The ISO currency code for settlement currency", CommandOptionType.SingleValue);
            var optionMarginAccount               = app.Option("--margin_account <margin_account>", "The margin account id", CommandOptionType.SingleValue);
            var optionReferenceAccount            = app.Option("--reference_account <reference_account>", "The reference account id", CommandOptionType.SingleValue);
            var optionBankIdentificationMargin    = app.Option("--bank_ident_margin <bank_identification_margin>", "The bank identification margin", CommandOptionType.SingleValue);
            var optionBankIdentificationReference = app.Option("--bank_ident_reference <bank_identification_reference>", "The bank identification reference", CommandOptionType.SingleValue);
            var optionWithdrawalAllowed           = app.Option("--withdrawal_allowed", "withdrawal allowed", CommandOptionType.NoValue);
            var optionInteractive = app.Option("-i|--interactive", "Enters interactive mode", CommandOptionType.NoValue);

            // action (for this command)
            app.OnExecute(
                () =>
            {
                AssetAccountType type = default;
                if ((string.IsNullOrEmpty(argumentAssetAccountId.Value) ||
                     string.IsNullOrEmpty(argumentOwnerId.Value) ||
                     string.IsNullOrEmpty(argumentIntermediaryId.Value) ||
                     !Enum.TryParse(argumentType.Value, out type)) &&
                    !optionInteractive.HasValue())
                {
                    app.ShowVersionAndHelp();
                    return;
                }

                var withdrawalAllowed = optionWithdrawalAllowed.HasValue();

                var reporter = new ConsoleReporter(console, options.Verbose.HasValue(), false);
                var helper   = new AccountHelper();

                var account = new InvestorAssetAccount
                {
                    AssetAccountId              = argumentAssetAccountId.Value,
                    OwnerId                     = argumentOwnerId.Value,
                    IntermediaryId              = argumentIntermediaryId.Value,
                    Type                        = type,
                    MarginAccount               = optionMarginAccount.Value(),
                    ReferenceAccount            = optionReferenceAccount.Value(),
                    BankIdentificationMargin    = optionBankIdentificationMargin.Value(),
                    BankIdentificationReference = optionBankIdentificationReference.Value(),
                    WithdrawalAllowed           = withdrawalAllowed,
                    SettlementCurrency          = optionSettlementCurrency.Value(),
                };

                reporter.Verbose("Prototype account (from command line arguments):");
                reporter.Verbose(JsonConvert.SerializeObject(account));

                if (!helper.IsValid(account) || optionInteractive.HasValue())
                {
                    try
                    {
                        account = helper.GetValid(account);
                    }
                    catch (NotSupportedException ex)
                    {
                        throw new CommandParsingException(app, $"Operation Aborted. {ex.Message}", ex);
                    }

                    reporter.Verbose("Validated account (from interactive console):");
                    reporter.Verbose(JsonConvert.SerializeObject(account));
                }

                options.Command = new AddInvestorAssetAccountCommand {
                    account = account
                };
            });
        }