Beispiel #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbName.Text) || string.IsNullOrEmpty(tbName.Name))
            {
                MessageBox.Show("Please enter a name for the alert to check.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (lbConditions.Items.Count == 0)
            {
                MessageBox.Show("Please enter at least one alert to check.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!_actionSet)
            {
                MessageBox.Show("Please select the action desired upon criteria match.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Alert newCondition = new Alert
            {
                Name        = tbName.Text,
                Description = tbDescription.Text,
                Enabled     = (bool)chbEnabled.IsChecked,
                Action      = fap.GetAction(),
                Criterias   = new List <Criteria>(),
                lights      = fap.GetSelectedLights(),
                Url         = tbUrl.Text
            };

            foreach (Criteria t in lbConditions.Items)
            {
                newCondition.Criterias.Add(t);
            }

            if (_oldName != null)
            {
                RssFeedAlertHandler.DeleteFeedAlert(_oldName);
            }

            if (RssFeedAlertHandler.SaveFeedAlert(newCondition))
            {
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("Therer was an error while saving the current Rss Feed Alert.", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 public RssFeedMonitorSettingsView()
 {
     _checkdelay = Properties.Settings.Default.UpdateInterval;
     _listalerts = new ObservableCollection <Alert>(RssFeedAlertHandler.LoadRssFeedAlerts());
 }
Beispiel #3
0
        public void CheckAlertAndTriggers()
        {
            List <Alert>    listAlert = RssFeedAlertHandler.LoadRssFeedAlerts();
            SyndicationFeed sf;

            foreach (Alert a in listAlert)
            {
                XmlReader xr = XmlReader.Create(a.Url);
                sf = SyndicationFeed.Load(xr);
                if (sf == null)
                {
                    return;
                }

                List <SyndicationItem> si = sf.Items.ToList();

                if (a.Criterias.Exists(x => x.RSSElement == "Title") == true)
                {
                    Criteria cr = (Criteria)a.Criterias.Select(x => x.RSSElement == "Title");
                    if (cr.Condition == "Contains")
                    {
                        si.RemoveAll(x => !x.Title.Text.Contains(cr.UserCondition));
                    }

                    if (cr.Condition == "Equals")
                    {
                        si.RemoveAll(x => x.Title.Text != cr.UserCondition);
                    }
                }

                if (a.Criterias.Exists(x => x.RSSElement == "Description") == true)
                {
                    Criteria cr = (Criteria)a.Criterias.Select(x => x.RSSElement == "Description");
                    if (cr.Condition == "Contains")
                    {
                        si.RemoveAll(x => !x.Summary.Text.Contains(cr.UserCondition));
                    }

                    if (cr.Condition == "Equals")
                    {
                        si.RemoveAll(x => x.Summary.Text != cr.UserCondition);
                    }
                }

                if (a.Criterias.Exists(x => x.RSSElement == "Publication Date") == true)
                {
                    Criteria cr = (Criteria)a.Criterias.Select(x => x.RSSElement == "Title");
                    if (cr.Condition == "Contains")
                    {
                        si.RemoveAll(x => !x.PublishDate.ToString().Contains(cr.UserCondition));
                    }

                    if (cr.Condition == "Equals")
                    {
                        si.RemoveAll(x => x.PublishDate.ToString() != cr.UserCondition);
                    }

                    if (cr.Condition == "Greater")
                    {
                        si.RemoveAll(x => x.PublishDate > DateTimeOffset.Parse(cr.UserCondition));
                    }

                    if (cr.Condition == "Lower")
                    {
                        si.RemoveAll(x => x.PublishDate < DateTimeOffset.Parse(cr.UserCondition));
                    }
                }

                if (a.Criterias.Exists(x => x.RSSElement == "Category") == true)
                {
                    Criteria cr = (Criteria)a.Criterias.Select(x => x.RSSElement == "Title");

                    /*if (cr.Condition == "Contains")
                     *  si.RemoveAll(x => !x.Categories.Contains.Text.Contains(cr.UserCondition));*/

                    /*if (cr.Condition == "Equals")
                     * si.RemoveAll(x => x.Title.Text != cr.UserCondition);*/
                }

                if (si.Count > 0)
                {
                    // Do ALERT ABOUT IT.
                }
            }
        }