Skip to content

Commit

Permalink
Merge pull request #3 from dotnet-campus/app
Browse files Browse the repository at this point in the history
支持更多业务接入
  • Loading branch information
TheUnknowName authored Mar 16, 2022
2 parents 1d73692 + 65f134d commit 469b76c
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 138 deletions.
6 changes: 3 additions & 3 deletions src/dotnetCampus.ApplicationStartupManager/IStartupContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Threading.Tasks;
using dotnetCampus.Configurations;
//using dotnetCampus.Configurations;

namespace dotnetCampus.ApplicationStartupManager
{
public interface IStartupContext
{
IAppConfigurator Configs { get; }
Task<string> ReadCacheAsync(string key, string @default = "");
//IAppConfigurator Configs { get; }
//Task<string> ReadCacheAsync(string key, string @default = "");
Task WaitStartupTaskAsync(string startupKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public interface IStartupManager
{
Task WaitStartupTaskAsync(string startupTaskKey);

StartupTask GetStartupTask<T>() where T : StartupTask;
StartupTaskBase GetStartupTask<T>() where T : StartupTaskBase;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace dotnetCampus.ApplicationStartupManager
{
internal sealed class NullObjectStartup : StartupTask
internal sealed class NullObjectStartup : StartupTaskBase
{

}
Expand Down
24 changes: 12 additions & 12 deletions src/dotnetCampus.ApplicationStartupManager/StartupContext.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
using System;
using System.Threading.Tasks;
using dotnetCampus.Configurations;
using dotnetCampus.Configurations.Core;
//using dotnetCampus.Configurations;
//using dotnetCampus.Configurations.Core;

namespace dotnetCampus.ApplicationStartupManager
{
internal class StartupContext : IStartupContext
{
public IStartupLogger Logger { get; }

public FileConfigurationRepo Configuration { get; }
//public FileConfigurationRepo Configuration { get; }

public IAppConfigurator Configs { get; }
//public IAppConfigurator Configs { get; }

public Func<Exception, Task> FastFail { get; }

private readonly Func<string, Task> _waitStartupTaskAsync;

public Task<string> ReadCacheAsync(string key, string @default = "")
{
return Configuration.TryReadAsync(key, @default);
}
//public Task<string> ReadCacheAsync(string key, string @default = "")
//{
// return Configuration.TryReadAsync(key, @default);
//}

Task IStartupContext.WaitStartupTaskAsync(string startupKey) => _waitStartupTaskAsync(startupKey);

public StartupContext(IStartupLogger logger, FileConfigurationRepo configuration,
public StartupContext(IStartupLogger logger, /*FileConfigurationRepo configuration,*/
Func<Exception, Task> fastFailAction, Func<string, Task> waitStartupAsync)
{
Logger = logger;
Configuration = configuration;
//Configuration = configuration;
_waitStartupTaskAsync = waitStartupAsync;
Configs = configuration.CreateAppConfigurator();
FastFail = fastFailAction ?? (exception => StartupTask.CompletedTask);
//Configs = configuration.CreateAppConfigurator();
FastFail = fastFailAction ?? (exception => StartupTaskBase.CompletedTask);
}
}
}
19 changes: 9 additions & 10 deletions src/dotnetCampus.ApplicationStartupManager/StartupLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@

namespace dotnetCampus.ApplicationStartupManager
{
public class StartupLogger : IStartupLogger
public class StartupLoggerBase : IStartupLogger
{
private readonly Stopwatch _mainWatch;

private readonly ConcurrentDictionary<string, (string name, long start, long elapsed)>
_milestoneDictionary = new ConcurrentDictionary<string, (string, long, long)>();
protected ConcurrentDictionary<string, (string threadName, long start, long elapsed)>
MilestoneDictionary { get; } = new ConcurrentDictionary<string, (string, long, long)>();

public StartupLogger()
public StartupLoggerBase()
{
_mainWatch = new Stopwatch();
_mainWatch.Start();
}

public void RecordTime(string milestoneName)
{
var start = _milestoneDictionary.Count > 0
? _milestoneDictionary.Max(x => x.Value.start + x.Value.elapsed)
var start = MilestoneDictionary.Count > 0
? MilestoneDictionary.Max(x => x.Value.start + x.Value.elapsed)
: 0;
var end = _mainWatch.ElapsedTicks;
_milestoneDictionary[milestoneName] =
MilestoneDictionary[milestoneName] =
(Thread.CurrentThread.Name ?? Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture),
start, end - start);
}
Expand All @@ -46,13 +46,12 @@ public async Task RecordDuration(string taskName, Func<Task<string>> task)
{
var end = _mainWatch.ElapsedTicks;
var elapse = end - begin;
_milestoneDictionary[taskName] = (threadName, begin, elapse);
MilestoneDictionary[taskName] = (threadName, begin, elapse);
}
}

public void ReportResult(IReadOnlyList<IStartupTaskWrapper> wrappers)
public virtual void ReportResult(IReadOnlyList<IStartupTaskWrapper> wrappers)
{
// todo 还没有具体实现
}
}
}
Loading

0 comments on commit 469b76c

Please sign in to comment.