public GoogleDownloadController(AccountDB acc, AccountDownloadListener notify) { //browser = webBrowser; browser = new WebBrowser(); Init(acc, notify); SetupWebBrowser(); }
public YahooDownloadController(AccountDB acc, AccountDownloadListener notify) { browser = new WebBrowser(); Init(acc, notify); SetupWebBrowser(); isManual = false; }
public bool IsDownloadingForAccount(AccountDB acc) { if(acc.Username.Equals(account.Username) && acc.AccountTypeId == account.AccountTypeId) { return true; } return false; }
private void Button_Click(object sender, RoutedEventArgs e) { account = new AccountDB(); account.HostType = HostType.TYPE_OUTLOOK; //account = dbController.GetOrAddAccountByAccountText("*****@*****.**"); //account.Password = "******"; downloadController.DownloadContacts(account, this); }
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; }
public LiveHotmailDownloadController(AccountDB acc, AccountDownloadListener notify) { browser = new WebView(); Init(acc, notify); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 1); timer.Tick += OnTimedEvent; browser.NavigationCompleted += webview_NavigationCompleted; scope = "wl.basic%20wl.contacts_emails%20wl.contacts_phone_numbers"; }
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 void AddOrUpdateAccountWhenImportingFromAccount(ref AccountDB account) { var data = GetAccountByUserNameAndAccountTypeId(account.Username, account.AccountTypeId); if (OpenConnection() == true) { SQLiteTransaction trans = connection.BeginTransaction(); try { SQLiteCommand comm = connection.CreateCommand(); comm.Transaction = trans; if (data.Id == 0) { comm.CommandText = "INSERT INTO account (username, password, account_type_id) VALUES(@user, @pass, @type)"; comm.Parameters.AddWithValue("@user", account.Username); comm.Parameters.AddWithValue("@pass", string.Empty); comm.Parameters.AddWithValue("@type", account.AccountTypeId); comm.ExecuteNonQuery(); SQLiteCommand lastIdComm = connection.CreateCommand(); lastIdComm.CommandText = "SELECT last_insert_rowid()"; account.Id = int.Parse(lastIdComm.ExecuteScalar().ToString()); trans.Commit(); } else { account.Id = data.Id; } } catch (Exception) { trans.Rollback(); } CloseConnection(); } }
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 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 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 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; }
public AccountDB GetAccountByUserName(string name) { string query = "SELECT account.id as Id, username as Username, password as Password, account.account_type_id as AccountTypeId "+ "from account where username=?"; //Create a list to store the result AccountDB account = connection.Query<AccountDB>(query, name).First(); if (account == null) { account = new AccountDB(); } return account; }
public ICloudDownloadController(AccountDB acc, AccountDownloadListener notify) { Init(acc, notify); clientBuildNumber = Assembly.GetEntryAssembly().GetName().Version.ToString(); clientId = Guid.NewGuid().ToString().ToUpper(); }
// import from account public void DoDownloadContacts(AccountDB account) { Grid_import.Visibility = Visibility.Collapsed; Grid_status.Visibility = Visibility.Visible; label_account_type.Content = account.AccountTypeName; label_account.Content = account.Username.Replace("_", "__"); downloadController.DownloadContacts(account, this); }
private void btn_ok_Click(object sender, RoutedEventArgs e) { DuplicateContactMode mode; if (radio_btn_allow_duplicate.IsChecked == true) { mode = DuplicateContactMode.ALLOW_ADD_NEW; } else if (radio_btn_replace_with_new.IsChecked == true) { mode = DuplicateContactMode.REPLACE_WITH_NEW_ITEM; } else { mode = DuplicateContactMode.DO_NOT_IMPORT; } dbController.UpdateDuplicateContactMode(mode); switch (importFrom) { case ImportFrom.Account: if (rb_gmail_account.IsChecked != true && rb_yahoo_account.IsChecked != true && rb_live_account.IsChecked != true && rb_outlook_account.IsChecked != true && rb_office_account.IsChecked != true && rb_exchange_account.IsChecked != true) { MessageBox.Show(CMLibrary.Properties.Resources.choose_account_type_error, "", MessageBoxButton.OK,MessageBoxImage.Exclamation); return; } if (rb_outlook_account.IsChecked == true) { if(!outlookController.IsOutlookRunning()) { MessageBox.Show(CMLibrary.Properties.Resources.outlook_not_running); return; } string outlookAccount = outlookController.getOutlookAccountName(); account = dbController.GetOrAddAccountByOutlookAccount(outlookAccount); DoDownloadContacts(account); } else { string accountText = tbox_account.Text.Trim(); if (!MyUtils.IsEmailValid(accountText)) { MessageBox.Show(CMLibrary.Properties.Resources.wrong_email_format); return; } string pass = tbox_password.Password.Trim(); if (pass.Length == 0) { MessageBox.Show(CMLibrary.Properties.Resources.please_type_password); return; } if(rb_gmail_account.IsChecked == true) { account = dbController.GetOrAddAccountByGmailAccount(accountText); account.Password = pass; DoDownloadContacts(account); } if (rb_yahoo_account.IsChecked == true) { account = dbController.GetOrAddAccountByYahooAccount(accountText); account.Password = pass; DoDownloadContacts(account); } if (rb_live_account.IsChecked == true) { account = dbController.GetOrAddAccountByLiveAccount(accountText); account.Password = pass; DoDownloadContacts(account); } if (rb_office_account.IsChecked == true) { account = dbController.GetOrAddAccountByOffice365Account(accountText); account.Password = pass; DoDownloadContacts(account); } if (rb_exchange_account.IsChecked == true) { account = dbController.GetOrAddAccountByExchangeAccount(accountText); account.Password = pass; DoDownloadContacts(account); } } break; case ImportFrom.File: if (String.IsNullOrEmpty(filePath)) { btn_browse_Click(null, null); return; } ImportFromFile(filePath); break; } }
private void btn_ok_Click(object sender, RoutedEventArgs e) { DuplicateContactMode mode; if (radio_btn_allow_duplicate.IsChecked == true) { mode = DuplicateContactMode.ALLOW_ADD_NEW; } else if (radio_btn_replace_with_new.IsChecked == true) { 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(CMLibrary.Properties.Resources.wrong_email_format); return; } string pass = tbox_password.Password.Trim(); if (pass.Length == 0) { MessageBox.Show(CMLibrary.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 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 GetAccountByUserNameAndAccountTypeId(string name, int accTypeId) { string query = "SELECT account.id as Id, username as Username, password as Password, account.account_type_id as AccountTypeId " + "from account where username=@name and account_type_id=?"; AccountDB account = connection.Query<AccountDB>(query, name, accTypeId).First(); if (account == null) { account = new AccountDB(); } return account; }
public ExchangeDownloadController(AccountDB acc, AccountDownloadListener notify) { Init(acc, notify); ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; }
public AccountDB AddOrUpdateAccountByUserPassAccTypeId(string user, string pass, int a_type_id) { string query = "SELECT id as Id, username as Username, password as Password, account_type_id as AccountTypeId " + "from account where username=? and account_type_id=?"; AccountDB account = connection.Query<AccountDB>(query, user, a_type_id).First(); if (account == null || account.Id <= 0) // this account is not in database, save it { account = new AccountDB(); int accountId = AddNewAccount(user, pass, a_type_id); account.Id = accountId; account.Username = user; account.Password = pass; account.AccountTypeId = a_type_id; } else // this account already in database, update password { query = "UPDATE account SET password=? WHERE id=?"; connection.Execute(query, pass, account.Id); account.Password = pass; } return account; }
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 WebBrowser GetWebBrowserByAccountDB(AccountDB account, AccountDownloadListener notify, bool flag) { //AccountDB acc; DownloadController downloadController; HostType hostType = account.HostType; //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; // } // else if (acc.SameWith(account)) // { // return downloadController.Browser; // } //} switch (hostType) { case HostType.TYPE_GMAIL: //downloadController = new GoogleDownloadController(account, notify, flag); //browser = downloadController.Browser; //browser.Navigate(new Uri("https://accounts.google.com/AccountChooser?continue=https%3A%2F%2Faccounts.google.com%2FManageAccount&hl=en")); break; case HostType.TYPE_YAHOO: //downloadController = new YahooDownloadController(account, notify, flag); //browser = downloadController.Browser; //browser.Navigate(new Uri("https://api.login.yahoo.com/oauth2/request_auth?client_id=dj0yJmk9MzNRcVMzbncwdE5ZJmQ9WVdrOU1YUXdXVlZWTXpRbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD01Nw--&redirect_uri=oob&response_type=code")); break; case HostType.TYPE_LIVE_HOTMAIL: //browser.Navigate(new Uri("https://login.live.com/")); break; } return browser; }
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 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 = pass; 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 void UpdateManualImportMode(AccountDB account, bool isManual) { HostType hostType = account.HostType; switch (hostType) { case HostType.TYPE_GMAIL: new GoogleDownloadController().UpdateManualImportMode(isManual); break; case HostType.TYPE_YAHOO: new YahooDownloadController().UpdateManualImportMode(isManual); break; } }
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 and username != @csv and username != @vcf " + "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); cmd.Parameters.AddWithValue("@csv", AccountDB.CSV_ACCOUNT_NAME); cmd.Parameters.AddWithValue("@vcf", AccountDB.VCF_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 OutlookDownloadController(AccountDB acc, AccountDownloadListener notify) { Init(acc, notify); }
public YahooDownloadController(AccountDB acc, AccountDownloadListener notify) { Browser = new WebView(); Init(acc, notify); SetupWebBrowser(); }