private void GetData(object sender, ElapsedEventArgs e) { lock (Lock) { foreach (var counterSet in CountersSets) { foreach (var counter in counterSet.CounterDatas) { counter.Value = counter.Counter.NextSample().RawValue; counter.Count = (long)((counter.Value - counter.OldValue) * Ratio); counter.OldValue = counter.Value; CounterResults.ExtensionAdd(counter.EquipmentName + counter.CounterName, new CountersResult(counter)); } } GotData?.Invoke(CounterResults.Values.ToList()); } }
internal static void InvokeGotData(object messageBuffer, int index, int length) { GotData?.Invoke(null, new GotDataEventArgs((MessageBuffer)messageBuffer, index, length)); }
/// <summary> /// returns true if more data to process, false otherwise /// </summary> /// <returns></returns> public bool NextDataPoint() { //Check if we have header of file if (!_haveheader) { ReadHeader(); } try { // get line type byte linetype = ReadByte(); // prepare a datapoiny DataPoint d; // get the tick switch (linetype) { case DataConst.EndData: return(false); case DataConst.StartData: return(true); case DataConst.FileVersion: return(true); case DataConst.DatapointStart: { //Get data point data List <byte> data = new List <byte>(); bool ended = false; while (!ended) { var lastbyte = ReadByte(); if (lastbyte == DataConst.DatapointEnd) { ended = true; } else { data.Add(lastbyte); } } //Convert data d = DataPointImpl.Deserialize(data.ToArray(), true); } ; break; default: { // weird data, try to keep reading ReadByte(); // but don't send this data, just get next record return(true); } } // send any data we have if (d != null) { GotData?.Invoke(this, d); } // count it Count++; // assume there is more return(true); } catch (EndOfStreamException) { return(false); } catch (ObjectDisposedException) { return(false); } catch (Exception exc) { _log.Error(exc, $"Unexpected error while reading file in datareader: {exc.Message}"); return(false); } }
private static void Timer_Elapsed(object sender, ElapsedEventArgs e) { try { computer.Accept(updateVisitor); for (int i = 0; i < computer.Hardware.Length; i++) { for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++) { switch (computer.Hardware[i].Sensors[j].SensorType) { case SensorType.Voltage: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "V"); break; case SensorType.Clock: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "MHz"); break; case SensorType.Fan: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "RPM"); break; case SensorType.Flow: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "L/h"); break; case SensorType.Power: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "W"); break; case SensorType.Data: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "GB"); break; case SensorType.Factor: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, ""); break; case SensorType.SmallData: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "MB"); break; case SensorType.Temperature: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "°C"); break; case SensorType.Throughput: if (computer.Hardware[i].Sensors[j].Value < 1) { PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value * 0x400 ?? 0, "KB/s"); } else { PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "MB/s"); } break; default: PerformanceDatas.ADD(computer.Hardware[i].Sensors[j].Name, computer.Hardware[i].Sensors[j].SensorType, computer.Hardware[i].Sensors[j].Value ?? 0, "%"); break; } } } GotData?.Invoke(); } catch {} }