private void ContactsList_Load(object sender, EventArgs e) { string nickname = "WhatsAPINet"; this.username = this.getUsername(); this.password = this.GetPassword(); if (!this.checkCredentials()) { bool validCredentials = false; do { //throw new Exception("Please enter credentials!"); WappCredentials creds = new WappCredentials(); DialogResult r = creds.ShowDialog(); if (r != System.Windows.Forms.DialogResult.OK) { //cancelled, close application Application.Exit(); return; } this.username = this.getUsername(); this.password = this.GetPassword(); if (!string.IsNullOrEmpty(this.username) && !string.IsNullOrEmpty(this.password)) { WappSocket.Create(username, password, "WinApp.NET", false); WappSocket.Instance.Connect(); WappSocket.Instance.Login(); if (WappSocket.Instance.ConnectionStatus == WhatsAppApi.WhatsApp.CONNECTION_STATUS.LOGGEDIN) { validCredentials = true; //write to config Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); AppSettingsSection app = config.AppSettings; app.Settings.Remove("Username"); app.Settings.Add("Username", this.username); app.Settings.Remove("Password"); app.Settings.Add("Password", this.password); config.Save(ConfigurationSaveMode.Modified); } else { WappSocket.Instance.Disconnect(); } } } while (!validCredentials); } ContactStore.CheckTable(); MessageStore.CheckTable(); WappSocket.Create(this.username, this.password, nickname, true); WappSocket.Instance.Connect(); WappSocket.Instance.Login(); WappSocket.Instance.sendNickname(nickname); WAlistener = new Thread(new ThreadStart(Listen)); WAlistener.IsBackground = true; WAlistener.Start(); //this.SyncWaContactsAsync(); Thread t = new Thread(new ThreadStart(SyncWaContactsAsync)); t.IsBackground = true; t.Start(); Thread alive = new Thread(new ThreadStart(KeepAlive)); alive.IsBackground = true; alive.Start(); int vertScrollWidth = SystemInformation.VerticalScrollBarWidth; this.flowLayoutPanel1.Padding = new Padding(0, 0, vertScrollWidth, 0); }
void Instance_OnLoginFailed(string data) { if (data == "not-authorized") { //show reg form WappCredentials creds = new WappCredentials(); DialogResult r = creds.ShowDialog(); if (r != System.Windows.Forms.DialogResult.OK) { //cancelled, close application Application.Exit(); return; } this.username = this.getUsername(); this.password = this.GetPassword(); if (!string.IsNullOrEmpty(this.username) && !string.IsNullOrEmpty(this.password)) { WappSocket.Create(this.username, this.password, "WinApp.NET", true); this.bindAll(); WappSocket.Instance.Connect(); } } if (data == "blocked") { throw new Exception("blocked!"); } }