示例#1
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData> ();

            await message.ConfirmAction();

            if (call == null)
            {
                return;
            }

            message.Handled = true;

            switch (call.Value)
            {
            case "AccListForm":
                var alf = new AccListForm();
                await this.NavigateTo(alf);

                break;

            default:
                message.Handled = false;
                break;
            }
        }
示例#2
0
        public override async Task Action(MessageResult message)
        {
            if (message.GetData <CallbackData>() is CallbackData call)
            {
                if (call.Method == "nav" && call.Value == "back")
                {
                    await NavigateTo(new MenuForm());
                }
                else if (call.Method == "assign-user")
                {
                    var deviceId = long.Parse(call.Value);
                    var task     = await db.Tasks.FindAsync(editTaskId);

                    task.ResponsibleDeviceId = deviceId;
                    db.Tasks.Update(task);
                    await db.SaveChangesAsync();

                    if (parentForm == null)
                    {
                        await NavigateTo(DI.Resolve(new MenuForm()));
                    }
                    else
                    {
                        await NavigateTo(DI.Resolve(parentForm));
                    }
                }
            }
        }
示例#3
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData> ();

            await message.ConfirmAction();

            if (call == null)
            {
                return;
            }

            message.Handled = true;

            var api = await ModelScoutAPI.ModelScoutAPIPooler.GetOrCreateApi(message.DeviceId);

            switch (call.Method)
            {
            case "GoToCfgAccForm":
                var caf = new CfgAccForm(Convert.ToInt64(call.Value));
                await this.NavigateTo(caf);

                break;

            case "GoToAddAccForm":
                PromptDialog pd = new PromptDialog(
                    "Введите токен аккаунта\n" +
                    "(Можно получить тут https://vkhost.github.io/)");

                pd.Closed += async(s, en) => {
                    ModelScoutAPI.Models.VkAcc vkAcc;
                    vkAcc = await api.CreateVkAcc(pd.Value);

                    if (vkAcc == null)
                    {
                        this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                        await this.Device.Send("Аккаунт не был добавлен. Проверьте токен");
                    }
                    else
                    {
                        this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                        await this.Device.Send($"Был добавлен аккаунт {vkAcc.FirstName} {vkAcc.LastName}");
                    }
                };

                await this.OpenModal(pd);

                break;

            case "GoToStartForm":
                var alf = new StartForm();
                await this.NavigateTo(alf);

                break;

            default:
                message.Handled = false;
                break;
            }
        }
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            await message.ConfirmAction();


            if (call == null)
            {
                return;
            }

            message.Handled = true;

            switch (call.Value)
            {
            case "button1":

                await this.Device.Send("Button 1 pressed");

                break;

            case "button2":

                await this.Device.Send("Button 2 pressed");

                break;

            case "button3":

                await this.Device.Send("Button 3 pressed");

                break;

            case "button4":

                await this.Device.Send("Button 4 pressed");

                break;

            case "back":

                var st = new Menu();

                await this.NavigateTo(st);

                break;

            default:

                message.Handled = false;

                break;
            }
        }
示例#5
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            await message.ConfirmAction();

            await message.DeleteMessage();

            message.Handled = true;

            if (call.Value == "testform1")
            {
                var tf = new TestForm();

                await this.NavigateTo(tf);
            }
            else if (call.Value == "alert")
            {
                AlertDialog ad = new AlertDialog("This is a message", "Ok");

                ad.ButtonClicked += async(s, en) =>
                {
                    var fto = new TestForm2();
                    await this.NavigateTo(fto);
                };

                await this.NavigateTo(ad);
            }
            else if (call.Value == "confirm")
            {
                ConfirmDialog pd = new ConfirmDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel"));

                pd.ButtonClicked += async(s, en) =>
                {
                    var tf = new TestForm2();

                    await pd.NavigateTo(tf);
                };

                await this.NavigateTo(pd);
            }
            else if (call.Value == "prompt")
            {
                PromptDialog pd = new PromptDialog("Please tell me your name ?");

                pd.Completed += async(s, en) =>
                {
                    await this.Device.Send("Hello " + pd.Value);
                };

                await this.OpenModal(pd);
            }
        }
示例#6
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData> ();

            await message.ConfirmAction();

            if (call == null)
            {
                return;
            }

            message.Handled = true;
            var api = await ModelScoutAPI.ModelScoutAPIPooler.GetOrCreateApi(message.DeviceId);

            int id;

            switch (call.Method)
            {
            case "AcceptClient":
                if (Int32.TryParse(call.Value, out id))
                {
                    await api.SetClientAccepted(id);
                }
                break;

            case "DeclineClient":
                if (Int32.TryParse(call.Value, out id))
                {
                    await api.SetClientDeclined(id);
                }
                break;

            case "NextSample":
                message.Handled = false;
                break;

            case "GoToStartForm":
                var sf = new StartForm();
                await this.NavigateTo(sf);

                break;

            default:
                message.Handled = false;
                break;
            }
        }
示例#7
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();
            await message.ConfirmAction();

            if (call.Method == "nav" && call.Value == "create")
            {
                await NavigateTo(new TaskCreationForm());
            }
            else if (call.Method == "nav" && call.Value == "list-assigned")
            {
                await NavigateTo(new TaskListForm(TaskListForm.DisplayMode.Assigned));
            }
            else if (call.Method == "nav" && call.Value == "list-created")
            {
                await NavigateTo(new TaskListForm(TaskListForm.DisplayMode.Created));
            }
        }
        public override async Task Action(MessageResult message)
        {
            if (message.Handled)
            {
                return;
            }

            if (!message.IsFirstHandler)
            {
                return;
            }

            var call = message.GetData <CallbackData>();

            if (call == null)
            {
                return;
            }

            message.Handled = true;

            await message.ConfirmAction();

            await message.DeleteMessage();

            ButtonBase button = this.Buttons.FirstOrDefault(a => a.Value == call.Value);

            if (button == null)
            {
                return;
            }

            OnButtonClicked(new ButtonClickedEventArgs(button)
            {
                Tag = this.Tag
            });

            if (AutoCloseOnClick)
            {
                await CloseForm();
            }
        }
示例#9
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            message.Handled = true;

            if (!message.IsAction)
            {
                return;
            }

            await message.ConfirmAction();

            await message.DeleteMessage();

            var buttons = this.Buttons.Aggregate((a, b) => a.Union(b).ToArray()).ToList();

            if (call == null)
            {
                return;
            }

            ButtonBase button = buttons.FirstOrDefault(a => a.Value == call.Value);

            if (button == null)
            {
                return;
            }

            OnButtonClicked(new ButtonClickedEventArgs(button)
            {
                Tag = this.Tag
            });

            FormBase fb = ButtonForms.ContainsKey(call.Value) ? ButtonForms[call.Value] : null;

            if (fb != null)
            {
                await this.NavigateTo(fb);
            }
        }
示例#10
0
        public async override Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            await message.ConfirmAction();


            if (call == null)
            {
                return;
            }

            switch (call.Value)
            {
            case "form":

                var form = new PerForm();

                await this.NavigateTo(form);

                break;

            case "step":

                var step = new PerStep();

                await this.NavigateTo(step);

                break;

            case "backtodashboard":

                var start = new Tests.Menu();

                await this.NavigateTo(start);

                break;
            }
        }
示例#11
0
        public async override Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            await message.ConfirmAction();

            if (call == null)
            {
                return;
            }

            switch (call.Value)
            {
            case "back":

                var start = new Start();

                await this.NavigateTo(start);

                break;
            }
        }
示例#12
0
        public override async Task Action(MessageResult message)
        {
            await base.Load(message);

            if (message.GetData <CallbackData>() is CallbackData call)
            {
                if (call.Method == "normal")
                {
                    Completed(Models.Priority.Medium);
                    await this.CloseForm();
                }
                else if (call.Method == "important")
                {
                    Completed(Models.Priority.High);
                    await this.CloseForm();
                }
                else if (call.Method == "unimportant")
                {
                    Completed(Models.Priority.Low);
                    await this.CloseForm();
                }
            }
        }
示例#13
0
        public override async Task Action(MessageResult message)
        {
            if (message.GetData <CallbackData>() is CallbackData call)
            {
                if (call.Method == "nav" && call.Value == "back")
                {
                    await NavigateTo(new MenuForm());
                }
                else if (call.Method == "edit")
                {
                    var editTaskId = Guid.Parse(call.Value);
                    await NavigateTo(DI.Resolve(new TaskEditForm(editTaskId)));
                }
                else if (call.Method == "delete")
                {
                    var deleteTaskId = Guid.Parse(call.Value);
                    var task         = await db.Tasks.FindAsync(deleteTaskId);

                    db.Tasks.Remove(task);
                    await db.SaveChangesAsync();
                }
                else if (call.Method == "accept")
                {
                    /*var deleteTaskId = Guid.Parse(call.Value);
                     * var task = await db.Tasks.FindAsync(deleteTaskId);
                     * db.Tasks.Remove(task);
                     * await db.SaveChangesAsync();*/
                }
                else if (call.Method == "reject")
                {
                    /*var deleteTaskId = Guid.Parse(call.Value);
                     * var task = await db.Tasks.FindAsync(deleteTaskId);
                     * db.Tasks.Remove(task);
                     * await db.SaveChangesAsync();*/
                }
            }
        }
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            if (call == null)
            {
                return;
            }

            message.Handled = true;

            await message.ConfirmAction();

            await message.DeleteMessage();

            ButtonBase button = this.Buttons.FirstOrDefault(a => a.Value == call.Value);

            if (button == null)
            {
                return;
            }

            OnButtonClicked(new ButtonClickedEventArgs(button));
        }
示例#15
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData> ();

            await message.ConfirmAction();

            if (call == null)
            {
                return;
            }

            message.Handled = true;
            var api = await ModelScoutAPI.ModelScoutAPIPooler.GetOrCreateApi(message.DeviceId);

            switch (call.Method)
            {
            case "RemoveVkAcc":
                var vkAcc = await api.GetVkAcc(this._vkAccId);

                ConfirmDialog pd = new ConfirmDialog(
                    $"Подтвердите удаление аккаунта {vkAcc.FirstName} {vkAcc.LastName}",
                    new ButtonBase("Да, удалить", "ok"),
                    new ButtonBase("Нет, я случайно нажала", "cancel"));

                Boolean Confirmed = false;
                pd.ButtonClicked += (s, en) => {
                    if (en.Button.Value == "ok")
                    {
                        Confirmed = true;
                    }
                    else if (en.Button.Value == "cancel")
                    {
                        Confirmed = false;
                    }
                };
                pd.Closed += async(s, en) => {
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Confirmed)
                    {
                        await api.RemoveVkAcc(vkAcc);

                        await pd.Device.Send("Аккаунт был удален.");

                        var alf = new AccListForm();
                        await this.NavigateTo(alf);
                    }
                    else
                    {
                        await pd.Device.Send("Аккаунт не был удален.");
                    }
                };

                await this.OpenModal(pd);

                break;

            case "GoToChangeCfgAccForm":
                var ccaf = new ChangeCfgAccForm(_vkAccId);
                await this.NavigateTo(ccaf);

                break;

            case "GoToAccListForm":
                var alf = new AccListForm();
                await this.NavigateTo(alf);

                break;

            default:
                message.Handled = false;
                break;
            }
        }
示例#16
0
        public override async Task Load(MessageResult message)
        {
            await base.Load(message);

            var task = await db.Tasks.FirstAsync(x => x.Id == editTaskId);

            switch (currentState)
            {
            case EditState.Watch:
                if (message.GetData <CallbackData>() is CallbackData call)
                {
                    if (call.Method == "back")
                    {
                        await NavigateTo(new MenuForm());
                    }
                    else if (call.Method == "edit-title")
                    {
                        currentState = EditState.Title;
                    }
                    else if (call.Method == "edit-description")
                    {
                        currentState = EditState.Description;
                    }
                    else if (call.Method == "responsible")
                    {
                        currentState = EditState.Responsible;
                    }
                    else if (call.Method == "deadline")
                    {
                        var deadlineSelection = new DateSelectionDialog();
                        deadlineSelection.Completed += date => {
                            task.Deadline = date;
                            db.Tasks.Update(task);
                            db.SaveChanges();
                        };
                        await OpenModal(deadlineSelection);
                    }
                    else if (call.Method == "priority")
                    {
                        var prioritySelection = new SelectPriorityDialog();
                        prioritySelection.Completed += priority => {
                            task.Priority = priority;
                            db.Tasks.Update(task);
                            db.SaveChanges();
                        };
                        await OpenModal(prioritySelection);
                    }
                }
                return;

            case EditState.Title:
                var newTitle = message.MessageText;
                task.Title = newTitle;
                db.Tasks.Update(task);
                await db.SaveChangesAsync();

                currentState = EditState.Watch;
                return;

            case EditState.Description:
                var newDescription = message.MessageText;
                task.Description = newDescription;
                db.Tasks.Update(task);
                await db.SaveChangesAsync();

                currentState = EditState.Watch;
                return;

            case EditState.Deadline:
                currentState = EditState.Watch;
                return;

            case EditState.Priority:
                currentState = EditState.Watch;
                return;

            default:
                return;
            }
        }
示例#17
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            await message.ConfirmAction();


            if (call == null)
            {
                return;
            }

            switch (call.Value)
            {
            case "text":

                var sf = new SimpleForm();

                await this.NavigateTo(sf);

                break;

            case "buttons":

                var bf = new ButtonTestForm();

                await this.NavigateTo(bf);

                break;

            case "progress":

                var pf = new ProgressTest();

                await this.NavigateTo(pf);

                break;

            case "registration":

                var reg = new Register.Start();

                await this.NavigateTo(reg);

                break;

            case "form1":

                var form1 = new TestForm();

                await this.NavigateTo(form1);

                break;

            case "form2":

                var form2 = new TestForm2();

                await this.NavigateTo(form2);

                break;

            case "data":

                message.Handled = true;

                var data = new DataForm();

                await this.NavigateTo(data);

                break;

            case "calendar":

                message.Handled = true;

                var calendar = new Controls.CalendarPickerForm();

                await this.NavigateTo(calendar);

                break;

            case "month":

                message.Handled = true;

                var month = new Controls.MonthPickerForm();

                await this.NavigateTo(month);

                break;

            case "treeview":

                message.Handled = true;

                var tree = new Controls.TreeViewForms();

                await this.NavigateTo(tree);

                break;

            case "togglebuttons":

                message.Handled = true;

                var tb = new Controls.ToggleButtons();

                await this.NavigateTo(tb);

                break;

            case "buttongrid":

                message.Handled = true;

                var bg = new Controls.ButtonGridForm();

                await this.NavigateTo(bg);

                break;

            case "buttongridfilter":

                message.Handled = true;

                var bg2 = new Controls.ButtonGridPagingForm();

                await this.NavigateTo(bg2);

                break;

            case "buttongridtags":

                message.Handled = true;

                var bg3 = new Controls.ButtonGridTagForm();

                await this.NavigateTo(bg3);

                break;

            case "multiview":

                message.Handled = true;

                var mvf = new MultiViewForm();

                await NavigateTo(mvf);


                break;

            case "checkedbuttonlist":

                message.Handled = true;

                var cbl = new CheckedButtonListForm();

                await NavigateTo(cbl);


                break;
            }
        }
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData>();

            await message.ConfirmAction();


            if (call == null)
            {
                return;
            }

            TelegramBotBase.Controls.ProgressBar Bar = null;

            switch (call.Value)
            {
            case "standard":

                Bar        = new TelegramBotBase.Controls.ProgressBar(0, 100, TelegramBotBase.Controls.ProgressBar.eProgressStyle.standard);
                Bar.Device = this.Device;

                break;

            case "squares":

                Bar        = new TelegramBotBase.Controls.ProgressBar(0, 100, TelegramBotBase.Controls.ProgressBar.eProgressStyle.squares);
                Bar.Device = this.Device;

                break;

            case "circles":

                Bar        = new TelegramBotBase.Controls.ProgressBar(0, 100, TelegramBotBase.Controls.ProgressBar.eProgressStyle.circles);
                Bar.Device = this.Device;

                break;

            case "lines":

                Bar        = new TelegramBotBase.Controls.ProgressBar(0, 100, TelegramBotBase.Controls.ProgressBar.eProgressStyle.lines);
                Bar.Device = this.Device;

                break;

            case "squaredlines":

                Bar        = new TelegramBotBase.Controls.ProgressBar(0, 100, TelegramBotBase.Controls.ProgressBar.eProgressStyle.squaredLines);
                Bar.Device = this.Device;

                break;

            case "start":

                var sf = new Menu();

                await this.NavigateTo(sf);

                return;

            default:

                return;
            }


            //Render Progress bar and show some "example" progress
            await Bar.Render(message);

            this.Controls.Add(Bar);

            for (int i = 0; i <= 100; i++)
            {
                Bar.Value++;
                await Bar.Render(message);

                Thread.Sleep(250);
            }
        }
示例#19
0
        public override async Task Action(MessageResult message)
        {
            var call = message.GetData <CallbackData> ();

            await message.ConfirmAction();

            if (call == null)
            {
                return;
            }

            var api = await ModelScoutAPI.ModelScoutAPIPooler.GetOrCreateApi(message.DeviceId);

            var vkAcc = await api.GetVkAcc(_vkAccId);

            message.Handled = true;

            PromptDialog pd;

            switch (call.Method)
            {
            case "ChangeCity":
                pd         = new PromptDialog("Введите id города:");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0)
                    {
                        vkAcc.City = result;
                        await this.Device.Send("Город изменен");

                        await api.SaveVkAcc(vkAcc);

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeCountry":
                pd         = new PromptDialog("Введите id страны:");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0)
                    {
                        vkAcc.Country = result;
                        await this.Device.Send("Страна изменена");

                        await api.SaveVkAcc(vkAcc);

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeBirthDay":
                pd         = new PromptDialog("Введите день рождения (0 - любой):");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0 && result <= 31)
                    {
                        vkAcc.BirthDay = result;
                        await api.SaveVkAcc(vkAcc);

                        await this.Device.Send("День рождения изменен");

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeBirthMonth":
                pd         = new PromptDialog("Введите месяц рождения (0 - любой)::");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0 && result <= 12)
                    {
                        vkAcc.BirthMonth = result;
                        await api.SaveVkAcc(vkAcc);

                        await this.Device.Send("Месяц рождения изменен");

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeAgeFrom":
                pd         = new PromptDialog("Введите нижний предел возраста:");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0)
                    {
                        vkAcc.AgeFrom = result;
                        await api.SaveVkAcc(vkAcc);

                        await this.Device.Send("Нижний предел возраста изменен");

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeAgeTo":
                pd         = new PromptDialog("Введите верхний предел возраста:");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0 && result <= 200)
                    {
                        vkAcc.AgeTo = result;
                        await api.SaveVkAcc(vkAcc);

                        await this.Device.Send("Верхний предел возраста изменен");

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeSex":
                pd         = new PromptDialog("Введите пол (0 - любой, 1 - ж, 2 - м):");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0 && result <= 2)
                    {
                        vkAcc.Sex = result;
                        await this.Device.Send("Пол изменен");

                        await api.SaveVkAcc(vkAcc);

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "ChangeLimit":
                pd = new PromptDialog(
                    "Введите лимит на добавление друзей\n" +
                    "(Этот лимит ограничивает кол-во заявок в друзья в день):");
                pd.Closed += async(s, en) => {
                    int result;
                    this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
                    if (Int32.TryParse(pd.Value, out result) && result >= 0)
                    {
                        vkAcc.FriendsLimit = result;
                        await this.Device.Send("Лимит изменен");

                        await api.SaveVkAcc(vkAcc);

                        await api.ClearUncheckedClients();
                    }
                    else
                    {
                        await this.Device.Send("Неверный ввод");
                    }
                };
                await this.OpenModal(pd);

                break;

            case "GoToCfgAccForm":
                var ccaf = new CfgAccForm(_vkAccId);
                await this.NavigateTo(ccaf);

                break;

            default:
                message.Handled = false;
                break;
            }
        }