示例#1
0
        /// <summary>
        /// Encodes the QR bill data as a text to be embedded in a QR code.
        /// <para>
        /// The specified bill data is first validated and cleaned.
        /// </para>
        /// <para>
        /// If the bill data is invalid, a <see cref="QRBillValidationException"/> is
        /// thrown, containing the validation result. For details about the
        /// validation result, see
        /// <a href="https://github.com/manuelbl/SwissQRBill/wiki/Bill-data-validation">Bill data
        /// validation</a>
        /// </para>
        /// </summary>
        /// <param name="bill">The bill data to encode.</param>
        /// <returns>The text to embed in a QR code.</returns>
        /// <exception cref="QRBillValidationException">The bill data is invalid.</exception>
        public static string EncodeQrCodeText(Bill bill)
        {
            ValidationResult result      = Validator.Validate(bill);
            Bill             cleanedBill = result.CleanedBill;

            if (result.HasErrors)
            {
                throw new QRBillValidationException(result);
            }

            return(QRCodeText.Create(cleanedBill));
        }
示例#2
0
 /// <summary>
 /// Decodes the text from a QR code and fills it into a <see cref="Bill"/> data structure
 /// <para>
 /// A subset of the validations related to embedded QR code text is run. It the
 /// validation fails, a <see cref="QRBillValidationException"/> is thrown containing
 /// the validation result. See the error messages marked with a dagger in
 /// <a href="https://github.com/manuelbl/SwissQRBill/wiki/Bill-data-validation">Bill data
 /// validation</a>.
 /// </para>
 /// </summary>
 /// <param name="text">The text to decode.</param>
 /// <returns>The decoded bill data.</returns>
 /// <exception cref="QRBillValidationException">If he text could not be decoded or the decoded bill data is invalid.</exception>
 public static Bill DecodeQrCodeText(string text)
 {
     return(QRCodeText.Decode(text));
 }
示例#3
0
 /// <summary>
 /// Creates an instance of the QR code for the specified bill data.
 /// <para>
 /// The bill data must have been validated and cleaned.
 /// </para>
 /// </summary>
 /// <param name="bill">The bill data.</param>
 internal QRCode(Bill bill)
 {
     _embeddedText = QRCodeText.Create(bill);
 }
示例#4
0
        /// <summary>
        /// Gets the text embedded in the QR code (according to the data structure defined by SIX).
        /// </summary>
        /// <param name="bill">The bill data.</param>
        /// <returns>The QR code text.</returns>
        public static string Create(Bill bill)
        {
            QRCodeText qrCodeText = new QRCodeText(bill);

            return(qrCodeText.CreateText());
        }