Пример #1
0
        private static void upgradeToMultiCalendar()
        {
            backupSettingsFile();

            XDocument xml = null;

            try {
                xml = XDocument.Load(Settings.ConfigFile);
                XElement settingsElement  = XMLManager.GetElement("Settings", xml);
                XElement calendarsElement = XMLManager.AddElement("Calendars", settingsElement);
                XElement calendarElement  = XMLManager.AddElement("Calendar", calendarsElement);

                //If a source element doesn't exist, the XML is not changed
                //Manually add Profile Name - it's critical to be able to select the right profile later on and a Settings.Save() might not have happened.
                XMLManager.AddElement("_ProfileName", calendarElement).Value = "Default";

                XMLManager.MoveElement("OutlookService", settingsElement, calendarElement);
                XMLManager.MoveElement("MailboxName", settingsElement, calendarElement);
                XMLManager.MoveElement("SharedCalendar", settingsElement, calendarElement);
                XMLManager.MoveElement("UseOutlookCalendar", settingsElement, calendarElement);
                XMLManager.MoveElement("CategoriesRestrictBy", settingsElement, calendarElement);
                XMLManager.MoveElement("Categories", settingsElement, calendarElement);
                XMLManager.MoveElement("OnlyRespondedInvites", settingsElement, calendarElement);
                XMLManager.MoveElement("OutlookDateFormat", settingsElement, calendarElement);
                XMLManager.MoveElement("OutlookGalBlocked", settingsElement, calendarElement);

                XMLManager.MoveElement("UseGoogleCalendar", settingsElement, calendarElement);
                XMLManager.MoveElement("CloakEmail", settingsElement, calendarElement);
                XMLManager.MoveElement("ExcludeDeclinedInvites", settingsElement, calendarElement);
                XMLManager.MoveElement("ExcludeGoals", settingsElement, calendarElement);

                XMLManager.MoveElement("SyncDirection", settingsElement, calendarElement);
                XMLManager.MoveElement("DaysInThePast", settingsElement, calendarElement);
                XMLManager.MoveElement("DaysInTheFuture", settingsElement, calendarElement);
                XMLManager.MoveElement("SyncInterval", settingsElement, calendarElement);
                XMLManager.MoveElement("SyncIntervalUnit", settingsElement, calendarElement);
                XMLManager.MoveElement("OutlookPush", settingsElement, calendarElement);
                XMLManager.MoveElement("AddLocation", settingsElement, calendarElement);
                XMLManager.MoveElement("AddDescription", settingsElement, calendarElement);
                XMLManager.MoveElement("AddDescription_OnlyToGoogle", settingsElement, calendarElement);
                XMLManager.MoveElement("AddReminders", settingsElement, calendarElement);
                XMLManager.MoveElement("UseGoogleDefaultReminder", settingsElement, calendarElement);
                XMLManager.MoveElement("UseOutlookDefaultReminder", settingsElement, calendarElement);
                XMLManager.MoveElement("ReminderDND", settingsElement, calendarElement);
                XMLManager.MoveElement("ReminderDNDstart", settingsElement, calendarElement);
                XMLManager.MoveElement("ReminderDNDend", settingsElement, calendarElement);
                XMLManager.MoveElement("AddAttendees", settingsElement, calendarElement);
                XMLManager.MoveElement("MaxAttendees", settingsElement, calendarElement);
                XMLManager.MoveElement("AddColours", settingsElement, calendarElement);
                XMLManager.MoveElement("MergeItems", settingsElement, calendarElement);
                XMLManager.MoveElement("DisableDelete", settingsElement, calendarElement);
                XMLManager.MoveElement("ConfirmOnDelete", settingsElement, calendarElement);
                XMLManager.MoveElement("TargetCalendar", settingsElement, calendarElement);
                XMLManager.MoveElement("CreatedItemsOnly", settingsElement, calendarElement);
                XMLManager.MoveElement("SetEntriesPrivate", settingsElement, calendarElement);
                XMLManager.MoveElement("SetEntriesAvailable", settingsElement, calendarElement);
                XMLManager.MoveElement("AvailabilityStatus", settingsElement, calendarElement);
                XMLManager.MoveElement("SetEntriesColour", settingsElement, calendarElement);
                XMLManager.MoveElement("SetEntriesColourValue", settingsElement, calendarElement);
                XMLManager.MoveElement("SetEntriesColourName", settingsElement, calendarElement);
                XMLManager.MoveElement("SetEntriesColourGoogleId", settingsElement, calendarElement);
                XMLManager.MoveElement("ColourMaps", settingsElement, calendarElement);
                XMLManager.MoveElement("SingleCategoryOnly", settingsElement, calendarElement);
                XMLManager.MoveElement("Obfuscation", settingsElement, calendarElement);

                XMLManager.MoveElement("ExtirpateOgcsMetadata", settingsElement, calendarElement);
                XMLManager.MoveElement("LastSyncDate", settingsElement, calendarElement);
            } catch (System.Exception ex) {
                OGCSexception.Analyse("Problem encountered whilst upgrading " + Settings.ConfigFilename, ex);
                throw ex;
            } finally {
                if (xml != null)
                {
                    xml.Root.Sort();
                    try {
                        xml.Save(Settings.ConfigFile);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse("Could not save upgraded settings file " + Settings.ConfigFile, ex);
                        throw ex;
                    }
                }
            }
        }