示例#1
0
        private async void Create()
        {
            if (Command["objectName"] != string.Empty)
            {
                ChatControl    chatControl    = new ChatControl(ChatsControl);
                MainWindow     mainWindow     = new MainWindow();
                SignalRManager signalRManager = new SignalRManager();
                string         chatName       = Command["objectName"];
                string         userName       = User.Name;

                bool isChatExists = Convert.ToBoolean(await ApiManager.Read($"api/chat/isChatExists/{chatName}"));
                if (!isChatExists)
                {
                    await ApiManager.Create("api/chat/create", $"{{'Name':'{chatName}', 'Creator':'{userName}'}}");

                    await ApiManager.Create("api/chat/user", $"{{ 'Chat':{{'Name':'{chatName}'}}, 'User':{{'Name':'{userName}'}} }}");

                    chatControl.AddTabItem(chatName);
                    mainWindow.UpdateUsersBox();

                    signalRManager.AddUserToChat(chatName, userName);
                }
                else
                {
                    MessageBox.Show("Чат с таким названием уже существует.");
                }
            }
            else
            {
                MessageBox.Show("Некорректное имя.");
            }
        }
示例#2
0
        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("Некорректная команда.");
            }
        }
示例#3
0
        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();
        }
示例#4
0
        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("Заполните все поля!");
            }
        }