commit
d52fd41467
@ -54,5 +54,10 @@ namespace TelegramBotBase.Args
|
||||
return false;
|
||||
}
|
||||
|
||||
public object GetObject(String key)
|
||||
{
|
||||
return Values[key];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,10 @@ namespace TelegramBotBase.Args
|
||||
{
|
||||
Values[key] = value;
|
||||
}
|
||||
public void SetObject(String key, object value)
|
||||
{
|
||||
Values[key] = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ namespace TelegramBotBase.Form
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public async Task LoadControls(MessageResult message)
|
||||
public virtual async Task LoadControls(MessageResult message)
|
||||
{
|
||||
//Looking for the control by id, if not listened, raise event for all
|
||||
if (message.RawData?.StartsWith("#c") ?? false)
|
||||
@ -228,7 +228,7 @@ namespace TelegramBotBase.Form
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ActionControls(MessageResult message)
|
||||
public virtual async Task ActionControls(MessageResult message)
|
||||
{
|
||||
//Looking for the control by id, if not listened, raise event for all
|
||||
if (message.RawData.StartsWith("#c"))
|
||||
@ -278,7 +278,7 @@ namespace TelegramBotBase.Form
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public async Task RenderControls(MessageResult message)
|
||||
public virtual async Task RenderControls(MessageResult message)
|
||||
{
|
||||
foreach (var b in this.Controls)
|
||||
{
|
||||
@ -400,6 +400,10 @@ namespace TelegramBotBase.Form
|
||||
/// <param name="control"></param>
|
||||
public void AddControl(ControlBase control)
|
||||
{
|
||||
//Duplicate check
|
||||
if (this.Controls.Contains(control))
|
||||
throw new ArgumentException("Control has been already added.");
|
||||
|
||||
control.ID = this.Controls.Count + 1;
|
||||
control.Device = this.Device;
|
||||
this.Controls.Add(control);
|
||||
|
||||
@ -47,6 +47,11 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
|
||||
public bool DeletePreviousMessage { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the reply message from a user.
|
||||
/// </summary>
|
||||
public bool DeleteReplyMessage { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Parsemode of the message.
|
||||
/// </summary>
|
||||
@ -197,7 +202,7 @@ namespace TelegramBotBase.Controls.Hybrid
|
||||
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
||||
|
||||
//Remove button click message
|
||||
if (this.DeletePreviousMessage)
|
||||
if (this.DeleteReplyMessage)
|
||||
await Device.DeleteMessage(result.MessageId);
|
||||
|
||||
result.Handled = true;
|
||||
|
||||
@ -198,7 +198,7 @@ namespace TelegramBotBase
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
|
||||
CustomConversionChecks(form, p, f);
|
||||
Tools.Conversion.CustomConversionChecks(form, p, f);
|
||||
|
||||
}
|
||||
catch
|
||||
@ -240,33 +240,7 @@ namespace TelegramBotBase
|
||||
|
||||
}
|
||||
|
||||
private static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, System.Reflection.PropertyInfo f)
|
||||
{
|
||||
//Newtonsoft Int64/Int32 converter issue
|
||||
if (f.PropertyType == typeof(Int32))
|
||||
{
|
||||
int i = 0;
|
||||
if(int.TryParse(p.Value.ToString(), out i))
|
||||
{
|
||||
f.SetValue(form, i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//Newtonsoft Double/Decimal converter issue
|
||||
if(f.PropertyType == typeof(Decimal) | f.PropertyType == typeof(Nullable<Decimal>))
|
||||
{
|
||||
decimal d = 0;
|
||||
if(decimal.TryParse(p.Value.ToString(), out d))
|
||||
{
|
||||
f.SetValue(form, d);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
38
TelegramBotBase/Tools/Conversion.cs
Normal file
38
TelegramBotBase/Tools/Conversion.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Tools
|
||||
{
|
||||
public static class Conversion
|
||||
{
|
||||
public static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, System.Reflection.PropertyInfo f)
|
||||
{
|
||||
//Newtonsoft Int64/Int32 converter issue
|
||||
if (f.PropertyType == typeof(Int32))
|
||||
{
|
||||
int i = 0;
|
||||
if (int.TryParse(p.Value.ToString(), out i))
|
||||
{
|
||||
f.SetValue(form, i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//Newtonsoft Double/Decimal converter issue
|
||||
if (f.PropertyType == typeof(Decimal) | f.PropertyType == typeof(Nullable<Decimal>))
|
||||
{
|
||||
decimal d = 0;
|
||||
if (decimal.TryParse(p.Value.ToString(), out d))
|
||||
{
|
||||
f.SetValue(form, d);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user