public GoogleDownloadController(AccountDB acc, AccountDownloadListener notify) { //browser = webBrowser; browser = new WebBrowser(); Init(acc, notify); SetupWebBrowser(); }
public bool IsDownloadingForAccount(AccountDB acc) { if(acc.Username.Equals(account.Username) && acc.AccountTypeId == account.AccountTypeId) { return true; } return false; }
public LiveHotmailDownloadController(AccountDB acc, AccountDownloadListener notify) { browser = new WebBrowser(); Init(acc, notify); browser.ScriptErrorsSuppressed = true; browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted); timer = new System.Timers.Timer(1000); timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); scope = "wl.basic%20wl.contacts_emails%20wl.contacts_phone_numbers"; }
public bool SameWith(AccountDB acc) { if (acc == null) { return false; } if (String.Compare(username, acc.Username) == 0 && accountTypeId == acc.AccountTypeId) { return true; } return false; }
// import from account public void DoDownloadContacts(AccountDB account) { panel_account.Visible = false; panel_status.Visible = true; panel_status.Location = new Point(0, 0); label_account_type.Text = account.AccountTypeName; label_account.Text = account.Username; downloadController.DownloadContacts(account, this); }
protected void Init(AccountDB acc, AccountDownloadListener notify) { this.account = acc; if (acc.HostType == HostType.TYPE_EXCHANGE_SERVER || acc.HostType == HostType.TYPE_OFFICE_365) { MAX_PROCESSING_SLEEP_COUNT = 360; // 360 x 500 = 180000: 3 minutes } this.listener = notify; AddNotifyStatusListener(notify); }
public void CheckUnExpectedPageForAccount(AccountDB account) { int len = listDownloadController.Count(); DownloadController controller; for (int i = 0; i < len; i++) { controller = listDownloadController[i]; if (controller.Account == account) { controller.CheckUnExpectedPage(); return; } } }
public void DownloadContacts(AccountDB acc, AccountDownloadListener notify) { HostType hostType = acc.HostType; DownloadController hostDownload = null; // remove old DownloadController first string username = acc.Username; int accTypeId = acc.AccountTypeId; DownloadController downloadController; AccountDB acc2; int len = listDownloadController.Count(); for (int i = 0; i < len; i++) { downloadController = listDownloadController[i]; acc2 = downloadController.Account; if (acc.SameWith(acc2)) { listDownloadController.RemoveAt(i); break; } } switch (hostType) { case HostType.TYPE_GMAIL: hostDownload = new GoogleDownloadController(acc, notify); break; case HostType.TYPE_YAHOO: hostDownload = new YahooDownloadController(acc, notify); break; case HostType.TYPE_LIVE_HOTMAIL: hostDownload = new LiveHotmailDownloadController(acc, notify); break; case HostType.TYPE_ICLOUD: hostDownload = new ICloudDownloadController(acc, notify); break; case HostType.TYPE_OUTLOOK: hostDownload = new OutlookDownloadController(acc, notify); break; case HostType.TYPE_EXCHANGE_SERVER: hostDownload = new ExchangeDownloadController(acc, notify); break; case HostType.TYPE_OFFICE_365: hostDownload = new Office365DownloadController(acc, notify); break; } if (hostDownload != null) { listDownloadController.Add(hostDownload); hostDownload.DownloadContacts(); } }
public bool IsDownloadUnExpectedPage(AccountDB acc) { DownloadController downloadController; int len = listDownloadController.Count(); for (int j = 0; j < len; j++) { downloadController = listDownloadController[j]; if (downloadController.Account == acc && downloadController.IsDownloadGotUnexpectedPage()) { return true; } } return false; }
public void CancelDownload(AccountDB acc) { int len = listDownloadController.Count(); DownloadController controller; for(int i = 0; i < len; i++) { controller = listDownloadController[i]; if(controller.IsDownloadingForAccount(acc)) { controller.CancelDownload(); return; } } }
public ExchangeDownloadController(AccountDB acc, AccountDownloadListener notify) { Init(acc, notify); ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; }
private void btn_ok_Click(object sender, EventArgs e) { DuplicateContactMode mode; if (radio_btn_allow_duplicate.Checked) { mode = DuplicateContactMode.ALLOW_ADD_NEW; } else if (radio_btn_replace_with_new.Checked) { mode = DuplicateContactMode.REPLACE_WITH_NEW_ITEM; } else { mode = DuplicateContactMode.DO_NOT_IMPORT; } dbController.UpdateDuplicateContactMode(mode); switch (importFrom) { case ImportFrom.Account: string accountText = tbox_account.Text.Trim(); if (!MyUtils.IsEmailValid(accountText)) { MessageBox.Show(ContactManagentLibrary.Properties.Resources.wrong_email_format); return; } string pass = tbox_password.Text.Trim(); if (pass.Length == 0) { MessageBox.Show(ContactManagentLibrary.Properties.Resources.please_type_password); return; } account = dbController.GetOrAddAccountByAccountText(accountText); account.Password = pass; DoDownloadContacts(account); break; case ImportFrom.File: if (String.IsNullOrEmpty(filePath)) { btn_browse_Click(null, null); return; } ImportFromFile(filePath); break; } }
public OutlookDownloadController(AccountDB acc, AccountDownloadListener notify) { Init(acc, notify); }
public AccountDB GetAccountByUserNameAndAccountTypeId(string name, int accTypeId) { string query = "SELECT * from account where username=@name and account_type_id=@accTypeId"; //Create a list to store the result AccountDB account = new AccountDB(); //Open connection if (this.OpenConnection() == true) { //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@accTypeId", accTypeId); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int id = Int32.Parse(dataReader["id"].ToString()); string password = dataReader["password"].ToString(); int account_type = Int32.Parse(dataReader["account_type_id"].ToString()); account.Id = id; account.Username = name; account.Password = password; account.AccountTypeId = account_type; break; } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return account; }
public AccountDB GetAccountByUserNameAndAccountTypeName(string username, string accountTypeName) { string query = "SELECT account.id as id, username, password, account.account_type_id as acc_type, name " + "FROM account, account_type where account.account_type_id = account_type.id and username = @username " + "and account_type.name = @account_type_name"; AccountDB account = new AccountDB(); //Open connection if (this.OpenConnection() == true) { //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@account_type_name", accountTypeName); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int id = Int32.Parse(dataReader["id"].ToString()); string password = dataReader["password"].ToString(); int account_type = Int32.Parse(dataReader["acc_type"].ToString()); string name = dataReader["name"].ToString(); account.Id = id; account.Username = username; account.Password = password; account.AccountTypeId = account_type; account.AccountTypeName = name; break; } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return account; }
public List<AccountDB> GetAllDisplayAccounts() { string query = "SELECT account.id as id, username, password, account.account_type_id as acc_type, name " + "FROM account, account_type where account.account_type_id = account_type.id and username != @self_name " + "order by account_type_id asc"; //Create a list to store the result List<AccountDB> list = new List<AccountDB>(); //Open connection if (this.OpenConnection() == true) { //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@self_name", AccountDB.SELF_ACCOUNT_NAME); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int id = Int32.Parse(dataReader["id"].ToString()); string username = dataReader["username"].ToString(); string password = dataReader["password"].ToString(); int account_type = Int32.Parse(dataReader["acc_type"].ToString()); string name = dataReader["name"].ToString(); AccountDB account = new AccountDB(); account.Id = id; account.Username = username; account.Password = password; account.AccountTypeId = account_type; account.AccountTypeName = name; list.Add(account); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return list; }
public AccountDB AddOrUpdateAccountByUserPassAccTypeId(string user, string pass, int a_type_id) { AccountDB account = new AccountDB(); //Open connection if (this.OpenConnection() == true) { string query = "SELECT * from account where username=@user and account_type_id=@a_type"; //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@user", user); cmd.Parameters.AddWithValue("@a_type", a_type_id); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); int accountId = -1; //Read the data and store them in the list while (dataReader.Read()) { accountId = Int32.Parse(dataReader["id"].ToString()); account.Id = accountId; account.Username = user; account.Password = password; account.AccountTypeId = a_type_id; break; } //close Data Reader dataReader.Close(); SQLiteTransaction trans = connection.BeginTransaction(); try { if (accountId > 0) // this account already in database, update password { SQLiteCommand comm = connection.CreateCommand(); comm.Transaction = trans; comm.CommandText = "UPDATE account SET password=@pass WHERE id=@id"; comm.Parameters.AddWithValue("@pass", pass); comm.Parameters.AddWithValue("@id", accountId); comm.ExecuteNonQuery(); account.Password = pass; } else // this account is not in database, save it { SQLiteCommand comm = connection.CreateCommand(); comm.Transaction = trans; comm.CommandText = "INSERT INTO account (username, password, account_type_id) VALUES(@user, @pass, @type)"; comm.Parameters.AddWithValue("@user", user); comm.Parameters.AddWithValue("@pass", pass); comm.Parameters.AddWithValue("@type", a_type_id); comm.ExecuteNonQuery(); SQLiteCommand lastIdComm = connection.CreateCommand(); lastIdComm.CommandText = "SELECT last_insert_rowid()"; accountId = Int32.Parse(lastIdComm.ExecuteScalar().ToString());; account.Id = accountId; account.Username = user; account.Password = pass; account.AccountTypeId = a_type_id; } trans.Commit(); } catch (Exception ex) { trans.Rollback(); } //close Connection this.CloseConnection(); } return account; }
public YahooDownloadController(AccountDB acc, AccountDownloadListener notify) { Browser = new WebBrowser(); Init(acc, notify); SetupWebBrowser(); }
public WebBrowser GetWebBrowserByAccountDB(AccountDB account) { AccountDB acc; DownloadController downloadController; int len = listDownloadController.Count(); for (int j = 0; j < len; j++) { downloadController = listDownloadController[j]; acc = downloadController.Account; if (acc.SameWith(account) && downloadController.IsDownloadGotUnexpectedPage()) { return downloadController.Browser; } } return null; }