コード例 #1
0
        public void AddSite()
        {
            SiteModel site = new SiteModel
            {
                Id       = Id,
                Url      = Url,
                Name     = Name,
                Priority = Priority
            };

            //Url = string.Empty;

            using var dbContext = new DailyDevDbContext();
            if (Id > 0)
            {
                dbContext.Update(site);
            }
            else
            {
                dbContext.SiteModels.Add(site);
            }
            dbContext.SaveChanges();
            Id         = 0;
            Url        = string.Empty;
            Name       = string.Empty;
            ButtonText = "Add Site";
            SetupSites();
        }
コード例 #2
0
        private async Task OnRemoveSiteAsync(SiteModel model)
        {
            using var dbContext = new DailyDevDbContext();
            dbContext.Remove(model);
            await dbContext.SaveChangesAsync();

            Sites.Remove(model);
            TotalBlogsCount = Sites.Count();
        }
コード例 #3
0
        public async Task OnItemSelectedAsync(SiteModel model)
        {
            if (model != null)
            {
                BlogPosts.Clear();
                ButtonText = "Update Site";
                Url        = model.Url;
                Name       = model.Name;
                Id         = model.Id;
                Priority   = model.Priority;

                FeedService service = new FeedService();
                var(feedModel, error) = await service.FetchAsync(model.Url);

                if (feedModel != null)
                {
                    BlogTitle = feedModel.Title;
                    BlogPosts.Clear();
                    foreach (FeedItemModel item in feedModel.Items)
                    {
                        BlogPosts.Add(item);
                    }
                }
                else
                {
                    var psi = new ProcessStartInfo
                    {
                        FileName        = model.Url,
                        UseShellExecute = true
                    };
                    Process.Start(psi);

                    NotificationBackground = Brushes.Red;
                    NotificationText       = error;
                    ShowNotification       = Visibility.Visible;



                    await Task.Factory.StartNew(
                        async() =>
                    {
                        await Task.Delay(2000);

                        NotificationBackground = Brushes.Green;
                        NotificationText       = string.Empty;
                        ShowNotification       = Visibility.Collapsed;
                    }
                        );
                }
            }
        }