Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Open collections of custom methods #17

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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