- adding Load method for controls

This commit is contained in:
FlorianDahn 2019-09-26 20:50:33 +02:00
parent 69e5a6717b
commit 256cac825f
3 changed files with 56 additions and 0 deletions

View File

@ -28,6 +28,14 @@ namespace TelegramBotBase.Base
/// </summary>
public bool Enabled { get; set; } = true;
public virtual async Task Load(MessageResult result)
{
}
public virtual async Task Action(MessageResult result, String value = null)
{

View File

@ -152,6 +152,33 @@ namespace TelegramBotBase.Form
}
/// <summary>
/// Gets invoked if a message was sent or an action triggered
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public async Task LoadControls(MessageResult message)
{
//Looking for the control by id, if not listened, raise event for all
if (message.RawData?.StartsWith("#c") ?? false)
{
var c = this.Controls.FirstOrDefault(a => a.ControlID == message.RawData.Split('_')[0]);
if (c != null)
{
await c.Load(message);
return;
}
}
foreach (var b in this.Controls)
{
if (!b.Enabled)
continue;
await b.Load(message);
}
}
/// <summary>
/// Gets invoked if the form gets loaded and on every message belongs to this context
/// </summary>
@ -162,6 +189,8 @@ namespace TelegramBotBase.Form
}
/// <summary>
/// Gets invoked if the user clicked a button.
/// </summary>
@ -186,6 +215,9 @@ namespace TelegramBotBase.Form
continue;
await b.Action(message);
if (message.Handled)
return;
}
}
@ -265,6 +297,10 @@ namespace TelegramBotBase.Form
await newForm.OnOpened(new EventArgs());
}
/// <summary>
/// Adds a control to the formular and sets its ID and Device.
/// </summary>
/// <param name="control"></param>
public void AddControl(ControlBase control)
{
control.ID = this.Controls.Count + 1;

View File

@ -267,6 +267,9 @@ namespace TelegramBotBase
//Pre Loading Event
await activeForm.PreLoad(e);
//Send Load event to controls
await activeForm.LoadControls(e);
//Loading Event
await activeForm.Load(e);
@ -279,7 +282,13 @@ namespace TelegramBotBase
//Render Event
if (!ds.FormSwitched)
{
await activeForm.RenderControls(e);
await activeForm.Render(e);
}
} while (ds.FormSwitched && i < NavigationMaximum);
@ -336,6 +345,9 @@ namespace TelegramBotBase
//Pre Loading Event
await activeForm.PreLoad(e);
//Send Load event to controls
await activeForm.LoadControls(e);
//Loading Event
await activeForm.Load(e);