public void TestConfigureAnotherInstanceId()
        {
            string result = ExecuteDaemon("-c \"{ 'XDaggerWallet':'1Nwa0TCr5umw5ZLAvKmHCl+SJDP21dyL', 'XDaggerPoolAddress':'xey.ti:13654', 'DeviceId':'p_0_d_0','AutoDecideInstanceId':'true' }\"");

            Assert.AreEqual(0, ParseResultCode(result), "Configure command should success.");

            try
            {
                result = ExecuteDaemon("-s install");
                Assert.AreEqual(0, ParseResultCode(result), "Service should be installed.");

                Assert.IsTrue(IsServiceExist(XDaggerServiceName, 0), "Found service in Windows Services.");

                result = ExecuteDaemon("-c \"{ 'AutoDecideInstanceId':'true' }\"");
                ConfigureOutput output = ParseResultData <ConfigureOutput>(result);

                Assert.AreEqual(output.InstanceId, 1, "InstanceId should be 1.");

                MinerConfig config = ReadConfigFile();
                Assert.IsTrue(config.InstanceType == MinerConfig.InstanceTypes.XDagger, "InstanceType is XDagger.");
                Assert.AreEqual(config.InstanceId, 1, "InstanceId in config should be 1.");
            }
            finally
            {
                TryUninstallService("XDaggerMinerWin", 0);
            }
        }
        public void TestConfigureEth()
        {
            string result = ExecuteDaemon("-c \"{ 'EthPoolAddress':'stratum1tcp://0x73037FE73337D16D799c64632C1c79C19C8A85E6eth.f2pool.com:8008', 'DeviceId':'p_0_d_0', 'AutoDecideInstanceId':'true' }\"");

            Assert.AreEqual(0, ParseResultCode(result), "Configure command should success.");

            ConfigureOutput output = ParseResultData <ConfigureOutput>(result);

            Assert.AreEqual(0, output.InstanceId, "InstanceId should be 0.");
        }
        public void TestConfigureXDagger()
        {
            string result = ExecuteDaemon("-c \"{ 'XDaggerWallet':'1Nwa0TCr5umw5ZLAvKmHCl+SJDP21dyL', 'XDaggerPoolAddress':'xey.ti:13654', 'DeviceId':'p_0_d_0','AutoDecideInstanceId':'true' }\"");

            Assert.AreEqual(0, ParseResultCode(result), "Configure command should success.");

            ConfigureOutput output = ParseResultData <ConfigureOutput>(result);

            Assert.IsNotNull(output?.InstanceId, "InstanceId should not be null.");
        }
        public void TestConfigureUpdateInstanceType()
        {
            string result = ExecuteDaemon("-c \"{ 'XDaggerWallet':'1Nwa0TCr5umw5ZLAvKmHCl+SJDP21dyL', 'XDaggerPoolAddress':'xey.ti:13654', 'DeviceId':'p_0_d_0','AutoDecideInstanceId':'true' }\"");

            Assert.AreEqual(ParseResultCode(result), 0, "Configure command should success.");

            try
            {
                result = ExecuteDaemon("-s install");
                Assert.AreEqual(ParseResultCode(result), 0, "Service should be installed.");

                Assert.IsTrue(IsServiceExist(XDaggerServiceName, 0), "Found service in Windows Services.");

                result = ExecuteDaemon("-c \"{ 'EthPoolAddress':'stratum1tcp://0x73037FE73337D16D799c64632C1c79C19C8A85E6eth.f2pool.com:8008', 'AutoDecideInstanceId':'true' }\"");

                Assert.IsTrue(IsServiceExist(XDaggerServiceName, 0), "Service is not changed after configuration command.");


                ConfigureOutput output = ParseResultData <ConfigureOutput>(result);

                Assert.AreEqual(output.InstanceId, 0, "InstanceId should be 0.");

                MinerConfig config = ReadConfigFile();
                Assert.IsTrue(config.InstanceType == MinerConfig.InstanceTypes.XDagger, "InstanceType is XDagger.");
                Assert.AreEqual(config.InstanceId, 0, "InstanceId in config should be 0.");
                Assert.IsTrue(config.UpdatedInstanceType == MinerConfig.InstanceTypes.Eth, "UpdatedInstanceType is XDagger.");
                Assert.AreEqual(config.UpdatedInstanceId, 0, "UpdatedInstanceId in config should be 0.");

                result = ExecuteDaemon("-s start");
                Assert.IsFalse(IsServiceExist(XDaggerServiceName, 0), "XDagger service should be uninstalled.");
                Assert.IsTrue(IsServiceExist(XDaggerEthServiceName, 0), "XDagger Eth service should be installed.");

                config = ReadConfigFile();
                Assert.IsTrue(config.InstanceType == MinerConfig.InstanceTypes.Eth, "InstanceType is XDagger.");
                Assert.AreEqual(config.InstanceId, 0, "InstanceId in config should be 0.");
                Assert.IsTrue(config.UpdatedInstanceType == null, "UpdatedInstanceType is null.");
                Assert.AreEqual(config.UpdatedInstanceId, null, "UpdatedInstanceId in config should be null.");
            }
            finally
            {
                TryUninstallService("XDaggerMinerWin", 0);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 设置 PC 端 主题样式
        /// </summary>
        /// <returns></returns>
        public ConfigureOutput ConfigurePC()
        {
            ConfigureOutput configure = new ConfigureOutput();

            configure.confcss  = "";
            configure.confhtml = "";
            configure.confjs   = "";
            if (BLLSession.UserInfoSessioin != null)
            {
                string path = FileHelper.defaultpath + "/MyConfigure/" + BLLSession.UserInfoSessioin.UserName + "/";
                FileHelper.CreatePath(path);
                configure.confcss       = FileHelper.GetFile(path, "conf.css");
                configure.confsidehtml  = FileHelper.GetFile(path, "conf_side.txt");
                configure.conffirsthtml = FileHelper.GetFile(path, "conf_first.txt");
                configure.conftailhtml  = FileHelper.GetFile(path, "conf_tail.txt");
                configure.confjs        = FileHelper.GetFile(path, "conf.js");
                configure.IsShowCSS     = BLLSession.UserInfoSessioin.BlogUserInfo.IsShowCSS;
                configure.IsDisCSS      = BLLSession.UserInfoSessioin.BlogUserInfo.IsDisCSS;
                configure.TerminalType  = "PC";
            }
            return(configure);
        }
        /// <summary>
        ///
        /// </summary>
        private void StepThree_ConfigXDaggerMiner()
        {
            logger.Trace("Start StepThree_ConfigXDaggerMiner.");

            MinerDevice selectedDevice = (cBxTargetDevice.SelectedIndex >= 0) ? displayedDeviceList.ElementAt(cBxTargetDevice.SelectedIndex) : null;

            if (selectedDevice == null)
            {
                MessageBox.Show("请选择一个硬件设备");
                return;
            }

            XDaggerConfig xDaggerConfig = new XDaggerConfig();

            xDaggerConfig.PoolAddress = txtXDaggerPoolAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(xDaggerConfig.PoolAddress))
            {
                MessageBox.Show("请输入矿池地址");
                return;
            }

            xDaggerConfig.WalletAddress = txtWalletAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(xDaggerConfig.WalletAddress))
            {
                MessageBox.Show("请输入钱包地址");
                return;
            }

            if (xDaggerConfig.WalletAddress.Length != 32)
            {
                MessageBox.Show("钱包必须为长度32位的字母与数字组合");
                return;
            }

            BackgroundWork <int?> .CreateWork(
                this,
                () => {
                ShowProgressIndicator("正在配置矿机", btnStepThreeNext, btnStepThreeBack);
            },
                () => {
                string commandParameters = string.Format(" -c \"{{ 'DeviceId':'{0}', 'XDaggerWallet':'{1}', 'XDaggerPoolAddress':'{2}', 'AutoDecideInstanceId':true }}\"",
                                                         selectedDevice.DeviceId,
                                                         xDaggerConfig.WalletAddress,
                                                         xDaggerConfig.PoolAddress);

                ConfigureOutput exeResult = createdClient.ExecuteDaemon <ConfigureOutput>(commandParameters);

                logger.Trace("ConfigureCommand finished with InstanceId: " + exeResult.InstanceId);
                return(exeResult.InstanceId);
            },
                (taskResult) => {
                HideProgressIndicator();

                if (taskResult.HasError)
                {
                    MessageBox.Show("配置矿机出现错误:" + taskResult.Exception.Message);
                    logger.Error("ConfigureCommand failed: " + taskResult.Exception.ToString());
                    return;
                }

                int?instanceId = taskResult.Result;
                if (instanceId == null)
                {
                    MessageBox.Show("配置矿机出现错误,未返回InstanceId.");
                    logger.Error("配置矿机出现错误,未返回InstanceId.");
                    return;
                }

                createdClient.InstanceId = instanceId.Value;

                // Save the currnet config into cache.
                createdClient.Device        = selectedDevice;
                createdClient.XDaggerConfig = xDaggerConfig;

                if (cKbWalletSaveToDefault.IsChecked ?? false)
                {
                    ManagerConfig.Current.DefaultXDagger = xDaggerConfig;
                    ManagerConfig.Current.SaveToFile();
                }

                SwitchUIToStep(4);
            }
                ).Execute();
        }
Beispiel #7
0
        public override CommandResult Execute(string parameter)
        {
            // Update the configuration
            ConfigureParameter configParameters = null;

            isInstanceUpdated = false;

            try
            {
                configParameters = JsonConvert.DeserializeObject <ConfigureParameter>(parameter);
            }
            catch (FormatException)
            {
                throw new TargetExecutionException(DaemonErrorCode.COMMAND_PARAM_ERROR, "The format of the Configuration content is not valid Json.");
            }

            MinerConfig config = MinerConfig.ReadFromFile();

            if (!string.IsNullOrEmpty(configParameters.DeviceId) || !string.IsNullOrEmpty(configParameters.DeviceName))
            {
                MinerManager minerManager = new MinerManager();

                List <MinerDevice> deviceList = minerManager.GetAllMinerDevices();
                bool deviceFound = false;
                foreach (MinerDevice device in deviceList)
                {
                    if (device.IsMatchId(configParameters.DeviceId) || string.Equals(device.GetDisplayName(), configParameters.DeviceName))
                    {
                        config.Device = new MinerConfigDevice(device.GetDeviceId(), device.GetDisplayName(), device.GetDeviceVersion(), device.GetDriverVersion());
                        deviceFound   = true;
                        break;
                    }
                }

                if (!deviceFound)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_DEVICE_NOT_FOUND, string.Format("Did not find the device matches DeviceId=[{0}] or DeviceName=[{1}]",
                                                                                                              configParameters.DeviceId,
                                                                                                              configParameters.DeviceName));
                }
            }

            if ((!string.IsNullOrEmpty(configParameters.XDaggerWallet) || !string.IsNullOrEmpty(configParameters.XDaggerPoolAddress)) &&
                !string.IsNullOrEmpty(configParameters.EthPoolAddress))
            {
                throw new TargetExecutionException(DaemonErrorCode.CONFIG_ONLY_ONE_INSTANCE_TYPE_ALLOWED, "Only one type of miner instance is allowed.");
            }

            if (configParameters.InstanceId.HasValue && configParameters.AutoDecideInstanceId)
            {
                throw new TargetExecutionException(DaemonErrorCode.COMMAND_PARAM_ERROR, "Cannot specify InstanceId while AutoDecideInstanceId is used.");
            }

            InstanceTypes?proposedInstanceType = null;

            if (!string.IsNullOrEmpty(configParameters.XDaggerWallet))
            {
                string wallet = configParameters.XDaggerWallet.Trim();

                // TODO: Should validate the Wallet address first
                if (false)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_WALLET_FORMET_ERROR, string.Format("Wallet format is not correct. Wallet=[{0}]", configParameters.XDaggerWallet));
                }

                if (false)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_WALLET_NOT_FOUND, string.Format("Wallet cannot be found. Wallet=[{0}]", configParameters.XDaggerWallet));
                }

                if (config.XDaggerMiner == null)
                {
                    config.XDaggerMiner = new XDaggerMinerConfig();
                }

                proposedInstanceType = MinerConfig.InstanceTypes.XDagger;
                config.XDaggerMiner.WalletAddress = wallet;
            }

            if (!string.IsNullOrEmpty(configParameters.XDaggerPoolAddress))
            {
                string poolAddress = configParameters.XDaggerPoolAddress.Trim();

                // TODO: Should validate the Wallet address first
                if (false)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_WALLET_FORMET_ERROR, string.Format("Wallet format is not correct. Wallet=[{0}]", configParameters.XDaggerWallet));
                }

                if (false)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_WALLET_NOT_FOUND, string.Format("Wallet cannot be found. Wallet=[{0}]", configParameters.XDaggerWallet));
                }

                if (config.XDaggerMiner == null)
                {
                    config.XDaggerMiner = new XDaggerMinerConfig();
                }

                proposedInstanceType            = MinerConfig.InstanceTypes.XDagger;
                config.XDaggerMiner.PoolAddress = poolAddress;
            }

            if (!string.IsNullOrEmpty(configParameters.EthPoolAddress))
            {
                string ethPoolAddress = configParameters.EthPoolAddress.Trim();

                // TODO: Should validate the Wallet address first
                if (false)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_WALLET_FORMET_ERROR, string.Format("Wallet format is not correct. Wallet=[{0}]", configParameters.XDaggerWallet));
                }

                if (false)
                {
                    throw new TargetExecutionException(DaemonErrorCode.CONFIG_WALLET_NOT_FOUND, string.Format("Wallet cannot be found. Wallet=[{0}]", configParameters.XDaggerWallet));
                }

                if (config.EthMiner == null)
                {
                    config.EthMiner = new EthMinerConfig();
                }

                proposedInstanceType        = MinerConfig.InstanceTypes.Eth;
                config.EthMiner.PoolAddress = ethPoolAddress;
            }

            ServiceProvider currentServiceProvider = ServiceProvider.GetServiceProvider(config.InstanceType);
            ServiceInstance currentServiceInstance = currentServiceProvider?.AquaireInstance(config.InstanceId);

            // Check the change of instance Type, if the service is already installed, put the new instance type into updated_instance_type, and detect new updated_instance_id
            if (currentServiceInstance != null && currentServiceInstance.IsServiceExist())
            {
                // Put the type into updated_instance_type
                if (proposedInstanceType == null)
                {
                    if (config.UpdatedInstanceType != null && configParameters.InstanceId != null)
                    {
                        config.UpdatedInstanceId = configParameters.InstanceId;
                    }
                }
                else if (proposedInstanceType != config.InstanceType)
                {
                    isInstanceUpdated          = true;
                    config.UpdatedInstanceType = proposedInstanceType;
                    config.UpdatedInstanceId   = DecideInstanceId(configParameters, proposedInstanceType.Value, true);
                }
            }
            else if (proposedInstanceType != null)
            {
                if (configParameters.AutoDecideInstanceId || (config.InstanceType != InstanceTypes.Unset && proposedInstanceType != config.InstanceType))
                {
                    isInstanceUpdated = true;
                }

                config.InstanceType = proposedInstanceType.Value;
                config.InstanceId   = DecideInstanceId(configParameters, proposedInstanceType.Value, false) ?? config.InstanceId;

                // Clear the updated ones
                config.UpdatedInstanceId   = null;
                config.UpdatedInstanceType = null;
            }

            // Save all of the changes into config file
            int retryTimes = 0;

            while (true)
            {
                try
                {
                    config.SaveToFile();

                    if (isInstanceUpdated)
                    {
                        return(CommandResult.CreateResult(ConfigureOutput.Create(config.UpdatedInstanceId ?? config.InstanceId)));
                    }
                    else
                    {
                        return(CommandResult.OKResult());
                    }
                }
                catch (Exception ex)
                {
                    if (retryTimes++ < IntermediateFailureRetryTimes)
                    {
                        Thread.Sleep(IntermediateFailureRetryPeriod);
                        continue;
                    }

                    throw new TargetExecutionException(DaemonErrorCode.UNKNOWN_ERROR, ex.Message);
                }
            }
        }
        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (cbxInstanceType.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个矿机类型.", "提示");
                return;
            }

            // Validate the config
            if (properties.InstanceType == MinerClient.InstanceTypes.XDagger)
            {
                if (!ValidateXDaggerConfig())
                {
                    return;
                }
            }
            else if (properties.InstanceType == MinerClient.InstanceTypes.Ethereum)
            {
                if (!ValidateEthConfig())
                {
                    return;
                }
            }

            MessageBoxResult mresult = MessageBox.Show($"确认要修改选定的{ minerClients.Count }个矿机的配置吗?", "确认", MessageBoxButton.YesNo);

            if (mresult == MessageBoxResult.No)
            {
                return;
            }

            // Execute configure command
            string configParameters = string.Empty;

            if (properties.InstanceType == MinerClient.InstanceTypes.XDagger)
            {
                configParameters = ComposeXDaggerConfigParameters();
            }
            else if (properties.InstanceType == MinerClient.InstanceTypes.Ethereum && properties.EthConfig.IsEmptyConfig())
            {
                configParameters = ComposeEthConfigParameters();
            }
            logger.Trace($"Composed configure command parameter: [{ configParameters }]");

            ProgressWindow progress = new ProgressWindow("正在修改矿机配置...",
                                                         this.minerClients,
                                                         (obj) => {
                MinerClient client = (MinerClient)obj;

                if (properties.InstanceType == MinerClient.InstanceTypes.Ethereum && !properties.EthConfig.IsEmptyConfig())
                {
                    configParameters = ComposeEthConfigParameters(client);
                }
                logger.Trace($"Composed configure command parameter: [{ configParameters }] on machine [{ client.MachineFullName }]");
                ConfigureOutput exeResult = client.ExecuteDaemon <ConfigureOutput>(configParameters);

                // If instance type changed, we need to decide the new instanceId
                if (client.InstanceTypeEnum != properties.InstanceType && exeResult.InstanceId != null)
                {
                    int finalInstanceId = AssignInstanceId(client.MachineFullName, properties.InstanceType, exeResult.InstanceId.Value);
                    if (finalInstanceId != exeResult.InstanceId)
                    {
                        client.ExecuteDaemon <ConfigureOutput>("-c \"{ 'InstanceId':'" + finalInstanceId.ToString() + "' }\"");
                    }

                    client.InstanceId = finalInstanceId;
                }

                //After the config command success, update the status of the client
                properties.UpdateClient(client);
            },
                                                         (result) => {
                this.HandleProgressResult(result.Result);
            }
                                                         );

            progress.ShowDialog();
        }