예제 #1
0
 public ManageController(
     UserManager <User> userManager,
     UrlEncoder urlEncoder,
     IEmailService emailService,
     IOptions <ClientAppSettings> client,
     IOptions <QRCodeSettings> qr
     )
 {
     _userManager  = userManager;
     _urlEncoder   = urlEncoder;
     _emailService = emailService;
     _client       = client.Value;
     _qr           = qr.Value;
 }
예제 #2
0
 public ManageController(
     UserManager <IdentityUser> userManager,
     RoleManager <IdentityRole> roleManager,
     UrlEncoder urlEncoder,
     IEmailService emailService,
     IOptions <ClientAppSettings> client,
     IOptions <QRCodeSettings> qr
     )
 {
     this._userManager  = userManager;
     this._roleManager  = roleManager;
     this._urlEncoder   = urlEncoder;
     this._emailService = emailService;
     this._client       = client.Value;
     this._qr           = qr.Value;
 }
    /// <summary>
    /// Generates the QR code as an image using the given parameters
    /// </summary>
    /// <param name="code">Code to generate by the QR code</param>
    /// <param name="qrCodeSettings">QR code settings</param>
    public Image GenerateQRCode(string code, QRCodeSettings qrCodeSettings)
    {
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

        qrCodeEncoder.QRCodeEncodeMode = GetEncoding(qrCodeSettings.Encoding);

        // Set scale
        try
        {
            qrCodeEncoder.QRCodeScale = qrCodeSettings.Size;
        }
        catch
        {
            qrCodeEncoder.QRCodeScale = 4;
        }

        qrCodeEncoder.QRCodeErrorCorrect = GetErrorCorrection(qrCodeSettings.Correction);

        // Set colors
        qrCodeEncoder.QRCodeForegroundColor = qrCodeSettings.FgColor ?? Color.Black;
        qrCodeEncoder.QRCodeBackgroundColor = qrCodeSettings.BgColor ?? Color.White;

        Image image = null;

        // Attempt to process all versions
        while (qrCodeSettings.Version <= 40)
        {
            if (!QRVersionSupported(qrCodeSettings.Version))
            {
                // Move to higher version
                qrCodeSettings.Version++;

                if (qrCodeSettings.Version > 40)
                {
                    throw new Exception("Version higher than 40 is not supported.");
                }
                continue;
            }

            try
            {
                // Try to get requested version
                qrCodeEncoder.QRCodeVersion = qrCodeSettings.Version;

                image = qrCodeEncoder.Encode(code);

                break;
            }
            catch (IndexOutOfRangeException)
            {
                // Try next version to fit the data
                qrCodeSettings.Version++;

                if (qrCodeSettings.Version > 40)
                {
                    throw;
                }
            }
        }

        return image;
    }
예제 #4
0
    /// <summary>
    /// Generates the QR code as an image using the given parameters
    /// </summary>
    /// <param name="code">Code to generate by the QR code</param>
    /// <param name="qrCodeSettings">QR code settings</param>
    public Image GenerateQRCode(string code, QRCodeSettings qrCodeSettings)
    {
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

        qrCodeEncoder.QRCodeEncodeMode = GetEncoding(qrCodeSettings.Encoding);

        // Set scale
        try
        {
            qrCodeEncoder.QRCodeScale = qrCodeSettings.Size;
        }
        catch
        {
            qrCodeEncoder.QRCodeScale = 4;
        }

        qrCodeEncoder.QRCodeErrorCorrect = GetErrorCorrection(qrCodeSettings.Correction);

        // Set colors
        qrCodeEncoder.QRCodeForegroundColor = qrCodeSettings.FgColor ?? Color.Black;
        qrCodeEncoder.QRCodeBackgroundColor = qrCodeSettings.BgColor ?? Color.White;

        Image image = null;

        // Attempt to process all versions
        while (qrCodeSettings.Version <= 40)
        {
            if (!QRVersionSupported(qrCodeSettings.Version))
            {
                // Move to higher version
                qrCodeSettings.Version++;

                if (qrCodeSettings.Version > 40)
                {
                    throw new Exception("Version higher than 40 is not supported.");
                }
                continue;
            }

            try
            {
                // Try to get requested version
                qrCodeEncoder.QRCodeVersion = qrCodeSettings.Version;

                image = qrCodeEncoder.Encode(code);

                break;
            }
            catch (IndexOutOfRangeException)
            {
                // Try next version to fit the data
                qrCodeSettings.Version++;

                if (qrCodeSettings.Version > 40)
                {
                    throw;
                }
            }
        }

        return(image);
    }