Exemplo n.º 1
0
 public static string GetQRCodeAsBase64(this User user)
 {
     if (string.IsNullOrEmpty(user.UserNumber))
     {
         return(null);
     }
     return(QRCodeUtils.GenerateQRCodeAsBase64(user.UserNumber));
 }
Exemplo n.º 2
0
        private void UpdateRoomInfo()
        {
            if (m_module.GetRoomPort() > 0)
            {
                string ipport = m_module.GetRoomIP() + ":" + m_module.GetRoomPort();
                txtRoomIPPort.text = ipport;

                imgRoomQR.enabled = true;
                Texture2D tex = QRCodeUtils.EncodeToImage(ipport, 256, 256);
                imgRoomQR.texture = tex;
            }
        }
Exemplo n.º 3
0
        public IActionResult PrintAllQRCodes()
        {
            // assume we are printing ALL attendees
            var labels = this.DatabaseContext.Attendee
                         .Select(i => new AttendeeLabel(i))
                         .ToList();

            var memoryStream = QRCodeUtils.GenerateLabelsAsPDF(labels);

            return(this.File(
                       memoryStream,
                       "application/pdf",
                       "qr-codes_use_avery-22806-labels.pdf"));
        }
Exemplo n.º 4
0
        private void OnImageLoaded(Stream stream, bool succeeded)
        {
            if (!succeeded)
            {
                m_ImageInfo = "fail to open camera";
                this.LogError("OnImageLoaded()" + m_ImageInfo);


                if (stream != null)
                {
                    stream.Dispose();
                }
                return;
            }

            try
            {
                var data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);
                var newImage = new Texture2D(512, 512);
                newImage.LoadImage(data);
                newImage.Apply();
                m_TexImage = newImage;

                string content = QRCodeUtils.DecodeFromImage(m_TexImage);
                if (string.IsNullOrEmpty(content))
                {
                    m_ImageInfo = "fail to decode QR code!";
                }
                else
                {
                    m_ImageInfo = "QR code decoding succuessful!";
                }

                inputIPPort.text = content;
            }
            catch (Exception e)
            {
                m_ImageInfo = "Error:" + e.Message;
                this.LogError("OnImageLoaded() " + m_ImageInfo);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
        private void RenderSecretKeyWithLease()
        {
            RSACryptoServiceProvider rsaProvider = GetDefaultKeyContainer();

            qrCodeBox.Image = QRCodeUtils.RenderSecretKey(BluetoothServer.secretKey);

            Timer publicKeyLease = new Timer();

            publicKeyLease.Tick    += new EventHandler(TimerEventProcessor);
            publicKeyLease.Interval = 15000;
            publicKeyLease.Start();

            setupNewTrustedDeviceLabel.Text = "Click <Continue Pairing> to obtain the public key value needed for pairing";
            startPairingButton.Text         = "Continue Pairing";
        }
        private void RenderPublicKeyWithLease()
        {
            RSACryptoServiceProvider rsaProvider = GetDefaultKeyContainer();

            qrCodeBox.Image = QRCodeUtils.RenderPublicKey(rsaProvider);

            Timer publicKeyLease = new Timer();

            publicKeyLease.Tick    += new EventHandler(TimerEventProcessor);
            publicKeyLease.Interval = 15000;
            publicKeyLease.Start();

            setupNewTrustedDeviceLabel.Text = "Turn on bluetooth, pair it with the pc and click <Final Step> to synchronize";
            startPairingButton.Text         = "Final Step";
        }
Exemplo n.º 7
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public string GenerateQRCode(string content)
        {
            var    _path    = AppDomain.CurrentDomain.BaseDirectory;
            string fileName = "QRCode\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";

            string HostUrl = ConfigurationManager.AppSettings["QRCodeAddress"];

            var fs = QRCodeUtils.DownQrCodeFile(content, _path + fileName, "");

            if (fs)
            {
                return(fileName.Replace('\\', '/'));
            }
            return("");
        }
        string GetQRImgUrl(string Id, int type = 1)
        {
            var    _path    = AppDomain.CurrentDomain.BaseDirectory;
            string fileName = "QRCode\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";

            string HostUrl = ConfigurationManager.AppSettings["QRCodeAddress"];
            string query   = "?APPID=0&Type=" + type + "&ActivityID=" + Id;

            var fs = QRCodeUtils.DownQrCodeFile(HostUrl + query, _path + fileName, "");

            if (fs)
            {
                return(fileName.Replace('\\', '/'));
            }
            return("");
        }
Exemplo n.º 9
0
        public IActionResult PrintTestQRCodes(int num = 12)
        {
            var testNumber = "123456";
            var labels     = new List <AttendeeLabel>();

            for (var i = 0; i < num; i++)
            {
                labels.Add(new AttendeeLabel
                {
                    UserNumber = testNumber
                });
            }

            var memoryStream = QRCodeUtils.GenerateLabelsAsPDF(labels.ToList());

            return(this.File(
                       memoryStream,
                       "application/pdf",
                       "test_qr_codes.pdf"));
        }
Exemplo n.º 10
0
        public IActionResult PrintQRCode(string userNumber)
        {
            IList <AttendeeLabel> labels = new List <AttendeeLabel>();

            // get the user
            var attendee = this.DatabaseContext.Attendee.FirstOrDefault(
                i => i.UserNumber == userNumber);

            if (attendee == null)
            {
                throw new ApplicationException("Attendee not found.");
            }
            else
            {
                labels.Add(new AttendeeLabel(attendee));
            }

            var memoryStream = QRCodeUtils.GenerateLabelsAsPDF(labels.ToList());

            return(this.File(
                       memoryStream,
                       "application/pdf",
                       $"attendee_{userNumber}_qr_code_use_avery-22806-labels.pdf"));
        }
Exemplo n.º 11
0
        public void CreateQRCode()
        {
            var img = QRCodeUtils.GenerateQrCode("http://www.singoo.top", 30, SystemUtils.GetMapPath("/TestSource/logo.png"));

            img.Save(FileUtils.Combine(SystemUtils.GetMapPath("/TestSource/ImageTest"), "qrcode.png"), System.Drawing.Imaging.ImageFormat.Png);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="rootPath"></param>
        /// <param name="agentModel"></param>
        private void GenerateQRCode(string rootPath, Tuple <Tuple <string, string>, Dictionary <Tuple <string, string>, List <string> > > agentModel)
        {
            if (!string.IsNullOrEmpty(rootPath) && agentModel != null)
            {
                Tuple <string, string> agentTuple = agentModel.Item1;
                string agentKey  = agentTuple.Item1.ToLower();
                string agentName = agentTuple.Item2;
                string agentPath = rootPath + "/" + agentKey;
                Stream stream    = null;
                Bitmap bmpt      = null;
                if (!Directory.Exists(agentPath))
                {
                    //先生成代理目录
                    Directory.CreateDirectory(agentPath);
                    dynamic codeJson = new { AgentBatchQR = agentKey };
                    stream = QRCodeUtils.GetQrCode(JsonConvert.SerializeObject(codeJson));
                    bmpt   = new Bitmap(stream);
                    //保存流到文件
                    bmpt.Save(string.Format("{0}/{1}.jpg", agentPath, agentName));
                    bmpt.Dispose();

                    string agentDir = agentPath + "/" + agentName;
                    if (!Directory.Exists(agentDir))
                    {
                        Directory.CreateDirectory(agentDir);
                    }

                    var    shopList     = agentModel.Item2;
                    string shopKey      = null;
                    string shopName     = null;
                    string shopPath     = null;
                    string shopFilePath = null;
                    string proFilePath  = null;
                    foreach (var item in shopList)
                    {
                        shopKey  = item.Key.Item1.ToLower();
                        shopName = item.Key.Item2;
                        shopPath = agentDir + "/" + shopKey;
                        if (!Directory.Exists(shopPath))
                        {
                            //创建店铺目录
                            Directory.CreateDirectory(shopPath);
                            shopFilePath = $"{shopPath}/{shopName}.jpg";
                            codeJson     = new { SellerBatchQR = shopKey };
                            stream       = QRCodeUtils.GetQrCode(JsonConvert.SerializeObject(codeJson));
                            bmpt         = new Bitmap(stream);
                            //保存文件
                            bmpt.Save(shopFilePath);
                            bmpt.Dispose();

                            if (!Directory.Exists($"{shopPath}/{shopName}"))
                            {
                                //创建店铺名称目录
                                Directory.CreateDirectory($"{shopPath}/{shopName}");
                                var proCodeList = shopList[item.Key];
                                //生成所有商品的二维码
                                foreach (var proItem in proCodeList)
                                {
                                    proFilePath = $"{shopPath}/{shopName}/{proItem}.jpg";
                                    codeJson    = new { ProductQRCodeUrl = proItem };
                                    stream      = QRCodeUtils.GetQrCode(JsonConvert.SerializeObject(codeJson));
                                    bmpt        = new Bitmap(stream);
                                    bmpt.Save(proFilePath);
                                    bmpt.Dispose();
                                }
                            }
                        }
                    }
                }
                else
                {
                    dynamic codeJson = new { AgentBatchQR = agentKey };
                    string  agentDir = agentPath + "/" + agentName;
                    if (!Directory.Exists(agentDir))
                    {
                        Directory.CreateDirectory(agentDir);
                    }
                    else
                    {
                        var    shopList     = agentModel.Item2;
                        string shopKey      = null;
                        string shopName     = null;
                        string shopPath     = null;
                        string shopFilePath = null;
                        string proFilePath  = null;
                        foreach (var item in shopList)
                        {
                            shopKey  = item.Key.Item1.ToLower();
                            shopName = item.Key.Item2;
                            shopPath = agentDir + "/" + shopKey;
                            if (!Directory.Exists(shopPath))
                            {
                                //创建店铺目录
                                Directory.CreateDirectory(shopPath);
                                shopFilePath = $"{shopPath}/{shopName}.jpg";
                                codeJson     = new { SellerBatchQR = shopKey };
                                stream       = QRCodeUtils.GetQrCode(JsonConvert.SerializeObject(codeJson));
                                bmpt         = new Bitmap(stream);
                                //保存文件
                                bmpt.Save(shopFilePath);
                                bmpt.Dispose();

                                if (!Directory.Exists($"{shopPath}/{shopName}"))
                                {
                                    //创建店铺名称目录
                                    Directory.CreateDirectory($"{shopPath}/{shopName}");
                                    var proCodeList = shopList[item.Key];
                                    //生成所有商品的二维码
                                    foreach (var proItem in proCodeList)
                                    {
                                        proFilePath = $"{shopPath}/{shopName}/{proItem}.jpg";
                                        codeJson    = new { ProductQRCodeUrl = proItem };
                                        stream      = QRCodeUtils.GetQrCode(JsonConvert.SerializeObject(codeJson));
                                        bmpt        = new Bitmap(stream);
                                        bmpt.Save(proFilePath);
                                        bmpt.Dispose();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
 private void RenderPublicKey(RSACryptoServiceProvider rsaProvider)
 {
     qrCodeBox.Image = QRCodeUtils.RenderPublicKey(rsaProvider);
 }