Exemple #1
0
        public RSSAtomFeed GetFeed(string id)
        {
            if (id == null)
            {
                Logger?.Log(nameof(RSSAtomFeedCollection), nameof(GetFeed), new ArgumentException($"{id} must be not-null"));
            }
            else if (string.IsNullOrEmpty(id))
            {
                Logger?.Log(nameof(RSSAtomFeedCollection), nameof(GetFeed), new ArgumentException($"{id} must be not empty string"));
            }
            else
            {
                return(Feeds.First(feed => feed.Id == id));
            }

            return(Feeds.First());
        }
        public FeedHandlerConfigWindowViewModel(LogViewer logViewer)
        {
            AddItem = ReactiveCommand.Create(() => Feeds.Add(
                                                 new FeedHandlerConfig
            {
                CheckEveryMinutes = 15,
                Regex             = ".*"
            }));
            DelItem   = ReactiveCommand.Create <string>(url => Feeds.Remove(Feeds.First(f => f.Url == url)));
            SaveItems = ReactiveCommand.Create(async() =>
            {
                await Helpers.SaveConfigFile <FeedHandler>(Feeds.ToList());
                CloseWindow.OnNext(true);
            });
            Cancel   = ReactiveCommand.Create(() => CloseWindow.OnNext(false));
            ViewLogs = ReactiveCommand.Create(async() =>
            {
                if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
                {
                    var window = new Window
                    {
                        Height  = 400,
                        Width   = 1200,
                        Content = logViewer
                    };
                    await window.ShowDialog(desktop.MainWindow);
                }
            });

            var config = Helpers.GetConfig <FeedHandler, List <FeedHandlerConfig> >();

            if (config.Count == 0)
            {
                AddItem.Execute().Subscribe();
            }
            else
            {
                config.ForEach(c => Feeds.Add(c));
            }
        }