mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
在 `TpTask.cs` 文件中,添加了 `using BetterGenshinImpact.GameTask.Common.Exceptions;` 引用,并在 `TpTask` 类中添加了对 `TpPointNotActivate` 异常的处理逻辑,当传送点未激活或不存在时,按下 ESC 键返回大地图界面,并抛出异常。同时在 `ClickTpPoint` 方法中,修改了判断逻辑,增加了对传送点未激活或不存在的异常处理。 在 `MapAssets.cs`、`NewRetry.cs`、`TaskControl.cs` 文件中,将 `Exception` 修改为 `System.Exception`。 在 `NormalEndException.cs` 和 `RetryException.cs` 文件中,删除了旧的异常类定义,并重新添加了新的异常类定义。 在 `TpPointNotActivate.cs` 文件中,添加了新的异常类 `TpPointNotActivate`。
51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
|
|
namespace BetterGenshinImpact.GameTask.Common;
|
|
|
|
/// <summary>
|
|
/// https://stackoverflow.com/questions/1563191/cleanest-way-to-write-retry-logic
|
|
/// </summary>
|
|
public static class NewRetry
|
|
{
|
|
public static void Do(Action action, TimeSpan retryInterval, int maxAttemptCount = 3)
|
|
{
|
|
_ = Do<object?>(() =>
|
|
{
|
|
action();
|
|
return null;
|
|
}, retryInterval, maxAttemptCount);
|
|
}
|
|
|
|
public static T Do<T>(Func<T> action, TimeSpan retryInterval, int maxAttemptCount = 3)
|
|
{
|
|
List<System.Exception> exceptions = [];
|
|
|
|
for (int attempted = 0; attempted < maxAttemptCount; attempted++)
|
|
{
|
|
try
|
|
{
|
|
if (attempted > 0)
|
|
{
|
|
Thread.Sleep(retryInterval);
|
|
}
|
|
|
|
return action();
|
|
}
|
|
catch (RetryException ex)
|
|
{
|
|
exceptions.Add(ex);
|
|
}
|
|
}
|
|
|
|
if (exceptions.Count > 0)
|
|
{
|
|
throw exceptions.Last();
|
|
}
|
|
throw new AggregateException(exceptions);
|
|
}
|
|
}
|