Small fixes and clarifications
This commit is contained in:
parent
2fc16b18da
commit
07dec0dc9d
@ -9,7 +9,7 @@ namespace TelegramBotBase.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IStateMachine
|
public interface IStateMachine
|
||||||
{
|
{
|
||||||
Type DefaultStateForm { get; }
|
Type FallbackStateForm { get; }
|
||||||
|
|
||||||
void SaveFormStates(SaveStatesEventArgs e);
|
void SaveFormStates(SaveStatesEventArgs e);
|
||||||
|
|
||||||
|
|||||||
@ -222,14 +222,15 @@ namespace TelegramBotBase
|
|||||||
//Skip classes where IgnoreState attribute is existing
|
//Skip classes where IgnoreState attribute is existing
|
||||||
if (form.GetType().GetCustomAttributes(typeof(IgnoreState), true).Length != 0)
|
if (form.GetType().GetCustomAttributes(typeof(IgnoreState), true).Length != 0)
|
||||||
{
|
{
|
||||||
if (statemachine.DefaultStateForm == null)
|
//Skip this form, when there is no fallback state form
|
||||||
|
if (statemachine.FallbackStateForm == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Replace form by default State one.
|
//Replace form by default State one.
|
||||||
se.FormUri = statemachine.DefaultStateForm.FullName;
|
se.FormUri = statemachine.FallbackStateForm.FullName;
|
||||||
se.QualifiedName = statemachine.DefaultStateForm.AssemblyQualifiedName;
|
se.QualifiedName = statemachine.FallbackStateForm.AssemblyQualifiedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Is Subclass of IStateForm
|
//Is Subclass of IStateForm
|
||||||
|
|||||||
@ -19,26 +19,26 @@ namespace TelegramBotBase.States
|
|||||||
|
|
||||||
public bool Overwrite { get; set; }
|
public bool Overwrite { get; set; }
|
||||||
|
|
||||||
public Type DefaultStateForm { get; private set; }
|
public Type FallbackStateForm { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will initialize the state machine.
|
/// Will initialize the state machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file">Path of the file and name where to save the session details.</param>
|
/// <param name="file">Path of the file and name where to save the session details.</param>
|
||||||
/// <param name="defaultStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
/// <param name="fallbackStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
||||||
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
||||||
public JSONStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
|
public JSONStateMachine(String file, Type fallbackStateForm = null, bool overwrite = true)
|
||||||
{
|
{
|
||||||
if (file is null)
|
if (file is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(file));
|
throw new ArgumentNullException(nameof(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.DefaultStateForm = defaultStateForm ?? typeof(FormBase);
|
this.FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
if (!this.DefaultStateForm.IsSubclassOf(typeof(FormBase)))
|
if (!this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("DefaultStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.FilePath = file;
|
this.FilePath = file;
|
||||||
|
|||||||
@ -19,26 +19,26 @@ namespace TelegramBotBase.States
|
|||||||
|
|
||||||
public bool Overwrite { get; set; }
|
public bool Overwrite { get; set; }
|
||||||
|
|
||||||
public Type DefaultStateForm { get; private set; }
|
public Type FallbackStateForm { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will initialize the state machine.
|
/// Will initialize the state machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file">Path of the file and name where to save the session details.</param>
|
/// <param name="file">Path of the file and name where to save the session details.</param>
|
||||||
/// <param name="defaultStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
/// <param name="fallbackStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
||||||
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
||||||
public SimpleJSONStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
|
public SimpleJSONStateMachine(String file, Type fallbackStateForm = null, bool overwrite = true)
|
||||||
{
|
{
|
||||||
if (file is null)
|
if (file is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(file));
|
throw new ArgumentNullException(nameof(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.DefaultStateForm = defaultStateForm ?? typeof(FormBase);
|
this.FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
if (!this.DefaultStateForm.IsSubclassOf(typeof(FormBase)))
|
if (!this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("DefaultStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.FilePath = file;
|
this.FilePath = file;
|
||||||
|
|||||||
@ -18,26 +18,26 @@ namespace TelegramBotBase.States
|
|||||||
|
|
||||||
public bool Overwrite { get; set; }
|
public bool Overwrite { get; set; }
|
||||||
|
|
||||||
public Type DefaultStateForm { get; private set; }
|
public Type FallbackStateForm { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will initialize the state machine.
|
/// Will initialize the state machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file">Path of the file and name where to save the session details.</param>
|
/// <param name="file">Path of the file and name where to save the session details.</param>
|
||||||
/// <param name="defaultStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
/// <param name="fallbackStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
||||||
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
||||||
public XMLStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
|
public XMLStateMachine(String file, Type fallbackStateForm = null, bool overwrite = true)
|
||||||
{
|
{
|
||||||
if (file is null)
|
if (file is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(file));
|
throw new ArgumentNullException(nameof(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.DefaultStateForm = defaultStateForm ?? typeof(FormBase);
|
this.FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
if (!this.DefaultStateForm.IsSubclassOf(typeof(FormBase)))
|
if (!this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("DefaultStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.FilePath = file;
|
this.FilePath = file;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user