public static void ReadConfiguration(String Configfilename) { if (File.Exists(Configfilename)) { // get all lines from the String[] PowerSensorConfigFileContent = File.ReadAllLines(Configfilename); Int32 LineNumber = 0; foreach (String LineElement in PowerSensorConfigFileContent) { String[] TokenizedLine = LineElement.Split(new char[1] { ' ' }); LineNumber++; if (!LineElement.StartsWith("#")) { PowerConsumptionSensor NewElement = new PowerConsumptionSensor(); if (TokenizedLine.Length == 4) { NewElement.PowerSensorName = TokenizedLine[0]; NewElement.InitialPowerSensorValue = Convert.ToDouble(TokenizedLine[2]); NewElement.Corrector = Convert.ToDouble(TokenizedLine[3]); if (DateTime.TryParse(TokenizedLine[1].Replace('_', ' '), out NewElement.InitialPowerSensorDate)) { PowerConsumptionSensors.Add(NewElement); } else { throw (new Exception("Power Sensor Configuration File - Error in line " + LineNumber + " - Could not parse DateTime")); } } else { throw (new Exception("Power Sensor Configuration File - Error in line " + LineNumber)); } } } } else { throw (new Exception("Power Sensor Configuration File not found!")); } }
public static void ReadConfiguration(String Configfilename) { if (File.Exists(Configfilename)) { // get all lines from the String[] PowerSensorConfigFileContent = File.ReadAllLines(Configfilename); Int32 LineNumber = 0; foreach (String LineElement in PowerSensorConfigFileContent) { String[] TokenizedLine = LineElement.Split(new char[1] { ' ' }); LineNumber++; if (!LineElement.StartsWith("#")) { PowerConsumptionSensor NewElement = new PowerConsumptionSensor(); if (TokenizedLine.Length == 4) { NewElement.PowerSensorName = TokenizedLine[0]; NewElement.InitialPowerSensorValue = Convert.ToDouble(TokenizedLine[2]); NewElement.Corrector = Convert.ToDouble(TokenizedLine[3]); if (DateTime.TryParse(TokenizedLine[1].Replace('_',' '), out NewElement.InitialPowerSensorDate)) { PowerConsumptionSensors.Add(NewElement); } else throw (new Exception("Power Sensor Configuration File - Error in line "+LineNumber+" - Could not parse DateTime")); } else throw (new Exception("Power Sensor Configuration File - Error in line "+LineNumber)); } } } else { throw (new Exception("Power Sensor Configuration File not found!")); } }