private async void Window_Closed(object sender, EventArgs e) { AuthorizationWindow authorizationWindow = new AuthorizationWindow(); SignalRManager signalRManager = new SignalRManager(); await ApiManager.Change($"api/authorization/logout", $"{{'Name':'{User.Name}', 'Password':'******'}}"); signalRManager.OnDisconnect(); Close(); authorizationWindow.Show(); }
private async void LoadPreviouslyOpenedChatsItems() { ChatControl chatControl = new ChatControl(ChatsControl); List <string> chatsNames = new List <string>(); string chatsJson = await ApiManager.Read($"api/chat/getChats/{User.Name}"); chatsNames = GetListValuesFromJson(chatsJson, "name"); foreach (string chatName in chatsNames) { chatControl.AddTabItem(chatName); await UpdateUsersBox(); } }
private async void Find() { if (Command["specialCommand"] == "-t" && Command["valueSpecialCommand"] != string.Empty && Command["objectName"] != string.Empty && ChatSelected != null) { try { SignalRManager signalRManager = new SignalRManager(); YouTubeManager youTubeManager = new YouTubeManager(); string channelName = Command["objectName"]; string videoName = Command["valueSpecialCommand"]; await youTubeManager.SetIdAndUrlVideo(videoName, channelName); signalRManager.SendMessage(ChatSelected, "yBot", youTubeManager.Url); ApiManager.Create("api/chat/message", $"{{\"ChatName\":\"{ChatSelected}\",\"Author\":\"yBot\",\"Text\":\"{youTubeManager.Url}\"}}"); if (Command["secondSpecialCommand"] == "-v") { youTubeManager.SetVideoInfo(); string viewsMessageLine = "Просмотров: " + youTubeManager.ViewCount.ToString(); signalRManager.SendMessage(ChatSelected, "yBot", viewsMessageLine); ApiManager.Create("api/chat/message", $"{{\"ChatName\":\"{ChatSelected}\",\"Author\":\"yBot\",\"Text\":\"{viewsMessageLine}\"}}"); } else if (Command["secondSpecialCommand"] == "-l") { youTubeManager.SetVideoInfo(); string likesMessageLine = "Лайков: " + youTubeManager.LikeCount.ToString(); signalRManager.SendMessage(ChatSelected, "yBot", likesMessageLine); ApiManager.Create("api/chat/message", $"{{\"ChatName\":\"{ChatSelected}\",\"Author\":\"yBot\",\"Text\":\"{likesMessageLine}\"}}"); } } catch { MessageBox.Show("Видео не найдено."); } } else { MessageBox.Show("Некорректная команда."); } }
private async void RenameUser() { if (Command["objectName"] != string.Empty) { SignalRManager signalRManager = new SignalRManager(); string userName; string newUserName; if (Command["specialCommand"] == "-l" && Command["valueSpecialCommand"] != string.Empty) { userName = Command["objectName"]; newUserName = Command["valueSpecialCommand"]; } else { userName = User.Name; newUserName = Command["objectName"]; } bool isNewUserExists = Convert.ToBoolean(await ApiManager.Read($"api/chat/isUserExists/{newUserName}")); bool isUserExists = Convert.ToBoolean(await ApiManager.Read($"api/chat/isUserExists/{userName}")); if (!isNewUserExists && isUserExists) { bool hasRight = Convert.ToBoolean(await ApiManager.Read($"api/chat/isTrueUser/{userName}/{User.Password}")); if (hasRight) { await ApiManager.Change($"api/chat/renameUser/{newUserName}", $"{{ 'Name':'{userName}' }}"); signalRManager.RenameUser(userName, newUserName); } else { MessageBox.Show("У вас нет прав на это действие."); } } else { MessageBox.Show("Вы пытаетесь переименовать несуществующего пользователя или пользователь с предложенным логином уже существует."); } } else { MessageBox.Show("Некорректное имя."); } }
public async Task UpdateUsersBox() { if (ChatSelected != null) { List <string> usersNames = new List <string>(); string usersJson = await ApiManager.Read($"api/chat/getUsers/{ChatSelected}"); usersNames = GetListValuesFromJson(usersJson, "name"); ChatControl.UsersBox[ChatSelected].Items.Clear(); foreach (string user in usersNames) { ChatControl.CreateListBoxItem(ChatSelected, user); } } }
public static void SendMessage() { MainWindow mainWindow = new MainWindow(); SignalRManager signalRManager = new SignalRManager(); string chatName = ChatSelected; string userName = User.Name; string message = ChatControl.TextBox[ChatSelected].Text; if (message != string.Empty) { signalRManager.SendMessage(chatName, userName, message); ApiManager.Create("api/chat/message", $"{{\"ChatName\":\"{chatName}\",\"Author\":\"{userName}\",\"Text\":\"{message}\"}}"); } ChatControl.TextBox[chatName].Clear(); }
public static async void CreateListBoxItem(string chatName, string userName) { SolidColorBrush userColorText = new SolidColorBrush(); string status = await ApiManager.Read($"api/chat/statusUser/{chatName}/{userName}"); bool isBanned = Convert.ToBoolean(await ApiManager.Read($"api/chat/isUserBanned/{chatName}/{userName}")); switch (status) { case User.creator: userColorText = User.creatorColor; break; case User.administrator: userColorText = User.administratorColor; break; case User.moderator: userColorText = User.moderatorColor; break; case User.user: userColorText = User.userColor; break; } if (isBanned) { userColorText = User.bannedColor; } ListBoxItem newListBoxItem = new ListBoxItem { Content = userName, Foreground = userColorText, FontFamily = new FontFamily("Segoe UI Semibold") }; UsersBox[chatName].Items.Add(newListBoxItem); }
private async void Connect() { if (Command["objectName"] != string.Empty) { string chatName = Command["objectName"]; string userName = User.Name; bool isChatExists = Convert.ToBoolean(await ApiManager.Read($"api/chat/isChatExists/{chatName}")); if (isChatExists) { bool isBanned = Convert.ToBoolean(await ApiManager.Read($"api/chat/isUserBanned/{chatName}/{userName}")); if (!isBanned) { ChatControl chatWindow = new ChatControl(ChatsControl); MainWindow mainWindow = new MainWindow(); SignalRManager signalRManager = new SignalRManager(); await ApiManager.Create("api/chat/user", $"{{ 'Chat':{{'Name':'{chatName}'}}, 'User':{{'Name':'{userName}'}} }}"); chatWindow.AddTabItem(chatName); mainWindow.UpdateUsersBox(); signalRManager.AddUserToChat(chatName, userName); } else { MessageBox.Show("Вы на время забанены в этом чате."); } } else { MessageBox.Show("Чата с таким названием не существует."); } } else { MessageBox.Show("Некорректное имя."); } }
private async void RegisterButton_Click(object sender, RoutedEventArgs e) { User.Name = UserNameBox.Text; User.Password = UserPasswordBox.Text; if (User.Name != string.Empty && User.Password != string.Empty) { if (IsAllowedName()) { bool isUserExists = Convert.ToBoolean(await ApiManager.Read($"api/chat/isUserExists/{User.Name}")); if (!isUserExists) { MainWindow mainWindow = new MainWindow(); SignalRManager signalRManager = new SignalRManager(); ApiManager.Create("api/authorization/register", $"{{'Name':'{User.Name}', 'Password':'******'}}"); signalRManager.OnConnect(); Close(); mainWindow.ShowDialog(); } else { MessageBox.Show("Пользователь с таким логином уже существует."); } } else { MessageBox.Show("Предложенный логин запрещен."); } } else { MessageBox.Show("Заполните все поля!"); } }