Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
bReader.Server: imporved db behavior.
Browse files Browse the repository at this point in the history
better ui function, minor fix.
  • Loading branch information
artiga033 committed Aug 25, 2021
1 parent efb8996 commit 480a15d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
30 changes: 22 additions & 8 deletions bReader.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
using bReader.Server.Data;
using bReader.Shared;
using bReader.Shared.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace bReader.Server
{
public class Program
{
public static void Main(string[] args)
{
var host = CreateHostBuilder(args);

host.Build().Run();
var host = CreateHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
using var db = scope.ServiceProvider.GetRequiredService<IDbContextFactory<FeedDbContext>>().CreateDbContext();
db.Database.Migrate();
var set = scope.ServiceProvider.GetRequiredService<ISettingService>();
InitSettings(set);
}
host.Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Expand All @@ -24,5 +30,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
{
webBuilder.UseStartup<Startup>();
});

protected static void InitSettings(ISettingService settingService)
{
Dictionary<string, string> dic = settingService.GetSettingsAsync().Result;
dic.AddIfNone("SourceUpdatePeriod", "60");

settingService.SaveSettingsAsync(dic);
}
}
}
2 changes: 1 addition & 1 deletion bReader.Server/Services/SettingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<bool> SaveSettingsAsync(Dictionary<string, string> settings)
using var context = _factory.CreateDbContext();
//use a lookuptable exchanging space with time
var lookup = await context.Settings.AsNoTracking().ToDictionaryAsync(x => x.Key, x => x.Id);
var sets = settings.Select(x => new AppSetting() { Id = lookup[x.Key], Key = x.Key, Value = x.Value });
var sets = settings.Select(x => new AppSetting() { Id = lookup.ContainsKey(x.Key)?lookup[x.Key]:0, Key = x.Key, Value = x.Value });
context.UpdateRange(sets);
this.cached = settings;// updated cached data
return await context.SaveChangesAsync() > 0;
Expand Down
5 changes: 0 additions & 5 deletions bReader.Shared/Components/AppSettingPanel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
protected async override Task OnInitializedAsync()
{
this.AppSettings = await SettingService.GetSettingsAsync();
InitDic(AppSettings);
await base.OnInitializedAsync();
}
protected async Task SaveSettingsAsync()
{
saveSuccess = await SettingService.SaveSettingsAsync(AppSettings);
savecomplete = true;
}
private void InitDic(Dictionary<string, string> dic)
{
this.AppSettings.AddIfNone("SourceUpdatePeriod", "60");
}
}
6 changes: 4 additions & 2 deletions bReader.Shared/Components/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
</div>
<nav class="@NavMenuCssClass">
<Nav>
<BlazorFluentUI.Routing.NavLink Name="首页" IconName="Home" Url=""></BlazorFluentUI.Routing.NavLink>
<BlazorFluentUI.Routing.NavLink Name="选项" IconName="Settings" Url="settings"></BlazorFluentUI.Routing.NavLink>
<div @onclick="ToggleNavMenu">
<BlazorFluentUI.Routing.NavLink Name="首页" IconName="Home" Url=""></BlazorFluentUI.Routing.NavLink>
<BlazorFluentUI.Routing.NavLink Name="选项" IconName="Settings" Url="settings"></BlazorFluentUI.Routing.NavLink>
</div>
<hr />
<NavLinkGroup Name="收藏" CollapseByDefault="false">
<div @onclick="ToggleNavMenu">
Expand Down
4 changes: 2 additions & 2 deletions bReader.Shared/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
</FooterTemplate>
</Dialog>
<Stack>
<CommandBar Items="commandBarItems"/>
<PrimaryButton Text="刷新所有RSS源" OnClick="async () => await RefreshAllFeeds()"></PrimaryButton>
<PrimaryButton Text="刷新所有RSS源" OnClick="async () => await RefreshAllFeeds()" Style="width:10em;align-self:flex-end;"></PrimaryButton>
<ProgressIndicator PercentComplete="feedRefreshPercent" Description="@progressDescription"></ProgressIndicator>
<CommandBar Items="commandBarItems"/>
@* if you delete this <div> tag, BlazorFluentUI would throw an exception, a JSON Eccption. Why? Why!*@
<div data-is-scrollable="true" style="height:60vh;overflow-y:auto;">
<DetailsList ItemsSource="Feeds"
Expand Down

0 comments on commit 480a15d

Please sign in to comment.