- Improvements to system calls

- system calls now async with await
- added start command to example
- added "handled" property to system call event args
This commit is contained in:
FlorianDahn
2019-03-20 16:57:10 +07:00
parent 816bf4cbbe
commit c6666f72bc
4 changed files with 42 additions and 19 deletions
+19 -1
View File
@@ -44,6 +44,10 @@ namespace TelegramBotBase.Form
}
/// <summary>
/// Gets invoked if gets navigated to this form
/// </summary>
/// <returns></returns>
public virtual async Task Opened()
{
@@ -62,17 +66,31 @@ namespace TelegramBotBase.Form
}
/// <summary>
/// Gets invoked if the form gets loaded and on every message belongs to this context
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task Load(MessageResult message)
{
}
/// <summary>
/// Gets invoked if the user has clicked a button.
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task Action(MessageResult message)
{
}
/// <summary>
/// Gets invoked at the end of the cycle to "Render" text, images, buttons, etc...
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task Render(MessageResult message)
{
+11 -14
View File
@@ -42,6 +42,8 @@ namespace TelegramBotBase
private static object __evSystemCall = new object();
public delegate Task SystemCallEventHandler(object sender, SystemCallEventArgs e);
private static object __evException = new object();
private static object __evUnhandledCall = new object();
@@ -220,7 +222,10 @@ namespace TelegramBotBase
if (e.IsSystemCall && this.SystemCalls.Contains(e.SystemCommand))
{
var sce = new SystemCallEventArgs(e.SystemCommand, e.SystemCallParameters, e.Message, ds.DeviceId, ds);
OnSystemCall(sce);
await OnSystemCall(sce);
if (sce.Handled)
return;
}
FormBase activeForm = null;
@@ -377,21 +382,13 @@ namespace TelegramBotBase
/// <summary>
/// Will be called if a system call gets raised
/// </summary>
public event EventHandler<SystemCallEventArgs> SystemCall
{
add
{
this.__Events.AddHandler(__evSystemCall, value);
}
remove
{
this.__Events.RemoveHandler(__evSystemCall, value);
}
}
public event SystemCallEventHandler SystemCall;
public void OnSystemCall(SystemCallEventArgs e)
public async Task OnSystemCall(SystemCallEventArgs e)
{
(this.__Events[__evSystemCall] as EventHandler<SystemCallEventArgs>)?.Invoke(this, e);
if (this.SystemCall != null)
await SystemCall(this, e);
}
/// <summary>
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyVersion("1.3.1.2")]
[assembly: AssemblyFileVersion("1.3.1.2")]