Skip to content

Commit

Permalink
Merge pull request #918 from sitkoru/net8
Browse files Browse the repository at this point in the history
Sitko.Core 11 for .NET 8
  • Loading branch information
SonicGD authored Jan 12, 2024
2 parents 91ad2af + 0e5e951 commit eae4ae5
Show file tree
Hide file tree
Showing 408 changed files with 4,725 additions and 7,945 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sitko.Core

Opinionated framework on top of .NET and ASP.NET Core for building microservices.
Opinionated framework on top of .NET 8 and ASP.NET Core for building microservices.

Provides base application and modules for fast application building.

Expand Down
235 changes: 104 additions & 131 deletions Sitko.Core.sln

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Sitko.Core.Apps.MudBlazorDemo.Data.Entities;
using Sitko.Core.Apps.MudBlazorDemo.Data.Repositories;
using MudBlazor.Charts;
using Sitko.Core.Apps.Blazor.Data.Entities;
using Sitko.Core.Blazor.MudBlazorComponents;
using Sitko.Core.Repository;

namespace Sitko.Core.Apps.MudBlazorDemo.Forms
namespace Sitko.Core.Apps.Blazor.Client.Components.Forms
{
public class BarForm : BaseMudRepositoryForm<BarModel, Guid, BarRepository>
public class BarForm : BaseMudRepositoryForm<BarModel, Guid, IRepository<BarModel, Guid>>
{
protected override Task ConfigureQueryAsync(IRepositoryQuery<BarModel> query)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Sitko.Core.Apps.Blazor.Data.Entities;
using Sitko.Core.Blazor.Forms;
using Sitko.Core.Blazor.MudBlazorComponents;
using Sitko.Core.Repository;

namespace Sitko.Core.Apps.Blazor.Client.Components.Forms;

public class FooForm : BaseMudRepositoryForm<FooModel, Guid, IRepository<FooModel, Guid>>
{
protected override async Task<FormSaveResult> AddAsync(FooModel entity)
{
await Task.Delay(2000);
return await base.AddAsync(entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Sitko.Core.Blazor.MudBlazorComponents;

namespace Sitko.Core.Apps.Blazor.Client.Components.Layout;

public class AppPageLayout : BaseMudPageLayout;
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Threading.Tasks;
using Sitko.Core.Apps.MudBlazorDemo.Data.Entities;
using Sitko.Core.Apps.MudBlazorDemo.Data.Repositories;
using Sitko.Core.Apps.Blazor.Data.Entities;
using Sitko.Core.Blazor.MudBlazorComponents;
using Sitko.Core.Repository;

namespace Sitko.Core.Apps.MudBlazorDemo.Components
namespace Sitko.Core.Apps.Blazor.Client.Components.Lists
{
public class BarRepositoryList : MudRepositoryTable<BarModel, Guid, BarRepository>
public class BarRepositoryList : MudRepositoryTable<BarModel, Guid, IRepository<BarModel, Guid>>
{
public Task UpdateAsync(BarModel barModel) =>
ExecuteRepositoryOperation(async repository =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@inherits BaseComponent
<h3>TestComponent</h3>

@code {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Sitko.Core.Apps.Blazor.Data.Entities;
using Sitko.Core.Repository.Remote;

namespace Sitko.Core.Apps.Blazor.Client.Data.Repositories;

public class BarModelRemoteRepository(RemoteRepositoryContext<BarModel, Guid> repositoryContext)
: BaseRemoteRepository<BarModel, Guid>(repositoryContext);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Sitko.Core.Apps.Blazor.Data.Entities;
using Sitko.Core.Repository.Remote;

namespace Sitko.Core.Apps.Blazor.Client.Data.Repositories;

public class FooModelRemoteRepository(RemoteRepositoryContext<FooModel, Guid> repositoryContext)
: BaseRemoteRepository<FooModel, Guid>(repositoryContext);
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@page "/Foos/Add"
@page "/Foos/{Id:guid}/Edit"
@using Sitko.Core.Apps.MudBlazorDemo.Data.Entities
@rendermode InteractiveAuto
@using Sitko.Core.Apps.Blazor.Data.Entities
@using Sitko.Core.Apps.Blazor.Client.Components.Forms
@inherits BaseComponent
<MudPageLayout Title="Edit" Description="Page description">
<AppPageLayout Title="Edit" Description="Page description">
<FooForm @ref="Form" EntityId="Id" Debug="true" OnAfterSave="AfterSaveAsync">
<ChildContent Context="formContext">
<MudPaper Class="pa-4">
Expand All @@ -21,7 +23,7 @@
</MudPaper>
</ChildContent>
</FooForm>
</MudPageLayout>
</AppPageLayout>

@code {

Expand Down
60 changes: 60 additions & 0 deletions apps/Blazor/Sitko.Core.Apps.Blazor.Client/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@page "/"
@using Sitko.Core.Apps.Blazor.Data.Entities
@rendermode InteractiveAuto
@inherits BaseComponent

<AppPageLayout Title="@LocalizationProvider["Title"]">
<MudGrid>
<MudItem xs="6" sm="4">
<MudAutocomplete @ref="IdFilterAutocomplete" T="BarModel" Label="ID" SearchFunc="@SearchIdsAsync" ResetValueOnEmptyText="true"
Value="FilterList.Model"
ToStringFunc="@(e => e == null ? null : $"{e.Bar}")"
ValueChanged="@(s => ChangeIdAsync(s == null ? null : s.Id))"/>
</MudItem>

<MudItem xs="6" sm="4">
<MudTextField T="string" Value="FilterList.Title" Label="Title" ValueChanged="SearchTitleAsync" Class="mt-0" Clearable="true">
</MudTextField>
</MudItem>

<MudItem xs="12" sm="4">
<MudDateRangePicker DateRange="FilterList.DateRange" Label="Дата" PickerVariant="PickerVariant.Dialog" DateRangeChanged="@(dateRange => ChangeDateAsync(dateRange))"/>
</MudItem>
</MudGrid>

<BarRepositoryList @bind-RowsPerPage="rowsPerPage" OnDataLoaded="CountSummaryAsync" @ref="barList" Class="mb-10" EnableUrlNavigation="true"
ConfigureQuery="ConfigureQueryAsync" AddParamsToUrl="AddParamsToUrlAsync"
GetParamsFromUrl="GetParamsFromUrlAsync">
<HeaderContent>
<MudTh>
<MudTableSortLabel SortLabel="@nameof(BarModel.Id)" InitialDirection="SortDirection.Descending" T="BarModel">Id</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortLabel="@nameof(BarModel.Bar)" T="BarModel">Название</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortLabel="@nameof(BarModel.Date)" T="BarModel">Дата</MudTableSortLabel>
</MudTh>
<MudTh></MudTh>
</HeaderContent>
<ChildContent>
<MudTd DataLabel="@nameof(BarModel.Id)">
<MudLink Href="@($"/Bars/{context.Id}/Edit")">@context.Id</MudLink>
</MudTd>
<MudTd DataLabel="@nameof(BarModel.Bar)">
@context.Bar
</MudTd>
<MudTd DataLabel="@nameof(BarModel.Date)">
@context.Date
</MudTd>
<MudTd>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" Size="Size.Small" StartIcon="@Icons.Material.Filled.Refresh" OnClick="@(() => barList.UpdateAsync(context))">Refresh</MudButton>
</MudTd>
</ChildContent>
<FooterContent>
<MudTFootRow Class="bold-text">
<MudTd>@Summary</MudTd>
</MudTFootRow>
</FooterContent>
</BarRepositoryList>
</AppPageLayout>
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using Sitko.Core.Apps.MudBlazorDemo.Components;
using Sitko.Core.Apps.MudBlazorDemo.Data.Entities;
using Sitko.Core.Apps.MudBlazorDemo.Data.Repositories;
using Sitko.Core.Apps.Blazor.Client.Components.Lists;
using Sitko.Core.Apps.Blazor.Data.Entities;
using Sitko.Core.Blazor.MudBlazorComponents;
using Sitko.Core.Repository;

namespace Sitko.Core.Apps.MudBlazorDemo.Pages
namespace Sitko.Core.Apps.Blazor.Client.Pages
{
public partial class Index
{
Expand All @@ -37,51 +32,11 @@ public partial class Index

private async Task CountSummaryAsync(TableState state, MudTableFilter filter) =>
Summary = await barList.SumAsync(model => model.Sum);
//
// private TableFilter<string>[] barFilter = Array.Empty<TableFilter<string>>();
// private BarForm frm = null!;
// private BarModel[] bars = Array.Empty<BarModel>();
// public BarModel? Bar { get; set; }
// private IStorage Storage => GetRequiredService<IStorage>();
//
// public BarRepository ScopedBarRepository => GetRequiredService<BarRepository>();
//
//
//
// protected override async Task InitializeAsync()
// {
// await base.InitializeAsync();
// var result = await GetRequiredService<BarRepository>().GetAllAsync();
// if (result.itemsCount == 0)
// {
// await GetRequiredService<BarRepository>().AddAsync(new BarModel { Bar = "Bar", Id = Guid.NewGuid() });
// result = await GetRequiredService<BarRepository>().GetAllAsync();
// }
//
// Bars = result.items;
// barFilter = (await GetRequiredService<BarContext>().Bars.Select(a => a.Bar).Distinct().ToListAsync())
// .Select(x => new TableFilter<string> { Text = x, Value = x }).ToArray();
// Bar = Bars.OrderBy(b => b.Id).First();
// }
//
// public BarModel[] Bars
// {
// get => bars;
// set => bars = value;
// }
//
// private static Task<object> GenerateMetadataAsync()
// {
// var metadata = new BarStorageMetadata();
// return Task.FromResult<object>(metadata);
// }
//
//

private FilterList FilterList { get; set; } = new();
private MudAutocomplete<BarModel> IdFilterAutocomplete { get; set; } = null!;

[Inject] private BarRepository BarRepository { get; set; } = null!;
[Inject] private IRepository<BarModel, Guid> BarRepository { get; set; } = null!;
private (BarModel[] items, int itemsCount) bars;

protected override async Task InitializeAsync()
Expand Down Expand Up @@ -115,13 +70,22 @@ private async Task SearchTitleAsync(string value)

private Task ConfigureQueryAsync(IRepositoryQuery<BarModel> query)
{
query
.Where(p => FilterList.Model == null || FilterList.Model.Id == Guid.Empty ||
p.Id == FilterList.Model.Id)
.Where(p => string.IsNullOrEmpty(FilterList.Title) || p.Bar == FilterList.Title)
.Where(p => FilterList.DateRange == null ||
(p.Date >= new DateTimeOffset((DateTime)FilterList.DateRange.Start!).UtcDateTime &&
p.Date <= new DateTimeOffset((DateTime)FilterList.DateRange.End!).UtcDateTime));
query.Where(model => model.Bar != "");
if (FilterList.Model is not null && FilterList.Model.Id != Guid.Empty)
{
query.Where(p => p.Id == FilterList.Model.Id);
}

if (!string.IsNullOrEmpty(FilterList.Title))
{
query.Where(p => p.Bar == FilterList.Title);
}

if (FilterList.DateRange is not null)
{
query.Where(p => p.Date >= new DateTimeOffset((DateTime)FilterList.DateRange.Start!).UtcDateTime &&
p.Date <= new DateTimeOffset((DateTime)FilterList.DateRange.End!).UtcDateTime);
}

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@using Microsoft.Extensions.Configuration
@using Sitko.Core.App.Logging
@inherits BaseComponent
<MudPageLayout Title="Logging">
@rendermode InteractiveAuto
<AppPageLayout Title="Logging">
<MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="@(() => SetLevel(LogEventLevel.Debug))">Set debug</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Info" OnClick="@(() => SetLevel(LogEventLevel.Information))">Set info</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Warning" OnClick="@(() => SetLevel(LogEventLevel.Warning))">Set warning</MudButton>
Expand All @@ -18,7 +19,7 @@
@debugView
</pre>
}
</MudPageLayout>
</AppPageLayout>

@code
{
Expand All @@ -36,7 +37,14 @@
{
while (!cts.IsCancellationRequested)
{
await Task.Delay(5000);
try
{
await Task.Delay(5000, cts.Token);
}
catch (OperationCanceledException)
{
break;
}
Logger.LogDebug("Debug");
Logger.LogInformation("Info");
Logger.LogWarning("Warning");
Expand All @@ -46,12 +54,12 @@

protected override async Task DisposeAsync(bool disposing)
{
await base.DisposeAsync(disposing);
if (logTask is not null)
{
cts.Cancel();
await cts.CancelAsync();
await logTask;
}
await base.DisposeAsync(disposing);
}

private Task SetLevel(LogEventLevel level)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@page "/QueryString"
@inherits BaseComponent
<MudPageLayout Title="QueryString">
@rendermode InteractiveAuto
<AppPageLayout Title="QueryString">
<p>
Guid: @Test
</p>
<MudLink Href="@($"/QueryString?test={Guid.NewGuid()}")">Change</MudLink>
</MudPageLayout>
</AppPageLayout>


@code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@page "/Bars/Add"
@page "/Bars/{Id:guid}/Edit"
@rendermode InteractiveAuto
@using Sitko.Core.Apps.Blazor.Client.Components.Forms
@inherits BaseComponent
<MudPageLayout Title="Edit" Breadcrumbs="Breadcrumbs" Description="Page description">
<AppPageLayout Title="Edit" Breadcrumbs="Breadcrumbs" Description="Page description">
<BarForm @ref="Form" EntityId="Id" Debug="true">
<ChildContent Context="formContext">
<MudPaper Class="pa-4">
Expand Down Expand Up @@ -120,14 +122,14 @@
</MudPaper>
</ChildContent>
</BarForm>
</MudPageLayout>
</AppPageLayout>

@code {

[Parameter]
public Guid Id { get; set; }

private IStorage<TestRemoteStorageOptions> Storage => GetRequiredService<IStorage<TestRemoteStorageOptions>>();
private IStorage Storage => GetRequiredService<IStorage>();

private static Task<object> GenerateMetadataAsync()
{
Expand Down
Loading

0 comments on commit eae4ae5

Please sign in to comment.