Async invoke fixes and ButtonGrid update

- removing unused imports
- adding null check for async handler invokes
- fixing PageCount calculation on ButtonGrid
This commit is contained in:
FlorianDahn 2021-02-27 20:51:47 +01:00
parent 426bb078af
commit 91048b4f7c
6 changed files with 22 additions and 9 deletions

View File

@ -55,7 +55,10 @@ namespace TelegramBotBase.Form
if (this.Events[__evInit] == null) if (this.Events[__evInit] == null)
return; return;
var handler = this.Events[__evInit].GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>(); var handler = this.Events[__evInit]?.GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>();
if (handler == null)
return;
foreach (var h in handler) foreach (var h in handler)
{ {
await Async.InvokeAllAsync<InitEventArgs>(h, this, e); await Async.InvokeAllAsync<InitEventArgs>(h, this, e);
@ -84,7 +87,10 @@ namespace TelegramBotBase.Form
if (this.Events[__evOpened] == null) if (this.Events[__evOpened] == null)
return; return;
var handler = this.Events[__evOpened].GetInvocationList().Cast<AsyncEventHandler<EventArgs>>(); var handler = this.Events[__evOpened]?.GetInvocationList().Cast<AsyncEventHandler<EventArgs>>();
if (handler == null)
return;
foreach (var h in handler) foreach (var h in handler)
{ {
await Async.InvokeAllAsync<EventArgs>(h, this, e); await Async.InvokeAllAsync<EventArgs>(h, this, e);
@ -114,7 +120,10 @@ namespace TelegramBotBase.Form
if (this.Events[__evClosed] == null) if (this.Events[__evClosed] == null)
return; return;
var handler = this.Events[__evClosed].GetInvocationList().Cast<AsyncEventHandler<EventArgs>>(); var handler = this.Events[__evClosed]?.GetInvocationList().Cast<AsyncEventHandler<EventArgs>>();
if (handler == null)
return;
foreach (var h in handler) foreach (var h in handler)
{ {
await Async.InvokeAllAsync<EventArgs>(h, this, e); await Async.InvokeAllAsync<EventArgs>(h, this, e);

View File

@ -149,7 +149,10 @@ namespace TelegramBotBase.Controls.Hybrid
public async Task OnButtonClicked(ButtonClickedEventArgs e) public async Task OnButtonClicked(ButtonClickedEventArgs e)
{ {
var handler = this.Events[__evButtonClicked].GetInvocationList().Cast<AsyncEventHandler<ButtonClickedEventArgs>>(); var handler = this.Events[__evButtonClicked]?.GetInvocationList().Cast<AsyncEventHandler<ButtonClickedEventArgs>>();
if (handler == null)
return;
foreach (var h in handler) foreach (var h in handler)
{ {
await Async.InvokeAllAsync<ButtonClickedEventArgs>(h, this, e); await Async.InvokeAllAsync<ButtonClickedEventArgs>(h, this, e);

View File

@ -6,7 +6,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TelegramBotBase.Args; using TelegramBotBase.Args;
using TelegramBotBase.Base; using TelegramBotBase.Base;
using static TelegramBotBase.Base.Async;
namespace TelegramBotBase.Controls.Hybrid namespace TelegramBotBase.Controls.Hybrid
{ {

View File

@ -160,7 +160,10 @@ namespace TelegramBotBase.Controls.Hybrid
public async Task OnButtonClicked(ButtonClickedEventArgs e) public async Task OnButtonClicked(ButtonClickedEventArgs e)
{ {
var handler = this.Events[__evButtonClicked].GetInvocationList().Cast<AsyncEventHandler<ButtonClickedEventArgs>>(); var handler = this.Events[__evButtonClicked]?.GetInvocationList().Cast<AsyncEventHandler<ButtonClickedEventArgs>>();
if (handler == null)
return;
foreach (var h in handler) foreach (var h in handler)
{ {
await Async.InvokeAllAsync<ButtonClickedEventArgs>(h, this, e); await Async.InvokeAllAsync<ButtonClickedEventArgs>(h, this, e);
@ -759,7 +762,7 @@ namespace TelegramBotBase.Controls.Hybrid
if (bf.Rows == 0) if (bf.Rows == 0)
return 1; return 1;
return (int)Math.Ceiling((decimal)(bf.Rows / (decimal)(MaximumRow - 3))); return (int)Math.Ceiling((decimal)(bf.Rows / (decimal)(MaximumRow - this.LayoutRows)));
} }
} }

View File

@ -5,7 +5,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TelegramBotBase.Args; using TelegramBotBase.Args;
using TelegramBotBase.Base; using TelegramBotBase.Base;
using static TelegramBotBase.Base.Async;
namespace TelegramBotBase.Form namespace TelegramBotBase.Form
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TelegramBotBase.Base; using TelegramBotBase.Base;
using static TelegramBotBase.Base.Async;
namespace TelegramBotBase.Form namespace TelegramBotBase.Form
{ {