Пример #1
0
        private void Sync_BTN_Click(object sender, EventArgs e)
        {
            // Create the SyncPair
            var pair = new SyncPair {
                GoogleName  = googleCal_CB.SelectedItem.ToString(),
                GoogleId    = m_googleFolders.Items[googleCal_CB.SelectedIndex].Id,
                OutlookName = outlookCal_CB.SelectedItem.ToString(),
                OutlookId   = m_outlookFolders[outlookCal_CB.SelectedIndex].EntryID
            };

            // Set the current outlook working folder to the folder selected by the user.
            pair.OutlookId = m_outlookFolders.First(x => x.Name == pair.OutlookName).EntryID;
            OutlookSync.Syncer.SetOutlookWorkingFolder(pair.OutlookId);

            // Set the current Google working folder
            pair.GoogleId = m_googleFolders.Items.First(x => x.Summary.Equals(pair.GoogleName)).Id;
            GoogleSync.Syncer.SetGoogleWorkingFolder(pair.GoogleId);

            Archiver.Instance.CurrentPair = pair;

            // Get the final list using the Syncer
            var finalList = m_syncer.GetFinalList(checkBox1.Checked, Start_DTP.Value, End_DTP.Value);

            if (finalList.Count == 0)
            {
                MessageBox.Show($"There are no differences between the {pair.GoogleName} Google Calender and the {pair.OutlookName} Outlook Calender.", "No Events", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                // Display the differences
                var compare = new CompareForm();
                compare.SetParent(this);
                compare.SetCalendars(pair);
                compare.LoadData(finalList);
                compare.Show(this);
            }
        }
Пример #2
0
        /// <summary>
        /// Synchronizes a list of sync pairs
        /// </summary>
        /// <param name="pairs">The list of pairs to sync</param>
        /// <param name="worker">A background work used to perform the sync</param>
        public SyncerResult SynchornizePairs(List <SyncPair> pairs, BackgroundWorker worker)
        {
            var currentSync = 0;

            StatusUpdate?.Invoke("- Starting Sync");

            float count = 0;

            m_syncingPairs = true;

            foreach (SyncPair pair in pairs)
            {
                StatusUpdate?.Invoke($"- Starting Sync for  {pair.OutlookName} and {pair.GoogleName}");

                m_outlookSync.SetOutlookWorkingFolder(pair.OutlookId);
                m_googleSync.SetGoogleWorkingFolder(pair.GoogleId);
                m_archiver.CurrentPair = pair;

                var finalList = GetFinalList();
                var progress  = ++count / pairs.Count;

                if (finalList.Count > 0)
                {
                    var compare = new CompareForm();
                    compare.SetCalendars(pair);
                    compare.LoadData(finalList);

                    if (!m_silentSync)
                    {
                        if (compare.ShowDialog() == DialogResult.OK)
                        {
                            SubmitChanges(compare.Data, worker, progress);
                        }
                    }
                    else
                    {
                        SubmitChanges(finalList, worker, progress);
                    }

                    currentSync++;
                }
                else
                {
                    if (!m_silentSync)
                    {
                        MessageBox.Show(
                            $"There are no differences between the {pair.GoogleName} Google Calender and the {pair.OutlookName} Outlook Calender.",
                            "No Events", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                    }

                    StatusUpdate?.Invoke("The was no items to sync.");
                }

                StatusUpdate?.Invoke($"- Sync Completed for {pair.OutlookName} and {pair.GoogleName}");
            }

            m_syncingPairs     = false;
            PerformActionToAll = false;
            m_archiver.Save();

            if (worker.WorkerReportsProgress)
            {
                worker.ReportProgress(100);
            }

            StatusUpdate?.Invoke("- Sync has been completed.");

            return(currentSync == 0 ? SyncerResult.NoDifferences :
                   currentSync == 1 ? SyncerResult.SingleSync : SyncerResult.MultiSync);
        }