private void OnNewRemoveBotCommand() { try { SelectedTelegramBotObject.StopBot(); TelegramBotObjectCollection.Remove(SelectedTelegramBotObject); SelectedTelegramBotObject = null; } catch (Exception e) { LogWriter.CreateLogEntry(string.Format("{0}\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : "")); return; } }
private void OnNewAddBotCommand() { this.Dialogs.Add(new ResponseConfigurationDialogTelegramBotConfigurationDialogViewModel() { OnOk = (sender) => { if ( sender.TelegramBot != null && sender.TelegramBot.TelegramUsers != null && sender.TelegramBot.TelegramUsers.Count > 0 && sender.TelegramBot.TelegramUsers.Where(x => x.UserStatus == TelegramUserStatus.UserIsAdmin).Select(x => x.UserStatus == TelegramUserStatus.UserIsAdmin).Single()) { this.TelegramMessageObject.Bot2Use = sender.TelegramBot; ResponseObjectModel.HasConfiguration = true; if (!TelegramBotObjectCollection.Contains(TelegramMessageObject.Bot2Use)) { TelegramBotObjectCollection.Add(TelegramMessageObject.Bot2Use); } if (this.TelegramBotObjectCollection.Count > 0 && SelectedTelegramBotObject == null) { SelectedTelegramBotObject = TelegramMessageObject.Bot2Use; } else { RaisePropertyChanged("SelectedTelegramBotObject"); } StatusMessage = string.Format("Online with ChatID: {0}", TelegramMessageObject.Bot2Use.TelegramUsers.Where(x => x.UserStatus == TelegramUserStatus.UserIsAdmin).Select(x => x.chatID).Single()); sender.Close(); } else { if (new MessageBoxViewModel { Caption = resLoader.getResource("messageBoxNoKnownTelegramUserCaption"), Message = resLoader.getResource("messageBoxNoKnownTelegramUserMessage"), Buttons = MessageBoxButton.YesNo, Image = MessageBoxImage.Question } .Show(this.Dialogs) == MessageBoxResult.Yes) { sender.TelegramBot = null; ResponseObjectModel.HasConfiguration = false; sender.Close(); } ResponseObjectModel.HasConfiguration = false; } }, OnCancel = (sender) => { sender.Close(); ResponseObjectModel.HasConfiguration = false; }, OnCloseRequest = (sender) => { sender.Close(); ResponseObjectModel.HasConfiguration = false; } }); }