private void setDefaults()
        {
            //Default values
            assignedClientIdentifier = "";
            PersonalClientIdentifier = "";
            PersonalClientSecret     = "";
            OutlookService           = OutlookCalendar.Service.DefaultMailbox;
            MailboxName          = "";
            SharedCalendar       = "";
            UseOutlookCalendar   = new MyOutlookCalendarListEntry();
            CategoriesRestrictBy = RestrictBy.Exclude;
            Categories           = new System.Collections.Generic.List <String>();
            OutlookDateFormat    = "g";

            UseGoogleCalendar = new MyGoogleCalendarListEntry();
            RefreshToken      = "";
            apiLimit_inEffect = false;
            apiLimit_lastHit  = DateTime.Parse("01-Jan-2000");
            GaccountEmail     = "";

            SyncDirection               = new SyncDirection();
            DaysInThePast               = 1;
            DaysInTheFuture             = 60;
            SyncInterval                = 0;
            SyncIntervalUnit            = "Hours";
            OutlookPush                 = false;
            AddDescription              = true;
            AddDescription_OnlyToGoogle = true;
            AddReminders                = false;
            UseGoogleDefaultReminder    = false;
            ReminderDND                 = false;
            ReminderDNDstart            = DateTime.Now.Date.AddHours(22);
            ReminderDNDend              = DateTime.Now.Date.AddDays(1).AddHours(6);
            AddAttendees                = false;
            MergeItems      = true;
            DisableDelete   = true;
            ConfirmOnDelete = true;
            Obfuscation     = new Obfuscate();

            ShowBubbleTooltipWhenSyncing = true;
            StartOnStartup           = false;
            StartInTray              = false;
            MinimiseToTray           = false;
            MinimiseNotClose         = false;
            ShowBubbleWhenMinimising = true;

            CreateCSVFiles = false;
            LoggingLevel   = "DEBUG";
            portable       = false;
            Proxy          = new SettingsProxy();

            alphaReleases    = false;
            Subscribed       = DateTime.Parse("01-Jan-2000");
            donor            = false;
            hideSplashScreen = false;

            lastSyncDate   = new DateTime(0);
            completedSyncs = 0;
            VerboseOutput  = false;
        }
Esempio n. 2
0
        public void ReclaimOrphanCalendarEntries(ref List <AppointmentItem> oAppointments, ref List <Event> gEvents)
        {
            log.Debug("Looking for orphaned items to reclaim...");

            //This is needed for people migrating from other tools, which do not have our GoogleID extendedProperty
            List <AppointmentItem> unclaimedAi = new List <AppointmentItem>();

            for (int o = oAppointments.Count - 1; o >= 0; o--)
            {
                AppointmentItem ai = oAppointments[o];
                //Find entries with no Google ID
                if (ai.UserProperties[gEventID] == null)
                {
                    unclaimedAi.Add(ai);
                    foreach (Event ev in gEvents)
                    {
                        //Use simple matching on start,end,subject,location to pair events
                        String sigAi = signature(ai);
                        String sigEv = GoogleCalendar.signature(ev);
                        if (Settings.Instance.Obfuscation.Enabled)
                        {
                            if (Settings.Instance.Obfuscation.Direction == SyncDirection.OutlookToGoogle)
                            {
                                sigAi = Obfuscate.ApplyRegex(sigAi, SyncDirection.OutlookToGoogle);
                            }
                            else
                            {
                                sigEv = Obfuscate.ApplyRegex(sigEv, SyncDirection.GoogleToOutlook);
                            }
                        }
                        if (sigAi == sigEv)
                        {
                            AddOGCSproperty(ref ai, gEventID, ev.Id);
                            updateCalendarEntry_save(ai);
                            unclaimedAi.Remove(ai);
                            MainForm.Instance.Logboxout("Reclaimed: " + GetEventSummary(ai), verbose: true);
                            break;
                        }
                    }
                }
            }
            if ((Settings.Instance.SyncDirection == SyncDirection.GoogleToOutlook ||
                 Settings.Instance.SyncDirection == SyncDirection.Bidirectional) &&
                unclaimedAi.Count > 0 &&
                !Settings.Instance.MergeItems && !Settings.Instance.DisableDelete && !Settings.Instance.ConfirmOnDelete)
            {
                if (MessageBox.Show(unclaimedAi.Count + " Outlook calendar items can't be matched to Google.\r\n" +
                                    "Remember, it's recommended to have a dedicated Outlook calendar to sync with, " +
                                    "or you may wish to merge with unmatched events. Continue with deletions?",
                                    "Delete unmatched Outlook items?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                {
                    foreach (AppointmentItem ai in unclaimedAi)
                    {
                        oAppointments.Remove(ai);
                    }
                }
            }
        }
Esempio n. 3
0
        private AppointmentItem createCalendarEntry(Event ev)
        {
            string itemSummary = GoogleCalendar.GetEventSummary(ev);

            log.Debug("Processing >> " + itemSummary);
            MainForm.Instance.Logboxout(itemSummary, verbose: true);

            AppointmentItem ai = IOutlook.UseOutlookCalendar().Items.Add() as AppointmentItem;

            //Add the Google event ID into Outlook appointment.
            AddOGCSproperty(ref ai, gEventID, ev.Id);

            ai.Start       = new DateTime();
            ai.End         = new DateTime();
            ai.AllDayEvent = (ev.Start.Date != null);
            ai             = OutlookCalendar.Instance.IOutlook.WindowsTimeZone_set(ai, ev);
            Recurrence.Instance.BuildOutlookPattern(ev, ai);

            ai.Subject = Obfuscate.ApplyRegex(ev.Summary, SyncDirection.GoogleToOutlook);
            if (Settings.Instance.AddDescription && ev.Description != null)
            {
                ai.Body = ev.Description;
            }
            ai.Location    = ev.Location;
            ai.Sensitivity = (ev.Visibility == "private") ? OlSensitivity.olPrivate : OlSensitivity.olNormal;
            ai.BusyStatus  = (ev.Transparency == "transparent") ? OlBusyStatus.olFree : OlBusyStatus.olBusy;

            if (Settings.Instance.AddAttendees && ev.Attendees != null)
            {
                foreach (EventAttendee ea in ev.Attendees)
                {
                    createRecipient(ea, ai);
                }
            }

            //Reminder alert
            if (Settings.Instance.AddReminders && ev.Reminders != null && ev.Reminders.Overrides != null)
            {
                foreach (EventReminder reminder in ev.Reminders.Overrides)
                {
                    if (reminder.Method == "popup")
                    {
                        ai.ReminderSet = true;
                        ai.ReminderMinutesBeforeStart = (int)reminder.Minutes;
                    }
                }
            }
            return(ai);
        }
Esempio n. 4
0
        private void setDefaults()
        {
            //Default values
            OutlookService     = OutlookCalendar.Service.DefaultMailbox;
            MailboxName        = "";
            EWSuser            = "";
            EWSpassword        = "";
            EWSserver          = "";
            UseOutlookCalendar = new MyOutlookCalendarListEntry();
            OutlookDateFormat  = "g";

            UseGoogleCalendar = new MyGoogleCalendarListEntry();
            RefreshToken      = "";
            apiLimit_inEffect = false;
            apiLimit_lastHit  = DateTime.Parse("01-Jan-2000");

            SyncDirection               = new SyncDirection();
            DaysInThePast               = 1;
            DaysInTheFuture             = 60;
            SyncInterval                = 0;
            SyncIntervalUnit            = "Hours";
            OutlookPush                 = false;
            AddDescription              = true;
            AddDescription_OnlyToGoogle = true;
            AddReminders                = false;
            AddAttendees                = true;
            MergeItems      = true;
            DisableDelete   = true;
            ConfirmOnDelete = true;
            Obfuscation     = new Obfuscate();

            ShowBubbleTooltipWhenSyncing = true;
            StartOnStartup           = false;
            StartInTray              = false;
            MinimiseToTray           = false;
            MinimiseNotClose         = false;
            ShowBubbleWhenMinimising = true;

            CreateCSVFiles = false;
            LoggingLevel   = "DEBUG";
            portable       = false;
            Proxy          = new SettingsProxy();

            alphaReleases = false;

            lastSyncDate   = new DateTime(0);
            completedSyncs = 0;
            VerboseOutput  = false;
        }
        private void setDefaults() {
            //Default values
            OutlookService = OutlookCalendar.Service.DefaultMailbox;
            MailboxName = "";
            EWSuser = "";
            EWSpassword = "";
            EWSserver = "";
            UseOutlookCalendar = new MyOutlookCalendarListEntry();
            OutlookDateFormat = "g";

            UseGoogleCalendar = new MyGoogleCalendarListEntry();
            RefreshToken = "";
            apiLimit_inEffect = false;
            apiLimit_lastHit = DateTime.Parse("01-Jan-2000");

            SyncDirection = new SyncDirection();
            DaysInThePast = 1;
            DaysInTheFuture = 60;
            SyncInterval = 0;
            SyncIntervalUnit = "Hours";
            OutlookPush = false;
            AddDescription = true;
            AddDescription_OnlyToGoogle = true;
            AddReminders = false;
            AddAttendees = true;
            MergeItems = true;
            DisableDelete = true;
            ConfirmOnDelete = true;
            Obfuscation = new Obfuscate();

            ShowBubbleTooltipWhenSyncing = true;
            StartOnStartup = false;
            StartInTray = false;
            MinimiseToTray = false;
            MinimiseNotClose = false;
            ShowBubbleWhenMinimising = true;

            CreateCSVFiles = false;
            LoggingLevel = "DEBUG";
            portable = false;
            Proxy = new SettingsProxy();

            alphaReleases = false;
            
            lastSyncDate = new DateTime(0);
            completedSyncs = 0;
            VerboseOutput = false;
        }
Esempio n. 6
0
        private void setDefaults()
        {
            //Default values
            assignedClientIdentifier = "";
            assignedClientSecret     = "";
            PersonalClientIdentifier = "";
            PersonalClientSecret     = "";
            OutlookService           = OutlookOgcs.Calendar.Service.DefaultMailbox;
            MailboxName          = "";
            SharedCalendar       = "";
            UseOutlookCalendar   = new OutlookCalendarListEntry();
            CategoriesRestrictBy = RestrictBy.Exclude;
            Categories           = new System.Collections.Generic.List <String>();
            OnlyRespondedInvites = false;
            OutlookDateFormat    = "g";
            outlookGalBlocked    = false;

            UseGoogleCalendar = new GoogleCalendarListEntry();
            apiLimit_inEffect = false;
            apiLimit_lastHit  = DateTime.Parse("01-Jan-2000");
            GaccountEmail     = "";
            CloakEmail        = true;

            SyncDirection               = Sync.Direction.OutlookToGoogle;
            DaysInThePast               = 1;
            DaysInTheFuture             = 60;
            SyncInterval                = 0;
            SyncIntervalUnit            = "Hours";
            OutlookPush                 = false;
            AddLocation                 = true;
            AddDescription              = true;
            AddDescription_OnlyToGoogle = true;
            AddReminders                = false;
            UseGoogleDefaultReminder    = false;
            UseOutlookDefaultReminder   = false;
            ReminderDND                 = false;
            ReminderDNDstart            = DateTime.Now.Date.AddHours(22);
            ReminderDNDend              = DateTime.Now.Date.AddDays(1).AddHours(6);
            AddAttendees                = false;
            AddColours            = false;
            MergeItems            = true;
            DisableDelete         = true;
            ConfirmOnDelete       = true;
            TargetCalendar        = Sync.Direction.OutlookToGoogle;
            CreatedItemsOnly      = true;
            SetEntriesPrivate     = false;
            SetEntriesAvailable   = false;
            SetEntriesColour      = false;
            SetEntriesColourValue = Microsoft.Office.Interop.Outlook.OlCategoryColor.olCategoryColorNone.ToString();
            SetEntriesColourName  = "None";
            Obfuscation           = new Obfuscate();

            MuteClickSounds = false;
            ShowBubbleTooltipWhenSyncing = true;
            StartOnStartup           = false;
            StartupDelay             = 0;
            StartInTray              = false;
            MinimiseToTray           = false;
            MinimiseNotClose         = false;
            ShowBubbleWhenMinimising = true;

            CreateCSVFiles = false;
            LoggingLevel   = "DEBUG";
            cloudLogging   = null;
            portable       = false;
            Proxy          = new SettingsProxy();

            alphaReleases       = !System.Windows.Forms.Application.ProductVersion.EndsWith("0.0");
            SkipVersion         = null;
            subscribed          = DateTime.Parse("01-Jan-2000");
            donor               = false;
            hideSplashScreen    = false;
            suppressSocialPopup = false;

            ExtirpateOgcsMetadata = false;

            lastSyncDate   = new DateTime(0);
            completedSyncs = 0;
            VerboseOutput  = true;
        }
Esempio n. 7
0
        public AppointmentItem UpdateCalendarEntry(AppointmentItem ai, Event ev, ref int itemModified, Boolean forceCompare = false)
        {
            if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)   //The exception child objects might have changed
            {
                log.Debug("Processing recurring master appointment.");
            }
            else
            {
                if (!forceCompare)   //Needed if the exception has just been created, but now needs updating
                {
                    if (Settings.Instance.SyncDirection != SyncDirection.Bidirectional)
                    {
                        if (DateTime.Parse(GoogleCalendar.GoogleTimeFrom(ai.LastModificationTime)) > DateTime.Parse(ev.Updated))
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        if (GoogleCalendar.OGCSlastModified(ev).AddSeconds(5) >= DateTime.Parse(ev.Updated))
                        {
                            //Google last modified by OGCS
                            return(null);
                        }
                        if (DateTime.Parse(GoogleCalendar.GoogleTimeFrom(ai.LastModificationTime)) > DateTime.Parse(ev.Updated))
                        {
                            return(null);
                        }
                    }
                }
            }

            String evSummary = GoogleCalendar.GetEventSummary(ev);

            log.Debug("Processing >> " + evSummary);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine(evSummary);

            RecurrencePattern oPattern = (ai.RecurrenceState == OlRecurrenceState.olApptNotRecurring) ? null : ai.GetRecurrencePattern();

            if (ev.Start.Date != null)
            {
                if (ai.RecurrenceState != OlRecurrenceState.olApptMaster)
                {
                    ai.AllDayEvent = true;
                }
                if (MainForm.CompareAttribute("Start time", SyncDirection.GoogleToOutlook, ev.Start.Date, ai.Start.ToString("yyyy-MM-dd"), sb, ref itemModified))
                {
                    if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)
                    {
                        oPattern.PatternStartDate = DateTime.Parse(ev.Start.Date);
                    }
                    else
                    {
                        ai.Start = DateTime.Parse(ev.Start.Date);
                    }
                }
                if (MainForm.CompareAttribute("End time", SyncDirection.GoogleToOutlook, ev.End.Date, ai.End.ToString("yyyy-MM-dd"), sb, ref itemModified))
                {
                    if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)
                    {
                        oPattern.PatternEndDate = DateTime.Parse(ev.End.Date);
                    }
                    else
                    {
                        ai.End = DateTime.Parse(ev.End.Date);
                    }
                }
            }
            else
            {
                if (ai.RecurrenceState != OlRecurrenceState.olApptMaster)
                {
                    ai.AllDayEvent = false;
                }
                if (MainForm.CompareAttribute("Start time",
                                              SyncDirection.GoogleToOutlook,
                                              GoogleCalendar.GoogleTimeFrom(DateTime.Parse(ev.Start.DateTime)),
                                              GoogleCalendar.GoogleTimeFrom(ai.Start), sb, ref itemModified))
                {
                    if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)
                    {
                        oPattern.PatternStartDate = DateTime.Parse(ev.Start.DateTime);
                    }
                    else
                    {
                        ai.Start = DateTime.Parse(ev.Start.DateTime);
                    }
                }
                if (MainForm.CompareAttribute("End time",
                                              SyncDirection.GoogleToOutlook,
                                              GoogleCalendar.GoogleTimeFrom(DateTime.Parse(ev.End.DateTime)),
                                              GoogleCalendar.GoogleTimeFrom(ai.End), sb, ref itemModified))
                {
                    if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)
                    {
                        oPattern.PatternEndDate = DateTime.Parse(ev.End.DateTime);
                    }
                    else
                    {
                        ai.End = DateTime.Parse(ev.End.DateTime);
                    }
                }
            }
            oPattern = (RecurrencePattern)ReleaseObject(oPattern);

            if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)
            {
                if (ev.Recurrence == null || ev.RecurringEventId != null)
                {
                    log.Debug("Converting to non-recurring events.");
                    ai.ClearRecurrencePattern();
                    itemModified++;
                }
                else
                {
                    Recurrence.Instance.CompareOutlookPattern(ev, ai, sb, ref itemModified);
                    Recurrence.Instance.UpdateOutlookExceptions(ai, ev);
                }
            }
            else if (ai.RecurrenceState == OlRecurrenceState.olApptNotRecurring)
            {
                if (!ai.IsRecurring && ev.Recurrence != null && ev.RecurringEventId == null)
                {
                    log.Debug("Converting to recurring appointment.");
                    Recurrence.Instance.CreateOutlookExceptions(ai, ev);
                    itemModified++;
                }
            }

            String summaryObfuscated = Obfuscate.ApplyRegex(ev.Summary, SyncDirection.GoogleToOutlook);

            if (MainForm.CompareAttribute("Subject", SyncDirection.GoogleToOutlook, summaryObfuscated, ai.Subject, sb, ref itemModified))
            {
                ai.Subject = summaryObfuscated;
            }
            if (!Settings.Instance.AddDescription)
            {
                ev.Description = "";
            }
            if (Settings.Instance.SyncDirection == SyncDirection.GoogleToOutlook || !Settings.Instance.AddDescription_OnlyToGoogle)
            {
                if (MainForm.CompareAttribute("Description", SyncDirection.GoogleToOutlook, ev.Description, ai.Body, sb, ref itemModified))
                {
                    ai.Body = ev.Description;
                }
            }

            if (MainForm.CompareAttribute("Location", SyncDirection.GoogleToOutlook, ev.Location, ai.Location, sb, ref itemModified))
            {
                ai.Location = ev.Location;
            }

            String oPrivacy = (ai.Sensitivity == OlSensitivity.olNormal) ? "default" : "private";
            String gPrivacy = (ev.Visibility == null ? "default" : ev.Visibility);

            if (MainForm.CompareAttribute("Private", SyncDirection.GoogleToOutlook, gPrivacy, oPrivacy, sb, ref itemModified))
            {
                ai.Sensitivity = (ev.Visibility != null && ev.Visibility == "private") ? OlSensitivity.olPrivate : OlSensitivity.olNormal;
            }
            String oFreeBusy = (ai.BusyStatus == OlBusyStatus.olFree) ? "transparent" : "opaque";
            String gFreeBusy = (ev.Transparency == null ? "opaque" : ev.Transparency);

            if (MainForm.CompareAttribute("Free/Busy", SyncDirection.GoogleToOutlook, gFreeBusy, oFreeBusy, sb, ref itemModified))
            {
                ai.BusyStatus = (ev.Transparency != null && ev.Transparency == "transparent") ? OlBusyStatus.olFree : OlBusyStatus.olBusy;
            }

            if (Settings.Instance.AddAttendees)
            {
                if (ev.Description != null && ev.Description.Contains("===--- Attendees ---==="))
                {
                    //Protect against <v1.2.4 where attendees were stored as text
                    log.Info("This event still has attendee information in the description - cannot sync them.");
                }
                else if (Settings.Instance.SyncDirection == SyncDirection.Bidirectional &&
                         ev.Attendees != null && ev.Attendees.Count == 0 && ai.Recipients.Count > 150)
                {
                    log.Info("Attendees not being synced - there are too many (" + ai.Recipients.Count + ") for Google.");
                }
                else
                {
                    //Build a list of Outlook attendees. Any remaining at the end of the diff must be deleted.
                    List <Recipient> removeRecipient = new List <Recipient>();
                    if (ai.Recipients != null)
                    {
                        foreach (Recipient recipient in ai.Recipients)
                        {
                            if (recipient.Name != ai.Organizer)
                            {
                                removeRecipient.Add(recipient);
                            }
                        }
                    }
                    if (ev.Attendees != null)
                    {
                        for (int g = ev.Attendees.Count - 1; g >= 0; g--)
                        {
                            bool          foundRecipient = false;
                            EventAttendee attendee       = ev.Attendees[g];

                            foreach (Recipient recipient in ai.Recipients)
                            {
                                if (!recipient.Resolved)
                                {
                                    recipient.Resolve();
                                }
                                String recipientSMTP = IOutlook.GetRecipientEmail(recipient);
                                if (recipientSMTP.ToLower() == attendee.Email.ToLower())
                                {
                                    foundRecipient = true;
                                    removeRecipient.Remove(recipient);

                                    //Optional attendee
                                    bool oOptional = (ai.OptionalAttendees != null && ai.OptionalAttendees.Contains(attendee.DisplayName ?? attendee.Email));
                                    bool gOptional = (attendee.Optional == null) ? false : (bool)attendee.Optional;
                                    if (MainForm.CompareAttribute("Recipient " + recipient.Name + " - Optional Check",
                                                                  SyncDirection.GoogleToOutlook, gOptional, oOptional, sb, ref itemModified))
                                    {
                                        if (gOptional)
                                        {
                                            recipient.Type = (int)OlMeetingRecipientType.olOptional;
                                        }
                                        else
                                        {
                                            recipient.Type = (int)OlMeetingRecipientType.olRequired;
                                        }
                                    }
                                    //Response is readonly in Outlook :(
                                    break;
                                }
                            }
                            if (!foundRecipient &&
                                (attendee.DisplayName != ai.Organizer)) //Attendee in Google is owner in Outlook, so can't also be added as a recipient)
                            {
                                sb.AppendLine("Recipient added: " + (attendee.DisplayName ?? attendee.Email));
                                createRecipient(attendee, ai);
                                itemModified++;
                            }
                        }
                    }

                    foreach (Recipient recipient in removeRecipient)
                    {
                        sb.AppendLine("Recipient removed: " + recipient.Name);
                        recipient.Delete();
                        itemModified++;
                    }
                }
            }
            //Reminders
            if (Settings.Instance.AddReminders)
            {
                if (ev.Reminders.Overrides != null)
                {
                    //Find the popup reminder in Google
                    for (int r = ev.Reminders.Overrides.Count - 1; r >= 0; r--)
                    {
                        EventReminder reminder = ev.Reminders.Overrides[r];
                        if (reminder.Method == "popup")
                        {
                            if (ai.ReminderSet)
                            {
                                if (MainForm.CompareAttribute("Reminder", SyncDirection.GoogleToOutlook, reminder.Minutes.ToString(), ai.ReminderMinutesBeforeStart.ToString(), sb, ref itemModified))
                                {
                                    ai.ReminderMinutesBeforeStart = (int)reminder.Minutes;
                                }
                            }
                            else
                            {
                                sb.AppendLine("Reminder: nothing => " + reminder.Minutes);
                                ai.ReminderSet = true;
                                ai.ReminderMinutesBeforeStart = (int)reminder.Minutes;
                                itemModified++;
                            } //if Outlook reminders set
                        }     //if google reminder found
                    }         //foreach reminder
                }
                else     //no google reminders set
                {
                    if (ai.ReminderSet)
                    {
                        sb.AppendLine("Reminder: " + ai.ReminderMinutesBeforeStart + " => removed");
                        ai.ReminderSet = false;
                        itemModified++;
                    }
                }
            }
            if (itemModified > 0)
            {
                MainForm.Instance.Logboxout(sb.ToString(), false, verbose: true);
                MainForm.Instance.Logboxout(itemModified + " attributes updated.", verbose: true);
                System.Windows.Forms.Application.DoEvents();
            }
            return(ai);
        }