コード例 #1
0
        private async void AddFeed(RoutedEventArgs e)
        {
            // Hides browser otherwise dialog gets behind it
            IsBrowserVisible = false;
            RaisePropertyChanged("IsBrowserVisible");
            var FeedText = await _dialogCoordinator.ShowInputAsync(this, "Add Feed", "Enter the URL of the feed:");

            if (FeedText != null)
            {
                string errMsg = null;
                try
                {
                    Uri       feedUri = new Uri(FeedText);
                    Data.Feed f       = new Data.Feed();
                    f.Location = feedUri;
                    f.UpdateFromUri(true, RetentionDays);
                    f.Save(true);
                    InitializeData(true);
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                if (errMsg != null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Add Feed", "Unable to create a feed for the supplied URL: " + errMsg);
                }
            }
            IsBrowserVisible = true;
            RaisePropertyChanged("IsBrowserVisible");
        }
コード例 #2
0
        private async void ImportOPML(RoutedEventArgs e)
        {
            try
            {
                OPML opml = new OPML();
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = false;
                openFileDialog.DefaultExt = ".opml";
                openFileDialog.Filter = "OPML Files (*.opml)|*.opml";

                Exception exc = null;

                if (openFileDialog.ShowDialog() == true)
                {
                    List<Feed> t = opml.Import(openFileDialog.FileName);
                    foreach (Feed f in t)
                    {
                        try
                        {
                            Data.Feed feed = new Data.Feed(f);
                            feed.Location = f.Location;
                            feed.Save(false);
                        }
                        catch (Exception ee)
                        {
                            exc = ee;
                        }
                    }

                    // Reload tree
                    InitializeData(true);


                    await _dialogCoordinator.ShowMessageAsync(this, "Import OPML", "OPML imported successfully. Allow some minutes to let feed titles update from the RSS feed.");

                    // Update details from the uri
                    Task updaterTask = Task.Factory.StartNew(async () =>
                    {
                        _updaterInPause = true;
                        foreach (Feed f in t)
                        {
                            try
                            {
                                Data.Feed feed = new Data.Feed(f);
                                feed.Location = f.Location;
                                feed.UpdateFromUri(true, RetentionDays);
                                feed.Save(true);
                            }
                            catch (Exception ee)
                            {
                                exc = ee;
                            }
                        }
                        _updaterInPause = false;

                        InitializeData(true);

                        if (exc != null)
                            await _dialogCoordinator.ShowMessageAsync(this, "Import OPML", "Unable to update feeds: " + exc.Message);

                    },
                    CancellationToken.None,
                    TaskCreationOptions.None,
                    TaskScheduler.Default);


                    if (exc != null)
                        throw exc;
                }
            }
            catch (Exception ex)
            {
                IsBrowserVisible = false;
                RaisePropertyChanged("IsBrowserVisible");
                await _dialogCoordinator.ShowMessageAsync(this, "Import OPML", "Unable to import: " + ex.Message);
            }
        }
コード例 #3
0
        private async void AddFeed(RoutedEventArgs e)
        {
            // Hides browser otherwise dialog gets behind it
            IsBrowserVisible = false;
            RaisePropertyChanged("IsBrowserVisible");
            var FeedText = await _dialogCoordinator.ShowInputAsync(this, "Add Feed", "Enter the URL of the feed:");
            if (FeedText != null)
            {
                string errMsg = null;
                try
                {
                    Uri feedUri = new Uri(FeedText);
                    Data.Feed f = new Data.Feed();
                    f.Location = feedUri;
                    f.UpdateFromUri(true, RetentionDays);
                    f.Save(true);
                    InitializeData(true);
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                if (errMsg != null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Add Feed", "Unable to create a feed for the supplied URL: " + errMsg);
                }
            }
            IsBrowserVisible = true;
            RaisePropertyChanged("IsBrowserVisible");

        }
コード例 #4
0
        private async void EditFeed(RoutedEventArgs e)
        {
            if (_selectedNode == null)
                return;
            SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode;
            Model.Feed selectedFeed = null;
            if (tvm.Node is Model.Feed)
            {
                selectedFeed = (Model.Feed)tvm.Node;
            }
            else
            {
                if (tvm.Node is Model.Host)
                {
                    try
                    {
                        Model.Host selectedHost = (Model.Host)tvm.Node;
                        IsBrowserVisible = false;
                        RaisePropertyChanged("IsBrowserVisible");
                        MetroDialogSettings diagSettings = new MetroDialogSettings();
                        diagSettings.DefaultText = selectedHost.Zoom.ToString();
                        var ZoomLevel = await _dialogCoordinator.ShowInputAsync(this, "Set Zoom Level", "Enter the desired zoom level for this host: ", diagSettings);
                        int prevZoom = selectedHost.Zoom;
                        selectedHost.Zoom = Int32.Parse(ZoomLevel.ToString());
                        Data.Host dh = new Data.Host(selectedHost);
                        dh.Save();

                        if (prevZoom != selectedHost.Zoom)
                        {
                            var msg = new SendSetZoomMessage(selectedHost.Zoom);
                            msg.SetImmediately = true;
                            Messenger.Default.Send<SendSetZoomMessage>(msg);
                        }
                    }
                    catch (Exception ex)
                    {
                        await _dialogCoordinator.ShowMessageAsync(this, "Set Zoom Level", "Unable to set zoom: " + ex.Message);
                    }
                    finally
                    {
                        IsBrowserVisible = true;
                        RaisePropertyChanged("IsBrowserVisible");
                    }
                }
                return;
            }


            // Hides browser otherwise dialog gets behind it
            IsBrowserVisible = false;
            RaisePropertyChanged("IsBrowserVisible");
            MetroDialogSettings dialogSettings = new MetroDialogSettings();
            dialogSettings.DefaultText = selectedFeed.Location.ToString();
            var FeedText = await _dialogCoordinator.ShowInputAsync(this, "Edit feed", "Enter the URL of the feed:", dialogSettings);
            if (FeedText != null)
            {
                string errMsg = null;
                try
                {
                    Uri feedUri = new Uri(FeedText);
                    Data.Feed f = new Data.Feed(selectedFeed);
                    f.Location = feedUri;
                    f.UpdateFromUri(true, RetentionDays);
                    f.Save(true);
                    InitializeData(true);
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                if (errMsg != null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Edit Feed", "Unable to edit feed with the supplied URL: " + errMsg);
                }
            }
            IsBrowserVisible = true;
            RaisePropertyChanged("IsBrowserVisible");
        }
コード例 #5
0
        private async void ImportOPML(RoutedEventArgs e)
        {
            try
            {
                OPML           opml           = new OPML();
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = false;
                openFileDialog.DefaultExt  = ".opml";
                openFileDialog.Filter      = "OPML Files (*.opml)|*.opml";

                Exception exc = null;

                if (openFileDialog.ShowDialog() == true)
                {
                    List <Feed> t = opml.Import(openFileDialog.FileName);
                    foreach (Feed f in t)
                    {
                        try
                        {
                            Data.Feed feed = new Data.Feed(f);
                            feed.Location = f.Location;
                            feed.Save(false);
                        }
                        catch (Exception ee)
                        {
                            exc = ee;
                        }
                    }

                    // Reload tree
                    InitializeData(true);


                    await _dialogCoordinator.ShowMessageAsync(this, "Import OPML", "OPML imported successfully. Allow some minutes to let feed titles update from the RSS feed.");

                    // Update details from the uri
                    Task updaterTask = Task.Factory.StartNew(async() =>
                    {
                        _updaterInPause = true;
                        foreach (Feed f in t)
                        {
                            try
                            {
                                Data.Feed feed = new Data.Feed(f);
                                feed.Location  = f.Location;
                                feed.UpdateFromUri(true, RetentionDays);
                                feed.Save(true);
                            }
                            catch (Exception ee)
                            {
                                exc = ee;
                            }
                        }
                        _updaterInPause = false;

                        InitializeData(true);

                        if (exc != null)
                        {
                            await _dialogCoordinator.ShowMessageAsync(this, "Import OPML", "Unable to update feeds: " + exc.Message);
                        }
                    },
                                                             CancellationToken.None,
                                                             TaskCreationOptions.None,
                                                             TaskScheduler.Default);


                    if (exc != null)
                    {
                        throw exc;
                    }
                }
            }
            catch (Exception ex)
            {
                IsBrowserVisible = false;
                RaisePropertyChanged("IsBrowserVisible");
                await _dialogCoordinator.ShowMessageAsync(this, "Import OPML", "Unable to import: " + ex.Message);
            }
        }
コード例 #6
0
        private async void EditFeed(RoutedEventArgs e)
        {
            if (_selectedNode == null)
            {
                return;
            }
            SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode;

            Model.Feed selectedFeed = null;
            if (tvm.Node is Model.Feed)
            {
                selectedFeed = (Model.Feed)tvm.Node;
            }
            else
            {
                if (tvm.Node is Model.Host)
                {
                    try
                    {
                        Model.Host selectedHost = (Model.Host)tvm.Node;
                        IsBrowserVisible = false;
                        RaisePropertyChanged("IsBrowserVisible");
                        MetroDialogSettings diagSettings = new MetroDialogSettings();
                        diagSettings.DefaultText = selectedHost.Zoom.ToString();
                        var ZoomLevel = await _dialogCoordinator.ShowInputAsync(this, "Set Zoom Level", "Enter the desired zoom level for this host: ", diagSettings);

                        int prevZoom = selectedHost.Zoom;
                        selectedHost.Zoom = Int32.Parse(ZoomLevel.ToString());
                        Data.Host dh = new Data.Host(selectedHost);
                        dh.Save();

                        if (prevZoom != selectedHost.Zoom)
                        {
                            var msg = new SendSetZoomMessage(selectedHost.Zoom);
                            msg.SetImmediately = true;
                            Messenger.Default.Send <SendSetZoomMessage>(msg);
                        }
                    }
                    catch (Exception ex)
                    {
                        await _dialogCoordinator.ShowMessageAsync(this, "Set Zoom Level", "Unable to set zoom: " + ex.Message);
                    }
                    finally
                    {
                        IsBrowserVisible = true;
                        RaisePropertyChanged("IsBrowserVisible");
                    }
                }
                return;
            }


            // Hides browser otherwise dialog gets behind it
            IsBrowserVisible = false;
            RaisePropertyChanged("IsBrowserVisible");
            MetroDialogSettings dialogSettings = new MetroDialogSettings();

            dialogSettings.DefaultText = selectedFeed.Location.ToString();
            var FeedText = await _dialogCoordinator.ShowInputAsync(this, "Edit feed", "Enter the URL of the feed:", dialogSettings);

            if (FeedText != null)
            {
                string errMsg = null;
                try
                {
                    Uri       feedUri = new Uri(FeedText);
                    Data.Feed f       = new Data.Feed(selectedFeed);
                    f.Location = feedUri;
                    f.UpdateFromUri(true, RetentionDays);
                    f.Save(true);
                    InitializeData(true);
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                if (errMsg != null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Edit Feed", "Unable to edit feed with the supplied URL: " + errMsg);
                }
            }
            IsBrowserVisible = true;
            RaisePropertyChanged("IsBrowserVisible");
        }