fix: reformat using C# rules
This commit is contained in:
@@ -6,87 +6,87 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.States
|
||||
namespace TelegramBotBase.States;
|
||||
|
||||
/// <summary>
|
||||
/// Is used for all complex data types. Use if other default machines are not working.
|
||||
/// </summary>
|
||||
public class JsonStateMachine : IStateMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Is used for all complex data types. Use if other default machines are not working.
|
||||
/// Will initialize the state machine.
|
||||
/// </summary>
|
||||
public class JsonStateMachine : IStateMachine
|
||||
/// <param name="file">Path of the file and name where to save the session details.</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 fallbackStateForm = null, bool overwrite = true)
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
FallbackStateForm = fallbackStateForm;
|
||||
|
||||
public bool Overwrite { get; 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="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 fallbackStateForm = null, bool overwrite = true)
|
||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
FallbackStateForm = fallbackStateForm;
|
||||
|
||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
|
||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Overwrite = overwrite;
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Overwrite = overwrite;
|
||||
}
|
||||
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public bool Overwrite { get; set; }
|
||||
|
||||
public Type FallbackStateForm { get; }
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
var content = File.ReadAllText(FilePath);
|
||||
|
||||
var sc = JsonConvert.DeserializeObject<StateContainer>(content, new JsonSerializerSettings
|
||||
{
|
||||
var content = File.ReadAllText(FilePath);
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
||||
});
|
||||
|
||||
var sc = JsonConvert.DeserializeObject<StateContainer>(content, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
||||
});
|
||||
|
||||
return sc;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new StateContainer();
|
||||
return sc;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
return new StateContainer();
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
if (!Overwrite)
|
||||
{
|
||||
if (!Overwrite)
|
||||
{
|
||||
throw new Exception("File exists already.");
|
||||
}
|
||||
|
||||
File.Delete(FilePath);
|
||||
throw new Exception("File exists already.");
|
||||
}
|
||||
|
||||
try
|
||||
File.Delete(FilePath);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
||||
});
|
||||
|
||||
File.WriteAllText(FilePath, content);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
||||
});
|
||||
|
||||
File.WriteAllText(FilePath, content);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,79 +6,80 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.States
|
||||
namespace TelegramBotBase.States;
|
||||
|
||||
/// <summary>
|
||||
/// Is used for simple object structures like classes, lists or basic datatypes without generics and other compiler
|
||||
/// based data types.
|
||||
/// </summary>
|
||||
public class SimpleJsonStateMachine : IStateMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Is used for simple object structures like classes, lists or basic datatypes without generics and other compiler based data types.
|
||||
/// Will initialize the state machine.
|
||||
/// </summary>
|
||||
public class SimpleJsonStateMachine : IStateMachine
|
||||
/// <param name="file">Path of the file and name where to save the session details.</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 fallbackStateForm = null, bool overwrite = true)
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
FallbackStateForm = fallbackStateForm;
|
||||
|
||||
public bool Overwrite { get; 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="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 fallbackStateForm = null, bool overwrite = true)
|
||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
FallbackStateForm = fallbackStateForm;
|
||||
|
||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
|
||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Overwrite = overwrite;
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Overwrite = overwrite;
|
||||
}
|
||||
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public bool Overwrite { get; set; }
|
||||
|
||||
public Type FallbackStateForm { get; }
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var content = File.ReadAllText(FilePath);
|
||||
var content = File.ReadAllText(FilePath);
|
||||
|
||||
var sc = JsonConvert.DeserializeObject<StateContainer>(content);
|
||||
var sc = JsonConvert.DeserializeObject<StateContainer>(content);
|
||||
|
||||
return sc;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new StateContainer();
|
||||
return sc;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
return new StateContainer();
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
if (!Overwrite)
|
||||
{
|
||||
if (!Overwrite)
|
||||
{
|
||||
throw new Exception("File exists already.");
|
||||
}
|
||||
|
||||
File.Delete(FilePath);
|
||||
throw new Exception("File exists already.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented);
|
||||
File.Delete(FilePath);
|
||||
}
|
||||
|
||||
File.WriteAllText(FilePath, content);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented);
|
||||
|
||||
File.WriteAllText(FilePath, content);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,90 +7,89 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.States
|
||||
namespace TelegramBotBase.States;
|
||||
|
||||
public class XmlStateMachine : IStateMachine
|
||||
{
|
||||
public class XmlStateMachine : IStateMachine
|
||||
/// <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="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 fallbackStateForm = null, bool overwrite = true)
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
FallbackStateForm = fallbackStateForm;
|
||||
|
||||
public bool Overwrite { get; 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="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 fallbackStateForm = null, bool overwrite = true)
|
||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
FallbackStateForm = fallbackStateForm;
|
||||
|
||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
|
||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Overwrite = overwrite;
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
{
|
||||
try
|
||||
{
|
||||
var serializer = new DataContractSerializer(typeof(StateContainer));
|
||||
|
||||
using (var reader = new StreamReader(FilePath))
|
||||
{
|
||||
using (var xml = new XmlTextReader(reader))
|
||||
{
|
||||
var sc = serializer.ReadObject(xml) as StateContainer;
|
||||
return sc;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new StateContainer();
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
if (!Overwrite)
|
||||
{
|
||||
throw new Exception("File exists already.");
|
||||
}
|
||||
|
||||
File.Delete(FilePath);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var serializer = new DataContractSerializer(typeof(StateContainer));
|
||||
|
||||
using (var sw = new StreamWriter(FilePath))
|
||||
{
|
||||
using (var writer = new XmlTextWriter(sw))
|
||||
{
|
||||
writer.Formatting = Formatting.Indented; // indent the Xml so it’s human readable
|
||||
serializer.WriteObject(writer, e.States);
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Overwrite = overwrite;
|
||||
}
|
||||
|
||||
}
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public bool Overwrite { get; set; }
|
||||
|
||||
public Type FallbackStateForm { get; }
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
{
|
||||
try
|
||||
{
|
||||
var serializer = new DataContractSerializer(typeof(StateContainer));
|
||||
|
||||
using (var reader = new StreamReader(FilePath))
|
||||
{
|
||||
using (var xml = new XmlTextReader(reader))
|
||||
{
|
||||
var sc = serializer.ReadObject(xml) as StateContainer;
|
||||
return sc;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return new StateContainer();
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
if (!Overwrite)
|
||||
{
|
||||
throw new Exception("File exists already.");
|
||||
}
|
||||
|
||||
File.Delete(FilePath);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var serializer = new DataContractSerializer(typeof(StateContainer));
|
||||
|
||||
using (var sw = new StreamWriter(FilePath))
|
||||
{
|
||||
using (var writer = new XmlTextWriter(sw))
|
||||
{
|
||||
writer.Formatting = Formatting.Indented; // indent the Xml so it’s human readable
|
||||
serializer.WriteObject(writer, e.States);
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user