コード例 #1
0
        public static void IdentifyEventDifferences(
            ref List <Event> google,             //need creating
            ref List <AppointmentItem> outlook,  //need deleting
            Dictionary <AppointmentItem, Event> compare)
        {
            log.Debug("Comparing Google events to Outlook items...");

            // Count backwards so that we can remove found items without affecting the order of remaining items
            for (int g = google.Count - 1; g >= 0; g--)
            {
                for (int o = outlook.Count - 1; o >= 0; o--)
                {
                    var i = outlook[o].UserProperties[gEventID] != null ? outlook[o].UserProperties[gEventID].Value.ToString() : "NULL";
                    if (outlook[o].UserProperties[gEventID] != null &&
                        outlook[o].UserProperties[gEventID].Value.ToString() == google[g].Id.ToString())
                    {
                        compare.Add(outlook[o], google[g]);
                        outlook.Remove(outlook[o]);
                        google.Remove(google[g]);
                        break;
                    }
                    else if (Settings.Instance.MergeItems)
                    {
                        //Remove the non-Google item so it doesn't get deleted
                        outlook.Remove(outlook[o]);
                    }
                }
            }

            if (Settings.Instance.DisableDelete)
            {
                outlook = new List <AppointmentItem>();
            }
            if (Settings.Instance.SyncDirection == SyncDirection.Bidirectional)
            {
                //Don't recreate any items that have been deleted in Outlook
                for (int g = google.Count - 1; g >= 0; g--)
                {
                    if (GoogleCalendar.hasLocalOutlookId(google[g], GoogleCalendar.oEntryID, Environment.MachineName))
                    {
                        google.Remove(google[g]);
                    }
                }
                //Don't delete any items that aren't yet in Google or just created in Google during this sync
                for (int o = outlook.Count - 1; o >= 0; o--)
                {
                    if (outlook[o].UserProperties[OutlookCalendar.gEventID] == null ||
                        outlook[o].LastModificationTime > Settings.Instance.LastSyncDate)
                    {
                        outlook.Remove(outlook[o]);
                    }
                }
            }
            if (Settings.Instance.CreateCSVFiles)
            {
                //Outlook Deletions
                log.Debug("Outputting items for deletion to CSV...");
                TextWriter tw = new StreamWriter(Path.Combine(Program.UserFilePath, "outlook_delete.csv"));
                foreach (AppointmentItem ai in outlook)
                {
                    tw.WriteLine(exportToCSV(ai));
                }
                tw.Close();

                //Outlook Creations
                log.Debug("Outputting items for creation to CSV...");
                tw = new StreamWriter(Path.Combine(Program.UserFilePath, "outlook_create.csv"));
                foreach (AppointmentItem ai in outlook)
                {
                    tw.WriteLine(OutlookCalendar.signature(ai));
                }
                tw.Close();
                log.Debug("Done.");
            }
        }