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 Office365DownloadController(AccountD acc, AccountDownloadListener notify)
 {
     Init(acc, notify);
     //var privateKey ="";
     //var publicKey = "";
     //RSAUtil.GetPublicAndPrivateKey(out privateKey, out publicKey);
 }
        public LiveHotmailDownloadController(AccountD acc, AccountDownloadListener notify)
        {
            browser = new WebView();
            Init(acc, notify);
            currentLookup = 1;

            SetupWebBrowser();
        }
        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 LiveHotmailDownloadController(AccountD 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 void DownloadContacts(List<AccountDB> list, AccountDownloadListener notify)
        {
            AccountDB acc;

            int len = list.Count;

            for (int i = 0; i < len; i++)
            {
                acc = list[i];
                DownloadContacts(acc, notify);
            }
        }
 protected void RemoveNotifyStatusListener(AccountDownloadListener notify)
 {
     listNotify.Remove(notify);
 }
 public void DownloadContacts(int account_type_id, string username, string password, AccountDownloadListener notify)
 {
     DBManager db = new DBManager();
     Account account = db.AddOrUpdateAccountByUserPassAccTypeId(username, password, account_type_id);
     if (account.Id > 0)
     {
         //DownloadContacts(account, notify);
     }
     else
     {
         notify.NotifyStatusByAccountId(-1, DownloadStatus.DATABASE_ERROR, ResourceStringLoader.GetString("database_error"));
     }
 }
 public ExchangeDownloadController(AccountDB acc, AccountDownloadListener notify)
 {
     Init(acc, notify);
     ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
 }
        public GoogleDownloadController(AccountD acc, AccountDownloadListener notify)
        {
            //browser = webBrowser;
            browser = new WebView();
            Init(acc, notify);
            SetupWebBrowser();

            currentLookup = 1;
        }
 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(string account_type_str, string username, string password, AccountDownloadListener notify)
 {
     DBManager db = new DBManager();
     AccountDB account = db.AddOrUpdateAccountByUserPassAccTypeString(username, password, account_type_str);
     if (account.Id > 0)
     {
         DownloadContacts(account, notify);
     }
     else
     {
         notify.NotifyStatusByUsername(username, DownloadStatus.DATABASE_ERROR, "Database Error");
     }
 }
 public YahooDownloadController(AccountDB acc, AccountDownloadListener notify)
 {
     Browser = new WebView();
     Init(acc, notify);
     SetupWebBrowser();
 }
 public ExchangeDownloadController(AccountD acc, AccountDownloadListener listener)
 {
     Init(acc, listener);            
 }
        public YahooDownloadController(AccountD acc, AccountDownloadListener notify)
        {
            browser = new WebView();
            Init(acc, notify);
            SetupWebBrowser();

            isReload = false;
            currentLookup = 1;
        }
        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 DownloadContacts(int account_type_id, string username, string password, AccountDownloadListener notify)
 {
     DBManager db = new DBManager();
     AccountDB account = db.AddOrUpdateAccountByUserPassAccTypeId(username, password, account_type_id);
     if (account.Id > 0)
     {
         DownloadContacts(account, notify);
     }
     else
     {
         notify.NotifyStatusByAccountId(-1, DownloadStatus.DATABASE_ERROR, CMController.Properties.Resources.database_error);
     }
 }
        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 WebBrowser GetDefaultWebBrowserByAccountDB(AccountDB account, AccountDownloadListener notify)
        {
            //AccountDB acc;
            DownloadController downloadController;
            HostType hostType = account.HostType;
            //var googleDownloadController = new GoogleDownloadController();

            //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);
                    browser = downloadController.Browser;
                    ClearCookies.SuppressWininetBehavior();
                    DeleteUrlCacheEntry("https://accounts.google.com/AccountChooser?continue=https%3A%2F%2Faccounts.google.com%2FManageAccount&hl=en");
                    browser.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<    a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(    c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((    new Date()).getTime()-1e11).toGMTString());}}}})())");
                    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);
                    browser = downloadController.Browser;
                    ClearCookies.SuppressWininetBehavior();
                    DeleteUrlCacheEntry("https://login.yahoo.com/");
                    browser.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<    a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(    c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((    new Date()).getTime()-1e11).toGMTString());}}}})())");
                    browser.Navigate(new Uri("https://login.yahoo.com/"));
                    break;
                case HostType.TYPE_LIVE_HOTMAIL:
                    downloadController = new LiveHotmailDownloadController(account, notify);
                    browser = downloadController.Browser;
                    ClearCookies.SuppressWininetBehavior();
                    DeleteUrlCacheEntry("https://login.live.com/");
                    browser.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<    a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(    c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((    new Date()).getTime()-1e11).toGMTString());}}}})())");
                    browser.Navigate(new Uri("https://login.live.com/"));
                    break;
            }

            return browser;
        }
 public OutlookDownloadController(AccountDB acc, AccountDownloadListener notify)
 {
     Init(acc, notify);
 }
 public ICloudDownloadController(AccountDB acc, AccountDownloadListener notify)
 {
     Init(acc, notify);
     clientBuildNumber = Assembly.GetEntryAssembly().GetName().Version.ToString();
     clientId = Guid.NewGuid().ToString().ToUpper();
 }