Browse Source

feat(Immortal) Disabling SQL

main
Jonathan McCaffrey 4 years ago
parent
commit
363d6835b8
  1. 8
      Components/Components.csproj
  2. 11
      Components/Navigation/DesktopNavComponent.razor
  3. 12
      Components/Navigation/MobileNavComponent.razor
  4. 10
      Components/Navigation/TabletNavComponent.razor
  5. 10
      Contexts/Contexts.csproj
  6. 8
      Contexts/DatabaseContext.cs
  7. 12
      IGP/App.razor
  8. 28
      IGP/IGP.csproj
  9. 33
      IGP/PageLayout.razor
  10. 100
      IGP/Pages/Agile/AgilePage.razor
  11. 66
      IGP/Pages/Agile/AgilePage.razor.css
  12. 9
      IGP/Pages/Agile/Parts/SprintComponent.razor
  13. 24
      IGP/Pages/ChangeLogPage.razor
  14. 13
      IGP/Pages/ChangeLogPage.razor.css
  15. 15
      IGP/Program.cs
  16. 5
      IGP/_Imports.razor
  17. 31
      Services/Development/AgileService.cs
  18. 48
      Services/Development/GitService.cs
  19. 54
      Services/IServices.cs
  20. 14
      Services/Services.csproj
  21. 28
      Services/Website/WebsiteService.cs

8
Components/Components.csproj

@ -6,6 +6,14 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<SupportedPlatform Include="browser" /> <SupportedPlatform Include="browser" />
</ItemGroup> </ItemGroup>

11
Components/Navigation/DesktopNavComponent.razor

@ -6,6 +6,8 @@
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@implements IDisposable @implements IDisposable
<div onmouseleave="@HoverOut" class="desktopNavContainer"> <div onmouseleave="@HoverOut" class="desktopNavContainer">
<div class="menuHeader" @onmouseover="() => NavigationService.ChangeNavigationState(NavigationStateType.Hovering_Menu)"> <div class="menuHeader" @onmouseover="() => NavigationService.ChangeNavigationState(NavigationStateType.Hovering_Menu)">
<NavLink href="/" class="websiteTitle"> <NavLink href="/" class="websiteTitle">
@ -98,11 +100,20 @@
@code { @code {
#if NO_SQL
[Parameter]
public List<WebSectionModel> WebSections { get; set; }
[Parameter]
public List<WebPageModel> WebPages { get; set; }
#else
[Parameter] [Parameter]
public DbSet<WebSectionModel> WebSections { get; set; } public DbSet<WebSectionModel> WebSections { get; set; }
[Parameter] [Parameter]
public DbSet<WebPageModel> WebPages { get; set; } public DbSet<WebPageModel> WebPages { get; set; }
#endif
protected override void OnInitialized() { protected override void OnInitialized() {
NavigationService.Subscribe(StateHasChanged); NavigationService.Subscribe(StateHasChanged);

12
Components/Navigation/MobileNavComponent.razor

@ -1,4 +1,6 @@
@using Model.Website 
@using Model.Website
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
<div class="mobileFooter"> <div class="mobileFooter">
<div class="mobileNavSectionsContainer"> <div class="mobileNavSectionsContainer">
@ -136,12 +138,20 @@
</style> </style>
@code { @code {
#if NO_SQL
[Parameter]
public List<WebSectionModel> WebSections { get; set; }
[Parameter]
public List<WebPageModel> WebPages { get; set; }
#else
[Parameter] [Parameter]
public DbSet<WebSectionModel> WebSections { get; set; } public DbSet<WebSectionModel> WebSections { get; set; }
[Parameter] [Parameter]
public DbSet<WebPageModel> WebPages { get; set; } public DbSet<WebPageModel> WebPages { get; set; }
#endif
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public NavigationManager NavigationManager { get; set; }

10
Components/Navigation/TabletNavComponent.razor

@ -142,11 +142,21 @@
@code { @code {
#if NO_SQL
[Parameter]
public List<WebSectionModel> WebSections { get; set; }
[Parameter]
public List<WebPageModel> WebPages { get; set; }
#else
[Parameter] [Parameter]
public DbSet<WebSectionModel> WebSections { get; set; } public DbSet<WebSectionModel> WebSections { get; set; }
[Parameter] [Parameter]
public DbSet<WebPageModel> WebPages { get; set; } public DbSet<WebPageModel> WebPages { get; set; }
#endif
bool NavOpen = true; bool NavOpen = true;

10
Contexts/Contexts.csproj

@ -6,6 +6,16 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;
NO_SQL;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;
NO_SQL;</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-preview.2.22153.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-preview.2.22153.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-preview.2.22153.1"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-preview.2.22153.1">

8
Contexts/DatabaseContext.cs

@ -1,4 +1,8 @@
using Microsoft.EntityFrameworkCore; #if NO_SQL
#else
using Microsoft.EntityFrameworkCore;
using Model.Website; using Model.Website;
using Model.Work.Git; using Model.Work.Git;
using Model.Work.Tasks; using Model.Work.Tasks;
@ -24,3 +28,5 @@ public class DatabaseContext : DbContext {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
} }
} }
#endif

12
IGP/App.razor

@ -1,5 +1,4 @@
@inject HttpClient HttpClient @inject HttpClient HttpClient
@inject DatabaseContext Database
<Router AppAssembly="@typeof(App).Assembly"> <Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData"> <Found Context="routeData">
@ -28,3 +27,14 @@
text-decoration-thickness: 3px; text-decoration-thickness: 3px;
} }
</style> </style>
@code {
#if NO_SQL
#else
[Inject]
DatabaseContext Database { get; set; }
#endif
}

28
IGP/IGP.csproj

@ -7,14 +7,32 @@
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest> <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="Pages\Agile\AgilePage.razor.css" />
<None Remove="Pages\ChangeLogPage.razor.css" />
</ItemGroup>
<ItemGroup>
<Content Include="Pages\Agile\AgilePage.razor.css" />
<Content Include="Pages\ChangeLogPage.razor.css" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-preview.2.22153.2" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-preview.2.22153.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-preview.2.22153.2" PrivateAssets="all" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-preview.2.22153.2" PrivateAssets="all" />
<!--
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-preview.2.22153.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-preview.2.22153.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0-preview.2.22153.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0-preview.2.22153.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-preview.2.22153.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-preview.2.22153.1" />
<NativeFileReference Include="e_sqlite3.o" /> <NativeFileReference Include="e_sqlite3.o" /> -->
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

33
IGP/PageLayout.razor

@ -3,30 +3,37 @@
@inject IWebsiteService WebService; @inject IWebsiteService WebService;
@implements IDisposable; @implements IDisposable;
@inject DatabaseContext Database;
<div class="layoutContainer" @onclick="OnPageClicked"> <div class="layoutContainer" @onclick="OnPageClicked">
@if (!WebService.IsLoaded()) { @if (!WebService.IsLoaded()) {
<LoadingComponent></LoadingComponent> <LoadingComponent></LoadingComponent>
} } else {
else {
<div class="content"> <div class="content">
@Body @Body
</div> </div>
<DesktopNavComponent WebSections=WebService.WebSectionModels <DesktopNavComponent WebSections=WebService.WebSectionModels
WebPages=WebService.WebPageModels/> WebPages=WebService.WebPageModels />
<TabletNavComponent WebSections=WebService.WebSectionModels <TabletNavComponent WebSections=WebService.WebSectionModels
WebPages=WebService.WebPageModels/> WebPages=WebService.WebPageModels />
<MobileNavComponent WebSections=WebService.WebSectionModels <MobileNavComponent WebSections=WebService.WebSectionModels
WebPages=WebService.WebPageModels/> WebPages=WebService.WebPageModels />
} }
</div> </div>
@code { @code {
bool NavOpen = true;
void OnNavClicked(EventArgs eventArgs) { #if NO_SQL
NavOpen = !NavOpen;
} #else
[Inject]
DatabaseContext Database { get; set; }
#endif
bool NavOpen = true;
void OnPageClicked(EventArgs eventArgs) { void OnPageClicked(EventArgs eventArgs) {
NavOpen = false; NavOpen = false;
@ -37,7 +44,13 @@
} }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
#if NO_SQL
await WebService.Load();
#else
await WebService.Load(Database); await WebService.Load(Database);
#endif
} }
void IDisposable.Dispose() { void IDisposable.Dispose() {

100
IGP/Pages/Agile/AgilePage.razor

@ -1,6 +1,5 @@
@implements IDisposable; @implements IDisposable;
@inject IAgileService AgileService; @inject IAgileService AgileService;
@inject DatabaseContext Database;
@layout PageLayout @layout PageLayout
@ -19,10 +18,18 @@
<div style="flex: 1; flex-grow: 1;"></div> <div style="flex: 1; flex-grow: 1;"></div>
<div class="sprintDates"> <div class="sprintDates">
<div class="sprintStartDate"> <div class="sprintStartDate">
<b>Start: </b>@sprint.StartDate.Value.ToString("dd/MM/yyyy") @if (sprint.StartDate != null)
{
<b>Start: </b>@sprint.StartDate.Value.ToString("dd/MM/yyyy")
}
</div> </div>
<div class="sprintEndDate"> <div class="sprintEndDate">
<b>End: </b>@sprint.EndDate.Value.ToString("dd/MM/yyyy") @if (sprint.EndDate != null)
{
<b>End: </b>@sprint.EndDate.Value.ToString("dd/MM/yyyy")
}
</div> </div>
</div> </div>
</summary> </summary>
@ -60,88 +67,27 @@ else {
} }
<style>
.agileViewContainer {
display: flex;
gap: 12px;
flex-direction: column;
}
.sprintDisplayContainer {
border: 4px solid var(--paper);
box-shadow: 0px 2px 12px rgba(0,0,0,0.2);
border-radius: 2px;
padding: 25px;
margin: auto;
width: 100%;
background-color:var(--paper);
}
@@media only screen and (max-width: 1025px) {
.sprintDisplayContainer {
padding: 2px;
}
}
.sprintSummary {
display: flex;
width: 100%;
}
.sprintDisplayContainer.@SprintType.Current.ToLower() {
border-color: #042901;
background-color:var(--paper);
}
.sprintDisplayContainer.@SprintType.Planned.ToLower() {
border-color: #2a2000;
background-color:var(--paper);
}
.sprintDisplayContainer.@SprintType.Completed.ToLower() {
border-color: #2a2000;
background-color:var(--paper);
}
details .sprintSummary::before {
content: "+";
font-weight: bolder;
font-size: 1.5rem;
padding-right: 8px;
}
details[open] .sprintSummary::before {
content: "-";
}
.sprintTitle {
width: 400px;
font-size: 1.6rem;
font-weight: 800;
}
.sprintDates {
width: 160px;
text-align: right;
}
</style>
@code { @code {
#if NO_SQL
[Parameter] [Parameter]
public DbSet<SprintModel> Sprints { get; set; } public List<TaskModel> Tasks { get; set; }
[Parameter]
public List<SprintModel> Sprints { get; set; }
#else
[Inject]
DatabaseContext Database { get; set; }
[Parameter] [Parameter]
public DbSet<TaskModel> Tasks { get; set; } public DbSet<TaskModel> Tasks { get; set; }
[Parameter]
public DbSet<SprintModel> Sprints { get; set; }
#endif
private readonly List<TaskModel> backlog = new(); private readonly List<TaskModel> backlog = new();
protected override void OnInitialized() { protected override void OnInitialized() {
AgileService.Subscribe(HasChanged); AgileService.Subscribe(HasChanged);
} }
@ -166,7 +112,11 @@ details[open] .sprintSummary::before {
} }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
#if NO_SQL
await AgileService.Load();
#else
await AgileService.Load(Database); await AgileService.Load(Database);
#endif
} }
} }

66
IGP/Pages/Agile/AgilePage.razor.css

@ -0,0 +1,66 @@

.agileViewContainer {
display: flex;
gap: 12px;
flex-direction: column;
}
.sprintDisplayContainer {
border: 4px solid var(--paper);
box-shadow: 0px 2px 12px rgba(0,0,0,0.2);
border-radius: 2px;
padding: 25px;
margin: auto;
width: 100%;
background-color: var(--paper);
}
@media only screen and (max-width: 1025px) {
.sprintDisplayContainer {
padding: 2px;
}
}
.sprintSummary {
display: flex;
width: 100%;
}
.sprintDisplayContainer.current {
border-color: #042901;
background-color: var(--paper);
}
.sprintDisplayContainer.planned {
border-color: #2a2000;
background-color: var(--paper);
}
.sprintDisplayContainer.completed {
border-color: #2a2000;
background-color: var(--paper);
}
details .sprintSummary::before {
content: "+";
font-weight: bolder;
font-size: 1.5rem;
padding-right: 8px;
}
details[open] .sprintSummary::before {
content: "-";
}
.sprintTitle {
width: 400px;
font-size: 1.6rem;
font-weight: 800;
}
.sprintDates {
width: 160px;
text-align: right;
}

9
IGP/Pages/Agile/Parts/SprintComponent.razor

@ -221,11 +221,16 @@
@code { @code {
#if NO_SQL
[Parameter] [Parameter]
public SprintModel Sprint { get; set; } public List<TaskModel> Tasks { get; set; }
#else
[Parameter] [Parameter]
public DbSet<TaskModel> Tasks { get; set; } public DbSet<TaskModel> Tasks { get; set; }
#endif
[Parameter]
public SprintModel Sprint { get; set; }
private List<TaskModel> selectedTasks { get; set; } private List<TaskModel> selectedTasks { get; set; }

24
IGP/Pages/ChangeLogPage.razor

@ -1,7 +1,6 @@
@page "/changelog" @page "/changelog"
@implements IDisposable; @implements IDisposable;
@inject IGitService GitService; @inject IGitService GitService;
@inject DatabaseContext Database;
@layout PageLayout @layout PageLayout
@ -47,7 +46,7 @@
</div> </div>
</div> </div>
<div> <div>
@foreach (var change in patch.ChangeModels) { @foreach (var change in Changes.FindAll(e => e.PatchModelId == patch.Id)) {
@if (!change.Important.Equals("True") && isViewImportant) { @if (!change.Important.Equals("True") && isViewImportant) {
continue; continue;
} }
@ -56,12 +55,12 @@
<div> <div>
<div> <div>
<b> <b>
- @change.Name <span>- @change.Name </span>
@if (change.Commit != CommitType.None) { @if (change.Commit != CommitType.None) {
<span>(@change.Commit)</span> <span>(@change.Commit)</span>
} }
: <span>: </span>
</b> @((MarkupString)change.Description) </b> @((MarkupString)change.Description)
</div> </div>
</div> </div>
@ -70,8 +69,6 @@
</div> </div>
</div> </div>
<br/>
} }
</PaperComponent> </PaperComponent>
@ -84,11 +81,22 @@ else {
@code { @code {
#if NO_SQL
[Parameter]
public List<PatchModel> Patches { get; set; }
[Parameter]
public List<ChangeModel> Changes { get; set; }
#else
[Inject]
DatabaseContext Database { get; set; }
[Parameter] [Parameter]
public DbSet<PatchModel> Patches { get; set; } public DbSet<PatchModel> Patches { get; set; }
[Parameter] [Parameter]
public DbSet<ChangeModel> Changes { get; set; } public DbSet<ChangeModel> Changes { get; set; }
#endif
private bool isViewImportant = true; private bool isViewImportant = true;
@ -113,7 +121,11 @@ else {
} }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
#if NO_SQL
GitService.Load();
#else
GitService.Load(Database); GitService.Load(Database);
#endif
} }
} }

13
IGP/Pages/ChangeLogPage.razor.css

@ -0,0 +1,13 @@
.patchContainer {
padding: 16px;
}
@media only screen and (max-width: 1025px) {
.patchContainer {
border: none;
padding-left: 8px;
padding-right: 8px;
padding-top: 16px;
padding-bottom: 16px;
}
}

15
IGP/Program.cs

@ -1,7 +1,14 @@
using Contexts;
using IGP; using IGP;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
#if NO_SQL
#else
using Contexts;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
#endif
using Services; using Services;
using Services.Immortal; using Services.Immortal;
using Services.Website; using Services.Website;
@ -31,7 +38,11 @@ builder.Services.AddSingleton(new HttpClient {
}); });
builder.Services.AddDbContext<DatabaseContext>(options => { options.UseSqlite("Data Source=./Database.db"); }); #if NO_SQL
#else
//builder.Services.AddDbContext<DatabaseContext>(options => { options.UseSqlite("Data Source=./Database.db"); });
#endif
builder.Services.AddSingleton<IWebsiteService, WebsiteService>(); builder.Services.AddSingleton<IWebsiteService, WebsiteService>();
builder.Services.AddSingleton<IAgileService, AgileService>(); builder.Services.AddSingleton<IAgileService, AgileService>();

5
IGP/_Imports.razor

@ -1,4 +1,6 @@
@using Components.Display 
@using Components.Display
@using Components.Feedback @using Components.Feedback
@using Components.Form @using Components.Form
@using Components.Info @using Components.Info
@ -7,7 +9,6 @@
@using Components.Navigation @using Components.Navigation
@using Components.Shared @using Components.Shared
@using Components.Utils @using Components.Utils
@using Contexts
@using IGP.Pages @using IGP.Pages
@using IGP.Pages.Agile.Parts @using IGP.Pages.Agile.Parts
@using IGP.Pages.BuildCalculator.Parts @using IGP.Pages.BuildCalculator.Parts

31
Services/Work/AgileService.cs → Services/Development/AgileService.cs

@ -1,4 +1,6 @@
using System.Net.Http.Json; 
using System.Net.Http.Json;
using Contexts; using Contexts;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Model.Work.Tasks; using Model.Work.Tasks;
@ -14,9 +16,17 @@ public class AgileService : IAgileService {
this.httpClient = httpClient; this.httpClient = httpClient;
} }
#if NO_SQL
public List<SprintModel> SprintModels { get; set; }
public List<TaskModel> TaskModels { get; set; }
#else
private DatabaseContext Database { get; set; } private DatabaseContext Database { get; set; }
public DbSet<SprintModel> SprintModels => Database.SprintModels; public DbSet<SprintModel> SprintModels => Database.SprintModels;
public DbSet<TaskModel> TaskModels => Database.TaskModels; public DbSet<TaskModel> TaskModels => Database.TaskModels;
#endif
public void Subscribe(Action action) { public void Subscribe(Action action) {
_onChange += action; _onChange += action;
@ -30,10 +40,26 @@ public class AgileService : IAgileService {
return isLoaded; return isLoaded;
} }
#if NO_SQL
public async Task Load() {
if (isLoaded) {
return;
}
SprintModels = (await httpClient.GetFromJsonAsync<SprintModel[]>("generated/SprintModels.json")).ToList();
TaskModels =(await httpClient.GetFromJsonAsync<TaskModel[]>("generated/TaskModels.json")).ToList();
isLoaded = true;
NotifyDataChanged();
}
#else
public async Task Load(DatabaseContext database) { public async Task Load(DatabaseContext database) {
Database = database; Database = database;
if (isLoaded) return; if (isLoaded) {
return;
}
Database.SprintModels.AddRange(await httpClient.GetFromJsonAsync<SprintModel[]>("generated/SprintModels.json")); Database.SprintModels.AddRange(await httpClient.GetFromJsonAsync<SprintModel[]>("generated/SprintModels.json"));
Database.TaskModels.AddRange(await httpClient.GetFromJsonAsync<TaskModel[]>("generated/TaskModels.json")); Database.TaskModels.AddRange(await httpClient.GetFromJsonAsync<TaskModel[]>("generated/TaskModels.json"));
@ -44,6 +70,7 @@ public class AgileService : IAgileService {
NotifyDataChanged(); NotifyDataChanged();
} }
#endif
public void Update() { public void Update() {
NotifyDataChanged(); NotifyDataChanged();

48
Services/Work/GitService.cs → Services/Development/GitService.cs

@ -1,7 +1,14 @@
using System.Net.Http.Json; 
using System.Net.Http.Json;
using Model.Work.Git;
#if NO_SQL
#else
using Contexts; using Contexts;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Model.Work.Git; #endif
namespace Services.Work; namespace Services.Work;
@ -14,9 +21,16 @@ public class GitService : IGitService {
this.httpClient = httpClient; this.httpClient = httpClient;
} }
public DatabaseContext Database { get; set; } #if NO_SQL
public List<ChangeModel> ChangeModels { get; set; }
public List<PatchModel> PatchModels { get; set; }
#else
public DbSet<ChangeModel> ChangeModels => Database.ChangeModels; public DbSet<ChangeModel> ChangeModels => Database.ChangeModels;
public DbSet<PatchModel> PatchModels => Database.PatchModels; public DbSet<PatchModel> PatchModels => Database.PatchModels;
public DatabaseContext Database { get; set; }
#endif
public void Subscribe(Action action) { public void Subscribe(Action action) {
_onChange += action; _onChange += action;
@ -30,20 +44,46 @@ public class GitService : IGitService {
return isLoaded; return isLoaded;
} }
#if NO_SQL
public async Task Load() {
if (isLoaded) {
return;
}
ChangeModels = (await httpClient.GetFromJsonAsync<ChangeModel[]>("generated/ChangeModels.json")).ToList();
PatchModels = (await httpClient.GetFromJsonAsync<PatchModel[]>("generated/PatchModels.json")).ToList();
isLoaded = true;
NotifyDataChanged();
}
#else
public async Task Load(DatabaseContext database) { public async Task Load(DatabaseContext database) {
Database = database; Database = database;
if (isLoaded) return; if (isLoaded) {
return;
}
Database.ChangeModels.AddRange(await httpClient.GetFromJsonAsync<ChangeModel[]>("generated/ChangeModels.json")); Database.ChangeModels.AddRange(await httpClient.GetFromJsonAsync<ChangeModel[]>("generated/ChangeModels.json"));
Database.PatchModels.AddRange(await httpClient.GetFromJsonAsync<PatchModel[]>("generated/PatchModels.json")); Database.PatchModels.AddRange(await httpClient.GetFromJsonAsync<PatchModel[]>("generated/PatchModels.json"));
Database.SaveChanges(); Database.SaveChanges();
isLoaded = true; isLoaded = true;
NotifyDataChanged(); NotifyDataChanged();
} }
#endif
public void Update() { public void Update() {
NotifyDataChanged(); NotifyDataChanged();
} }

54
Services/IServices.cs

@ -1,4 +1,6 @@
using Contexts; 
using Contexts;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Model.Immortal.BuildOrders; using Model.Immortal.BuildOrders;
using Model.Immortal.Economy; using Model.Immortal.Economy;
@ -12,34 +14,72 @@ using Services.Immortal;
namespace Services; namespace Services;
public interface IAgileService { public interface IWebsiteService {
public DbSet<SprintModel> SprintModels { get; } #if NO_SQL
public DbSet<TaskModel> TaskModels { get; } public List<WebPageModel> WebPageModels { get; set; }
public List<WebSectionModel> WebSectionModels { get; set; }
#else
public DbSet<WebPageModel> WebPageModels { get; }
public DbSet<WebSectionModel> WebSectionModels { get; }
#endif
public void Subscribe(Action action); public void Subscribe(Action action);
public void Unsubscribe(Action action); public void Unsubscribe(Action action);
public void Update(); public void Update();
#if NO_SQL
public Task Load();
#else
public Task Load(DatabaseContext database); public Task Load(DatabaseContext database);
#endif
public bool IsLoaded(); public bool IsLoaded();
} }
public interface IWebsiteService { public interface IAgileService {
public DbSet<WebPageModel> WebPageModels { get; }
public DbSet<WebSectionModel> WebSectionModels { get; } #if NO_SQL
public List<SprintModel> SprintModels { get; set; }
public List<TaskModel> TaskModels { get; set; }
#else
public DbSet<SprintModel> SprintModels { get; }
public DbSet<TaskModel> TaskModels { get; }
#endif
public void Subscribe(Action action); public void Subscribe(Action action);
public void Unsubscribe(Action action); public void Unsubscribe(Action action);
public void Update(); public void Update();
#if NO_SQL
public Task Load();
#else
public Task Load(DatabaseContext database); public Task Load(DatabaseContext database);
#endif
public bool IsLoaded(); public bool IsLoaded();
} }
public interface IGitService { public interface IGitService {
#if NO_SQL
public List<ChangeModel> ChangeModels { get; set; }
public List<PatchModel> PatchModels { get; set; }
#else
public DbSet<ChangeModel> ChangeModels { get; } public DbSet<ChangeModel> ChangeModels { get; }
public DbSet<PatchModel> PatchModels { get; } public DbSet<PatchModel> PatchModels { get; }
#endif
public void Subscribe(Action action); public void Subscribe(Action action);
public void Unsubscribe(Action action); public void Unsubscribe(Action action);
public void Update(); public void Update();
#if NO_SQL
public Task Load();
#else
public Task Load(DatabaseContext database); public Task Load(DatabaseContext database);
#endif
public bool IsLoaded(); public bool IsLoaded();
} }

14
Services/Services.csproj

@ -6,13 +6,21 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;NO_SQL;</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="YamlDotNet" Version="11.2.1"/> <PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Contexts\Contexts.csproj"/> <ProjectReference Include="..\Contexts\Contexts.csproj" />
<ProjectReference Include="..\Model\Model.csproj"/> <ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

28
Services/Website/WebsiteService.cs

@ -14,9 +14,20 @@ public class WebsiteService : IWebsiteService {
this.httpClient = httpClient; this.httpClient = httpClient;
} }
#if NO_SQL
public List<WebSectionModel> WebSectionModels { get; set; }
public List<WebPageModel> WebPageModels { get; set; }
#else
private DatabaseContext Database { get; set; } private DatabaseContext Database { get; set; }
public DbSet<WebSectionModel> WebSectionModels => Database.WebSectionModels; public DbSet<WebSectionModel> WebSectionModels => Database.WebSectionModels;
public DbSet<WebPageModel> WebPageModels => Database.WebPageModels; public DbSet<WebPageModel> WebPageModels => Database.WebPageModels;
#endif
public void Subscribe(Action action) { public void Subscribe(Action action) {
_onChange += action; _onChange += action;
@ -30,10 +41,23 @@ public class WebsiteService : IWebsiteService {
return isLoaded; return isLoaded;
} }
#if NO_SQL
public async Task Load() {
if (isLoaded) {return;}
WebPageModels = (await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json")).ToList();
WebSectionModels =(await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json")).ToList();
isLoaded = true;
NotifyDataChanged();
}
#else
public async Task Load(DatabaseContext database) { public async Task Load(DatabaseContext database) {
Database = database; Database = database;
if (isLoaded) return; if (isLoaded) {return;}
Database.WebPageModels.AddRange(await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json")); Database.WebPageModels.AddRange(await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"));
Database.WebSectionModels.AddRange( Database.WebSectionModels.AddRange(
@ -45,6 +69,8 @@ public class WebsiteService : IWebsiteService {
NotifyDataChanged(); NotifyDataChanged();
} }
#endif
public void Update() { public void Update() {
NotifyDataChanged(); NotifyDataChanged();

Loading…
Cancel
Save