Skip to content

Commit

Permalink
Merge pull request #12 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Codespilot authored Jan 10, 2024
2 parents 7058aa1 + d71da6e commit 559baec
Show file tree
Hide file tree
Showing 207 changed files with 6,433 additions and 2,229 deletions.
66 changes: 39 additions & 27 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnablePackageVersionOverride>true</EnablePackageVersionOverride>
<EuoniaPackageVersion>8.1.15</EuoniaPackageVersion>
<EuoniaPackageVersion>8.1.16</EuoniaPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageVersion Include="Dapper" Version="2.1.24" />
<PackageVersion Include="Dapper.Contrib" Version="2.0.78" />
<PackageVersion Include="Dapper.SqlBuilder" Version="2.0.78" />
Expand All @@ -31,9 +32,20 @@
<PackageVersion Include="Grpc.Net.Client" Version="2.59.0" />
<PackageVersion Include="Grpc.Tools" Version="2.60.0" />
<PackageVersion Include="IdentityModel" Version="6.2.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="3.1.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.2.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Emoji" Version="4.2.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.2.1" />
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" />
<PackageVersion Include="Refit" Version="7.0.0" />
<PackageVersion Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageVersion Include="Refit.Newtonsoft.Json" Version="7.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.10" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2">
Expand All @@ -44,57 +56,57 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" $(TargetFrameworkVersion.Equals('v6.0')) ">
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[6.0.0,7.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="[6.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFrameworkVersion.Equals('v7.0')) ">
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="[7.0.13,8.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="[7.0.14,8.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="[7.0.14,8.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="[7.0.14,8.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[7.0.0,8.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="[7.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="7.0.0-preview.1" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFrameworkVersion.Equals('v8.0')) ">
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="[8.0.0,9.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="[8.0.0,9.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="[8.0.0,9.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="[8.0.0,9.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[8.0.0,9.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="[8.0.0]" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="7.0.0-preview.1" />
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ graph TD
Starfish.Service --> Starfish.Common
Starfish.Client --> Starfish.Common
Starfish.Webapp --> Starfish.Client
Starfish.Webapp --> Starfish.Common
Starfish.Webapp --> Starfish.Transit
```

## Requirements/环境要求
Expand Down
10 changes: 2 additions & 8 deletions Samples/common.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<Project>
<Import Project="..\global.props" />

<PropertyGroup>
<RootNamespace>Nerosoft.Starfish.Sample</RootNamespace>
<Version>1.0.0</Version>
<Authors>damon</Authors>
<Company>Nerosoft Co., Ltd.</Company>
<Product>Starfish</Product>
<Copyright>© 2018-2023 Nerosoft. All Rights Reserved.</Copyright>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<LangVersion>latest</LangVersion>
<Description>A lightweight powerful distributed configuration server for .NET application.</Description>
<RepositoryUrl>https://github.com/NerosoftDev/Starfish/</RepositoryUrl>
</PropertyGroup>
Expand Down
9 changes: 5 additions & 4 deletions Source/Starfish.Client/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ internal class Constants
{
public class RequestHeaders
{
public const string AppId = "app-id";
public const string AppSecret = "app-secret";
public const string AppEnv = "app-env";
public const string TeamId = "starfish-team-id";
public const string AppId = "starfish-app-id";
public const string AppSecret = "starfish-app-secret";
public const string AppEnv = "starfish-app-env";
}
}
}
3 changes: 3 additions & 0 deletions Source/Starfish.Client/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@
<data name="IDS_ERROR_STARFISH_SECTION_NOT_FOUND" xml:space="preserve">
<value>Starfish section not found in configuration.</value>
</data>
<data name="IDS_ERROR_SCHEMA_NOT_SUPPORTED" xml:space="preserve">
<value>Schema {0} is not supported.</value>
</data>
</root>
1 change: 1 addition & 0 deletions Source/Starfish.Client/Starfish.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<Import Project="..\common.props" />

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<Title>Sratfish configuration client</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
2 changes: 1 addition & 1 deletion Source/Starfish.Client/StarfishConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private async void OnHostChanged(object sender, HostChangedEventArgs args)
{
"http" or "https" => new HttpConfigurationClient(uri, _options.AppId, _options.AppSecret, _options.Environment),
"ws" or "wss" => new SocketConfigurationClient(uri, _options.AppId, _options.AppSecret, _options.Environment),
_ => throw new NotSupportedException($"Schema {uri.Scheme} is not supported."),
_ => throw new NotSupportedException(string.Format(Resources.IDS_ERROR_SCHEMA_NOT_SUPPORTED, uri.Scheme)),
};
try
{
Expand Down
125 changes: 107 additions & 18 deletions Source/Starfish.Common/AsyncHelper.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,123 @@
using System.Globalization;
namespace Nerosoft.Starfish.Common;

namespace Nerosoft.Starfish.Common;
/// <summary>
/// Provides some helper methods to work with async methods.
/// </summary>
public static class AsyncHelper
{
private static readonly TaskFactory _factory = new(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default);

public static TResult RunSync<TResult>(Func<Task<TResult>> func)
{
var cultureUi = CultureInfo.CurrentUICulture;
var culture = CultureInfo.CurrentCulture;
return _factory.StartNew(() =>
var oldContext = SynchronizationContext.Current;
var context = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(context);
TResult result = default;
context.Post(async _ =>
{
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = cultureUi;
return func();
}).Unwrap().GetAwaiter().GetResult();
try
{
result = await func();
}
catch (Exception exception)
{
context.Exception = exception;
throw;
}
finally
{
context.EndMessageLoop();
}
}, null);
context.BeginMessageLoop();
SynchronizationContext.SetSynchronizationContext(oldContext);
return result;
}

public static void RunSync(Func<Task> func)
{
var cultureUi = CultureInfo.CurrentUICulture;
var culture = CultureInfo.CurrentCulture;
_factory.StartNew(() =>
var oldContext = SynchronizationContext.Current;
var context = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(context);
context.Post(async _ =>
{
try
{
await func();
}
catch (Exception exception)
{
context.Exception = exception;
throw;
}
finally
{
context.EndMessageLoop();
}
}, null);
context.BeginMessageLoop();

SynchronizationContext.SetSynchronizationContext(oldContext);
}

private class ExclusiveSynchronizationContext : SynchronizationContext
{
private bool done;
public Exception Exception { get; set; }
readonly AutoResetEvent workItemsWaiting = new(false);
readonly Queue<Tuple<SendOrPostCallback, object>> items = new();

public override void Send(SendOrPostCallback d, object state)
{
throw new NotSupportedException("We cannot send to our same thread");
}

public override void Post(SendOrPostCallback callback, object state)
{
lock (items)
{
items.Enqueue(Tuple.Create(callback, state));
}
workItemsWaiting.Set();
}

public void EndMessageLoop()
{
Post(_ => done = true, null);
}

public void BeginMessageLoop()
{
if (done)
{
return;
}
while (!done)
{
Tuple<SendOrPostCallback, object> task = null;
lock (items)
{
if (items.Count > 0)
{
task = items.Dequeue();
}
}
if (task != null)
{
task.Item1(task.Item2);
if (Exception != null) // the method threw an exception
{
throw new AggregateException("AsyncHelper.Run method threw an exception.", Exception);
}
}
else
{
workItemsWaiting.WaitOne();
}
}
}

public override SynchronizationContext CreateCopy()
{
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = cultureUi;
return func();
}).Unwrap().GetAwaiter().GetResult();
return this;
}
}
}
Loading

0 comments on commit 559baec

Please sign in to comment.