Exemplo n.º 1
0
        private async void Client_TryAction(object sender, MessageResult e)
        {
            DeviceSession ds = e.Device;

            if (ds == null)
            {
                ds = await this.Sessions.StartSession <T>(e.DeviceId);

                e.Device = ds;
            }

            ds.LastAction  = DateTime.Now;
            ds.LastMessage = e.Message;

            FormBase activeForm = null;

            int i = 0;

            //Should formulars get navigated (allow maximum of 10, to dont get loops)
            do
            {
                i++;

                //Reset navigation
                ds.FormSwitched = false;

                activeForm = ds.ActiveForm;

                //Pre Loading Event
                await activeForm.PreLoad(e);

                //Send Load event to controls
                await activeForm.LoadControls(e);

                //Loading Event
                await activeForm.Load(e);

                //Action Event
                if (!ds.FormSwitched)
                {
                    //Send Action event to controls
                    await activeForm.ActionControls(e);

                    //Send Action event to form itself
                    await activeForm.Action(e);

                    if (!e.Handled)
                    {
                        var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds);
                        OnUnhandledCall(uhc);

                        if (uhc.Handled)
                        {
                            e.Handled = true;
                            if (!ds.FormSwitched)
                            {
                                break;
                            }
                        }
                    }
                }

                //Render Event
                if (!ds.FormSwitched)
                {
                    await activeForm.RenderControls(e);

                    await activeForm.Render(e);
                }

                e.IsFirstHandler = false;
            } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10));
        }
Exemplo n.º 2
0
        //private async Task Client_TryMessage(object sender, MessageResult e)
        //{
        //    DeviceSession ds = e.Device;
        //    if (ds == null)
        //    {
        //        ds = await this.Sessions.StartSession<T>(e.DeviceId);
        //        e.Device = ds;

        //        ds.LastMessage = e.Message;

        //        OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
        //    }

        //    ds.LastAction = DateTime.Now;
        //    ds.LastMessage = e.Message;

        //    //Is this a bot command ?
        //    if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0)
        //    {
        //        var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds);
        //        await OnBotCommand(sce);

        //        if (sce.Handled)
        //            return;
        //    }

        //    FormBase activeForm = null;

        //    int i = 0;

        //    //Should formulars get navigated (allow maximum of 10, to dont get loops)
        //    do
        //    {
        //        i++;

        //        //Reset navigation
        //        ds.FormSwitched = false;

        //        activeForm = ds.ActiveForm;

        //        //Pre Loading Event
        //        await activeForm.PreLoad(e);

        //        //Send Load event to controls
        //        await activeForm.LoadControls(e);

        //        //Loading Event
        //        await activeForm.Load(e);

        //        //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document)
        //        if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Contact | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Location |
        //            e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Photo | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Video | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Audio)
        //        {
        //            await activeForm.SentData(new DataResult(e));
        //        }

        //        //Render Event
        //        if (!ds.FormSwitched)
        //        {
        //            await activeForm.RenderControls(e);

        //            await activeForm.Render(e);
        //        }

        //        e.IsFirstHandler = false;

        //    } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10));


        //}

        private async Task Client_Loop(object sender, MessageResult e)
        {
            DeviceSession ds = e.Device;

            if (ds == null)
            {
                ds = await this.Sessions.StartSession <T>(e.DeviceId);

                e.Device       = ds;
                ds.LastMessage = e.Message;

                OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
            }

            ds.LastAction  = DateTime.Now;
            ds.LastMessage = e.Message;

            //Is this a bot command ?
            if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0)
            {
                var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds);
                await OnBotCommand(sce);

                if (sce.Handled)
                {
                    return;
                }
            }

            FormBase activeForm = null;

            int i = 0;

            //Should formulars get navigated (allow maximum of 10, to dont get loops)
            do
            {
                i++;

                //Reset navigation
                ds.FormSwitched = false;

                activeForm = ds.ActiveForm;

                //Pre Loading Event
                await activeForm.PreLoad(e);

                //Send Load event to controls
                await activeForm.LoadControls(e);

                //Loading Event
                await activeForm.Load(e);

                //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document)
                if (e.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Location |
                    e.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio)
                {
                    await activeForm.SentData(new DataResult(e));
                }

                //Action Event
                if (!ds.FormSwitched && e.IsAction)
                {
                    //Send Action event to controls
                    await activeForm.ActionControls(e);

                    //Send Action event to form itself
                    await activeForm.Action(e);

                    if (!e.Handled)
                    {
                        var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds);
                        OnUnhandledCall(uhc);

                        if (uhc.Handled)
                        {
                            e.Handled = true;
                            if (!ds.FormSwitched)
                            {
                                break;
                            }
                        }
                    }
                }

                if (!ds.FormSwitched)
                {
                    //Render Event
                    await activeForm.RenderControls(e);

                    await activeForm.Render(e);
                }

                e.IsFirstHandler = false;
            } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10));
        }