protected override void ResolveVariable(Variable variable, IVariableResolver resolver) { if (variable.Format == VariableFormat.Ascii) { if (variable.VerifyEntry == false) { string Message = Orgamkt5CardReader.LayoutDisplayMessage("Enter {0}\n(Len:{1}-{2}) ", variable.Length, variable.Name, variable.MinLength, variable.Length); variable.Value = this.GetVariableValue(Message, variable, resolver); } else { do { string Message = Orgamkt5CardReader.LayoutDisplayMessage("Enter {0}\n(Len:{1}-{2}) ", variable.Length, variable.Name, variable.MinLength, variable.Length); byte[] FirstPin = this.GetVariableValue(Message, variable, resolver); Message = Orgamkt5CardReader.LayoutDisplayMessage("Re-Enter {0}\n(Len:{1}-{2}) ", variable.Length, variable.Name, variable.MinLength, variable.Length); byte[] SecondPin = this.GetVariableValue(Message, variable, resolver); if (FirstPin.HasEqualValue(SecondPin)) { variable.Value = FirstPin; } else { this.DisplayMessage(Orgamkt5CardReader.LayoutDisplayMessage("Error: Value mismatch\nPlease try again.", 0), TimeSpan.FromSeconds(5)); } } while (true); } } else { base.ResolveVariable(variable, resolver); } }
private byte[] GetVariableValue(string message, Variable variable, IVariableResolver resolver) { byte[] Data = null; do { CardCommand Command = new CardCommand(); Command.Cla = 0x20; Command.Ins = 0x16; Command.P1 = 0x50; // Keyboard Command.P2 = 0x02; // Display '*' Command.AppendData(0x50, Encoding.ASCII.GetBytes(message)); //Display Message Command.AppendData(0x80, 0x60); //Timeout //For variable timeout use: Command.Append(0x80, (byte) (timeout.TotalSeconds <= 60 ? timeout.TotalSeconds : 60)); //Timeout Command.Le = 0x00; CardResponse Response; try { resolver.NotifyVariableEntryBegins(variable.Name); Response = this.SendCommandToReader(Command); } finally { resolver.NotifyVariableEntryEnded(); } switch (Response.Status) { case 0x9000: Data = Response.Data; break; case 0x6401: throw new UserCancelException(); case 0x6410: //TODO: auslagern in UIHandler if (MessageBox.Show("The card readers pinpad is disabled.\n Please turn it on.", "Message", MessageBoxButtons.OKCancel) == DialogResult.OK) { continue; } else { throw new UserCancelException(); } case 0x6400: //TODO: auslagern in UIHandler if (MessageBox.Show("There was a timeout entering the PIN at the card reader.\nDo you want to retry?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes) { continue; } else { throw new UserCancelException(); } default: throw new UnableToResolveVariableException(variable, $"Card reader returned unknown code 0x{Response.Status:4X}"); } if (Data != null && (Data.Length < variable.MinLength || Data.Length > variable.Length)) { this.DisplayMessage(Orgamkt5CardReader.LayoutDisplayMessage("Pin entry error!\nPlease retry!", 0), TimeSpan.FromSeconds(2)); Data = null; } } while (Data == null); this.ClearDisplay(); return(Data); }