Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
            }
        }