public void Load()
        {
            var content = File.ReadAllText(path);

            var fans = fansRegex.Matches(content)
                       .Cast <Match>()
                       .Select(m => new Fan
            {
                Id      = m.Groups["id"].Value,
                Name    = m.Groups["name"].Value,
                Active  = bool.Parse(m.Groups["active"].Value),
                Logged  = bool.Parse(m.Groups["logged"].Value),
                Variate = bool.Parse(m.Groups["variate"].Value),
                Min     = int.Parse(m.Groups["min"].Value),
                Max     = int.Parse(m.Groups["max"].Value),
            })
                       .ToDictionary(f => f.Id);


            var temps = tempRegex.Matches(content)
                        .Cast <Match>()
                        .Select(m => new Temp
            {
                Id     = m.Groups["id"].Value,
                Name   = m.Groups["name"].Value,
                Active = bool.Parse(m.Groups["active"].Value),
            })
                        .Where(t => t.Active)
                        .ToDictionary(t => t.Id);

            var controllers = fanControllerRegex.Matches(content)
                              .Cast <Match>()
                              .Select(m => new FanController
            {
                Id     = m.Groups["id"].Value,
                Name   = m.Groups["name"].Value,
                Active = bool.Parse(m.Groups["enabled"].Value),
                Fan    = fans[m.Groups["pwm"].Value],
                Method = (Methods)int.Parse(m.Groups["method"].Value)
            })
                              .ToDictionary(fc => fc.Id);

            var controllerTempsCollection = controllers.Values.ToDictionary(c => c.Id, c => new List <FanControllerTemp>());

            var controllerTemps = fanControllerTempRegex.Matches(content)
                                  .Cast <Match>()
                                  .Select(m =>
            {
                var temp = new FanControllerTemp(temps[m.Groups["temp"].Value])
                {
                    MinTemp    = int.Parse(m.Groups["min"].Value),
                    MaxTemp    = int.Parse(m.Groups["max"].Value),
                    Hysteresis = int.Parse(m.Groups["hysteresis"].Value),
                    PointsRaw  = m.Groups["points"].Value
                };
                controllerTempsCollection[m.Groups["id"].Value].Add(temp);
                return(temp);
            })
                                  .ToList();

            var curves = controllerTemps
                         .GroupBy(ct => ct.PointsRaw)
                         .Select(g => new Curve(g.Key, g.Key.Split(' ').Select(int.Parse).ToList()))
                         .ToDictionary(c => c.Id);

            Fans = fans
                   .Values;

            Curves = curves
                     .Values
                     .ToList();

            Temps = temps
                    .Values;

            Config = controllers.Values.Select(c => new FanControllerConfig
            {
                Controller = c,
                Curves     = controllerTempsCollection[c.Id]
                             .GroupBy(t => t.PointsRaw)
                             .Select(g => new CurveConfig(curves[g.Key], g.ToList()))
                             .ToList()
            })
                     .ToList();
        }
Beispiel #2
0
 public FanControllerTempViewModel(FanControllerTemp model, CurveConfig config)
 {
     this.model  = model;
     this.config = config;
     Name        = model.Temp.Name;
 }