private void Sync_ProgressUpdate(ProgressUpdater update) { if (update.HasError) { ShowErrorBox(update.Error, update.ErrorTech); } lblCurrentTask.Invoke(new UpdateTextCallback(UpdateCurrentTask), new object[] { update.CurrentTask }); lblToBeCreated.Invoke(new UpdateTextCallback(this.UpdateToBeCreated), new object[] { update.ToBeCreated.ToString() }); lblToBeDeleted.Invoke(new UpdateTextCallback(this.UpdateToBeDeleted), new object[] { update.ToBeDeleted.ToString() }); lblToBeUpdated.Invoke(new UpdateTextCallback(this.UpdateToBeUpdated), new object[] { update.ToBeUpdated.ToString() }); lblVpContacts.Invoke(new UpdateTextCallback(this.UpdateVpContacts), new object[] { update.VPContacts.ToString() }); lblGoogleContacts.Invoke(new UpdateTextCallback(this.UpdateGoogleContacts), new object[] { update.GoogleContacts.ToString() }); cmdSync.Invoke(new UpdateBoolCallback(this.UpdateGoogleContacts), new object[] { update.IsRunning }); }
/// <summary> /// Start the Sync of contacts. /// </summary> public void DoSync() { _status = new ProgressUpdater(); _status.IsRunning = true; _status.CurrentTask = "Getting VP Contacts"; ProgressUpdate(_status); Dictionary <string, VPContact> vpContacts = VPConnect.GetContacts(Environment.UserName); if (vpContacts == null) { _status.HasError = true; _status.IsRunning = false; _status.Error = "Could not get contacts from VP, stopping sync"; ProgressUpdate(_status); return; } _status.VPContacts = vpContacts.Count; ProgressUpdate(_status); _status.CurrentTask = "Logging into Google"; ProgressUpdate(_status); var auth = GConnect.Authenticate(); _status.CurrentTask = "Getting Google Contacts"; ProgressUpdate(_status); var gContacts = GConnect.GetGroupContacts(auth); _status.GoogleContacts = gContacts.TotalResults; List <Contact> toBeDeleted; _status.CurrentTask = "Analyzing data......"; ProgressUpdate(_status); vpContacts = CheckGoogleContacts(vpContacts, gContacts, out toBeDeleted); Dictionary <string, VPContact> toBeCreated = vpContacts.Where(item => item.Value.ActionNeeded == VPContact.SyncAction.Create) .ToDictionary(key => key.Key, value => value.Value); Dictionary <string, VPContact> toBeUpdated = vpContacts.Where(item => item.Value.ActionNeeded == VPContact.SyncAction.Update) .ToDictionary(key => key.Key, value => value.Value); _status.ToBeCreated = toBeCreated.Count; _status.ToBeUpdated = toBeUpdated.Count; _status.ToBeDeleted = toBeDeleted.Count; _status.CurrentTask = "Creating Google Contacts"; ProgressUpdate(_status); CreateContacts(auth, toBeCreated); _status.CurrentTask = "Updating existing Google Contacts"; ProgressUpdate(_status); UpdateContacts(auth, toBeUpdated); _status.CurrentTask = "Deleting unwanted Google Contacts"; ProgressUpdate(_status); DeleteContacts(auth, toBeDeleted); _status.CurrentTask = "Done...."; _status.IsRunning = false; ProgressUpdate(_status); }