private void Sync_ThreadStarter() { TimerSwitch(false); SetLastSyncText("Syncing..."); SetSyncConsoleText(DateTime.Now + " Sync started" + Environment.NewLine); SetFormEnabled(false); if (_sync == null) { _sync = new Syncronizer(); _sync.Logger = new Logger(); _sync.DuplicatesFound += new Syncronizer.NotificationHandler(_sync_DuplicatesFound); _sync.ErrorEncountered += new Syncronizer.NotificationHandler(_sync_ErrorEncountered); } _sync.SyncProfile = tbSyncProfile.Text; _sync.SyncOption = _syncOption; try { _sync.LoginToGoogle(UserName.Text, Password.Text); _sync.LoginToOutlook(); _sync.Logger.ClearLog(); _sync.Sync(); SetLastSyncText("Last synced at " + lastSync.ToString()); AppendSyncConsoleText((_sync.Logger as Logger).messages); AppendSyncConsoleText(DateTime.Now + " Sync complete" + Environment.NewLine); notifyIcon.BalloonTipTitle = "Complete"; notifyIcon.BalloonTipText = string.Format("{0}. Sync complete.\n Synced: {2} out of {1}.\n Deleted: {3}.", DateTime.Now, _sync.TotalCount, _sync.SyncedCount, _sync.DeletedCount); notifyIcon.BalloonTipIcon = ToolTipIcon.Info; notifyIcon.ShowBalloonTip(5000); } catch (Exception ex) { _sync.Logger.Log(ex.Message, EventType.Error); AppendSyncConsoleText((_sync.Logger as Logger).messages); AppendSyncConsoleText(DateTime.Now + " Sync failed" + Environment.NewLine); notifyIcon.BalloonTipTitle = "Error"; notifyIcon.BalloonTipText = ex.Message; notifyIcon.BalloonTipIcon = ToolTipIcon.Error; notifyIcon.ShowBalloonTip(5000); } lastSync = DateTime.Now; TimerSwitch(true); SetFormEnabled(true); }
private void Sync_ThreadStarter() { TimerSwitch(false); SetLastSyncText("Syncing..."); SetSyncConsoleText(DateTime.Now + " Sync started" + Environment.NewLine); SetFormEnabled(false); if (_sync == null) { _sync = new Syncronizer(); _sync.Logger = new Logger(); _sync.DuplicatesFound += new Syncronizer.NotificationHandler(_sync_DuplicatesFound); _sync.ErrorEncountered += new Syncronizer.NotificationHandler(_sync_ErrorEncountered); } _sync.SyncProfile = tbSyncProfile.Text; _sync.OutlookProfile = tbOutlookProfile.Text; _sync.SyncOption = _syncOption; try { _sync.LoginToGoogle(UserName.Text, Password.Text); bool loginOutlookFailed = false; try { _sync.LoginToOutlook(); } catch { loginOutlookFailed = true; _sync = null; _sync = new Syncronizer(); _sync.Logger = new Logger(); _sync.DuplicatesFound += new Syncronizer.NotificationHandler(_sync_DuplicatesFound); _sync.ErrorEncountered += new Syncronizer.NotificationHandler(_sync_ErrorEncountered); _sync.SyncProfile = tbSyncProfile.Text; _sync.OutlookProfile = tbOutlookProfile.Text; _sync.SyncOption = _syncOption; _sync.LoginToGoogle(UserName.Text, Password.Text); } if (loginOutlookFailed == true) { _sync.LoginToOutlook(); } _sync.Logger.ClearLog(); _sync.Sync(); SetLastSyncText("Last synced at " + lastSync.ToString()); AppendSyncConsoleText((_sync.Logger as Logger).messages); AppendSyncConsoleText(DateTime.Now + " Sync complete" + Environment.NewLine); //notifyIcon.BalloonTipTitle = "Complete"; //notifyIcon.BalloonTipText = string.Format("{0}. Sync complete.\n Synced: {2} out of {1}.\n Deleted: {3}.", DateTime.Now, _sync.TotalCount, _sync.SyncedCount, _sync.DeletedCount); //notifyIcon.BalloonTipIcon = ToolTipIcon.Info; //notifyIcon.ShowBalloonTip(5000); } catch (Exception ex) { _sync.Logger.Log(ex.Message, EventType.Error); AppendSyncConsoleText((_sync.Logger as Logger).messages); AppendSyncConsoleText(DateTime.Now + " Sync failed" + Environment.NewLine); notifyIcon.BalloonTipTitle = "Error"; notifyIcon.BalloonTipText = ex.Message; notifyIcon.BalloonTipIcon = ToolTipIcon.Error; notifyIcon.ShowBalloonTip(5000); } lastSync = DateTime.Now; TimerSwitch(true); SetFormEnabled(true); }