fix: remove obsolete properties & fix NRE

This commit is contained in:
ZavaruKitsu 2022-10-08 20:37:21 +03:00
parent d566cf858e
commit 8d02b54b05
9 changed files with 28 additions and 45 deletions

View File

@ -11,7 +11,7 @@ namespace TelegramBotBaseTest;
internal class Program internal class Program
{ {
private static void Main(string[] args) private static async Task Main(string[] args)
{ {
var apiKey = ""; var apiKey = "";
@ -48,16 +48,14 @@ internal class Program
Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? "")); Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? ""));
}; };
bb.Start(); await bb.Start();
Console.WriteLine("Telegram Bot started..."); Console.WriteLine("Telegram Bot started...");
Console.WriteLine("Press q to quit application."); Console.WriteLine("Press q to quit application.");
Console.ReadLine(); Console.ReadLine();
bb.Stop(); await bb.Stop();
} }
private static async Task Bb_BotCommand(object sender, BotCommandEventArgs en) private static async Task Bb_BotCommand(object sender, BotCommandEventArgs en)

View File

@ -32,7 +32,7 @@ public class ButtonGridForm : AutoCleanForm
bf.AddButtonRow(new ButtonBase("Button3", "b3"), new ButtonBase("Button4", "b4")); bf.AddButtonRow(new ButtonBase("Button3", "b3"), new ButtonBase("Button4", "b4"));
_mButtons.ButtonsForm = bf; _mButtons.DataSource.ButtonForm = bf;
_mButtons.ButtonClicked += Bg_ButtonClicked; _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}"); await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
} }
} }
} }

View File

@ -38,7 +38,7 @@ public class ButtonGridPagingForm : AutoCleanForm
bf.AddButtonRow(new ButtonBase(c.EnglishName, c.EnglishName)); bf.AddButtonRow(new ButtonBase(c.EnglishName, c.EnglishName));
} }
_mButtons.ButtonsForm = bf; _mButtons.DataSource.ButtonForm = bf;
_mButtons.ButtonClicked += Bg_ButtonClicked; _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}"); await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
} }
} }
} }

View File

@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using TelegramBotBase.Args; using TelegramBotBase.Args;
using TelegramBotBase.Controls.Hybrid; using TelegramBotBase.Controls.Hybrid;
using TelegramBotBase.DataSources;
using TelegramBotBase.Enums; using TelegramBotBase.Enums;
using TelegramBotBase.Form; using TelegramBotBase.Form;
using TelegramBotBaseTest.Tests.Controls.Subclass; using TelegramBotBaseTest.Tests.Controls.Subclass;
@ -26,9 +27,9 @@ public class MultiViewForm : AutoCleanForm
_bg = new ButtonGrid _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.ButtonClicked += Bg_ButtonClicked;
_bg.KeyboardType = EKeyboardType.ReplyKeyboard; _bg.KeyboardType = EKeyboardType.ReplyKeyboard;
AddControl(_bg); AddControl(_bg);
@ -47,4 +48,4 @@ public class MultiViewForm : AutoCleanForm
break; break;
} }
} }
} }

View File

@ -33,7 +33,7 @@ public class MessageResult : ResultBase
/// <summary> /// <summary>
/// The message id /// The message id
/// </summary> /// </summary>
public new int MessageId => public override int MessageId =>
UpdateData?.Message?.MessageId UpdateData?.Message?.MessageId
?? Message?.MessageId ?? Message?.MessageId
?? UpdateData?.CallbackQuery?.Message?.MessageId ?? UpdateData?.CallbackQuery?.Message?.MessageId
@ -45,6 +45,13 @@ public class MessageResult : ResultBase
public MessageType MessageType => Message?.Type ?? MessageType.Unknown; public MessageType MessageType => Message?.Type ?? MessageType.Unknown;
public override Message Message =>
UpdateData?.Message
?? UpdateData?.EditedMessage
?? UpdateData?.ChannelPost
?? UpdateData?.EditedChannelPost
?? UpdateData?.CallbackQuery?.Message;
/// <summary> /// <summary>
/// Is this an action ? (i.e. button click) /// Is this an action ? (i.e. button click)
/// </summary> /// </summary>

View File

@ -12,7 +12,7 @@ public class ResultBase : EventArgs
public virtual long DeviceId { get; set; } public virtual long DeviceId { get; set; }
public int MessageId => Message.MessageId; public virtual int MessageId => Message.MessageId;
public virtual Message Message { get; set; } public virtual Message Message { get; set; }
@ -42,4 +42,4 @@ public class ResultBase : EventArgs
{ {
} }
} }
} }

View File

@ -55,15 +55,6 @@ public class ButtonGrid : ControlBase
public string ConfirmationText { get; set; } = ""; 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> /// <summary>
/// Data source of the items. /// Data source of the items.
/// </summary> /// </summary>
@ -746,4 +737,4 @@ public class ButtonGrid : ControlBase
break; break;
} }
} }
} }

View File

@ -55,13 +55,6 @@ public class CheckedButtonList : ControlBase
public string ConfirmationText { get; set; } = ""; 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> /// <summary>
/// Data source of the items. /// Data source of the items.
/// </summary> /// </summary>
@ -277,7 +270,7 @@ public class CheckedButtonList : ControlBase
foreach (var c in CheckedRows) foreach (var c in CheckedRows)
{ {
lst.Add(ButtonsForm[c][0]); lst.Add(DataSource.ButtonForm[c][0]);
} }
return lst; return lst;
@ -418,7 +411,7 @@ public class CheckedButtonList : ControlBase
Updated(); Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, false)); await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, false));
} }
else if (result.MessageText.EndsWith(UncheckedIconLabel)) else if (result.MessageText.EndsWith(UncheckedIconLabel))
{ {
@ -435,7 +428,7 @@ public class CheckedButtonList : ControlBase
Updated(); Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, true)); await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, true));
} }
//else if (this.EnableSearch) //else if (this.EnableSearch)
//{ //{
@ -589,7 +582,7 @@ public class CheckedButtonList : ControlBase
Updated(); Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, true)); await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, true));
} }
break; break;
@ -604,7 +597,7 @@ public class CheckedButtonList : ControlBase
Updated(); Updated();
await OnCheckedChanged(new CheckedChangedEventArgs(ButtonsForm[index], index, false)); await OnCheckedChanged(new CheckedChangedEventArgs(DataSource.ButtonForm[index], index, false));
} }
break; break;

View File

@ -63,13 +63,6 @@ public class TaggedButtonGrid : MultiView
public string ConfirmationText { get; set; } 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> /// <summary>
/// Data source of the items. /// Data source of the items.
/// </summary> /// </summary>
@ -1017,4 +1010,4 @@ public class TaggedButtonGrid : MultiView
} }
#endregion #endregion
} }