示例#1
0
        private void btn_GenerateQR_Click(object sender, EventArgs e)
        {
            this.SafeExecuteAction(() =>
            {
                if (!Directory.Exists(Settings.Default.QrCodeLocation))
                {
                    MyMessageBox.ShowDialog(this, $"QR location does not exist: {Settings.Default.QrCodeLocation}. Check config.", "Robo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(Settings.Default.QrCodeLocation);

                    foreach (FileInfo file in directoryInfo.GetFiles("*.jpg"))
                    {
                        file.Delete();
                    }
                    List <Tables> tables      = presenter.GetAll();
                    List <string> tablesCodes = new List <string>();
                    foreach (Tables table in tables)
                    {
                        tablesCodes.Add(table.Token);
                    }
                    string resultGenerateQR = QRCodeManager.GenerateQR(Settings.Default.QrCodeLocation, this.lbl_IPValue.Text, Settings.Default.Protocol, tablesCodes);
                    MyMessageBox.ShowDialog(this, resultGenerateQR, "Robo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Process.Start(Settings.Default.QrCodeLocation);
                }
            });
        }
示例#2
0
    // ----------------------------------------------------------------
    private IEnumerator UploadImageForQR()
    {
        string filename = settingManager.computerId + string.Format("{0:HHmmssfff}", DateTime.Now);

        // Create HMAC string
        Encoding encoding   = Encoding.UTF8;
        var      keyByte    = encoding.GetBytes("HKSM Children Zone Facial");
        string   hmacString = "";

        using (var hmacsha256 = new HMACSHA256(keyByte))
        {
            hmacsha256.ComputeHash(encoding.GetBytes(filename));
            hmacString = ByteToString(hmacsha256.Hash);
        }
        var photoBytes = finalPhotoTex2d.EncodeToJPG(settingManager.photoQuality);

        // Upload to server + Get QR code
        WWWForm form = new WWWForm();

        form.AddField("s", hmacString);
        form.AddField("d", filename);
        form.AddBinaryData("fileToUpload", photoBytes, filename + ".jpg", "image/jpg");

        WWW wwwRequest = new WWW(settingManager.uploadQRUrl, form);

        YucoDebugger.instance.Log("uploadQRUrl = " + settingManager.uploadQRUrl, "UploadImageForQR", "GameRoot");
        yield return(wwwRequest);

        if (!string.IsNullOrEmpty(wwwRequest.error))
        {
            // ***** TO-DO: URL error, should go to Error page
            YucoDebugger.instance.LogError(wwwRequest.error, "UploadImageForQR", "GameRoot");
        }
        else
        {
            YucoDebugger.instance.Log(wwwRequest.text, "UploadImageForQR", "UploadImage");
            JsonData jsonData = JsonMapper.ToObject(wwwRequest.text);

            if (jsonData["result"] != null)
            {
                if (jsonData["result"].ToString() == "success")
                {
                    YucoDebugger.instance.Log("Upload Succeeded: URL = " + jsonData["url"].ToString(), "UploadImageForQR", "GameRoot");
                    qrManager.GenerateQR(jsonData["url"].ToString());
                    webApiMgr.RecordQrUploaded();
                }
                else if (jsonData["result"].ToString() == "error")
                {
                    // ***** TO-DO: URL error, should go to Error page
                    YucoDebugger.instance.LogError("Upload error: " + jsonData["msg"].ToString(), "UploadImageForQR", "GameRoot");
                }
            }
        }
    }