private void RefreshList(notificationSetting affSetting)
 {
     foreach (var c in affSetting.notificationList)
     {
         lvnotifications.Items.Add(c);
     }
 }
示例#2
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     //create the notifyicon (it's a resource declared in NotifyIconResources.xaml
     notifyIcon = (TaskbarIcon)FindResource("NotifyIcon");
     notificationSettings = notificationSettingParser.ParseXMLfile("Settings.xml");
     // for the time span we have to convert into seconds
     this.dispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, notificationSettings.interval / 1000), DispatcherPriority.Normal, OnTimerTick, Dispatcher);
     this.dispatcherTimer.Start();
 }
        public static void SaveToXMLFile(notificationSetting settings, string settingsFile)
        {
            XDocument xDoc = new XDocument();
            XElement elem = new XElement("notificationSettings");
            elem.Add(new XElement("interval", settings.interval));
            elem.Add(new XElement("showUptime", settings.showUpTime));
            elem.Add(new XElement("randomShow", settings.randomShow));
            elem.Add(new XElement("limitRunningTime", settings.limitRunningTime,
                            new XAttribute("from", settings.runFrom.ToShortTimeString()),
                            new XAttribute("until", settings.runUntil.ToShortTimeString())));

            elem.Add (new XElement("notifications",

                from notification in settings.notificationList
                select new XElement("notification", notification.notificationString)
                )
                );

            xDoc.Add(elem);
            xDoc.Save(settingsFile);
        }
        public static notificationSetting ParseXMLfile(string settingsFile)
        {
            var notificationSettings = new notificationSetting();
            XDocument doc = XDocument.Load(settingsFile);
            XElement generalElement = doc
                .Element("notificationSettings");
            notificationSettings.interval = int.Parse(generalElement.Element("interval").Value);
            notificationSettings.showUpTime = int.Parse(generalElement.Element("showUptime").Value);
            notificationSettings.limitRunningTime = bool.Parse(generalElement.Element("limitRunningTime").Value);
            notificationSettings.runFrom = DateTime.Parse(generalElement.Element("limitRunningTime").Attribute("from").Value);
            notificationSettings.runUntil = DateTime.Parse(generalElement.Element("limitRunningTime").Attribute("until").Value);
            notificationSettings.randomShow = bool.Parse(generalElement.Element("randomShow").Value);

            notificationSettings.notificationList = (from c in doc.Descendants("notification")
                                                   select new notification(c.Value)
                                                   //{
                                                     //  notificationString = c.Value
                                                   //}
                                                   ).ToList<notification>();
            return notificationSettings;
        }
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            notificationSetting affSetting = new notificationSetting();

            affSetting.interval = int.Parse(txtInterval.Text) * 1000;// convert to ms
            affSetting.showUpTime = int.Parse(txtShowUpTime.Text) * 1000;// convert to ms
            affSetting.limitRunningTime = (bool)chkLimitRunningTime.IsChecked;
            affSetting.runFrom = DateTime.Parse(timeFrom.Text);
            affSetting.runUntil = DateTime.Parse(timeTo.Text);
            affSetting.randomShow = (bool)chkShowRandomly.IsChecked;

            foreach (var c in lvnotifications.Items)
            {

                affSetting.notificationList.Add(new notification(((notification)c).notificationString));
            }

            // Store into file and refresh the app
            notificationSettingParser.SaveToXMLFile(affSetting, "Settings.XML");
            App thisApp = (App)App.Current;
            thisApp.notificationSettings = affSetting;
        }