Small fixes and clarifications

This commit is contained in:
FlorianDahn 2020-05-04 02:20:16 +02:00
parent 2fc16b18da
commit 07dec0dc9d
5 changed files with 23 additions and 22 deletions

View File

@ -9,7 +9,7 @@ namespace TelegramBotBase.Interfaces
{
public interface IStateMachine
{
Type DefaultStateForm { get; }
Type FallbackStateForm { get; }
void SaveFormStates(SaveStatesEventArgs e);

View File

@ -222,14 +222,15 @@ namespace TelegramBotBase
//Skip classes where IgnoreState attribute is existing
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;
}
//Replace form by default State one.
se.FormUri = statemachine.DefaultStateForm.FullName;
se.QualifiedName = statemachine.DefaultStateForm.AssemblyQualifiedName;
se.FormUri = statemachine.FallbackStateForm.FullName;
se.QualifiedName = statemachine.FallbackStateForm.AssemblyQualifiedName;
}
//Is Subclass of IStateForm

View File

@ -19,26 +19,26 @@ namespace TelegramBotBase.States
public bool Overwrite { get; set; }
public Type DefaultStateForm { get; private set; }
public Type FallbackStateForm { get; private set; }
/// <summary>
/// Will initialize the state machine.
/// </summary>
/// <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>
public JSONStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
public JSONStateMachine(String file, Type fallbackStateForm = null, bool overwrite = true)
{
if (file is null)
{
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;

View File

@ -19,26 +19,26 @@ namespace TelegramBotBase.States
public bool Overwrite { get; set; }
public Type DefaultStateForm { get; private set; }
public Type FallbackStateForm { get; private set; }
/// <summary>
/// Will initialize the state machine.
/// </summary>
/// <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>
public SimpleJSONStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
public SimpleJSONStateMachine(String file, Type fallbackStateForm = null, bool overwrite = true)
{
if (file is null)
{
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;

View File

@ -18,26 +18,26 @@ namespace TelegramBotBase.States
public bool Overwrite { get; set; }
public Type DefaultStateForm { get; private set; }
public Type FallbackStateForm { get; private set; }
/// <summary>
/// Will initialize the state machine.
/// </summary>
/// <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>
public XMLStateMachine(String file, Type defaultStateForm = null, bool overwrite = true)
public XMLStateMachine(String file, Type fallbackStateForm = null, bool overwrite = true)
{
if (file is null)
{
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;