/// <summary> /// EventHandler for ItemAdd Event of InboxFolder /// </summary> /// <param name="Item">The Item wich was added to InboxFolder</param> private void Items_ItemAdd(object Item) { if (MutexManager.InFullSync()) { return; } try { // Check the ItemType, could be a MeetingAccept or something else if (Item is Ol.ContactItem) { // Cast to ContactItem Object Ol.ContactItem contact = (Ol.ContactItem)Item; if (MutexManager.IsBlocked(contact)) { logger.Debug("Removing contact " + OutlookAdapter.ContactItemDisplay(contact) + " from mutex file"); MutexManager.ClearBlockedContact(contact); return; } logger.Info("Adding " + OutlookAdapter.ContactItemDisplay(contact)); // Do something with Item GoogleAdapter ga = new GoogleAdapter(Config.Username, Config.Password, logger); MutexManager.AddToBlockedContacts(contact); ga.CreateContactFromOutlookAsync(contact); // Release COM Object contact = null; } } catch (System.Exception ex) { logger.Error(ex.Message); logger.Debug(ex.StackTrace.ToString()); MessageBox.Show(ex.Message); } }
private void Items_ItemChange(object Item) { if (MutexManager.InFullSync()) { return; } try { if (Item is ContactItem) { ContactItem item = (ContactItem)Item; if (MutexManager.IsBlocked(item)) { logger.Debug("Removing contact " + OutlookAdapter.ContactItemDisplay(item) + " from mutex file"); MutexManager.ClearBlockedContact(item); return; } logger.Info("Adding " + OutlookAdapter.ContactItemDisplay(item) + " to mutex file"); MutexManager.AddToBlockedContacts(item); logger.Info("Updating " + OutlookAdapter.ContactItemDisplay(item)); GoogleAdapter ga = new GoogleAdapter(Config.Username, Config.Password, logger); ga.UpdateContactFromOutlookAsync(item, null); } } catch (System.Exception ex) { logger.Error(ex.Message); logger.Debug(ex.StackTrace.ToString()); MessageBox.Show(ex.Message); } }
public void SyncFromGoogle() { do { try { Monitor.Enter(ContactSync.SynchRoot); try { logger.Info("Starting sync from Google..."); DateTime lastFetch = GetLastGoogleFetch(); logger.Debug("Last fetch date: " + lastFetch.ToShortDateString()); if (StartSynching != null) { StartSynching(this); } try { logger.Info("Obtaining updated Google contacts"); List <Contact> contacts = googleAdapter.ContactsChangedSince(lastFetch); foreach (Contact c in contacts) { if (MutexManager.IsBlocked(c)) { logger.Debug("Removing contact " + GoogleAdapter.ContactDisplay(c) + " from mutex file"); MutexManager.ClearBlockedContact(c); continue; } logger.Info("Syncronizing " + GoogleAdapter.ContactDisplay(c)); logger.Debug("Adding " + GoogleAdapter.ContactDisplay(c) + " to mutex list"); MutexManager.AddToBlockedContacts(c); outlookAdapter.UpdateContactFromGoogle(c, null); logger.Info(GoogleAdapter.ContactDisplay(c) + " syncrhonized"); if (Thread.CurrentThread.ThreadState == ThreadState.AbortRequested) { return; } } } finally { if (EndSynching != null) { EndSynching(this); } } logger.Debug("Setting last fetch date"); SetLastGoogleFetch(DateTime.Now); logger.Info("Waiting for " + Interval + " milliseconds."); } finally { Monitor.Exit(ContactSync.SynchRoot); } Thread.Sleep(Interval); } catch (System.Exception ex) { logger.Info(ex.Message); logger.Debug(ex.StackTrace.ToString()); if (ex.Message.ToLower().Contains("captcha")) { MessageBox.Show("You need to enter a captcha to validate your account.\r\n" + "GContactsSync will redirect you to the validation page.\r\n" + "Press OK on the next message box when you have finished validating."); System.Diagnostics.Process.Start("https://www.google.com/accounts/DisplayUnlockCaptcha"); MessageBox.Show("Press OK after validating your Google Account"); } else { MessageBox.Show("Error " + ex.Message); } } } while (Thread.CurrentThread.ThreadState != ThreadState.AbortRequested); }