Exemplo n.º 1
0
 private void kiosItem_Tapped(object sender, TappedRoutedEventArgs e)
 {
     if (gridviewKiosList.SelectedItem != null)
     {
         splitviewKios.IsPaneOpen = !splitviewKios.IsPaneOpen;
         if (KiosVm != null)
         {                    
             KiosVm.SelectedStore = (Kios)gridviewKiosList.SelectedItem;
             MessageInbox msg = new MessageInbox(KiosVm.SelectedStore.OwnerId, KiosVm.SelectedStore.Username, KiosVm.SelectedStore.Avatar);                           
             MessageInboxViewModel.UserChated = msg;                    
             ProductVm.GetProductsOfStore(TYPEGET.START);
             CommentVm.GetCommentOfStore(TYPEGET.START);                    
         }
         gridviewKiosList.SelectedItem = null;
     }
 }
Exemplo n.º 2
0
        public async Task<bool> sendMessage(string message)
        {
            try {
                if (MediateClass.UserVM != null)
                {
                    //receiverID = (receiverID == -1 || receiverID == 0 || receiverID == MediateClass.UserVM.UserInfo.UserId) ? UserChated : receiverID;
                    receiverID = UserChated.UserID;
                    int userId = MediateClass.UserVM.UserInfo.UserId;
                    string name = MediateClass.UserVM.UserInfo.Username;
                    string avatar = MediateClass.UserVM.UserInfo.Avatar;
                    DateTime inboxDate = DateTime.Now;

                    MessageInbox inbox = new MessageInbox
                    {
                        UserID = receiverID,
                        OwnerID = userId,
                        UserName = name,
                        Avatar = avatar,
                        InboxDate = inboxDate,
                        Content = message
                    };
                    if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection)
                    {
                        if (!isSended)
                        {
                            isSended = true;                                                                                    
                            JToken body = JToken.FromObject(inbox);
                            var result = await App.MobileService.InvokeApiAsync("MessageInboxes", body, HttpMethod.Post, null);
                            if (result.ToString() != "{}")
                            {
                                inbox = result.ToObject<MessageInbox>();                                
                                JObject jsonRequest = JObject.FromObject(inbox);
                                Debug.WriteLine("JSON: " + jsonRequest);
                                _socket.Send(jsonRequest);
                                MessageList.Add(inbox);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message.ToString(), "Message!").ShowAsync();
                return false;
            }
            finally
            {
                isSended = false;
            }
            return true;
        }
Exemplo n.º 3
0
        public void InitSocket()
        {            
            DispatcherTimer timer = new DispatcherTimer();
            timer.Tick += updateMessageListUponReceivingMessage;
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Start();

            _socket.On(Socket.EVENT_CONNECT, () =>
            {
                _socket.Emit("testwp", "hi");
            });

            _socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
                JObject received = (JObject)data;
                receivedMessage = received.ToObject<MessageInbox>();
            });
        }
Exemplo n.º 4
0
 private void updateMessageListUponReceivingMessage(object sender, object e)
 {
     if (this != null)
     {
         if (receivedMessage != null)
         {
             //receiverID = receivedMessage.OwnerID;
             Debug.WriteLine("RECEIVED: " + receivedMessage.Content);
             MessageList.Add(receivedMessage);
             if(MediateClass.InboxPage != null)
                 MediateClass.InboxPage.ScrollToBottom();
             receivedMessage = null;
         }
     }
 }