コード例 #1
0
        public IRpcMethodResult EncryptWallet(string passphrase)
        {
            try
            {
                var result   = false;
                var settting = new SettingComponent().GetSetting();

                if (settting.Encrypt)
                {
                    LogHelper.Error("Error occured in EncrypWallet API");
                    throw new CommonException(ErrorCode.Service.Wallet.CAN_NOT_ENCRYPT_AN_ENCRYPTED_WALLET);
                }

                result = new WalletComponent().EncryptWallet(passphrase);
                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            SettingComponent t = (SettingComponent)target;

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            {
                m_SettingHelperInfo.Draw();
            }
            EditorGUI.EndDisabledGroup();

            if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
            {
                EditorGUILayout.LabelField("Setting Count", t.Count > 0 ? t.Count.ToString() : "<Unknown>");
            }

            if (EditorApplication.isPlaying)
            {
                if (GUILayout.Button("Save Settings"))
                {
                    t.Save();
                }
                if (GUILayout.Button("Remove All Settings"))
                {
                    t.RemoveAllSettings();
                }
            }

            serializedObject.ApplyModifiedProperties();

            Repaint();
        }
コード例 #3
0
        public IRpcMethodResult WalletPassphraseChange(string currentPassphrase, string newPassphrase)
        {
            try
            {
                var settting = new SettingComponent().GetSetting();

                if (!settting.Encrypt)
                {
                    throw new CommonException(ErrorCode.Service.Wallet.CAN_NOT_CHANGE_PASSWORD_IN_AN_UNENCRYPTED_WALLET);
                }

                WalletComponent wc = new WalletComponent();
                wc.ChangePassword(currentPassphrase, newPassphrase);
                _cache.Remove("WalletPassphrase");
                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #4
0
        public IRpcMethodResult WalletPassphrase(string passphrase)
        {
            try
            {
                var settting = new SettingComponent().GetSetting();

                if (!settting.Encrypt)
                {
                    LogHelper.Error("Error occured in WalletPassphrase API");
                    throw new CommonException(ErrorCode.Service.Wallet.CAN_NOT_ENCRYPT_AN_ENCRYPTED_WALLET);
                }

                var result = false;
                if (new WalletComponent().CheckPassword(passphrase))
                {
                    _cache.Set <string>("WalletPassphrase", passphrase, new MemoryCacheEntryOptions()
                    {
                        SlidingExpiration = new TimeSpan(0, 5, 0)
                    });

                    result = true;
                }
                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #5
0
        public static void SaveCard(this SettingComponent setting, UserCard userCard)
        {
            var userCardList = setting.GetObject <List <UserCard> >(Constant.Setting.UserCard);

            bool HasCard = false;

            for (int i = 0; i < userCardList.Count; i++)
            {
                if (userCardList[i].id == userCard.id)
                {
                    //覆盖
                    userCardList[i].name    = userCard.name;
                    userCardList[i].content = userCard.content;
                    userCardList[i].type    = userCard.type;
                    HasCard = true;
                }
            }

            //保存
            if (!HasCard)
            {
                userCardList.Add(userCard);
            }

            setting.SetObject(Constant.Setting.UserCard, userCardList);
        }
コード例 #6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            SettingComponent t = (SettingComponent)target;

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            {
                m_SettingHelperInfo.Draw();
            }
            EditorGUI.EndDisabledGroup();

            if (EditorApplication.isPlaying)
            {
                if (GUILayout.Button("Save Settings"))
                {
                    t.Save();
                }
                if (GUILayout.Button("Remove All Settings"))
                {
                    t.RemoveAllSettings();
                }
            }

            serializedObject.ApplyModifiedProperties();

            Repaint();
        }
コード例 #7
0
ファイル: WalletController.cs プロジェクト: omcdev/blockchain
        public IRpcMethodResult BackupWallet(string targetAddress)
        {
            try
            {
                WalletComponent  component        = new WalletComponent();
                SettingComponent settingComponent = new SettingComponent();
                Setting          setting          = settingComponent.GetSetting();

                if (setting.Encrypt)
                {
                    if (string.IsNullOrEmpty(_cache.Get <string>("WalletPassphrase")))
                    {
                        throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED);
                    }
                    component.BackupWallet(targetAddress, _cache.Get <string>("WalletPassphrase"));
                }
                else
                {
                    component.BackupWallet(targetAddress, null);
                }
                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #8
0
        private string DecryptPrivateKey(string privateKey)
        {
            var setting = new SettingComponent().GetSetting();

            if (setting.Encrypt)
            {
                if (!string.IsNullOrWhiteSpace(_cache.Get <string>("WalletPassphrase")))
                {
                    try
                    {
                        return(AES128.Decrypt(privateKey, _cache.Get <string>("WalletPassphrase")));
                    }
                    catch
                    {
                        throw new CommonException(ErrorCode.Service.Transaction.WALLET_DECRYPT_FAIL);
                    }
                }
                else
                {
                    //是否需要调用解密的逻辑
                    throw new CommonException(ErrorCode.Service.Transaction.WALLET_DECRYPT_FAIL);
                }
            }
            else
            {
                return(privateKey);
            }
        }
コード例 #9
0
 public MainFormModel(SettingComponent settings, ExportPointMatrix matrix, TargetRectangle rectangle, WindowHandle handle)
 {
     this.settings   = settings;
     this.matrix     = matrix;
     this.rectangle  = rectangle;
     this.handle     = handle;
     isThreadRunning = false;
 }
コード例 #10
0
        public IRpcMethodResult GetNewAddress(string tag)
        {
            try
            {
                var       accountComponent = new AccountComponent();
                Account   account          = null;
                var       setting          = new SettingComponent().GetSetting();
                AccountOM result           = null;

                if (setting.Encrypt)
                {
                    if (!string.IsNullOrWhiteSpace(_cache.Get <string>("WalletPassphrase")))
                    {
                        account            = accountComponent.GenerateNewAccount();
                        account.IsDefault  = true;
                        account.PrivateKey = AES128.Encrypt(account.PrivateKey, _cache.Get <string>("WalletPassphrase"));
                        accountComponent.UpdatePrivateKeyAr(account);
                    }
                    else
                    {
                        throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED);
                    }
                }
                else
                {
                    account           = accountComponent.GenerateNewAccount();
                    account.IsDefault = true;
                }

                if (account != null)
                {
                    account.Tag = tag;
                    accountComponent.UpdateTag(account.Id, tag);

                    result           = new AccountOM();
                    result.Address   = account.Id;
                    result.PublicKey = account.PublicKey;
                    result.Balance   = account.Balance;
                    result.IsDefault = account.IsDefault;
                    result.WatchOnly = account.WatchedOnly;
                    result.Tag       = account.Tag;
                }

                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #11
0
    protected internal override void OnEnter(IFsm <IProcedureManager> procedureOwner)
    {
        base.OnEnter(procedureOwner);

        // 加载框架Event组件
        settingComponent = UnityGameFramework.Runtime.GameEntry.GetComponent <SettingComponent>();

        settingComponent.SetInt("HP", 100);
        settingComponent.Save();

        Log.Info(settingComponent.GetInt("HP"));
    }
コード例 #12
0
        public static void RemoveGameData(this SettingComponent setting, int gameId)
        {
            var gameDataList = setting.GetObject <List <GameData> >(Constant.Setting.GameData);

            for (int i = 0; i < gameDataList.Count; i++)
            {
                if (gameDataList[i].gameId == gameId)
                {
                    gameDataList.RemoveAt(i);
                    setting.SetObject(Constant.Setting.GameData, gameDataList);
                    break;
                }
            }
        }
コード例 #13
0
        public static void RemoveCard(this SettingComponent setting, int cardId)
        {
            var userCardList = setting.GetObject <List <UserCard> >(Constant.Setting.UserCard);

            for (int i = 0; i < userCardList.Count; i++)
            {
                if (userCardList[i].id == cardId)
                {
                    userCardList.RemoveAt(i);
                    setting.SetObject(Constant.Setting.UserCard, userCardList);
                    break;
                }
            }
        }
コード例 #14
0
    protected internal override void OnEnter(IFsm <IProcedureManager> procedureOwner)
    {
        base.OnEnter(procedureOwner);

        // 加载框架Event组件
        EventComponent   Event   = UnityGameFramework.Runtime.GameEntry.GetComponent <EventComponent>();
        SettingComponent Setting = UnityGameFramework.Runtime.GameEntry.GetComponent <SettingComponent>();

        // 加载框架Event组件
        localizationComponent = UnityGameFramework.Runtime.GameEntry.GetComponent <LocalizationComponent>();
        //// 订阅UI加载成功事件
        Event.Subscribe(LoadDictionarySuccessEventArgs.EventId, OnLoadDictionarySuccess);

        Language language = localizationComponent.Language;

        Log.Info(language);

        string languageString = Setting.GetString(Constant.Setting.Language);

        if (!string.IsNullOrEmpty(languageString))
        {
            try
            {
                language = (Language)Enum.Parse(typeof(Language), languageString);
            }
            catch
            {
            }
        }

        if (language != Language.English &&
            language != Language.ChineseSimplified &&
            language != Language.ChineseTraditional &&
            language != Language.Korean)
        {
            // 若是暂不支持的语言,则使用英语
            language = Language.English;

            Setting.SetString(Constant.Setting.Language, language.ToString());
            Setting.Save();
        }

        localizationComponent.Language = language;

        Log.Info(language);

        localizationComponent.LoadDictionary("Default", LoadType.Text, this);
    }
コード例 #15
0
 public void InitComponent(Transform componentRoot)
 {
     this.ComponentRoot    = componentRoot;
     DataNodeComponent     = FindAndRegisterComponent <DataNodeComponent>();
     DataTableComponent    = FindAndRegisterComponent <DataTableComponent>();
     DownloadComponent     = FindAndRegisterComponent <DownloadComponent>();
     FsmComponent          = FindAndRegisterComponent <FSMComponent>();
     ResourceComponent     = FindAndRegisterComponent <ResourceComponent>();
     SettingComponent      = FindAndRegisterComponent <SettingComponent>();
     SoundComponent        = FindAndRegisterComponent <SoundComponent>();
     TimerComponent        = FindAndRegisterComponent <TimerComponent>();
     WebComponent          = FindAndRegisterComponent <WebComponent>();
     UpdateComponent       = FindAndRegisterComponent <UpdateComponent>();
     LocalizationComponent = FindAndRegisterComponent <LocalizationComponent>();
     VideoComponent        = FindAndRegisterComponent <VideoComponent>();
     InputComponent        = FindAndRegisterComponent <InputComponent>();
     SceneComponent        = FindAndRegisterComponent <SceneComponent>();
 }
コード例 #16
0
        static void Main()
        {
            WindowHandle      handle    = WindowHandle.GetInstance();
            SettingComponent  settings  = SettingComponent.GetInstance();
            TargetRectangle   rectangle = TargetRectangle.GetInstance();
            ExportPointMatrix matrix    = ExportPointMatrix.GetInstance();

            if (RunningInstance() == null)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm(handle, rectangle, settings, matrix));
            }
            else
            {
                MessageBox.Show("有一个和本程序相同的应用程序已经在运行, 请不要同时运行多个本程序.\n\n这个程序即将退出。",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #17
0
        public override void OnInspectorGUI()
        {
            SettingComponent t = (SettingComponent)target;

            if (EditorApplication.isPlaying)
            {
                if (GUILayout.Button("Save Settings"))
                {
                    t.Save();
                }
                if (GUILayout.Button("Remove All Settings"))
                {
                    t.RemoveAllSettings();
                }
            }

            serializedObject.ApplyModifiedProperties();

            Repaint();
        }
コード例 #18
0
        public IRpcMethodResult SetConfirmations(long confirmations)
        {
            try
            {
                var settingComponent = new SettingComponent();
                var setting          = settingComponent.GetSetting();

                setting.Confirmations = confirmations;
                settingComponent.SaveSetting(setting);

                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #19
0
        public IRpcMethodResult SetTxFee(long feePerKB)
        {
            try
            {
                var settingComponent = new SettingComponent();
                var setting          = settingComponent.GetSetting();

                setting.FeePerKB = feePerKB;
                settingComponent.SaveSetting(setting);

                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #20
0
ファイル: WalletController.cs プロジェクト: omcdev/blockchain
        public IRpcMethodResult WalletLock()
        {
            try
            {
                var settting = new SettingComponent().GetSetting();

                if (!settting.Encrypt)
                {
                    return(Ok());
                }

                _cache.Remove("WalletPassphrase");
                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #21
0
        public IRpcMethodResult GetTxSettings()
        {
            try
            {
                var settingComponent = new SettingComponent();
                var setting          = settingComponent.GetSetting();

                var result = new GetTxSettingsOM();
                result.Confirmations = setting.Confirmations;
                result.FeePerKB      = setting.FeePerKB;
                result.Encrypt       = setting.Encrypt;

                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #22
0
        public static void SaveGame(this SettingComponent setting, GameData gameData)
        {
            var gameDataList = setting.GetObject <List <GameData> >(Constant.Setting.GameData);

            bool HasGame = false;

            for (int i = 0; i < gameDataList.Count; i++)
            {
                if (gameDataList[i].gameId == gameData.gameId)
                {
                    //覆盖
                    gameDataList[i] = gameData;
                    HasGame         = true;
                }
            }

            //保存
            if (!HasGame)
            {
                gameDataList.Add(gameData);
            }

            setting.SetObject(Constant.Setting.GameData, gameDataList);
        }
コード例 #23
0
        public IRpcMethodResult WalletLock()
        {
            try
            {
                var settting = new SettingComponent().GetSetting();

                if (!settting.Encrypt)
                {
                    LogHelper.Error("Error occured in WalletLock API");
                    throw new CommonException(ErrorCode.Service.Wallet.CAN_NOT_ENCRYPT_AN_ENCRYPTED_WALLET);
                }

                _cache.Remove("WalletPassphrase");
                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #24
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            SettingComponent t = target as SettingComponent;

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            {
                m_SettingHelperInfo.Draw();
            }
            EditorGUI.EndDisabledGroup();

            if (EditorApplication.isPlaying)
            {
                if (GUILayout.Button("Save Settings"))
                {
                    t.Save();
                }
                if (GUILayout.Button("Remove All Settings"))
                {
                    t.RemoveAllKeys();
                }
            }
        }
コード例 #25
0
 private void OnSetting()
 {
     SettingComponent.ShowHideUIGameSetting(true);
 }
コード例 #26
0
        public static List <UserCard> GetUserCards(this SettingComponent setting)
        {
            var userCardList = setting.GetObject <List <UserCard> >(Constant.Setting.UserCard);

            return(userCardList);
        }
コード例 #27
0
        public static List <IProcessItem> GenerateProcessQueue(
            ExportPointMatrix matrix,
            TargetRectangle rectangle,
            WindowHandle handle,
            SettingComponent settings)
        {
            List <IProcessItem> queue = new List <IProcessItem>();
            IProcessItem        procItem;

            switch (settings.ProcessType)
            {
            case ProcessTypeFlags.MAINBOARD_FIND_HANDLE:
                procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, false);
                queue.Add(procItem);
                procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.MAINBOARD_FIND_RECTANGLE:
                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0);
                queue.Add(procItem);
                procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                queue.Add(procItem);
                procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "GXWND", 1);
                queue.Add(procItem);
                procItem = new ProcessItem_GetControlRectangle(handle);
                queue.Add(procItem);
                procItem = new ProcessItem_CalcRectExportPointMatrix(matrix, rectangle, settings.RowDeviation, settings.ColumnDeviation);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.MAINBOARD_CHECK_POSITION:
            {
                IIterator matrixPointIterator = matrix.Iterator();
                for (; !matrixPointIterator.IsDone(); matrixPointIterator.Next())
                {
                    ExportPointMatrixItem item = matrixPointIterator.CurrentItem();
                    if (!item.IsAvaliable)
                    {
                        continue;          // 没被选中忽略
                    }
                    else
                    {
                        procItem = new ProcessItem_MouseMove(item.PointX, item.PointY);
                        queue.Add(procItem);
                    }
                }
            }
            break;

            case ProcessTypeFlags.OVERWRITE_PARENT_WND:
                procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_WINDOW:
                procItem = new ProcessItem_FindWindow(handle, settings.StringParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_WINDOW_EX:
                procItem = new ProcessItem_FindWindowEx(handle, settings.StringParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_WINDOW_BY_NAME:
                procItem = new ProcessItem_FindWindowByName(handle, settings.StringParam, settings.IntParam, false);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_CONTROL_BY_CLASSNAME:
                procItem = new ProcessItem_FindCtrlByCtrlClass(handle, settings.StringParam, settings.IntParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.FIND_CONTROL_BY_NAME:
                procItem = new ProcessItem_FindCtrlByCtrlName(handle, settings.StringParam, settings.IntParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.GET_WINDOW_RECTANGLE:
                procItem = new ProcessItem_GetControlRectangle(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.CALCULATE_RECTANGLE_EXPORT_POINT_MATRIX:
                procItem = new ProcessItem_CalcRectExportPointMatrix(matrix, rectangle, settings.RowDeviation, settings.RowDeviation);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.SET_COMBOBOX_CURSEL:
                procItem = new ProcessItem_SetComboBoxCrusel(handle, settings.IntParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.SET_TEXTBOX_VALUE:
                procItem = new ProcessItem_SetTextBoxValue(handle, settings.StringParam);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.CONTROL_MOUSE_LBUTTON_CLICK:
                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.MOUSE_LBUTTON_CLICK:
                procItem = new ProcessItem_NormMouseLeftButtonClick();
                queue.Add(procItem);
                break;

            case ProcessTypeFlags.DEFAULT:
            {
                IIterator matrixPointIterator = matrix.Iterator();
                for (; !matrixPointIterator.IsDone(); matrixPointIterator.Next())
                {
                    ExportPointMatrixItem item = matrixPointIterator.CurrentItem();
                    // 判断该位置是否被选中
                    if (!item.IsAvaliable)
                    {
                        continue;          // 没被选中忽略
                    }
                    else
                    // 开始执行既定步骤
                    {
                        // 鼠标移动到该位置
                        procItem = new ProcessItem_MouseMove(item.PointX, item.PointY);
                        queue.Add(procItem);
                        // 鼠标点击该位置
                        procItem = new ProcessItem_NormMouseLeftButtonClick();
                        queue.Add(procItem);
                        /* 弹出图片详情后 */
                        // 获取主窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 找到 Plate 1 控件句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 找到 Process... 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Process...", 0);
                        queue.Add(procItem);
                        // 点击 Process 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);

                        /* 弹出 Image Stitching 后 */
                        // 获取 Image Stitching 窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, "Image Stitching", 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 ComboBox 句柄
                        procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "ComboBox", 0);
                        queue.Add(procItem);
                        // 设置 ComboBox 选项为第 1 个
                        procItem = new ProcessItem_SetComboBoxCrusel(handle, 0);
                        queue.Add(procItem);
                        // 获取 Edit 句柄
                        procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "Edit", 0);
                        queue.Add(procItem);
                        // 设置 Edit 值为 50.00
                        procItem = new ProcessItem_SetTextBoxValue(handle, "50.00");
                        queue.Add(procItem);
                        // 获取 OK 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "OK", 0);
                        queue.Add(procItem);
                        // 点击 OK 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);

                        /* 弹出 Image Processing 窗口后 */

                        for (int i = 0; i < 3; i++)
                        {
                            // 找到 Image Processing 窗口句柄
                            procItem = new ProcessItem_FindWindowByName(handle, "Image Processing", 0, true);
                            queue.Add(procItem);
                            procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                            queue.Add(procItem);
                            // 分别选择不同选项
                            switch (i)
                            {
                            case 0:             // DAPI + GFP, 无需操作复选框
                                break;

                            case 1:             // DAPI, 取消选中 GFP
                                                // 获取 GFP 复选框句柄
                                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[GFP 469,525]", 0);
                                queue.Add(procItem);
                                // 点击 GFP 按钮
                                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                                queue.Add(procItem);
                                break;

                            case 2:             // GFP, 取消选中 DAPI
                                                // 获取 DAPI 复选框句柄
                                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[DAPI 377,447]", 0);
                                queue.Add(procItem);
                                // 点击 DAPI 复选框
                                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                                queue.Add(procItem);
                                // 获取 GFP 复选框句柄
                                procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[GFP 469,525]", 0);
                                queue.Add(procItem);
                                // 点击 GFP 复选框
                                procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                                queue.Add(procItem);
                                break;
                            }
                            // 获取 Save Image Set 按钮句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save Image Set", 0);
                            queue.Add(procItem);
                            // 点击 Save Image Set 按钮
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);

                            /* 弹出 Image Save Options 窗口后 */
                            // 获取 Save Image Options 窗口句柄
                            procItem = new ProcessItem_FindWindowByName(handle, "Image Save Options", 0, true);
                            queue.Add(procItem);
                            procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                            queue.Add(procItem);
                            // 获取 Save picture for presentation 单选框句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save picture for presentation", 0);
                            queue.Add(procItem);
                            // 点击 Save picture for presentation 单选框
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);
                            // 获取 Save entire image (1 camera pixel resolution) 单选框句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save entire image (1 camera pixel resolution)", 0);
                            queue.Add(procItem);
                            // 点击 Save entire image (1 camera pixel resolution) 单选框
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);
                            // 获取 OK 按钮句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "OK", 0);
                            queue.Add(procItem);
                            // 点击 OK 按钮
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);

                            /* 弹出 Save As Picture 窗口后 */
                            // 获取 Save As Picture 窗口句柄
                            procItem = new ProcessItem_FindWindowByName(handle, "Save As Picture", 0, false);
                            queue.Add(procItem);
                            procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                            queue.Add(procItem);
                            // 获取文件名输入框
                            // 获取文件名输入框的句柄
                            procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "Edit", 0);
                            queue.Add(procItem);
                            // 设置文件名(eg. ExpHlp_Expo_PosA1_DAPI_GFP_2017100112)
                            StringBuilder sb = new StringBuilder();
                            sb.AppendFormat("ExpHlp_Expo_Pos{0}_", item.PointDescription);
                            switch (i)
                            {
                            case 0:
                                // DAPI + GFP
                                sb.Append("DAPI_GFP_");
                                break;

                            case 1:
                                // DAPI
                                sb.Append("DAPI_");
                                break;

                            case 2:
                                // GFP
                                sb.Append("GFP_");
                                break;
                            }
                            sb.Append(DateTime.Now.ToString("yyyyMMddHHmm"));
                            procItem = new ProcessItem_SetTextBoxValue(handle, sb.ToString());
                            queue.Add(procItem);
                            // 获取 保存 按钮的句柄
                            procItem = new ProcessItem_FindCtrlByCtrlName(handle, "保存", 0);
                            queue.Add(procItem);
                            // 点击 保存 按钮
                            procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                            queue.Add(procItem);
                        }

                        /* 执行完成 Image Processing 窗口操作后 */
                        // 找到 Image Processing 窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, "Image Processing", 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 Close 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Close", 0);
                        queue.Add(procItem);
                        // 点击 Close 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);
                        // 获取主窗口句柄
                        procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, true);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 Plate 1 控件句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0);
                        queue.Add(procItem);
                        procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle);
                        queue.Add(procItem);
                        // 获取 Close 按钮句柄
                        procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Close", 1);
                        queue.Add(procItem);
                        // 点击 Close 按钮
                        procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle);
                        queue.Add(procItem);
                    }
                }
            }
            break;
            }
            return(queue);
        }
コード例 #28
0
 public GeneralSettingModel(ExportPointMatrix instance, SettingComponent settings)
 {
     this.instance = instance;
     this.settings = settings;
 }
コード例 #29
0
        public IRpcMethodResult EstimateTxFeeForSendToAddress(string toAddress, long amount, string comment, string commentTo, bool deductFeeFromAmount)
        {
            try
            {
                EstimateTxFeeOM result               = new EstimateTxFeeOM();
                var             utxoComponent        = new UtxoComponent();
                var             txComponent          = new TransactionComponent();
                var             settingComponent     = new SettingComponent();
                var             addressBookComponent = new AddressBookComponent();
                var             accountComponent     = new AccountComponent();

                if (!AccountIdHelper.AddressVerify(toAddress))
                {
                    throw new CommonException(ErrorCode.Service.Transaction.TO_ADDRESS_INVALID);
                }

                var setting   = settingComponent.GetSetting();
                var utxos     = utxoComponent.GetAllConfirmedOutputs();
                var tx        = new TransactionMsg();
                var totalSize = tx.Serialize().Length;

                var output = new OutputMsg();
                output.Amount     = amount;
                output.Index      = 0;
                output.LockScript = Script.BuildLockScipt(toAddress);
                output.Size       = output.LockScript.Length;
                tx.Outputs.Add(output);
                totalSize += output.Serialize().Length;

                var blockComponent  = new BlockComponent();
                var lastBlockHeight = blockComponent.GetLatestHeight();

                var    totalInput  = 0L;
                var    index       = 0;
                double totalAmount = amount;
                double totalFee    = setting.FeePerKB * ((double)totalSize / 1024.0);

                while (index < utxos.Count)
                {
                    var account = accountComponent.GetAccountById(utxos[index].AccountId);

                    if (account != null && !string.IsNullOrWhiteSpace(account.PrivateKey))
                    {
                        var   utxoTX    = txComponent.GetTransactionMsgByHash(utxos[index].TransactionHash);
                        Block utxoBlock = blockComponent.GetBlockEntiytByHash(utxos[index].BlockHash);

                        if (utxoTX == null || utxoBlock == null)
                        {
                            index++;
                            continue;
                        }

                        if (!utxoBlock.IsVerified)
                        {
                            index++;
                            continue;
                        }

                        if (Time.EpochTime < utxoTX.Locktime)
                        {
                            index++;
                            continue;
                        }

                        if (utxoTX.InputCount == 1 && utxoTX.Inputs[0].OutputTransactionHash == Base16.Encode(HashHelper.EmptyHash()))
                        {
                            var blockHeight = utxoBlock.Height;

                            if (lastBlockHeight - blockHeight < 100L)
                            {
                                index++;
                                continue;
                            }
                        }

                        var input = new InputMsg();
                        input.OutputTransactionHash = utxos[index].TransactionHash;
                        input.OutputIndex           = utxos[index].OutputIndex;
                        input.UnlockScript          = Script.BuildUnlockScript(input.OutputTransactionHash, input.OutputIndex, Base16.Decode(decryptPrivateKey(account.PrivateKey)), Base16.Decode(account.PublicKey));
                        input.Size = input.UnlockScript.Length;
                        tx.Inputs.Add(input);

                        var size = input.Serialize().Length;
                        totalSize  += size;
                        totalFee   += setting.FeePerKB * ((double)size / 1024.0);
                        totalInput += utxos[index].Amount;
                    }
                    else
                    {
                        index++;
                        continue;
                    }

                    if (!deductFeeFromAmount)
                    {
                        totalAmount = amount + totalFee;
                    }

                    if (totalInput >= (long)Math.Ceiling(totalAmount))
                    {
                        var size = output.Serialize().Length;

                        if ((totalInput - (long)Math.Ceiling(totalAmount)) > (setting.FeePerKB * (double)size / 1024.0))
                        {
                            totalSize += size;
                            totalFee  += setting.FeePerKB * ((double)size / 1024.0);
                        }

                        break;
                    }

                    index++;
                }

                if (totalInput < totalAmount)
                {
                    throw new CommonException(ErrorCode.Service.Transaction.BALANCE_NOT_ENOUGH);
                }

                if (deductFeeFromAmount)
                {
                    output.Amount -= (long)Math.Ceiling(totalFee);

                    if (output.Amount <= 0)
                    {
                        throw new CommonException(ErrorCode.Service.Transaction.SEND_AMOUNT_LESS_THAN_FEE);
                    }
                }

                result.totalFee  = Convert.ToInt64(totalFee);
                result.totalSize = Convert.ToInt32(totalSize);

                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
コード例 #30
0
        public IRpcMethodResult SendMany(string fromAccount, SendManyOutputIM[] receivers, string[] feeDeductAddresses)
        {
            try
            {
                string result                      = null;
                var    utxoComponent               = new UtxoComponent();
                var    txComponent                 = new TransactionComponent();
                var    settingComponent            = new SettingComponent();
                var    addressBookComponent        = new AddressBookComponent();
                var    accountComponent            = new AccountComponent();
                var    transactionCommentComponent = new TransactionCommentComponent();
                var    blockComponent              = new BlockComponent();
                var    lastBlockHeight             = blockComponent.GetLatestHeight();

                var    setting     = settingComponent.GetSetting();
                var    utxos       = utxoComponent.GetAllConfirmedOutputs();
                var    tx          = new TransactionMsg();
                double totalOutput = 0;
                var    totalSize   = tx.Serialize().Length;

                if (receivers == null || receivers.Length == 0)
                {
                    throw new CommonException(ErrorCode.Service.Transaction.TO_ADDRESS_INVALID);
                }

                foreach (var receiver in receivers)
                {
                    if (!AccountIdHelper.AddressVerify(receiver.address))
                    {
                        throw new CommonException(ErrorCode.Service.Transaction.TO_ADDRESS_INVALID);
                    }

                    var output = new OutputMsg();
                    output.Amount     = receiver.amount;
                    output.Index      = tx.Outputs.Count;
                    output.LockScript = Script.BuildLockScipt(receiver.address);
                    output.Size       = output.LockScript.Length;
                    tx.Outputs.Add(output);

                    totalSize   += output.Serialize().Length;
                    totalOutput += receiver.amount;
                }

                foreach (var address in feeDeductAddresses)
                {
                    if (receivers.Where(r => r.address == address).Count() == 0)
                    {
                        throw new CommonException(ErrorCode.Service.Transaction.FEE_DEDUCT_ADDRESS_INVALID);
                    }
                }

                var    totalInput  = 0L;
                var    index       = 0;
                double totalFee    = setting.FeePerKB * ((double)totalSize / 1024.0);
                double totalAmount = totalOutput;

                while (index < utxos.Count)
                {
                    var account = accountComponent.GetAccountById(utxos[index].AccountId);

                    if (account != null && !string.IsNullOrWhiteSpace(account.PrivateKey))
                    {
                        var   utxoTX    = txComponent.GetTransactionMsgByHash(utxos[index].TransactionHash);
                        Block utxoBlock = blockComponent.GetBlockEntiytByHash(utxos[index].BlockHash);

                        if (utxoTX == null || utxoBlock == null)
                        {
                            index++;
                            continue;
                        }

                        if (!utxoBlock.IsVerified)
                        {
                            index++;
                            continue;
                        }

                        if (Time.EpochTime < utxoTX.Locktime)
                        {
                            index++;
                            continue;
                        }

                        if (utxoTX.InputCount == 1 && utxoTX.Inputs[0].OutputTransactionHash == Base16.Encode(HashHelper.EmptyHash()))
                        {
                            var blockHeight = utxoBlock.Height;

                            if (lastBlockHeight - blockHeight < 100L)
                            {
                                index++;
                                continue;
                            }
                        }

                        var input = new InputMsg();
                        input.OutputTransactionHash = utxos[index].TransactionHash;
                        input.OutputIndex           = utxos[index].OutputIndex;
                        input.UnlockScript          = Script.BuildUnlockScript(input.OutputTransactionHash, input.OutputIndex, Base16.Decode(decryptPrivateKey(account.PrivateKey)), Base16.Decode(account.PublicKey));
                        input.Size = input.UnlockScript.Length;
                        tx.Inputs.Add(input);

                        var size = input.Serialize().Length;
                        totalSize  += size;
                        totalFee   += setting.FeePerKB * ((double)size / 1024.0);
                        totalInput += utxos[index].Amount;
                    }
                    else
                    {
                        index++;
                        continue;
                    }

                    if (feeDeductAddresses == null || feeDeductAddresses.Length == 0)
                    {
                        totalAmount = totalOutput + totalFee;
                    }

                    if (totalInput >= (long)Math.Ceiling(totalAmount))
                    {
                        var size = tx.Outputs[0].Serialize().Length;

                        if ((totalInput - (long)Math.Ceiling(totalAmount)) > (setting.FeePerKB * (double)size / 1024.0))
                        {
                            totalSize += size;
                            totalFee  += setting.FeePerKB * ((double)size / 1024.0);

                            if (feeDeductAddresses == null || feeDeductAddresses.Length == 0)
                            {
                                totalAmount = totalOutput + totalFee;
                            }


                            var newAccount = accountComponent.GenerateNewAccount();

                            if (setting.Encrypt)
                            {
                                if (!string.IsNullOrWhiteSpace(_cache.Get <string>("WalletPassphrase")))
                                {
                                    newAccount.PrivateKey = AES128.Encrypt(newAccount.PrivateKey, _cache.Get <string>("WalletPassphrase"));
                                    accountComponent.UpdatePrivateKeyAr(newAccount);
                                }
                                else
                                {
                                    throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED);
                                }
                            }

                            var newOutput = new OutputMsg();
                            newOutput.Amount     = totalInput - (long)Math.Ceiling(totalAmount);
                            newOutput.Index      = tx.Outputs.Count;
                            newOutput.LockScript = Script.BuildLockScipt(newAccount.Id);
                            newOutput.Size       = newOutput.LockScript.Length;
                            tx.Outputs.Add(newOutput);
                        }

                        break;
                    }

                    index++;
                }

                if (totalInput < totalAmount)
                {
                    throw new CommonException(ErrorCode.Service.Transaction.BALANCE_NOT_ENOUGH);
                }

                if (feeDeductAddresses != null && feeDeductAddresses.Length > 0)
                {
                    var averageFee = totalFee / feeDeductAddresses.Length;

                    for (int i = 0; i < receivers.Length; i++)
                    {
                        if (feeDeductAddresses.Contains(receivers[i].address))
                        {
                            tx.Outputs[i].Amount -= (long)Math.Ceiling(averageFee);

                            if (tx.Outputs[i].Amount <= 0)
                            {
                                throw new CommonException(ErrorCode.Service.Transaction.SEND_AMOUNT_LESS_THAN_FEE);
                            }
                        }
                    }
                }

                tx.Timestamp = Time.EpochTime;
                tx.Hash      = tx.GetHash();
                txComponent.AddTransactionToPool(tx);
                Startup.P2PBroadcastTransactionAction(tx.Hash);
                result = tx.Hash;

                for (int i = 0; i < receivers.Length; i++)
                {
                    var receiver = receivers[i];

                    if (!string.IsNullOrWhiteSpace(receiver.tag))
                    {
                        addressBookComponent.SetTag(receiver.address, receiver.tag);
                    }

                    if (!string.IsNullOrWhiteSpace(receiver.comment))
                    {
                        transactionCommentComponent.Add(tx.Hash, i, receiver.comment);
                    }
                }

                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }