- adding Load method for controls
This commit is contained in:
parent
69e5a6717b
commit
256cac825f
@ -28,6 +28,14 @@ namespace TelegramBotBase.Base
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Enabled { get; set; } = true;
|
public bool Enabled { get; set; } = true;
|
||||||
|
|
||||||
|
|
||||||
|
public virtual async Task Load(MessageResult result)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public virtual async Task Action(MessageResult result, String value = null)
|
public virtual async Task Action(MessageResult result, String value = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -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>
|
/// <summary>
|
||||||
/// Gets invoked if the form gets loaded and on every message belongs to this context
|
/// Gets invoked if the form gets loaded and on every message belongs to this context
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -162,6 +189,8 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets invoked if the user clicked a button.
|
/// Gets invoked if the user clicked a button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -186,6 +215,9 @@ namespace TelegramBotBase.Form
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
await b.Action(message);
|
await b.Action(message);
|
||||||
|
|
||||||
|
if (message.Handled)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +297,10 @@ namespace TelegramBotBase.Form
|
|||||||
await newForm.OnOpened(new EventArgs());
|
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)
|
public void AddControl(ControlBase control)
|
||||||
{
|
{
|
||||||
control.ID = this.Controls.Count + 1;
|
control.ID = this.Controls.Count + 1;
|
||||||
|
|||||||
@ -267,6 +267,9 @@ namespace TelegramBotBase
|
|||||||
//Pre Loading Event
|
//Pre Loading Event
|
||||||
await activeForm.PreLoad(e);
|
await activeForm.PreLoad(e);
|
||||||
|
|
||||||
|
//Send Load event to controls
|
||||||
|
await activeForm.LoadControls(e);
|
||||||
|
|
||||||
//Loading Event
|
//Loading Event
|
||||||
await activeForm.Load(e);
|
await activeForm.Load(e);
|
||||||
|
|
||||||
@ -279,7 +282,13 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
//Render Event
|
//Render Event
|
||||||
if (!ds.FormSwitched)
|
if (!ds.FormSwitched)
|
||||||
|
{
|
||||||
|
|
||||||
|
await activeForm.RenderControls(e);
|
||||||
|
|
||||||
await activeForm.Render(e);
|
await activeForm.Render(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} while (ds.FormSwitched && i < NavigationMaximum);
|
} while (ds.FormSwitched && i < NavigationMaximum);
|
||||||
|
|
||||||
@ -336,6 +345,9 @@ namespace TelegramBotBase
|
|||||||
//Pre Loading Event
|
//Pre Loading Event
|
||||||
await activeForm.PreLoad(e);
|
await activeForm.PreLoad(e);
|
||||||
|
|
||||||
|
//Send Load event to controls
|
||||||
|
await activeForm.LoadControls(e);
|
||||||
|
|
||||||
//Loading Event
|
//Loading Event
|
||||||
await activeForm.Load(e);
|
await activeForm.Load(e);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user