Пример #1
0
        public T ExecuteDaemon <T>(string parameters, bool disableTrace = false)
        {
            if (this.Machine == null)
            {
                throw new ArgumentNullException("The Machine object is not initialized in MinerClient. " + this.MachineFullName);
            }

            TargetMachineExecutor executor = TargetMachineExecutor.GetExecutor(this.Machine, disableTrace);
            string daemonFullPath          = Path.Combine(this.BinaryPath, WinMinerReleaseBinary.DaemonExecutionFileName);

            return(executor.ExecuteCommandAndThrow <T>(daemonFullPath, parameters));
        }
        private void StepThree_RetrieveDeviceList()
        {
            logger.Trace("Start StepThree_RetrieveDeviceList.");

            txtWalletAddress.Text      = ManagerConfig.Current.DefaultXDagger.WalletAddress;
            txtXDaggerPoolAddress.Text = ManagerConfig.Current.DefaultXDagger.PoolAddress;
            txtWalletAddressEth.Text   = ManagerConfig.Current.DefaultEth.WalletAddress;
            txtEmailAddressEth.Text    = ManagerConfig.Current.DefaultEth.EmailAddress;
            txtEthWorkerName.Text      = ManagerConfig.Current.DefaultEth.WorkerName;
            if (ManagerConfig.Current.DefaultEth.PoolIndex != null)
            {
                cBxTargetEthPool.SelectedIndex = ManagerConfig.Current.DefaultEth.PoolIndex.GetHashCode();
            }
            if (ManagerConfig.Current.DefaultEth.PoolHostIndex != null)
            {
                cBxTargetEthPoolHost.SelectedIndex = ManagerConfig.Current.DefaultEth.PoolHostIndex.Value;
            }

            MinerMachine existingMachine = ManagerInfo.Current.Machines.FirstOrDefault(m => m.FullName.Equals(createdClient.MachineFullName));

            if (existingMachine != null && existingMachine.Devices != null && existingMachine.Devices.Count > 0)
            {
                // This machine has been queried before and the devices are saved in the ManagerInfo cache, read it
                displayedDeviceList = existingMachine.Devices;
                cBxTargetDevice.Items.Clear();
                cBxTargetDeviceEth.Items.Clear();
                logger.Trace("Got Devices from ManagerInfo cache. Count: " + displayedDeviceList.Count);
                foreach (MinerDevice device in displayedDeviceList)
                {
                    cBxTargetDevice.Items.Add(device.DisplayName);
                    cBxTargetDeviceEth.Items.Add(device.DisplayName);
                }
            }
            else
            {
                // Didn't find the machine in cache, use Executor to retrieve it
                TargetMachineExecutor executor = TargetMachineExecutor.GetExecutor(createdClient.Machine);
                string daemonFullPath          = IO.Path.Combine(createdClient.BinaryPath, WinMinerReleaseBinary.DaemonExecutionFileName);

                BackgroundWork <List <DeviceOutput> > .CreateWork(
                    this,
                    () =>
                {
                    ShowProgressIndicator("正在获取硬件信息", btnStepThreeNext, btnStepThreeBack);
                },
                    () =>
                {
                    return(executor.ExecuteCommandAndThrow <List <DeviceOutput> >(daemonFullPath, "-l"));
                },
                    (taskResult) =>
                {
                    HideProgressIndicator();
                    if (taskResult.HasError)
                    {
                        MessageBox.Show("查询系统硬件信息错误:" + taskResult.Exception.Message);
                        logger.Error("ExecuteCommand failed: " + taskResult.Exception.ToString());
                        return;
                    }
                    List <DeviceOutput> devices = taskResult.Result;

                    if (devices == null || devices.Count == 0)
                    {
                        MessageBox.Show("没有找到任何满足条件的硬件,请检查目标机器配置");
                        logger.Warning("没有找到任何满足条件的硬件,请检查目标机器配置");
                        return;
                    }

                    cBxTargetDevice.Items.Clear();
                    cBxTargetDeviceEth.Items.Clear();
                    logger.Trace("Got Devices count: " + devices.Count);
                    foreach (DeviceOutput deviceOut in devices)
                    {
                        MinerDevice device = new MinerDevice(deviceOut.DeviceId, deviceOut.DisplayName, deviceOut.DeviceVersion, deviceOut.DriverVersion);
                        displayedDeviceList.Add(device);
                        cBxTargetDevice.Items.Add(device.DisplayName);
                        cBxTargetDeviceEth.Items.Add(device.DisplayName);

                        createdClient.Machine.Devices.Add(device);
                    }
                }
                    ).Execute();
            }
        }
        /// <summary>
        /// Check the existance of the client, and check version/config if exists
        /// </summary>
        private void StepOne_ValidateTargetPath()
        {
            logger.Trace("Start StepOne_ValidateTargetPath.");

            string username = createdClient.Machine.Credential?.UserName;
            string password = createdClient.Machine.Credential?.LoginPlainPassword;

            networkFileAccess = new NetworkFileAccess(createdClient.MachineFullName, username, password);

            try
            {
                networkFileAccess.EnsureDirectory(createdClient.DeploymentFolder);

                while (networkFileAccess.DirectoryExists(createdClient.BinaryPath))
                {
                    createdClient.GenerateFolderSuffix();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("目标路径错误:" + ex.Message);
                logger.Error("Got Exception while creating directory: " + ex.ToString());

                // Enable the UI
                btnStepOneNext.IsEnabled = true;
                return;
            }

            // Testing Remote Powershell Connection
            try
            {
                TargetMachineExecutor executor = TargetMachineExecutor.GetExecutor(createdClient.MachineFullName);
                if (username != null)
                {
                    executor.SetCredential(username, password);
                }

                executor.TestConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show("目标机器远程执行测试失败,请按照文档先在目标机器上执行XDaggerMinerAssistant.");
                logger.Error("Got Exception while testing remote powershell: " + ex.ToString());

                // Enable the UI
                btnStepOneNext.IsEnabled = true;
                return;
            }

            /*
             * BackgroundWork<bool>.CreateWork(
             *  this,
             *  () => {
             *      ShowProgressIndicator("正在扫描已存在矿机", btnStepOneNext);
             *  },
             *  () => {
             *      logger.Trace("Start scanning existing services on target machine.");
             *      return ServiceUtils.HasExistingService(createdClient.MachineFullName);
             *  },
             *  (taskResult) => {
             *
             *      HideProgressIndicator();
             *
             *      bool hasExistingService = false;
             *      if (taskResult.HasError)
             *      {
             *          //// MessageBox.Show("扫描目标机器错误:" + taskResult.Exception.ToString());
             *          logger.Error("Scann finished with error: " + taskResult.Exception.ToString());
             *      }
             *      else
             *      {
             *          hasExistingService = taskResult.Result;
             *      }
             *
             *      if (hasExistingService)
             *      {
             *          logger.Warning("Scann finished miner instance found.");
             *
             *          MessageBoxResult result = MessageBox.Show("检测到目标机器上已有矿机,确定要装新的矿机吗?", "确认", MessageBoxButton.YesNo);
             *          if (result == MessageBoxResult.No)
             *          {
             *              logger.Information("User cancelled while prompting install new instance.");
             *              btnStepOneNext.IsEnabled = true;
             *              return;
             *          }
             *      }
             *
             *      btnStepOneNext.IsEnabled = true;
             *      SwitchUIToStep(2);
             *  }
             *  ).Execute();
             */

            btnStepOneNext.IsEnabled = true;
            SwitchUIToStep(2);
        }