fix: remove obsolete properties & fix NRE

This commit is contained in:
ZavaruKitsu
2022-10-08 20:37:35 +03:00
parent d566cf858e
commit 8d02b54b05
9 changed files with 28 additions and 45 deletions
+3 -5
View File
@@ -11,7 +11,7 @@ namespace TelegramBotBaseTest;
internal class Program
{
private static void Main(string[] args)
private static async Task Main(string[] args)
{
var apiKey = "";
@@ -48,16 +48,14 @@ internal class Program
Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? ""));
};
bb.Start();
await bb.Start();
Console.WriteLine("Telegram Bot started...");
Console.WriteLine("Press q to quit application.");
Console.ReadLine();
bb.Stop();
await bb.Stop();
}
private static async Task Bb_BotCommand(object sender, BotCommandEventArgs en)
@@ -32,7 +32,7 @@ public class ButtonGridForm : AutoCleanForm
bf.AddButtonRow(new ButtonBase("Button3", "b3"), new ButtonBase("Button4", "b4"));
_mButtons.ButtonsForm = bf;
_mButtons.DataSource.ButtonForm = bf;
_mButtons.ButtonClicked += Bg_ButtonClicked;
@@ -66,4 +66,4 @@ public class ButtonGridForm : AutoCleanForm
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
}
}
}
}
@@ -38,7 +38,7 @@ public class ButtonGridPagingForm : AutoCleanForm
bf.AddButtonRow(new ButtonBase(c.EnglishName, c.EnglishName));
}
_mButtons.ButtonsForm = bf;
_mButtons.DataSource.ButtonForm = bf;
_mButtons.ButtonClicked += Bg_ButtonClicked;
@@ -63,4 +63,4 @@ public class ButtonGridPagingForm : AutoCleanForm
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
}
}
}
}
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using TelegramBotBase.Args;
using TelegramBotBase.Controls.Hybrid;
using TelegramBotBase.DataSources;
using TelegramBotBase.Enums;
using TelegramBotBase.Form;
using TelegramBotBaseTest.Tests.Controls.Subclass;
@@ -26,9 +27,9 @@ public class MultiViewForm : AutoCleanForm
_bg = new ButtonGrid
{
ButtonsForm = new ButtonForm()
DataSource = new ButtonFormDataSource()
};
_bg.ButtonsForm.AddButtonRow("Back", "$back$");
_bg.DataSource.ButtonForm.AddButtonRow("Back", "$back$");
_bg.ButtonClicked += Bg_ButtonClicked;
_bg.KeyboardType = EKeyboardType.ReplyKeyboard;
AddControl(_bg);
@@ -47,4 +48,4 @@ public class MultiViewForm : AutoCleanForm
break;
}
}
}
}
+8 -1
View File
@@ -33,7 +33,7 @@ public class MessageResult : ResultBase
/// <summary>
/// The message id
/// </summary>
public new int MessageId =>
public override int MessageId =>
UpdateData?.Message?.MessageId
?? Message?.MessageId
?? UpdateData?.CallbackQuery?.Message?.MessageId
@@ -45,6 +45,13 @@ public class MessageResult : ResultBase
public MessageType MessageType => Message?.Type ?? MessageType.Unknown;
public override Message Message =>
UpdateData?.Message
?? UpdateData?.EditedMessage
?? UpdateData?.ChannelPost
?? UpdateData?.EditedChannelPost
?? UpdateData?.CallbackQuery?.Message;
/// <summary>
/// Is this an action ? (i.e. button click)
/// </summary>
+2 -2
View File
@@ -12,7 +12,7 @@ public class ResultBase : EventArgs
public virtual long DeviceId { get; set; }
public int MessageId => Message.MessageId;
public virtual int MessageId => Message.MessageId;
public virtual Message Message { get; set; }
@@ -42,4 +42,4 @@ public class ResultBase : EventArgs
{
}
}
}
}
+1 -10
View File
@@ -55,15 +55,6 @@ public class ButtonGrid : ControlBase
public string ConfirmationText { get; set; } = "";
/// <summary>
/// </summary>
[Obsolete("This property is obsolete. Please use the DataSource property instead.")]
public ButtonForm ButtonsForm
{
get => DataSource.ButtonForm;
set => DataSource = new ButtonFormDataSource(value);
}
/// <summary>
/// Data source of the items.
/// </summary>
@@ -746,4 +737,4 @@ public class ButtonGrid : ControlBase
break;
}
}
}
}
@@ -55,13 +55,6 @@ public class CheckedButtonList : ControlBase
public string ConfirmationText { get; set; } = "";
[Obsolete("This property is obsolete. Please use the DataSource property instead.")]
public ButtonForm ButtonsForm
{
get => DataSource.ButtonForm;
set => DataSource = new ButtonFormDataSource(value);
}
/// <summary>
/// Data source of the items.
/// </summary>
@@ -277,7 +270,7 @@ public class CheckedButtonList : ControlBase
foreach (var c in CheckedRows)
{
lst.Add(ButtonsForm[c][0]);
lst.Add(DataSource.ButtonForm[c][0]);
}
return lst;
@@ -418,7 +411,7 @@ public class CheckedButtonList : ControlBase
Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, false));
await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, false));
}
else if (result.MessageText.EndsWith(UncheckedIconLabel))
{
@@ -435,7 +428,7 @@ public class CheckedButtonList : ControlBase
Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, true));
await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, true));
}
//else if (this.EnableSearch)
//{
@@ -589,7 +582,7 @@ public class CheckedButtonList : ControlBase
Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, true));
await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, true));
}
break;
@@ -604,7 +597,7 @@ public class CheckedButtonList : ControlBase
Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, false));
await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, false));
}
break;
@@ -63,13 +63,6 @@ public class TaggedButtonGrid : MultiView
public string ConfirmationText { get; set; }
[Obsolete("This property is obsolete. Please use the DataSource property instead.")]
public ButtonForm ButtonsForm
{
get => DataSource.ButtonForm;
set => DataSource = new ButtonFormDataSource(value);
}
/// <summary>
/// Data source of the items.
/// </summary>
@@ -1017,4 +1010,4 @@ public class TaggedButtonGrid : MultiView
}
#endregion
}
}