예제 #1
0
        //TODO: сделать init
        //public static T Create<T>() where T : BaseStateMachine
        //{
        //	var messageSender = ExpressBotService.Configuration.ServiceProvider.GetService<BotMessageSender>();
        //	var
        //}

        /// <summary>
        /// Загружает конечный автомат из ранее сериализованного в json состояния
        /// </summary>
        /// <param name="value">JSON-строка</param>
        /// <param name="messageSender">Отправщик сообщений Express</param>
        /// <returns></returns>
        public T FromJson <T>(string value, IBotMessageSender messageSender, UserMessage userMessage) where T : BaseStateMachine
        {
            var restoredObject = JsonConvert.DeserializeObject(value, serializerSettings);

            if (!(restoredObject is T restoredSm))
            {
                return(null);
            }

            using var scope = ScopeFactory.CreateScope();
            var diSm = scope.ServiceProvider.GetService <T>();

            if (diSm != null)
            {
                diSm.firstStep          = restoredSm.firstStep;
                diSm.isFinished         = restoredSm.isFinished;
                diSm.MessageSender      = messageSender;
                diSm.Model              = restoredSm.Model;
                diSm.state              = restoredSm.state;
                diSm.state.StateMachine = diSm;
                diSm.UserMessage        = userMessage;
                return(diSm);
            }

            restoredSm.MessageSender = messageSender;
            restoredSm.UserMessage   = userMessage;
            return(restoredSm);
        }
예제 #2
0
 public async Task InvokeAsync(UserMessage message, IBotMessageSender sender)
 {
     if (message.Command.Body.ToLower() == "hello")
     {
         await sender.ReplyTextMessageAsync(message, "hi!");
     }
     else
     {
         await next(message);
     }
 }
예제 #3
0
 /// <summary>
 /// Создаёт конечный автомат с начальным состоянием, указанным в качестве аргументоа
 /// </summary>
 /// <param name="messageSender">Отправщик сообщений Express</param>
 protected BaseStateMachine(IBotMessageSender messageSender, IServiceScopeFactory scopeFactory)
 {
     MessageSender = messageSender;
     ScopeFactory  = scopeFactory;
 }
 public ChatMessageAction(IBotMessageSender messageSender) : base(messageSender)
 {
 }
예제 #5
0
 public HelpAction(IBotMessageSender messageSender) : base(messageSender)
 {
 }
예제 #6
0
 public StartAction(IBotMessageSender messageSender, DemoStateMachine stateMachine) : base(messageSender)
 {
     this.stateMachine = stateMachine;
 }
예제 #7
0
 public SayHelloAction(IBotMessageSender messageSender) : base(messageSender)
 {
 }
예제 #8
0
 public SayDateAction(IBotMessageSender messageSender) : base(messageSender)
 {
 }
예제 #9
0
 public DemoStateMachine(IBotMessageSender messageSender, IServiceScopeFactory scopeFactory) : base(messageSender, scopeFactory)
 {
 }
예제 #10
0
#pragma warning disable CS1591
        public BotAction(IBotMessageSender messageSender)
#pragma warning restore CS1591
        {
            MessageSender = messageSender;
        }