fix!: get rid of async void
This commit is contained in:
parent
5ab15621a0
commit
f41fdf90ed
@ -20,5 +20,5 @@ var bot = BotBaseBuilder.Create()
|
|||||||
.DefaultLanguage()
|
.DefaultLanguage()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
|
|||||||
@ -80,7 +80,7 @@ public class BotBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start your Bot
|
/// Start your Bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start()
|
public async Task Start()
|
||||||
{
|
{
|
||||||
if (Client == null)
|
if (Client == null)
|
||||||
{
|
{
|
||||||
@ -89,16 +89,15 @@ public class BotBase
|
|||||||
|
|
||||||
Client.MessageLoop += Client_MessageLoop;
|
Client.MessageLoop += Client_MessageLoop;
|
||||||
|
|
||||||
|
|
||||||
if (StateMachine != null)
|
if (StateMachine != null)
|
||||||
{
|
{
|
||||||
Sessions.LoadSessionStates(StateMachine);
|
await Sessions.LoadSessionStates(StateMachine);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Enable auto session saving
|
//Enable auto session saving
|
||||||
if (GetSetting(ESettings.SaveSessionsOnConsoleExit, false))
|
if (GetSetting(ESettings.SaveSessionsOnConsoleExit, false))
|
||||||
{
|
{
|
||||||
Console.SetHandler(() => { Sessions.SaveSessionStates(); });
|
Console.SetHandler(() => { Sessions.SaveSessionStates().GetAwaiter().GetResult(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceSession.MaxNumberOfRetries = GetSetting(ESettings.MaxNumberOfRetries, 5);
|
DeviceSession.MaxNumberOfRetries = GetSetting(ESettings.MaxNumberOfRetries, 5);
|
||||||
@ -141,7 +140,7 @@ public class BotBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop your Bot
|
/// Stop your Bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Stop()
|
public async Task Stop()
|
||||||
{
|
{
|
||||||
if (Client == null)
|
if (Client == null)
|
||||||
{
|
{
|
||||||
@ -149,11 +148,9 @@ public class BotBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
Client.MessageLoop -= Client_MessageLoop;
|
Client.MessageLoop -= Client_MessageLoop;
|
||||||
|
|
||||||
|
|
||||||
Client.StopReceiving();
|
Client.StopReceiving();
|
||||||
|
|
||||||
Sessions.SaveSessionStates();
|
await Sessions.SaveSessionStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -407,4 +404,4 @@ public class BotBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,7 @@ public class NavigationController : FormBase, IStateForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void LoadState(LoadStateEventArgs e)
|
public async Task LoadState(LoadStateEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Get("$controller.history.count") == null)
|
if (e.Get("$controller.history.count") == null)
|
||||||
{
|
{
|
||||||
@ -144,13 +144,13 @@ public class NavigationController : FormBase, IStateForm
|
|||||||
form.Client = Client;
|
form.Client = Client;
|
||||||
form.NavigationController = this;
|
form.NavigationController = this;
|
||||||
|
|
||||||
form.OnInit(new InitEventArgs());
|
await form.OnInit(new InitEventArgs());
|
||||||
|
|
||||||
History.Add(form);
|
History.Add(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveState(SaveStateEventArgs e)
|
public Task SaveState(SaveStateEventArgs e)
|
||||||
{
|
{
|
||||||
e.Set("$controller.history.count", History.Count.ToString());
|
e.Set("$controller.history.count", History.Count.ToString());
|
||||||
|
|
||||||
@ -175,6 +175,8 @@ public class NavigationController : FormBase, IStateForm
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task NavigationController_Init(object sender, InitEventArgs e)
|
private async Task NavigationController_Init(object sender, InitEventArgs e)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using TelegramBotBase.Args;
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
|
|
||||||
namespace TelegramBotBase.Interfaces;
|
namespace TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
@ -7,7 +8,7 @@ namespace TelegramBotBase.Interfaces;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IStateForm
|
public interface IStateForm
|
||||||
{
|
{
|
||||||
void LoadState(LoadStateEventArgs e);
|
Task LoadState(LoadStateEventArgs e);
|
||||||
|
|
||||||
void SaveState(SaveStateEventArgs e);
|
Task SaveState(SaveStateEventArgs e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,25 +118,25 @@ public class SessionBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the previously saved states from the machine.
|
/// Loads the previously saved states from the machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async void LoadSessionStates()
|
public async Task LoadSessionStates()
|
||||||
{
|
{
|
||||||
if (BotBase.StateMachine == null)
|
if (BotBase.StateMachine == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadSessionStates(BotBase.StateMachine);
|
await LoadSessionStates(BotBase.StateMachine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the previously saved states from the machine.
|
/// Loads the previously saved states from the machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async void LoadSessionStates(IStateMachine statemachine)
|
public async Task LoadSessionStates(IStateMachine statemachine)
|
||||||
{
|
{
|
||||||
if (statemachine == null)
|
if (statemachine == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("StateMachine",
|
throw new ArgumentNullException(nameof(statemachine),
|
||||||
"No StateMachine defined. Please set one to property BotBase.StateMachine");
|
"No StateMachine defined. Please set one to property BotBase.StateMachine");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ public class SessionBase
|
|||||||
{
|
{
|
||||||
Values = s.Values
|
Values = s.Values
|
||||||
};
|
};
|
||||||
iform.LoadState(ls);
|
await iform.LoadState(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -251,11 +251,11 @@ public class SessionBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves all open states into the machine.
|
/// Saves all open states into the machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SaveSessionStates(IStateMachine statemachine)
|
public async Task SaveSessionStates(IStateMachine statemachine)
|
||||||
{
|
{
|
||||||
if (statemachine == null)
|
if (statemachine == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("StateMachine",
|
throw new ArgumentNullException(nameof(statemachine),
|
||||||
"No StateMachine defined. Please set one to property BotBase.StateMachine");
|
"No StateMachine defined. Please set one to property BotBase.StateMachine");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ public class SessionBase
|
|||||||
{
|
{
|
||||||
//Loading Session states
|
//Loading Session states
|
||||||
var ssea = new SaveStateEventArgs();
|
var ssea = new SaveStateEventArgs();
|
||||||
iform.SaveState(ssea);
|
await iform.SaveState(ssea);
|
||||||
|
|
||||||
se.Values = ssea.Values;
|
se.Values = ssea.Values;
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ public class SessionBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves all open states into the machine.
|
/// Saves all open states into the machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SaveSessionStates()
|
public async Task SaveSessionStates()
|
||||||
{
|
{
|
||||||
if (BotBase.StateMachine == null)
|
if (BotBase.StateMachine == null)
|
||||||
{
|
{
|
||||||
@ -343,6 +343,6 @@ public class SessionBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SaveSessionStates(BotBase.StateMachine);
|
await SaveSessionStates(BotBase.StateMachine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user