Example #1
0
        private void StepThree_CopyBinary_Sync()
        {
            int startedWorkCount  = 0;
            int finishedWorkCount = 0;

            foreach (MinerClient client in createdClients)
            {
                if (client.CurrentDeploymentStatus == MinerClient.DeploymentStatus.Downloaded)
                {
                    continue;
                }

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

                NetworkFileAccess fileAccess = new NetworkFileAccess(client.MachineFullName, username, password);


                startedWorkCount++;
                BackgroundWork <int> .CreateWork(this, () => { },
                                                 () => {
                    if (fileAccess.DirectoryExists(client.BinaryPath))
                    {
                        if (client.HasFolderSuffix && client.CurrentDeploymentStatus == MinerClient.DeploymentStatus.Downloaded)
                        {
                            logger.Information($"Directory {client.BinaryPath} on machine {client.MachineFullName} already exists, so skip copying.");
                            return(0);
                        }
                        else
                        {
                            client.GenerateFolderSuffix();
                        }
                    }

                    fileAccess.DirectoryCopy(winMinerBinary.ExtractedBinaryPath, client.BinaryPath);
                    return(0);
                },
                                                 (taskResult) => {
                    finishedWorkCount++;
                    if (taskResult.HasError)
                    {
                        logger.Error("Got error while copying binaries: " + taskResult.Exception.ToString());
                    }
                    else
                    {
                        client.CurrentDeploymentStatus = MinerClient.DeploymentStatus.Downloaded;
                        dataGridMachineDeployment.Refresh();
                    }
                }
                                                 ).Execute();
            }

            while (finishedWorkCount < startedWorkCount)
            {
                Thread.Sleep(30);
            }
        }
Example #2
0
        public void DeleteBinaries()
        {
            if (this.CurrentDeploymentStatus < DeploymentStatus.Downloaded)
            {
                // There should not be binaries, just ignore
                this.CurrentDeploymentStatus = DeploymentStatus.NotExist;
                return;
            }

            try
            {
                string username = this.Machine?.Credential?.UserName;
                string password = this.Machine?.Credential?.LoginPlainPassword;

                NetworkFileAccess fileAccess = new NetworkFileAccess(this.MachineFullName, username, password);
                fileAccess.DirectoryDelete(BinaryPath);

                this.CurrentDeploymentStatus = MinerClient.DeploymentStatus.NotExist;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <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);
        }
Example #4
0
        public void DoWork()
        {
            startedWorksCount  = 0;
            finishedWorksCount = 0;

            foreach (KeyValuePair <string, MachineConnectivity> keyValue in connectivityResults)
            {
                MachineConnectivity connectivity = keyValue.Value;

                if (connectivity.CanPing ?? false)
                {
                    continue;
                }

                startedWorksCount++;

                string machineName = keyValue.Key;
                BackgroundWork <bool> .CreateWork(window, () => { },
                                                  () =>
                {
                    return(PingUtil.PingHost(machineName));
                },
                                                  (taskResult) =>
                {
                    bool result = false;
                    if (taskResult.HasError)
                    {
                        result = false;
                    }
                    else
                    {
                        result = taskResult.Result;
                    }

                    ConsolidatePingResult(machineName, result);
                }
                                                  ).Execute();
            }

            foreach (KeyValuePair <string, MachineConnectivity> keyValue in connectivityResults)
            {
                MachineConnectivity connectivity = keyValue.Value;

                if (connectivity.CanRemotePathAccess ?? false)
                {
                    continue;
                }

                startedWorksCount++;

                string machineName = keyValue.Key;
                string userName    = connectivity.Machine.Credential?.UserName;
                string password    = connectivity.Machine.Credential?.LoginPlainPassword;

                NetworkFileAccess fileAccess = new NetworkFileAccess(machineName, userName, password);

                BackgroundWork.CreateWork(window, () => { },
                                          () =>
                {
                    fileAccess.EnsureDirectory(testingFolderPath);
                    fileAccess.CanAccessDirectory(testingFolderPath);
                    return(0);
                },
                                          (taskResult) =>
                {
                    bool result = true;
                    if (taskResult.HasError)
                    {
                        logger.Error($"Testing of RemotePathAccess failed for machine [{ machineName }]. Message: { taskResult.Exception.ToString() }");
                        result = false;
                    }

                    ConsolidateRemotePathAccessResult(machineName, result);
                }
                                          ).Execute();
            }

            foreach (KeyValuePair <string, MachineConnectivity> keyValue in connectivityResults)
            {
                MachineConnectivity connectivity = keyValue.Value;
                MinerMachine        machine      = connectivity.Machine;
                if (connectivity.CanRemotePowershell ?? false)
                {
                    continue;
                }

                startedWorksCount++;

                string machineName = keyValue.Key;

                BackgroundWork.CreateWork(window, () => { },
                                          () =>
                {
                    TargetMachineExecutor executor = TargetMachineExecutor.GetExecutor(machineName);
                    if (machine.Credential != null)
                    {
                        executor.SetCredential(machine.Credential.UserName, machine.Credential.LoginPlainPassword);
                    }

                    executor.TestConnection();
                    return(0);
                },
                                          (taskResult) =>
                {
                    bool result = true;
                    if (taskResult.HasError)
                    {
                        logger.Error($"Testing of RemotePathAccess failed for machine [{ machineName }]. Message: { taskResult.Exception.ToString() }");
                        result = false;
                    }

                    ConsolidateRemotePowershellResult(machineName, result);
                }
                                          ).Execute();
            }

            while (finishedWorksCount < startedWorksCount)
            {
                Thread.Sleep(30);
            }
        }