Exemplo n.º 1
0
        public static List <MinerMachine> DetectMachinesInLocalNetwork()
        {
            List <MinerMachine> machineList = new List <MinerMachine>();

            List <string> ipAddressList = GetLocalNetworkIPs();

            foreach (string ipAddress in ipAddressList)
            {
                if (ipAddress.EndsWith(".1") || ipAddress.EndsWith(".255"))
                {
                    continue;
                }

                string name = GetMachineName(ipAddress);
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                MinerMachine machine = new MinerMachine()
                {
                    FullName = name, IpAddressV4 = ipAddress
                };
                machineList.Add(machine);
            }

            return(machineList);
        }
Exemplo n.º 2
0
 public void AddMachine(MinerMachine machine)
 {
     if (!connectivityResults.ContainsKey(machine.FullName))
     {
         connectivityResults[machine.FullName] = new MachineConnectivity(machine);
     }
 }
Exemplo n.º 3
0
        public void AddOrUpdateMachine(MinerMachine machine)
        {
            MinerMachine existingMachine = this.Machines.FirstOrDefault(m => m.FullName.Equals(machine.FullName));

            if (existingMachine != null)
            {
                // Duplicated machines, update the machine information
                if (machine.Devices.Count > existingMachine.Devices.Count)
                {
                    existingMachine.Devices = machine.Devices;
                }

                if (!string.IsNullOrEmpty(machine.IpAddressV4))
                {
                    existingMachine.IpAddressV4 = machine.IpAddressV4;
                }

                if (!string.IsNullOrEmpty(machine.CredentialId))
                {
                    existingMachine.CredentialId = machine.CredentialId;
                }
            }
            else
            {
                this.Machines.Add(machine);
            }
        }
Exemplo n.º 4
0
        private void StepFour_RetrieveDeviceList_Sync()
        {
            int startedWorkCount  = 0;
            int finishedWorkCount = 0;

            foreach (MinerClient client in createdClients)
            {
                if (client.Machine.Devices != null && client.Machine.Devices.Count > 0)
                {
                    continue;
                }

                MinerMachine existingMachine = ManagerInfo.Current.Machines.FirstOrDefault(m => m.FullName.Equals(client.Machine.FullName));
                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
                    client.Machine.Devices = existingMachine.Devices;
                }
                else
                {
                    // Didn't find the machine in cache, use Executor to retrieve it
                    startedWorkCount++;
                    BackgroundWork <List <DeviceOutput> > .CreateWork(this, () => { },
                                                                      () =>
                    {
                        return(client.ExecuteDaemon <List <DeviceOutput> >("-l"));
                    },
                                                                      (taskResult) =>
                    {
                        finishedWorkCount++;
                        if (taskResult.HasError)
                        {
                            logger.Error($"ExecuteCommand on machine [{ client.Machine.FullName }] failed: " + taskResult.Exception.ToString());
                            return;
                        }

                        client.Machine.Devices            = new List <MinerDevice>();
                        List <DeviceOutput> deviceOutputs = taskResult.Result;
                        if (deviceOutputs == null || deviceOutputs.Count == 0)
                        {
                            logger.Warning("没有找到任何满足条件的硬件,请检查目标机器配置");
                            return;
                        }

                        foreach (DeviceOutput output in deviceOutputs)
                        {
                            MinerDevice device = new MinerDevice(output.DeviceId, output.DisplayName, output.DeviceVersion, output.DriverVersion);
                            client.Machine.Devices.Add(device);
                        }
                    }
                                                                      ).Execute();
                }
            }

            while (finishedWorkCount < startedWorkCount)
            {
                Thread.Sleep(30);
            }
        }
Exemplo n.º 5
0
 public void RemoveItem(MinerMachine machine)
 {
     for (int i = 0; i < dataGridItems.Count; i++)
     {
         if (dataGridItems[i].FullName.Equals(machine.FullName))
         {
             dataGridItems.RemoveAt(i);
             return;
         }
     }
     this.dataGrid.Items.Refresh();
 }
Exemplo n.º 6
0
        private void InputMachine_OnFinished(object sender, MachineNameEventArgs e)
        {
            MinerMachine machine = new MinerMachine()
            {
                FullName = e.MachineName
            };

            AddToMachineList(new List <MinerMachine>()
            {
                machine
            });

            needRefreshMachineConnections = true;
        }
Exemplo n.º 7
0
        public static TargetMachineExecutor GetExecutor(MinerMachine machine, bool disableTrace = false)
        {
            if (machine == null)
            {
                return(null);
            }

            TargetMachineExecutor executor = GetExecutor(machine?.FullName);

            if (machine.Credential != null)
            {
                executor.SetCredential(machine.Credential.UserName, machine.Credential.LoginPlainPassword);
            }

            executor.disableTrace = disableTrace;

            return(executor);
        }
        private void btnStepOneNext_Click(object sender, RoutedEventArgs e)
        {
            logger.Trace("btnStepOneNext Clicked.");

            string targetMachineName     = txtMachineName.Text?.Trim();
            string targetMachinePath     = txtTargetPath.Text?.Trim();
            string targetMachineUserName = txtTargetUserName.Text?.Trim();
            string targetMachinePassword = txtTargetUserPassword.Password?.Trim();

            if (string.IsNullOrEmpty(targetMachineName))
            {
                MessageBox.Show("机器名不可以为空,本机名请写LOCALHOST.", "提示");
                return;
            }

            MinerMachine clientMachine = new MinerMachine()
            {
                FullName = targetMachineName.ToUpper()
            };

            if (!clientMachine.IsLocalMachine() &&
                (string.IsNullOrEmpty(targetMachineName) || string.IsNullOrEmpty(targetMachinePassword)))
            {
                MessageBox.Show("请填写用于连接目标机器的用户名和密码信息", "提示");
                return;
            }

            if (!string.IsNullOrEmpty(targetMachineUserName) && !string.IsNullOrEmpty(targetMachinePassword))
            {
                MachineCredential credential = new MachineCredential();
                credential.UserName = targetMachineUserName.ToLower();
                credential.SetLoginPassword(targetMachinePassword);
                clientMachine.Credential = credential;
            }

            createdClient = new MinerClient(clientMachine, targetMachinePath);

            // Check whether this target is already in Miner Manager Client list

            // Check the machine name and path is accessasible
            StepOne_ValidateTargetMachine();
        }
        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();
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
 public BrowseNetworkMachine(MinerMachine machine)
 {
     this.minerMachine = machine;
 }
Exemplo n.º 12
0
 public MachineDataGridItem(MinerMachine machine)
 {
     this.minerMachine = machine;
 }
Exemplo n.º 13
0
 public void AddItem(MinerMachine machine)
 {
     dataGridItems.Add(new MachineDataGridItem(machine));
     this.dataGrid.Items.Refresh();
 }