diff --git a/TelegramBotBase/Interfaces/IStateMachine.cs b/TelegramBotBase/Interfaces/IStateMachine.cs
index 47b590e..7ba2c7c 100644
--- a/TelegramBotBase/Interfaces/IStateMachine.cs
+++ b/TelegramBotBase/Interfaces/IStateMachine.cs
@@ -3,11 +3,14 @@ using System.Collections.Generic;
using System.Text;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
+using TelegramBotBase.Form;
namespace TelegramBotBase.Interfaces
{
public interface IStateMachine
{
+ Type DefaultStateForm { get; }
+
void SaveFormStates(SaveStatesEventArgs e);
StateContainer LoadFormStates();
diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs
index 9991681..8859cb0 100644
--- a/TelegramBotBase/SessionBase.cs
+++ b/TelegramBotBase/SessionBase.cs
@@ -88,7 +88,7 @@ namespace TelegramBotBase
if (d != null)
{
this.SessionList.Remove(deviceId);
-
+
}
}
@@ -222,7 +222,14 @@ namespace TelegramBotBase
//Skip classes where IgnoreState attribute is existing
if (form.GetType().GetCustomAttributes(typeof(IgnoreState), true).Length != 0)
{
- continue;
+ if (statemachine.DefaultStateForm == null)
+ {
+ continue;
+ }
+
+ //Replace form by default State one.
+ se.FormUri = statemachine.DefaultStateForm.FullName;
+ se.QualifiedName = statemachine.DefaultStateForm.AssemblyQualifiedName;
}
//Is Subclass of IStateForm
diff --git a/TelegramBotBase/States/JSONStateMachine.cs b/TelegramBotBase/States/JSONStateMachine.cs
index fa6d3bf..1e46f36 100644
--- a/TelegramBotBase/States/JSONStateMachine.cs
+++ b/TelegramBotBase/States/JSONStateMachine.cs
@@ -5,6 +5,7 @@ using System.Runtime.Serialization.Formatters;
using System.Text;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
+using TelegramBotBase.Form;
using TelegramBotBase.Interfaces;
namespace TelegramBotBase.States
@@ -18,13 +19,28 @@ namespace TelegramBotBase.States
public bool Overwrite { get; set; }
- public JSONStateMachine(String file, bool overwrite = true)
+ public Type DefaultStateForm { get; private set; }
+
+ ///
+ /// Will initialize the state machine.
+ ///
+ /// Path of the file and name where to save the session details.
+ /// Type of Form which will be saved instead of Form which has attribute declared. Needs to be subclass of .
+ /// Declares of the file could be overwritten.
+ public JSONStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
{
if (file is null)
{
throw new ArgumentNullException(nameof(file));
}
+ this.DefaultStateForm = defaultStateForm ?? typeof(FormBase);
+
+ if (!this.DefaultStateForm.IsSubclassOf(typeof(FormBase)))
+ {
+ throw new ArgumentException("DefaultStateForm is not a subclass of FormBase");
+ }
+
this.FilePath = file;
this.Overwrite = overwrite;
}
diff --git a/TelegramBotBase/States/SimpleJSONStateMachine.cs b/TelegramBotBase/States/SimpleJSONStateMachine.cs
index ee685ac..d895d20 100644
--- a/TelegramBotBase/States/SimpleJSONStateMachine.cs
+++ b/TelegramBotBase/States/SimpleJSONStateMachine.cs
@@ -5,6 +5,7 @@ using System.Runtime.Serialization.Formatters;
using System.Text;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
+using TelegramBotBase.Form;
using TelegramBotBase.Interfaces;
namespace TelegramBotBase.States
@@ -18,13 +19,28 @@ namespace TelegramBotBase.States
public bool Overwrite { get; set; }
- public SimpleJSONStateMachine(String file, bool overwrite = true)
+ public Type DefaultStateForm { get; private set; }
+
+ ///
+ /// Will initialize the state machine.
+ ///
+ /// Path of the file and name where to save the session details.
+ /// Type of Form which will be saved instead of Form which has attribute declared. Needs to be subclass of .
+ /// Declares of the file could be overwritten.
+ public SimpleJSONStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
{
if (file is null)
{
throw new ArgumentNullException(nameof(file));
}
+ this.DefaultStateForm = defaultStateForm ?? typeof(FormBase);
+
+ if (!this.DefaultStateForm.IsSubclassOf(typeof(FormBase)))
+ {
+ throw new ArgumentException("DefaultStateForm is not a subclass of FormBase");
+ }
+
this.FilePath = file;
this.Overwrite = overwrite;
}
diff --git a/TelegramBotBase/States/XMLStateMachine.cs b/TelegramBotBase/States/XMLStateMachine.cs
index 0661579..ab5ca7a 100644
--- a/TelegramBotBase/States/XMLStateMachine.cs
+++ b/TelegramBotBase/States/XMLStateMachine.cs
@@ -7,6 +7,7 @@ using System.Xml;
using System.Xml.Serialization;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
+using TelegramBotBase.Form;
using TelegramBotBase.Interfaces;
namespace TelegramBotBase.States
@@ -17,13 +18,28 @@ namespace TelegramBotBase.States
public bool Overwrite { get; set; }
- public XMLStateMachine(String file, bool overwrite = true)
+ public Type DefaultStateForm { get; private set; }
+
+ ///
+ /// Will initialize the state machine.
+ ///
+ /// Path of the file and name where to save the session details.
+ /// Type of Form which will be saved instead of Form which has attribute declared. Needs to be subclass of .
+ /// Declares of the file could be overwritten.
+ public XMLStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
{
if (file is null)
{
throw new ArgumentNullException(nameof(file));
}
+ this.DefaultStateForm = defaultStateForm ?? typeof(FormBase);
+
+ if (!this.DefaultStateForm.IsSubclassOf(typeof(FormBase)))
+ {
+ throw new ArgumentException("DefaultStateForm is not a subclass of FormBase");
+ }
+
this.FilePath = file;
this.Overwrite = overwrite;
}