/// <summary> /// Extract saved sessions from SavedConnectionInfo data structure to the List of Dictionaries (hashes). /// This data structure is used to fill GlobalVar.ConfigSessionsData at the program startup. Later, /// it is used to check whether there were any configuration changes. /// </summary> /// <param name="sessions"></param> /// <returns></returns> public List <Dictionary <string, object> > ExtractConfigSessionsData(SavedConnectionInfo sessions) { List <Dictionary <string, object> > ConfigSessionsData = new List <Dictionary <string, object> >(); for (int i = 0; i < sessions.hostnames.Count; i++) { string password = null; if (sessions.passwords[i] == null) { password = "******"; } else { password = sessions.passwords[i]; } ConfigSessionsData.Add(new Dictionary <string, object>() { { "hostname", sessions.hostnames[i] }, { "username", sessions.usernames[i] }, { "password", password }, { "c_count", sessions.counts[i] }, { "group", (sessions.groups[i] == null ? " " : sessions.groups[i]) }, { "sub_group", (sessions.sub_groups[i] == null ? " " : sessions.sub_groups[i]) } }); } return(ConfigSessionsData); }
/// <summary> /// Get saved sessions from sessions.xml configuration file. /// </summary> /// <returns>Class with Lists of sessions conenction info</returns> public SavedConnectionInfo get_Sessions() { SavedConnectionInfo xml_connection_info = new SavedConnectionInfo(); String filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PuTTYStorm", "sessions.xml"); try { using (XmlReader reader = XmlReader.Create(filePath)) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "hostname": if (reader.Read()) { xml_connection_info.hostnames.Add(reader.Value); } break; case "username": if (reader.Read()) { xml_connection_info.usernames.Add(reader.Value); } break; case "password": if (reader.Read()) { // Handle passwordless login if (reader.Value == " ") { xml_connection_info.passwords.Add(null); } else { xml_connection_info.passwords.Add(AESEncryptDecrypt.Decrypt(reader.Value)); } } break; case "count": if (reader.Read()) { xml_connection_info.counts.Add(reader.Value); } break; case "group": if (reader.Read()) { if (reader.Value == " ") { xml_connection_info.groups.Add(null); } else { xml_connection_info.groups.Add(reader.Value); } } break; case "subgroup": if (reader.Read()) { if (reader.Value == " ") { xml_connection_info.sub_groups.Add(null); } else { xml_connection_info.sub_groups.Add(reader.Value); } } break; } } } } } catch (Exception e) { MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } return(xml_connection_info); }