Adding SaveSessionState to SessionBase
Feature request: https://github.com/MajMcCloud/TelegramBotFramework/issues/2
This commit is contained in:
parent
259fa54236
commit
c2e33da277
@ -33,7 +33,7 @@ namespace TelegramBotBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of all running/active sessions
|
/// List of all running/active sessions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SessionBase Sessions { get; set; }
|
public SessionBase<T> Sessions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
||||||
@ -79,7 +79,8 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
this.BotCommands = new List<BotCommand>();
|
this.BotCommands = new List<BotCommand>();
|
||||||
|
|
||||||
this.Sessions = new SessionBase();
|
this.Sessions = new SessionBase<T>();
|
||||||
|
this.Sessions.BotBase = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -193,10 +194,7 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
this.Client.TelegramClient.StopReceiving();
|
this.Client.TelegramClient.StopReceiving();
|
||||||
|
|
||||||
if (this.StateMachine != null)
|
this.Sessions.SaveSessionStates();
|
||||||
{
|
|
||||||
this.Sessions.SaveSessionStates(this.StateMachine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -16,12 +16,15 @@ namespace TelegramBotBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for managing all active sessions
|
/// Base class for managing all active sessions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SessionBase
|
public class SessionBase<T>
|
||||||
|
where T : FormBase
|
||||||
{
|
{
|
||||||
public MessageClient Client { get; set; }
|
public MessageClient Client { get; set; }
|
||||||
|
|
||||||
public Dictionary<long, DeviceSession> SessionList { get; set; }
|
public Dictionary<long, DeviceSession> SessionList { get; set; }
|
||||||
|
|
||||||
|
public BotBase<T> BotBase { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public SessionBase()
|
public SessionBase()
|
||||||
{
|
{
|
||||||
@ -295,5 +298,17 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
statemachine.SaveFormStates(new SaveStatesEventArgs(sc));
|
statemachine.SaveFormStates(new SaveStatesEventArgs(sc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves all open states into the machine.
|
||||||
|
/// </summary>
|
||||||
|
public void SaveSessionStates()
|
||||||
|
{
|
||||||
|
if (this.BotBase.StateMachine == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
this.SaveSessionStates(this.BotBase.StateMachine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user