Example #1
0
 /// <summary>
 /// Configure window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnConfigure_Click(object sender, RibbonControlEventArgs e)
 {
     using (ConnectionSettings c = new ConnectionSettings())
     {
         LoggerProvider.Instance.Logger.Debug("Click on ConnectionSettings");
         c.ShowDialog();
         lastStatistic.Clear();
     }
     //if (SettingsProvider.Instance.UserName.Length > 0)
     //    btnSync.Enabled = true;
     //else
     //    btnSync.Enabled = false;
 }
Example #2
0
        /// <summary>
        /// realize steps to synchronize data
        /// </summary>
        public void Synchronize()
        {
            _lastStatistic.Clear();

            #region read data from source
            syncinfo.ActualNextStep();
            /// need read contacts from oulook
            _ActualStep = 1;
            LoggerProvider.Instance.Logger.Debug("Synchronize step 1 ({0})", Constants.SyncSteps()[_ActualStep]);
            UpdateSyncInfo();
            Step1ReadOutlook();
            syncinfo.ActualNextStep();
            /// need read all cntact from google
            _ActualStep = 2;
            LoggerProvider.Instance.Logger.Debug("Synchronize step 2 ({0})", Constants.SyncSteps()[_ActualStep]);
            UpdateSyncInfo();
            Step2ReadGoogle();
            syncinfo.ActualNextStep();
            #endregion

            #region Insert data to other side
            //if (SettingsProvider.Instance.IsAddToGoogle)
            {
                /// Next step Insert new contact to google
                _ActualStep = 3;
                LoggerProvider.Instance.Logger.Debug("Synchronize step 3 ({0})", Constants.SyncSteps()[_ActualStep]);
                UpdateSyncInfo();
                Step3AddToGoogle();
                syncinfo.ActualNextStep();
            }
            /// Insert new contact to Outlook
            //if (SettingsProvider.Instance.IsAddToOutlook)
            {
                _ActualStep = 4;
                LoggerProvider.Instance.Logger.Debug("Synchronize step 4 ({0})", Constants.SyncSteps()[_ActualStep]);
                UpdateSyncInfo();
                Step4AddToOutlook();
                syncinfo.ActualNextStep();
#if (DUMP_CONTACTS)
                DumpContactToLog(ref ouContacts);
                DumpContactToLog(ref goContacts);
#endif
            }
            #endregion

            #region Delete old contacts
            /// Delete contact from outlook
            //if (SettingsProvider.Instance.IsDeleteFromOutlook)
            {
                _ActualStep = 5;
                LoggerProvider.Instance.Logger.Debug("Synchronize step 5 ({0})", Constants.SyncSteps()[_ActualStep]);
                UpdateSyncInfo();
                Step5DeleteInOutlook();
                syncinfo.ActualNextStep();
            }
            /// Delete contact from Google
            //if (SettingsProvider.Instance.IsDeleteFromGoogle)
            {
                _ActualStep = 6;
                LoggerProvider.Instance.Logger.Debug("Synchronize step 6 ({0})", Constants.SyncSteps()[_ActualStep]);
                UpdateSyncInfo();
                Step6DeleteInGoogle();
                syncinfo.ActualNextStep();
#if (DUMP_CONTACTS)
                DumpContactToLog(ref ouContacts);
                DumpContactToLog(ref goContacts);
#endif
            }
            #endregion

            #region Update statistic on screen
            syncinfo.GoogleContacts  = goContacts.Count;
            syncinfo.OutlookContacts = ouContacts.Count;
            syncinfo.Update();
            #endregion

            #region Update both side
            /// Update contact
            _ActualStep = 7;
            LoggerProvider.Instance.Logger.Debug("Synchronize step 7 ({0})", Constants.SyncSteps()[_ActualStep]);
            UpdateSyncInfo();
            Step7Update();
            syncinfo.ActualNextStep();
#if (DUMP_CONTACTS)
            DumpContactToLog(ref ouContacts);
            DumpContactToLog(ref goContacts);
#endif
            #endregion

            #region Reset first update flag
            if (SettingsProvider.Instance.IsFirstTime)
            {
                SettingsProvider.Instance.IsFirstTime = false;
                SettingsProvider.Instance.Save();
                LoggerProvider.Instance.Logger.Debug("First time synchronize finish. Next is standard synchronization");
            }
            #endregion

            LoggerProvider.Instance.Logger.Debug("Synchronize ends");

            #region Write to cache
            if (SettingsProvider.Instance.IsUseGoogleCache)
            {
                Utils.WriteGoogleToCache(goContacts);
            }
            if (SettingsProvider.Instance.IsUseOutlookCache)
            {
                Utils.WriteOutlookToCache(ouContacts);
            }
            #endregion
        }