コード例 #1
0
        public void LoadCurrentInfo()
        {
            logger.Information("Start LoadCurrentInfo.");

            // Fill the rich object data to each object
            foreach (MinerMachine machine in managerInfo.Machines)
            {
                if (!string.IsNullOrEmpty(machine.CredentialId))
                {
                    MachineCredential credential = managerInfo.Credentials.FirstOrDefault(c => c.Id == machine.CredentialId);
                    if (credential == null)
                    {
                        throw new InvalidDataException($"LoadCurrentInfo error: cannot find CredentialId { machine.CredentialId } in ManagerInfo.");
                    }

                    machine.Credential = credential;
                }
            }

            foreach (MinerClient client in managerInfo.Clients)
            {
                MinerMachine machine = managerInfo.Machines.FirstOrDefault(m => m.FullName == client.MachineFullName);
                if (machine == null)
                {
                    throw new InvalidDataException($"LoadCurrentInfo error: cannot find machine with name { client.MachineFullName } in ManagerInfo.");
                }

                client.Machine = machine;
            }
        }
コード例 #2
0
        public void AddClient(MinerClient client)
        {
            logger.Information("Start AddClient.");

            if (client == null)
            {
                logger.Error("New Client should not be null");
                throw new ArgumentNullException("New Client should not be null");
            }

            if (client.Machine == null)
            {
                logger.Error("New Client Machine should not be null");
                throw new ArgumentNullException("New Client Machine should not be null");
            }

            client.StatusChanged  += ClientStatusChanged;
            client.MachineFullName = client.Machine.FullName;

            MinerMachine      newMachine    = client.Machine;
            MachineCredential newCredential = newMachine.Credential;

            if (newCredential != null)
            {
                newMachine.CredentialId = managerInfo.AddOrUpdateCredential(newMachine.Credential);
            }

            managerInfo.AddOrUpdateMachine(newMachine);

            this.ClientList.Add(client);
            this.SaveCurrentInfo();
        }