/// <summary> /// </summary> private void SaveCurrentSessionInfo() { if (GenUtil.SafeToBool(ConfigurationManager.AppSettings["disableSession"])) { return; } StreamWriter sw = null; try { string iniPath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] { '\\' }) + "\\" + "session.ini"; sw = new StreamWriter(iniPath, false); var sso = new SessionObject(); sso.txtQuery = GenUtil.NormalizeEol(txtQuery.Text); sso.txtRowLimit = GenUtil.SafeTrim(txtRowLimit.Text); sso.txtSiteUrl = GenUtil.SafeTrim(txtSiteUrl.Text); sso.txtViewAttributes = GenUtil.NormalizeEol(txtViewAttributes.Text); sso.txtViewFields = GenUtil.NormalizeEol(txtViewFields.Text); sso.txtUsername = formChooser.credUsername; sso.txtPassword = formChooser.credPassword; sso.txtDomain = formChooser.credDomain; sso.appMode = ((int)formChooser.appMode).ToString(); var xml = XmlSerialization.Serialize(sso); sw.Write(xml); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (sw != null) { sw.Dispose(); } } }
/// <summary> /// </summary> static public SessionObject GetRecentSessionInfo() { StreamReader sr = null; SessionObject sessionObject = new SessionObject(); if (GenUtil.SafeToBool(ConfigurationManager.AppSettings["disableSession"])) { return(sessionObject); } try { string iniPath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] { '\\' }) + "\\" + "session.ini"; var fi = new FileInfo(iniPath); if (fi.Exists) { sr = new StreamReader(iniPath); var content = sr.ReadToEnd(); sessionObject = XmlSerialization.Deserialize <SessionObject>(content); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (sr != null) { sr.Dispose(); } } return(sessionObject); }