public void UpdateBoothPairing(string com_port, string booth_label) { var pairing = BoothPairings.Where(x => x.ComPort.Equals(com_port)).FirstOrDefault(); if (pairing != null) { //If the booth pairing already exists in our collection, let's update it. pairing.BoothLabel = booth_label; pairing.LastUpdated = DateTime.Now; } else { //Otherwise, create a new booth pairing to be stored. BoothPairing new_pairing = new BoothPairing(booth_label, com_port, DateTime.Now); BoothPairings.Add(new_pairing); } }
public void ReadBoothPairings() { string booth_pairings_file_name = _booth_pairings_file_name; FileInfo booth_pairings_file_info = new FileInfo(booth_pairings_file_name); if (booth_pairings_file_info.Exists) { //Open a stream to read the booth pairings configuration file try { //Load the configuration file List <string> lines = TxBDC_Common.ConfigurationFileLoader.LoadConfigurationFile(booth_pairings_file_name); //Now parse the input for (int i = 0; i < lines.Count; i++) { string thisLine = lines[i]; string[] splitString = thisLine.Split(new char[] { ',' }, 4); string booth_name = splitString[0].Trim(); string com_port = splitString[1].Trim(); DateTime last_updated = DateTime.MinValue; //Parse out the "last updated" date and time if it exists if (splitString.Length >= 3) { string last_updated_string = splitString[2].Trim(); last_updated = DateTime.Parse(last_updated_string); } //Instantiate a booth pairing object BoothPairing pairing = new BoothPairing(booth_name, com_port, last_updated); //Add the booth pairing to our set BoothPairings.Add(pairing); } } catch { //empty } } }