Ejemplo n.º 1
0
        private void syncItem_Click(object sender, EventArgs e)
        {
            String menuItemText = (sender as ToolStripMenuItem).Text;

            SettingsStore.Calendar profile = Settings.Instance.Calendars.First(cal => cal._ProfileName == menuItemText);
            if (profile != null)
            {
                Sync.Engine.Instance.JobQueue.Add(new Sync.Engine.Job("NotificationTray", profile));
            }
            else
            {
                log.Error("Unable to find a profile by the name: " + menuItemText);
            }
        }
Ejemplo n.º 2
0
        public static void ExportElement(Object settingStore, String nodeName, object nodeValue, string filename)
        {
            XDocument xml = null;

            try {
                xml = XDocument.Load(filename);
            } catch (System.Exception ex) {
                OGCSexception.Analyse("Failed to load " + filename, ex, true);
                throw;
            }
            XElement settingsXE = null;

            try {
                settingsXE = xml.Descendants(ns + "Settings").FirstOrDefault();
            } catch (System.Exception ex) {
                log.Debug(filename + " head: " + xml.ToString().Substring(0, Math.Min(200, xml.ToString().Length)));
                OGCSexception.Analyse("Could not access 'Settings' element.", ex, true);
                return;
            }
            XElement xe        = null;
            XElement xeProfile = null;

            try {
                if (Settings.Profile.GetType(settingStore) == Settings.Profile.Type.Calendar)
                {
                    //It's a Calendar setting
                    SettingsStore.Calendar calSettings = settingStore as SettingsStore.Calendar;
                    XElement        xeCalendars        = settingsXE.Elements(ns + "Calendars").First();
                    List <XElement> xeCalendar         = xeCalendars.Elements(ns + Settings.Profile.Type.Calendar.ToString()).ToList();
                    xeProfile = xeCalendar.First(c => c.Element(ns + "_ProfileName").Value == calSettings._ProfileName);
                    xe        = xeProfile.Elements(ns + nodeName).First();
                }
                else if (settingStore is Settings)
                {
                    //It's a "global" setting
                    xe = settingsXE.Elements(ns + nodeName).First();
                }
                if (nodeValue == null && nodeName == "CloudLogging")   //Nullable Boolean node(s)
                {
                    XNamespace i = "http://www.w3.org/2001/XMLSchema-instance";
                    xe.SetAttributeValue(i + "nil", "true"); //Add nullable attribute 'i:nil="true"'
                    xe.SetValue(String.Empty);
                }
                else
                {
                    xe.SetValue(nodeValue);
                    if (nodeValue is Boolean && nodeValue != null)
                    {
                        xe.RemoveAttributes(); //Remove nullable attribute 'i:nil="true"'
                    }
                }
                xml.Save(filename);
                log.Debug("Setting '" + nodeName + "' updated to '" + nodeValue + "'");
            } catch (System.Exception ex) {
                if (OGCSexception.GetErrorCode(ex) == "0x80131509")   //Sequence contains no elements
                {
                    log.Debug("Adding Setting " + nodeName + " for " + settingStore.ToString() + " to " + filename);
                    if (xeProfile != null)
                    {
                        xeProfile.Add(new XElement(ns + nodeName, nodeValue));
                    }
                    else
                    {
                        settingsXE.Add(new XElement(ns + nodeName, nodeValue));
                    }
                    xml.Root.Sort();
                    xml.Save(filename);
                }
                else
                {
                    OGCSexception.Analyse("Failed to export setting " + nodeName + "=" + nodeValue + " for " + settingStore.ToString() + " to " + filename + " file.", ex);
                }
            }
        }