/// <summary> /// Turns a command string into an <see cref="ActivateOption"/>. /// </summary> /// <param name="payCommand">Activation command from command line.</param> /// <returns>The class with activation properties.</returns> public static ActivateOption DecodeActivation(this string activationCommand) { string[] args = activationCommand.Split(' '); ActivateOption activation = new ActivateOption(); CommandLine.Parser.Default.ParseArguments(args, activation); return(activation); }
/// <summary> /// Decodes the command name and performs the corresponding action. /// The commands supported are: /// - "ativar": activate and connect to one terminal; /// - "pagar": pay something; /// - "resumo": transaction sumamry, it can be filtered by approved /// transactions, not approved or cancelled transactions or all transactions; /// - "cancel": cancel a transaction by it's Stone ID; /// - "sair": disconnect from the terminal and exit the application. /// </summary> /// <param name="command">Command typed by the user.</param> /// <returns>Whether it has to exit the application or not.</returns> public static bool Decode(this string command) { string[] args = command.Split(' '); string commandName = args[0]; string baseCommand = string.Join(" ", args, 1, args.Length - 1); switch (commandName) { case "ativar": ActivateOption activation = baseCommand.DecodeActivation(); AuthorizationCore.GetInstance() .TryActivate(activation); break; case "pagar": TransactionOption transaction = baseCommand.DecodeTransaction(); AuthorizationCore.GetInstance() .Authorize(transaction); break; case "resumo": ShowTransactionsOption showOptions = baseCommand.DecodeShowTransactions(); AuthorizationCore.GetInstance() .ShowTransactions(showOptions); break; case "cancelar": CancelationOption cancelation = baseCommand.DecodeCancelation(); AuthorizationCore.GetInstance() .Cancel(cancelation); break; case "sair": AuthorizationCore.GetInstance() .ClosePinpad(); return(true); } return(false); }
/// <summary> /// Try to connect to the pinpad. /// </summary> /// <param name="activation">Data to connect to the pinpad.</param> /// <returns>True if the pinpad was found and connected.</returns> public bool TryActivate(ActivateOption activation) { try { // Tries to connect to one pinpad: this.StoneAuthorizer = DeviceProvider .ActivateAndGetOneOrFirst(activation.StoneCode, null, activation.Port); // Show result: this.StoneAuthorizer.ShowPinpadOnConsole(); } catch (PinpadNotFoundException) { Console.WriteLine("Pinpad nao encontrado."); } catch (Exception) { Console.WriteLine("Erro ao ativar o terminal. Você está usando o StoneCode correto?"); } return(this.IsUsable); }