Skip to content

Commit

Permalink
Merge pull request #17 from GeneralLibrary/dev
Browse files Browse the repository at this point in the history
feature: Open collections of custom methods
  • Loading branch information
JusterZhu authored Nov 25, 2023
2 parents 3cc7c7e + 0fce6a3 commit 59fe557
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
41 changes: 21 additions & 20 deletions src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public override GeneralClientBootstrap LaunchAsync()

private async Task<GeneralClientBootstrap> BaseLaunch()
{
//bool isSuccess = await ExecuteCustomOptions();
//if (!isSuccess) return this;
await ExecuteCustomOptions();
var versionService = new VersionService();
var mainResp = await versionService.ValidationVersion(Packet.MainUpdateUrl);
var upgradeResp = await versionService.ValidationVersion(Packet.UpdateUrl);
Expand Down Expand Up @@ -161,11 +160,11 @@ public GeneralClientBootstrap SetCustomSkipOption(Func<Task<bool>> func)
/// <param name="func"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public GeneralClientBootstrap AddCustomOption(Func<bool> func)
public GeneralClientBootstrap AddCustomOption(List<Func<bool>> funcs)
{
if(func == null) throw new ArgumentNullException(nameof(func));
_customOptions.Add(func);
return this;
if (funcs == null || !funcs.Any()) throw new ArgumentNullException(nameof(funcs));
_customOptions.AddRange(funcs);
return this;
}

/// <summary>
Expand All @@ -175,10 +174,10 @@ public GeneralClientBootstrap AddCustomOption(Func<bool> func)
/// <param name="func"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public GeneralClientBootstrap AddCustomOption(Func<Task<bool>> func)
public GeneralClientBootstrap AddCustomOption(List<Func<Task<bool>>> funcs)
{
if (func == null) throw new ArgumentNullException(nameof(func));
_customTaskOptions.Add(func);
if (funcs == null || !funcs.Any()) throw new ArgumentNullException(nameof(funcs));
_customTaskOptions.AddRange(funcs);
return this;
}

Expand Down Expand Up @@ -223,24 +222,26 @@ private async Task<bool> IsSkip(bool isForcibly)
/// Performs all injected custom operations.
/// </summary>
/// <returns></returns>
private async Task<bool> ExecuteCustomOptions()
private async Task ExecuteCustomOptions()
{
if (_customOptions.Any())
{
_customOptions.ForEach(option => option.Invoke());
return true;
}

if (_customTaskOptions.Any())
{
foreach (var option in _customTaskOptions)
{
await option.Invoke();
var isSuccess = await option.Invoke();
if (!isSuccess)
Core.Events.EventManager.Instance.Dispatch<Action<object, Core.Events.CommonArgs.ExceptionEventArgs>>(this, new Core.Events.CommonArgs.ExceptionEventArgs($"{nameof(option)}Execution failure!"));
}
}
else if (_customOptions.Any())
{
foreach (var option in _customOptions)
{
var isSuccess = option.Invoke();
if (!isSuccess)
Core.Events.EventManager.Instance.Dispatch<Action<object, Core.Events.CommonArgs.ExceptionEventArgs>>(this, new Core.Events.CommonArgs.ExceptionEventArgs($"{nameof(option)}Execution failure!"));
}
return true;
}

return true;
}

#endregion Private Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public ExceptionEventArgs(Exception exception)
_exception = exception;
}

public ExceptionEventArgs(string mesage)=> _exception = new Exception(mesage);

public Exception Exception => _exception;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void WaitForProcessToStart(string applicationPath, TimeSpan timeout, Act
var startTime = DateTime.UtcNow;
while (DateTime.UtcNow - startTime < timeout)
{
Thread.Sleep(10 * 1000);
Thread.Sleep(2 * 1000);
if (!process.HasExited)
{
callbackAction?.Invoke(applicationPath);
Expand Down

0 comments on commit 59fe557

Please sign in to comment.