initial upload
This commit is contained in:
parent
a0aa9cc28e
commit
f857f43df4
553 changed files with 46169 additions and 13 deletions
53
src/Server/Insight.Server/Extensions/Async.cs
Normal file
53
src/Server/Insight.Server/Extensions/Async.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.Threading.Tasks.Dataflow;
|
||||
|
||||
namespace Insight.Server.Extensions
|
||||
{
|
||||
public static class Async
|
||||
{
|
||||
public static async Task ParallelForEach<T>(
|
||||
this IAsyncEnumerable<T> source,
|
||||
Func<T, Task> body,
|
||||
int maxDegreeOfParallelism = DataflowBlockOptions.Unbounded,
|
||||
TaskScheduler scheduler = null)
|
||||
{
|
||||
var options = new ExecutionDataflowBlockOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism
|
||||
};
|
||||
|
||||
if (scheduler != null)
|
||||
options.TaskScheduler = scheduler;
|
||||
|
||||
var block = new ActionBlock<T>(body, options);
|
||||
|
||||
await foreach (var item in source)
|
||||
block.Post(item);
|
||||
|
||||
block.Complete();
|
||||
await block.Completion;
|
||||
}
|
||||
|
||||
public static async Task ParallelForEach<T>(
|
||||
this IEnumerable<T> source,
|
||||
Func<T, Task> body,
|
||||
int maxDegreeOfParallelism = DataflowBlockOptions.Unbounded,
|
||||
TaskScheduler scheduler = null)
|
||||
{
|
||||
var options = new ExecutionDataflowBlockOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism
|
||||
};
|
||||
|
||||
if (scheduler != null)
|
||||
options.TaskScheduler = scheduler;
|
||||
|
||||
var block = new ActionBlock<T>(body, options);
|
||||
|
||||
foreach (var item in source)
|
||||
block.Post(item);
|
||||
|
||||
block.Complete();
|
||||
await block.Completion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Insight.Server.Extensions
|
||||
{
|
||||
public static class ConfigurationExtensions
|
||||
{
|
||||
public static IConfigurationBuilder Defaults(this IConfigurationBuilder configuration)
|
||||
{
|
||||
configuration.Sources.Clear();
|
||||
configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||
return configuration.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue