/// <summary> /// Read setting from config /// </summary> /// <returns>ThermoRecord with setting values.</returns> static ThermoRecord ReadConfig() { string freezingStr = HelperAdapter.GetProperty("freezing"); string boilingStr = HelperAdapter.GetProperty("boiling"); string flunctuationStr = HelperAdapter.GetProperty("fluctuating"); ThermoItem freezingThermo = ThermoItem.getThermo(freezingStr); ThermoItem boilingThermo = ThermoItem.getThermo(boilingStr); ThermoItem flunctuationThermo = ThermoItem.getThermo(flunctuationStr); ThermoRecord thermoRecord = new ThermoRecord(boilingThermo.GetThermoInCels(), freezingThermo.GetThermoInCels(), flunctuationThermo.GetThermoInCels()); return(thermoRecord); }
/// <summary> /// Start the test /// </summary> /// <param name="args">No Args needs</param> static void Main(string[] args) { ThermoRecord thermoRecord = ReadConfig(); string ordIn = Console.ReadLine(); while (ordIn.Length != 0) { try { ThermoItem item = ThermoItem.getThermo(ordIn); Console.WriteLine(item); thermoRecord.AddRecord(item); } catch (Exception ex) { Console.WriteLine(ex.Message); } ordIn = Console.ReadLine(); } }
/// <summary> /// Get input string change to Celsius /// </summary> /// <param name="thermoStr"> input string of temperature, which allows both "50C","40 C", "45 F","556F" and so on.</param> /// <returns>The TheroItem contains Cels value.</returns> public static ThermoItem getThermo(string thermoStr) { if (thermoStr.Contains("C")) { String[] splitV = thermoStr.Trim().Split('C'); float num; bool success = float.TryParse(splitV[0], out num); if (success == true && splitV[1] == "") { ThermoItem t1 = new ThermoItem(num); return(t1); } else { throw new Exception("Not a valid format of ceisius for : " + thermoStr); } } ; if (thermoStr.Contains("F")) { String[] splitV = thermoStr.Trim().Split('F'); float num; bool success = float.TryParse(splitV[0], out num); if (success == true && splitV[1] == "") { num = (num - 32) * 5 / 9; ThermoItem t1 = new ThermoItem(num); return(t1); } else { throw new Exception("Not a valid format of Fahrenheit for : " + thermoStr); } } throw new Exception("Not a valid input : " + thermoStr); }
/// <summary> /// The logic of the alert: /// 1. In start, if not in normal status, no alert. /// 2. If in normal status, then enter abnormal status, alert. /// 3. If in abnormal status, then enter another abnormal status, alert. /// 4, If in abnormal status, then will have flunctuating to reenter normal status. /// </summary> /// <param name="item"></param> public void AddRecord(ThermoItem item) { float t = item.GetThermoInCels(); if (status == RecordStatus.Init) { if (t <= downerTriggrt) { status = RecordStatus.Freezed; } else if (t >= upperTrigger) { status = RecordStatus.Boiled; } else { status = RecordStatus.Normal; } } else { if (status == RecordStatus.Normal) { if (t <= downerTriggrt) { status = RecordStatus.Freezed; iMyAlert.Alert("Freezing"); } else if (t >= upperTrigger) { status = RecordStatus.Boiled; iMyAlert.Alert("Boiling"); } else { status = RecordStatus.Normal; } } if (status == RecordStatus.Boiled) { if (t <= downerTriggrt) { status = RecordStatus.Freezed; iMyAlert.Alert("Freezing"); } else if (t >= upperTrigger - flunctuating) { status = RecordStatus.Boiled; } else { status = RecordStatus.Normal; } } if (status == RecordStatus.Freezed) { if (t <= downerTriggrt + flunctuating) { status = RecordStatus.Freezed; } else if (t >= upperTrigger) { status = RecordStatus.Boiled; iMyAlert.Alert("Boiling"); } else { status = RecordStatus.Normal; } } } }