Adding simplified versions for BotBaseBuilder serialization options.

This commit is contained in:
Florian Zevedei 2023-09-12 14:40:12 +02:00
parent d34df46087
commit 98eba1c5f9
2 changed files with 66 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using Telegram.Bot;
using Telegram.Bot.Types;
@ -314,19 +315,63 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
return this;
}
/// <summary>
/// Uses the application runtime path to load and write a states.json file.
/// </summary>
/// <returns></returns>
public ILanguageSelectionStage UseJSON()
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "states.json");
_stateMachine = new JsonStateMachine(path);
return this;
}
/// <summary>
/// Uses the given path to load and write a states.json file.
/// </summary>
/// <returns></returns>
public ILanguageSelectionStage UseJSON(string path)
{
_stateMachine = new JsonStateMachine(path);
return this;
}
/// <summary>
/// Uses the application runtime path to load and write a states.json file.
/// </summary>
/// <returns></returns>
public ILanguageSelectionStage UseSimpleJSON()
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "states.json");
_stateMachine = new SimpleJsonStateMachine(path);
return this;
}
/// <summary>
/// Uses the given path to load and write a states.json file.
/// </summary>
/// <returns></returns>
public ILanguageSelectionStage UseSimpleJSON(string path)
{
_stateMachine = new SimpleJsonStateMachine(path);
return this;
}
/// <summary>
/// Uses the application runtime path to load and write a states.xml file.
/// </summary>
/// <returns></returns>
public ILanguageSelectionStage UseXML()
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "states.xml");
_stateMachine = new XmlStateMachine(path);
return this;
}
/// <summary>
/// Uses the given path to load and write a states.xml file.
/// </summary>
/// <returns></returns>
public ILanguageSelectionStage UseXML(string path)
{
_stateMachine = new XmlStateMachine(path);

View File

@ -18,6 +18,13 @@ public interface ISessionSerializationStage
/// <returns></returns>
ILanguageSelectionStage UseSerialization(IStateMachine machine);
/// <summary>
/// Using the complex version of .Net JSON, which can serialize all objects.
/// Saves in application directory.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
ILanguageSelectionStage UseJSON();
/// <summary>
/// Using the complex version of .Net JSON, which can serialize all objects.
@ -26,6 +33,13 @@ public interface ISessionSerializationStage
/// <returns></returns>
ILanguageSelectionStage UseJSON(string path);
/// <summary>
/// Use the easy version of .Net JSON, which can serialize basic types, but not generics and others.
/// Saves in application directory.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
ILanguageSelectionStage UseSimpleJSON();
/// <summary>
/// Use the easy version of .Net JSON, which can serialize basic types, but not generics and others.
@ -34,6 +48,13 @@ public interface ISessionSerializationStage
/// <returns></returns>
ILanguageSelectionStage UseSimpleJSON(string path);
/// <summary>
/// Uses the XML serializer for session serialization.
/// Saves in application directory.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
ILanguageSelectionStage UseXML();
/// <summary>
/// Uses the XML serializer for session serialization.