Ejemplo n.º 1
0
        public Worker(
            ILogger <Worker> logger,
            IOptions <Settings> settings,
            IHostEnvironment environment)
        {
            _logger      = logger;
            _environment = environment;
            _settings    = settings.Value;
            this.ipmiFanControlClients = new Dictionary <string, IPMIFanControlClient>();
            this.tempClients           = new Dictionary <string, TemperatureClient>();
            this._lastTenTempsCache    = new Dictionary <string, List <int> >();

            if (_settings.HostSettings == null)
            {
                throw new Exception("no config found!");
            }

            foreach (var hostSetting in _settings.HostSettings)
            {
                if (this._lastTenTempsCache.ContainsKey(hostSetting.Name))
                {
                    throw new Exception("Duplicate client name detected.");
                }

                this._lastTenTempsCache.Add(hostSetting.Name, new List <int>(_settings.RollingAverageNumberOfTemps));

                var fanControlClient = new IPMIFanControlClient()
                {
                    _logger = logger,
                    PathToIpmiToolIfNotDefault = hostSetting.PathToIpmiToolIfNotDefault,
                    Platform     = this._settings.Platform,
                    IpmiHost     = hostSetting.Host,
                    IpmiUser     = hostSetting.User,
                    IpmiPassword = hostSetting.Password,
                };
                this.ipmiFanControlClients.Add(hostSetting.Name, fanControlClient);

                TemperatureClient client = null;
                if (string.Compare(hostSetting.Type, "ipmi", true) == 0)
                {
                    client = new TemperatureIpmiClient(fanControlClient, hostSetting.RegexToRetrieveTemp,
                                                       CheckTemperatureControlCommand);
                }
                else if (string.Compare(hostSetting.Type, "ssh_lm_sensors", true) == 0)
                {
                    client = new TemperatureLMSensorsClient(hostSetting.LMHost, hostSetting.LMUser, hostSetting.LMPassword,
                                                            hostSetting.RegexToRetrieveTemp, this._logger);
                }
                else
                {
                    throw new Exception("no match host type");
                }

                this.tempClients.Add(hostSetting.Name,
                                     client);
            }
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                var temperatureObject = await TemperatureClient.DeleteTemperature(id);

                if (temperatureObject != null)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(temperatureObject));
                }
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
        public async Task <ActionResult> Edit(TemperatureModel temperatureModel)
        {
            try
            {
                var temperatureObject = await TemperatureClient.PutTemperature(temperatureModel.TemperatureId, temperatureModel);

                if (temperatureObject != null)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(temperatureObject));
                }
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
        // GET: Temperatures/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            var temperatureObject = await TemperatureClient.GetTemperature(id);

            return(View(temperatureObject));
        }
        // GET: Temperatures
        public async Task <ActionResult> Index()
        {
            var temperatureObjects = await TemperatureClient.GetTemperatures();

            return(View(temperatureObjects));
        }