Esempio n. 1
0
        private async void Register_Click(object sender, EventArgs e)
        {
            var nw = DateTimeOffset.UtcNow;
            //var ew = nw.AddYears(1);
            var ew = nw.AddMinutes(5);

            IDateTimeProvider provider = new UtcDateTimeProvider();
            string            salt;
            string            Cid = null;
            string            mtyenc;
            Register_Return   mcd;
            var aws_body = new Dictionary <string, object>();

            using (RegistryKey Rkey = Registry.CurrentUser.OpenSubKey(@"Software\Medical_Profile", true))
            {
                Cid = Rkey.GetValue("Cid", null).ToString();

                if (Key.Text is object && !((Key.Text ?? "") == (string.Empty ?? "")))
                {
                    key_encrypted = Enc256.Encrypt(Key.Text, Enc256.Scramble(keys));
                    salt          = Enc256.Getsalt(key_encrypted);

                    var payload = new Dictionary <string, object>()
                    {
                        { "aud", "http://medicalprofilecard.com" }, { "exp", ew.ToUnixTimeSeconds() }, { "register", key_encrypted }
                    };

                    payload["cid"]          = Cid;
                    payload["User_Name"]    = Environment.UserName;
                    payload["Machine_Name"] = Environment.MachineName;

                    aws_body["vector_code"] = "4152";

                    Application.UseWaitCursor = true;
                    mcd = await Aws.Register_aysnc(installation_url, keys, salt, payload, aws_body);

                    Application.UseWaitCursor = false;
                    mtyenc = Enc256.Decrypt(mcd.eval, Enc256.Scramble(keys), 18926);

                    if (mtyenc is object)
                    {
                        Rkey.SetValue("eval", mtyenc);
                    }
                }
            }

            Close();
        }
Esempio n. 2
0
        static async Task <int> Write_exception(string Ex, bool show = false)
        {
            Dictionary <string, object> aws_body = new Dictionary <string, object>();
            string       Wrtim  = DateTime.Now.ToString("yyyyMMddHHmmss");
            var          claims = Mpf.Gen_Claims();
            Dsave_return Dr;

            aws_body.Clear();
            aws_body["ukey"]          = Enc256.Encrypt(Mpf.cid + Mpf.Mpck.Dlab, Mpf.cid + Mpf.Mpck.Dlab, Mpf.Mpck.Iterations);
            aws_body["wrtim"]         = Wrtim;
            aws_body["exception"]     = Ex;
            Application.UseWaitCursor = true;
            Dr = await Aws.Save_exception(Mpf.Mpck.Url, Mpf.enck, Mpf.Mpck.Salt, claims, aws_body);

            Application.UseWaitCursor = false;
            if (show)
            {
                FlexibleMessageBox.Show(Ex, "Unhandled Exception");
            }

            return(Dr.code);
        }
Esempio n. 3
0
        private async Task <Dsave_return> save_blk()
        {
            if (run_timer)
            {
                Ettb.Text = start_timer(SW);
            }

            var          claims = Gen_Claims();
            string       Wrtim  = DateTime.Now.ToString("yyyyMMddHHmmss");
            var          Sblk   = new Save_blk();
            Sblock       Sb;
            string       js;
            string       jse;
            Dsave_return dr;

            if (saved_type)
            {
                // Dsi = dsaves.SelectedItem
                Ds = Dsi.Value;
                if (string.IsNullOrEmpty(Patient.Text))
                {
                    Patient.Text = Ds.Name;
                }
            }

            if (string.IsNullOrEmpty(Patient.Text))
            {
                Patient.Text = "Unknown_" + Wrtim;
            }

            if (!string.IsNullOrEmpty(Patient.Text) && Ds is object && !string.IsNullOrEmpty(Ds.Name))
            {
                if (!((Patient.Text ?? "") == (Ds.Name ?? "")))
                {
                    saved_type = false;
                }
            }

            Sblk.Practice = Practice.Text;
            if (Department.Items.Count > 1)
            {
                Sblk.Department = Department.Text;
            }
            else
            {
                Sblk.Department = dept_tbox.Text;
            }

            Sblk.Patient           = Patient.Text;
            Sblk.Patient_id        = Patientid.Text;
            Sblk.Address           = address.Text;
            Sblk.DOB               = DOB.Text;
            Sblk.Emergency_contact = econtact.Text;
            Sblk.Insurance         = ins.Text;
            if (atpv.Count > 1)
            {
                Sblk.Priph = prv_combo.Text;
            }
            else
            {
                Sblk.Priph = priph.Text;
            }

            Sblk.Phone       = Phone.Text;
            Sblk.Prtitle     = ppgb.Text;
            Sblk.Sptitle     = sptitle.Text;
            Sblk.Secph       = secph.Text;
            Sblk.Sec_visible = Mpck.Sec_visible;
            foreach (KeyValuePair <int, string> s in bl_used)
            {
                Sb = new Sblock();
                {
                    var withBlock = Sb;
                    withBlock.num    = s.Key;
                    withBlock.header = Controls[s.Value].Controls[0].Text;
                    withBlock.body   = Controls[s.Value].Controls[1].Text;
                }

                Sblk.Blk_list.Add(Sb);
            }

            aws_body.Clear();
            js = JsonConvert.SerializeObject(Sblk, Formatting.Indented);
            aws_body["skey"] = Enc256.Encrypt(Sblk.Patient, Enc256.Iterscramble(cid + Mpck.Dlab, Mpck.Iterations));
            var switchExpr = save_ver;

            switch (switchExpr)
            {
            case 1:
            {
                jse = Enc256.Encrypt(js, Enc256.Iterscramble(cid), Convert.ToInt32(Mpck.Iterations % 10 + 2));
                aws_body["skey"] = Enc256.Encrypt(Sblk.Patient, Enc256.Iterscramble(cid + Mpck.Dlab), Mpck.Iterations % 10 + 2);
                break;
            }

            default:
            {
                jse = Enc256.Encrypt(js, Enc256.Iterscramble(cid, Mpck.Iterations), Convert.ToInt32(Mpck.Iterations / (double)3));
                aws_body["skey"] = Enc256.Encrypt(Sblk.Patient, Enc256.Iterscramble(cid + Mpck.Dlab, Mpck.Iterations));
                break;
            }
            }

            aws_body["ukey"] = Enc256.Encrypt(cid + Mpck.Dlab, cid + Mpck.Dlab, Mpck.Iterations);
            if (saved_type)
            {
                if (string.IsNullOrEmpty(Ds.lwtim))
                {
                    aws_body["wrtim"] = Wrtim;
                    aws_body["lwtim"] = Wrtim;
                }
                else
                {
                    aws_body["wrtim"] = Ds.wrtim;
                    aws_body["lwtim"] = Wrtim;
                }
            }
            else
            {
                aws_body["wrtim"] = Wrtim;
                aws_body["lwtim"] = Wrtim;
            }

            aws_body["vers"]          = save_ver.ToString();
            aws_body["value"]         = jse;
            Application.UseWaitCursor = true;
            dr = await Aws.Pat_save_aysnc(Mpck.Url, enck, Mpck.Salt, claims, aws_body);

            Application.UseWaitCursor = false;
            Add_saved_item(dr.ds[0]);
            Data_altered = false;
            if (run_timer)
            {
                Ettb.Text = stop_timer(SW);
            }

            return(dr);
        }