Beispiel #1
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;
                }));
            }
        }
Beispiel #2
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
        }
Beispiel #3
0
 private void TaskChangedEvent(object sender, TaskMessage task)
 {
     TaskChangedEventHandler?.Invoke(sender, task);
 }