private void EstablishConnectionToServer() { ConnectionManager.Instance.DisconnectEvent += OnDisconnected; ConnectionManager.Instance.AcknowledgeEvent += OnAcknowledge; string username; string userPassword; string mailServerName; if (IsFileMailServerExists() == false) { Login login = new Login(); Hide(); login.ShowDialog(); Show(); } else { string combinedPath = Path.Combine(_mainEmailsPath, "mailServer.dat"); using (FileStream fileStream = new FileStream(combinedPath, FileMode.Open)) { //StringFormatter BinaryFormatter binaryFormatter = new BinaryFormatter(); string userDetails = binaryFormatter.Deserialize(fileStream).ToString(); //handling an empty file text List<string> userDetailsList = userDetails.Split(';').ToList<string>(); username = userDetailsList[0].Substring(2, userDetailsList[0].Length - 4); userPassword = userDetailsList[1]; mailServerName= userDetailsList[2]; //check isUserValid and remove "connect" and then ConnectionManager.Instance.Init(mailServerName, username, userPassword); } } }
private void OnDisconnected() { MessageBox.Show("Username or password are incorrect, please try logging in again."); Login login = new Login(); login.Show(); login.Focus(); }