Пример #1
0
        public void ComplaintContent()
        {
            SetUpUserCache();
            controller.Registration(cache);
            User user = context.User.Where(u => u.UserEmail == cache.user_email).First();

            controller.Activate(user.UserHash);
            cache.user_token = user.UserToken;
            User anotherUser = CreateAnotherUser();

            cache.opposide_public_token = anotherUser.UserPublicToken;
            var       chat      = controller.CreateChat(cache);
            ChatCache chatCache = new ChatCache()
            {
                user_token   = user.UserToken,
                chat_token   = chat.Value.data.chat_token,
                message_text = "Test message."
            };

            cache.complaint             = "Test block.";
            cache.user_token            = anotherUser.UserToken;
            cache.opposide_public_token = user.UserPublicToken;
            var message = controller.SendMessage(chatCache);

            cache.message_id = message.Value.data.message_id;
            var success = controller.ComplaintContent(cache);

            Assert.AreEqual(success.Value.success, true);
        }
Пример #2
0
        public void SelectMessages()
        {
            SetUpUserCache();
            controller.Registration(cache);
            User user = context.User.Where(u => u.UserEmail == cache.user_email).First();

            controller.Activate(user.UserHash);
            cache.user_token = user.UserToken;
            controller.Profile(cache);
            User anotherUser = CreateAnotherUser();

            cache.opposide_public_token = anotherUser.UserPublicToken;
            var       chat      = controller.CreateChat(cache);
            ChatCache chatCache = new ChatCache()
            {
                user_token = user.UserToken,
                chat_token = chat.Value.data.chat_token,
                page       = 0,
                count      = 1
            };

            controller.SendMessage(chatCache);
            var success = controller.SelectMessages(chatCache);

            Assert.AreEqual(success.Value.success, true);
        }
Пример #3
0
        public void GetChatsWithoutMessage()
        {
            DeleteUsers();
            User      firstUser  = CreateMockingUser();
            User      secondUser = CreateMockingUser();
            var       firstRoom  = chats.CreateChat(firstUser.UserToken, secondUser.UserPublicToken, ref message);
            ChatCache cache      = new ChatCache();

            cache.user_token = firstUser.UserToken;
            var successWithoutMessage = chats.GetChats(firstUser.UserId, 0, 2);

            Assert.AreEqual(successWithoutMessage[0].user.user_id, secondUser.UserId);
            Assert.AreEqual(successWithoutMessage[0].chat.chat_id, firstRoom.ChatId);
            Assert.AreEqual(successWithoutMessage[0].last_message, null);
        }
Пример #4
0
        public ActionResult <dynamic> MessagePhoto(IFormFile photo)
        {
            string    message = null;
            ChatCache cache   = new ChatCache()
            {
                user_token = Request.Form["user_token"],
                chat_token = Request.Form["chat_token"]
            };
            Message result = chats.UploadMessagePhoto(photo, cache, ref message);

            if (result != null)
            {
                return(new { success = true, data = chats.ResponseMessage(result) });
            }
            return(Return500Error(message));
        }
Пример #5
0
        public ActionResult <dynamic> SendMessage(ChatCache cache)
        {
            string  answer  = null;
            Message message = chats.CreateMessage(
                cache.message_text, cache.user_token, cache.chat_token, ref answer);

            if (message != null)
            {
                return(new
                {
                    success = true,
                    data = chats.ResponseMessage(message)
                });
            }
            return(Return500Error(answer));
        }
Пример #6
0
        public void MessagePhoto()
        {
            User      first = CreateMockingUser();
            Chatroom  room  = chats.CreateChat(first.UserToken, CreateMockingUser().UserPublicToken, ref message);
            ChatCache cache = new ChatCache()
            {
                user_token = first.UserToken,
                chat_token = room.ChatToken
            };
            FormFile file     = saver.CreateFormFile();
            Message  success  = chats.MessagePhoto(file, first.UserId, room.ChatId, ref message);
            Message  nullable = chats.MessagePhoto(null, first.UserId, room.ChatId, ref message);

            saver.system.DeleteFile(success.UrlFile);
            Assert.AreEqual(success.UserId, first.UserId);
            Assert.AreEqual(nullable, null);
        }
Пример #7
0
        public ActionResult <dynamic> SelectMessages(ChatCache cache)
        {
            string message = null;

            cache.count = cache.count == 0 ? 50 : cache.count;
            User user = users.GetUserByToken(cache.user_token, ref message);

            if (user != null)
            {
                dynamic messages = chats.GetMessages(
                    user.UserId, cache.chat_token, cache.page, cache.count, ref message);
                if (messages != null)
                {
                    return(new { success = true, data = messages });
                }
            }
            return(Return500Error(message));
        }
Пример #8
0
        public Message UploadMessagePhoto(IFormFile photo, ChatCache cache, ref string message)
        {
            User user = users.GetUserByToken(cache.user_token, ref message);

            if (user != null)
            {
                Chatroom room = context.Chatroom.Where(ch
                                                       => ch.ChatToken == cache.chat_token).FirstOrDefault();
                if (room != null)
                {
                    return(MessagePhoto(photo, user.UserId, room.ChatId, ref message));
                }
                else
                {
                    message = "Server can't define chat by 'chat_token' key.";
                }
            }
            return(null);
        }
Пример #9
0
        public void GetChatsWithBlocking()
        {
            DeleteUsers();
            User   firstUser     = CreateMockingUser();
            User   secondUser    = CreateMockingUser();
            User   thirdUser     = CreateMockingUser();
            var    firstRoom     = chats.CreateChat(firstUser.UserToken, secondUser.UserPublicToken, ref message);
            var    secondRoom    = chats.CreateChat(firstUser.UserToken, thirdUser.UserPublicToken, ref message);
            var    firstMessage  = chats.CreateMessage("Testing text.", firstUser.UserToken, firstRoom.ChatToken, ref message);
            var    secondMessage = chats.CreateMessage("Testing text.", firstUser.UserToken, secondRoom.ChatToken, ref message);
            Blocks blocks        = new Blocks(new Users(context, new Validator()), context);

            blocks.BlockUser(firstUser.UserToken, secondUser.UserPublicToken, "Test block.", ref message);
            ChatCache cache = new ChatCache();

            cache.user_token = firstUser.UserToken;
            var successWithBlocking = chats.GetChats(firstUser.UserId, 0, 2);

            Assert.AreEqual(successWithBlocking[0].user.user_id, thirdUser.UserId);
            Assert.AreEqual(successWithBlocking[0].chat.chat_id, secondRoom.ChatId);
            Assert.AreEqual(successWithBlocking[0].last_message.message_id, secondMessage.MessageId);
        }
Пример #10
0
        public void SendMessage()
        {
            SetUpUserCache();
            controller.Registration(cache);
            User user = context.User.Where(u => u.UserLogin == cache.user_login).First();

            cache.user_token = user.UserToken;
            controller.Profile(cache);
            User anotherUser = CreateAnotherUser();

            cache.opposide_public_token = anotherUser.UserPublicToken;
            var       chat      = controller.CreateChat(cache);
            ChatCache chatCache = new ChatCache()
            {
                user_token   = user.UserToken,
                chat_token   = chat.Value.data.chat_token,
                message_text = "Test message."
            };
            var success = controller.SendMessage(chatCache);

            Assert.AreEqual(success.Value.success, true);
        }
Пример #11
0
        public ChatEntry(string imageUrl, string text, string username, bool send)
        {
            Text.Text     = text;
            UserName.Text = username;
            var cachedImage = ChatCache.CacheLookup(imageUrl, username);
            var bitmap      = new BitmapImage();
            var stream      = File.OpenRead(cachedImage);

            bitmap.BeginInit();
            bitmap.CacheOption  = BitmapCacheOption.OnLoad;
            bitmap.StreamSource = stream;
            bitmap.EndInit();
            stream.Close();
            stream.Dispose();
            var myImageSource = new ImageBrush {
                ImageSource = bitmap
            };

            Img.Fill                     = myImageSource;
            Img.Width                    = 42;
            Img.Height                   = 42;
            Text.VerticalAlignment       = VerticalAlignment.Center;
            Text.HorizontalAlignment     = HorizontalAlignment.Right;
            Text.TextWrapping            = TextWrapping.Wrap;
            Text.MaxWidth                = 420;
            Img.VerticalAlignment        = VerticalAlignment.Center;
            Img.HorizontalAlignment      = HorizontalAlignment.Right;
            UserName.VerticalAlignment   = VerticalAlignment.Center;
            UserName.HorizontalAlignment = HorizontalAlignment.Right;

            UserName.FontWeight = FontWeights.Bold;
            UserName.FontSize   = 14.0;
            Text.FontSize       = 14.0;
            if (!send)
            {
                ChatCache.CacheImage(imageUrl, username);
            }
        }
Пример #12
0
        public void GetChats()
        {
            DeleteUsers();
            User      firstUser     = CreateMockingUser();
            User      secondUser    = CreateMockingUser();
            User      thirdUser     = CreateMockingUser();
            var       firstRoom     = chats.CreateChat(firstUser.UserToken, secondUser.UserPublicToken, ref message);
            var       secondRoom    = chats.CreateChat(firstUser.UserToken, thirdUser.UserPublicToken, ref message);
            var       thirdMessage  = chats.CreateMessage("Third message.", firstUser.UserToken, firstRoom.ChatToken, ref message);
            var       firstMessage  = chats.CreateMessage("First message.", firstUser.UserToken, firstRoom.ChatToken, ref message);
            var       secondMessage = chats.CreateMessage("Second message.", firstUser.UserToken, secondRoom.ChatToken, ref message);
            ChatCache cache         = new ChatCache();

            cache.user_token = firstUser.UserToken;
            var success = chats.GetChats(firstUser.UserId, 0, 2);

            Assert.AreEqual(success[0].user.user_id, secondUser.UserId);
            Assert.AreEqual(success[1].user.user_id, thirdUser.UserId);
            Assert.AreEqual(success[0].chat.chat_id, firstRoom.ChatId);
            Assert.AreEqual(success[1].chat.chat_id, secondRoom.ChatId);
            Assert.AreEqual(success[0].last_message.message_id, firstMessage.MessageId);
            Assert.AreEqual(success[1].last_message.message_id, secondMessage.MessageId);
        }
/*    public void ChatsCache()
    {
        Hashtable chatsCache = new Hashtable();
    }*/

        public ChatCache CreateChatCache()
        {
            ChatCache chatCache = new ChatCache();
            chatCache.messageCache = new MessageItem[maxMsg];
            chatCache.numMsg = 0;
            chatCache.last = 0;

            return chatCache;
        }
Пример #14
0
 public ChatHub(ChatCache memoryCache)
 {
     _cache = memoryCache.cache;
 }
Пример #15
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     ChatCache.Clear();
     SendMessage("Disconnected!", true);
 }