Пример #1
0
        public void RefreshInterface()
        {
            switch (task.type)
            {
            case TaskType.LoadKey:
            {
                LoadKeyTaskMessage loadTask = task as LoadKeyTaskMessage;
                tbTime.Text    = loadTask.time.ToString();
                tbMessage.Text = loadTask.message;

                if (loadTask.color == TaskColor.Red)
                {
                    bdTask.BorderBrush = new SolidColorBrush(Colors.Red);
                    tbTime.Foreground  = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    bdTask.BorderBrush = new SolidColorBrush(Colors.YellowGreen);
                    tbTime.Foreground  = new SolidColorBrush(Colors.YellowGreen);
                }
                break;
            }

            case TaskType.TxSend:
            {
                SendTaskMessage sendTask = task as SendTaskMessage;
                tbTime.Text = sendTask.time.ToString();

                tbMessage.Text = String.Format(StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_MESSAGE", iLang), sendTask.message, sendTask.from, sendTask.to, sendTask.amount, sendTask.assetID);

                if (sendTask.color == TaskColor.Red)
                {
                    bdTask.BorderBrush = new SolidColorBrush(Colors.Red);
                    tbTime.Foreground  = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    bdTask.BorderBrush = new SolidColorBrush(Colors.YellowGreen);
                    tbTime.Foreground  = new SolidColorBrush(Colors.YellowGreen);
                }
                break;
            }
            }
        }
Пример #2
0
        private void SafeExecute(Action test)
        {
            try
            {
                test.Invoke();
            }
            catch (Exception)
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    // show status
                    StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_SP_SEDDING_FAILED", iLang));

                    SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_FAILED", iLang), TaskColor.Red);
                    Constant.TaskMessages.Add(taskMessage);
                    TaskChangedEventHandler?.Invoke(this, taskMessage);
                    isSendCoin = true;
                }));
            }
        }
Пример #3
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            #region Check Fields
            string strCheckRet = CheckFieldFormat();

            if (strCheckRet != "STR_SP_SUCCESS")
            {
                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString(strCheckRet, iLang));
                return;
            }

            if (!isSendCoin)
            {
                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_SEND_COIN_ERROR_WAITING", iLang));
                return;
            }

            bool ret = false;
            using (Quras_gui_wpf.Dialogs.AlertDialog dlg = new Quras_gui_wpf.Dialogs.AlertDialog(Application.Current.MainWindow, StringTable.GetInstance().GetString("STR_ALERT_DLG_TITLE", iLang), StringTable.GetInstance().GetString("STR_ALERT_SEND_TX", iLang)))
            {
                ret = (bool)dlg.ShowDialog();
            }

            if (ret == false)
            {
                return;
            }
            #endregion

            #region Sending Coin
            SendCoinThread scthread = new SendCoinThread();
            scthread.Amount            = txbAmount.Text;
            scthread.Fee               = txbFeeAmount.Text;
            scthread.FromAddr          = fromAddress;
            scthread.ToAddr            = txbReceiveAddress.Text;
            scthread.TaskChangedEvent += TaskChangedEvent;

            AssetState             state = Blockchain.Default.GetAssetState(AssetsManager.GetInstance().GetAssetID(cmbAssetType.Text));
            Global.AssetDescriptor asset = new Global.AssetDescriptor(state);

            scthread.Asset = asset;

            ThreadStart starter = new ThreadStart(scthread.DoWork);
            starter += () => {
                // Do what you want in the callback
                this.Dispatcher.Invoke(new Action(() =>
                {
                    // Show the status
                    StaticUtils.ShowMessageBox(StaticUtils.GreenBrush, StringTable.GetInstance().GetString("STR_SP_SENDING_SUCCESSFULLY", iLang));

                    SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_FINISHED", iLang));
                    Constant.TaskMessages.Add(taskMessage);
                    TaskChangedEventHandler?.Invoke(sender, taskMessage);
                    isSendCoin = true;
                }));
            };

            this.Dispatcher.Invoke(new Action(() =>
            {
                // show status
                StaticUtils.ShowMessageBox(StaticUtils.BlueBrush, StringTable.GetInstance().GetString("STR_SP_SENDING_TX", iLang));

                SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_START", iLang));
                Constant.TaskMessages.Add(taskMessage);
                TaskChangedEventHandler?.Invoke(sender, taskMessage);
                isSendCoin = false;
            }));

            Thread thread = new Thread(() => SafeExecute(() => starter()))
            {
                IsBackground = true
            };

            try
            {
                thread.Start();
            }
            catch (Exception)
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    // show status
                    StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_SP_SEDDING_FAILED", iLang));

                    SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_FAILED", iLang), TaskColor.Red);
                    Constant.TaskMessages.Add(taskMessage);
                    TaskChangedEventHandler?.Invoke(sender, taskMessage);
                    isSendCoin = true;
                }));
            }
            #endregion

            #region Initialize fields
            txbReceiveAddress.Text = "";
            txbAmount.Text         = "";
            #endregion
        }