private List <ISensor> UpdateSensors()
        {
            _computer.Accept(_updateVisitor);

            var sensors = new List <ISensor>();
            var visitor = new SensorVisitor(s => { if (s.Identifier.ToString().Contains("cpu"))
                                                   {
                                                       sensors.Add(s);
                                                   }
                                            });

            visitor.VisitComputer(_computer);

            return(sensors);
        }
예제 #2
0
        private bool OpenExistingLogFile()
        {
            if (!File.Exists(fileName))
            {
                return(false);
            }

            try
            {
                string line;
                using (var reader = new StreamReader(fileName))
                    line = reader.ReadLine();

                if (string.IsNullOrEmpty(line))
                {
                    return(false);
                }

                identifiers = line.Split(',').Skip(1).ToArray();
            }
            catch
            {
                identifiers = null;
                return(false);
            }

            if (identifiers.Length == 0)
            {
                identifiers = null;
                return(false);
            }

            sensors = new ISensor[identifiers.Length];
            var visitor = new SensorVisitor(sensor =>
            {
                for (var i = 0; i < identifiers.Length; i++)
                {
                    if (sensor.Identifier.ToString() == identifiers[i])
                    {
                        sensors[i] = sensor;
                    }
                }
            });

            visitor.VisitComputer(computer);
            return(true);
        }
예제 #3
0
        private void CreateNewLogFile()
        {
            IList <ISensor> list    = new List <ISensor>();
            SensorVisitor   visitor = new SensorVisitor(sensor =>
            {
                list.Add(sensor);
            });

            visitor.VisitComputer(computer);
            sensors     = list.ToArray();
            identifiers = sensors.Select(s => s.Identifier.ToString()).ToArray();

            using (StreamWriter writer = new StreamWriter(fileName, false))
            {
                writer.Write(",");
                for (int i = 0; i < sensors.Length; i++)
                {
                    writer.Write(sensors[i].Identifier);
                    if (i < sensors.Length - 1)
                    {
                        writer.Write(",");
                    }
                    else
                    {
                        writer.WriteLine();
                    }
                }

                writer.Write("Time,");
                for (int i = 0; i < sensors.Length; i++)
                {
                    writer.Write('"');
                    writer.Write(sensors[i].Name);
                    writer.Write('"');
                    if (i < sensors.Length - 1)
                    {
                        writer.Write(",");
                    }
                    else
                    {
                        writer.WriteLine();
                    }
                }
            }
        }
예제 #4
0
        public InfluxDBWrapper(Computer computer, string host, int port)
        {
            this.host     = host;
            this.port     = port;
            this.database = "ohm";

            this.computer = computer;
            this.computer.HardwareAdded   += HardwareAdded;
            this.computer.HardwareRemoved += HardwareRemoved;

            IList <ISensor> list    = new List <ISensor>();
            SensorVisitor   visitor = new SensorVisitor(sensor => {
                list.Add(sensor);
            });

            visitor.VisitComputer(computer);
            sensors     = list.ToArray();
            identifiers = sensors.Select(s => s.Identifier.ToString()).ToArray();
        }