Beispiel #1
0
        private async void UpdateSceernSource(Bitmap bm)
        {
            //BitmapImage img = ImageSupportInstance.getInstance().BitmapToImageSource(bm).Clone();
            //userCam.Source = img.Clone();

            MemoryStream ms = new MemoryStream();

            bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[]      byteImage      = ms.ToArray();
            byte[]      afterreprocess = ImageSupportInstance.getInstance().PreProcessImage(byteImage, 100, 50, System.Drawing.Imaging.ImageFormat.Jpeg);
            string      result         = Convert.ToBase64String(afterreprocess);
            BitmapImage img2           = ImageSupportInstance.getInstance().ConvertFromBaseString(result);

            userCam.Source = img2;
            result         = AppInstance.getInstance().GetUser().Id + "\0" + result;
            byteImage      = new byte[1];
            afterreprocess = new byte[1];
            ms.Close();


            try
            {
                await connection.InvokeAsync("SendMessageToGroup", ConversationId.ToString(),
                                             result);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void Userinfopopup_UpdateIconEventhandler(object sender, EventArgs e)
        {
            string basestr = ImageSupportInstance.getInstance().getUserBase64Image(AppInstance.getInstance().GetUser().Id);

            Useravatar     = ImageSupportInstance.getInstance().ConvertFromBaseString(basestr);
            userimg.Source = Useravatar;
        }
        public AddUserToChatDialog(long conversationid)
        {
            InitializeComponent();
            this.ConversationId = conversationid;

            Contacts = new ObservableCollection <ContactListItem>();
            List <Contact> contacts = AppInstance.getInstance().GetContacts();

            foreach (Contact contact in contacts)
            {
                long id = contact.FromUserId;
                if (id == AppInstance.getInstance().GetUser().Id)
                {
                    id = contact.ToUserId;
                }
                Contacts.Add(new ContactListItem()
                {
                    ToUserId   = contact.ToUserId,
                    Status     = contact.Status,
                    FromUserId = contact.FromUserId,
                    Username   = AppInstance.getInstance().GetFullname(id),
                    IsSelected = false,
                    Avatar     = ImageSupportInstance.getInstance().GetUserImageFromId(id)
                });;;
            }
            lvContact.ItemsSource = Contacts;
        }
Beispiel #4
0
        public MessageImageBox(string Title, string content, string arriveTime, long userid, Side side)
        {
            InitializeComponent();
            ImgBase64 = ImageSupportInstance.getInstance().getImageResourceBaseString(long.Parse(content));
            byte[]       data         = System.Convert.FromBase64String(ImgBase64);
            MemoryStream memoryStream = new MemoryStream(data);
            var          imageSource  = new BitmapImage();

            imageSource.BeginInit();
            imageSource.StreamSource = memoryStream;
            imageSource.EndInit();
            ImageMessContent.Source = imageSource;

            this.Title    = Title;
            TileMess.Text = Title + "    " + arriveTime;

            Avatar          = ImageSupportInstance.getInstance().GetUserImageFromId(userid);
            ImgMess1.Source = Avatar;
            ImgMess2.Source = Avatar;

            if (side == Side.User)
            {
                ImgMess1.Visibility = Visibility.Hidden;
                ImageMessContent.HorizontalAlignment = HorizontalAlignment.Right;
                TileMess.HorizontalAlignment         = HorizontalAlignment.Right;
                TileMess.Text = arriveTime;
            }
            else
            {
                ImgMess2.Visibility = Visibility.Hidden;
            }
        }
Beispiel #5
0
        private void Bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Contact> contactList = new List <Contact>();
            ObservableCollection <ContactListItem> contactItems = new ObservableCollection <ContactListItem>();

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Ultils.url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                    HttpResponseMessage response = client.GetAsync("/api/Users/Owner/Contacts", HttpCompletionOption.ResponseContentRead).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        contactList = response.Content.ReadAsAsync <List <Contact> >().Result;
                    }
                }
            }
            catch (Exception ee)
            {
            }


            foreach (Contact contact in contactList)
            {
                if (contact.Status == 1)
                {
                    long id = contact.FromUserId;
                    if (id == AppInstance.getInstance().GetUser().Id)
                    {
                        id = contact.ToUserId;
                    }

                    using (HttpClient client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(Ultils.url);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                        HttpResponseMessage response = client.GetAsync("/api/Users/" + id, HttpCompletionOption.ResponseContentRead).Result;
                        User users = response.Content.ReadAsAsync <User>().Result;
                        AppInstance.getInstance().SetFullname(users.Id, users.FullName);
                        contactItems.Add(new ContactListItem()
                        {
                            ToUserId   = contact.ToUserId,
                            Username   = AppInstance.getInstance().GetFullname(id),
                            Status     = 1,
                            FromUserId = contact.FromUserId,
                            Avatar     = ImageSupportInstance.getInstance().GetUserImageFromId(id)
                        });;
                    }
                }
            }
            e.Result = contactItems;
        }
Beispiel #6
0
        private void sendImagebtn_Click(object sender, RoutedEventArgs e)
        {
            string path = ImageSupportInstance.getInstance().OpenChooseImageDialogBox();

            if (!path.Equals(""))
            {
                SendImage(path);
            }
        }
Beispiel #7
0
        //================================================================================

        private async Task LoadContact()
        {
            string         url         = Ultils.getUrl();
            List <Contact> contactList = new List <Contact>();

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                HttpResponseMessage response = client.GetAsync("/api/Users/Owner/Contacts", HttpCompletionOption.ResponseContentRead).Result;
                contactList = await response.Content.ReadAsAsync <List <Contact> >();

                if (response.IsSuccessStatusCode)
                {
                    AppInstance.getInstance().SetContacts(contactList);
                }
            }

            foreach (Contact contact in contactList)
            {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);

                    HttpResponseMessage response = client.GetAsync("/api/Users/" + contact.FromUserId, HttpCompletionOption.ResponseContentRead).Result;
                    User users = await response.Content.ReadAsAsync <User>();

                    AppInstance.getInstance().SetFullname(users.Id, users.FullName);

                    response = client.GetAsync("/api/Users/" + contact.ToUserId, HttpCompletionOption.ResponseContentRead).Result;
                    users    = await response.Content.ReadAsAsync <User>();

                    AppInstance.getInstance().SetFullname(users.Id, users.FullName);

                    long id = contact.FromUserId;
                    if (id == AppInstance.getInstance().GetUser().Id)
                    {
                        id = contact.ToUserId;
                    }

                    ContactViews.Add(new ContactListItem()
                    {
                        ToUserId   = contact.ToUserId,
                        Status     = contact.Status,
                        FromUserId = contact.FromUserId,
                        Avatar     = ImageSupportInstance.getInstance().GetUserImageFromId(id)
                    });
                }
            }
        }
Beispiel #8
0
        private void LoadUserList()
        {
            Users = new ObservableCollection <ConversationMemberItem>();
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Ultils.url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                HttpResponseMessage response = client.GetAsync("/api/Conversations/" + ConversationId, HttpCompletionOption.ResponseContentRead).Result;
                if (response.IsSuccessStatusCode)
                {
                    Conversation conversation = response.Content.ReadAsAsync <Conversation>().Result;
                    ConversationHost = conversation.HostUserId;
                }
            }

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Ultils.url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                HttpResponseMessage response = client.GetAsync("/api/Conversations/Members?id=" + ConversationId, HttpCompletionOption.ResponseContentRead).Result;
                //HttpResponseMessage response = client.PostAsJsonAsync("/api/ConversationsView/Members", AppInstance.getInstance().getUser().Id).Result;
                List <User> users = response.Content.ReadAsAsync <List <User> >().Result;
                foreach (User Conv_users in users)
                {
                    ConversationMemberItem mem = new ConversationMemberItem()
                    {
                        FullName    = Conv_users.Username,
                        Id          = Conv_users.Id,
                        isAdmin     = false,
                        Role        = Conv_users.Role,
                        Username    = Conv_users.Username,
                        AllowDelete = true,
                        Avatar      = ImageSupportInstance.getInstance().GetUserImageFromId(Conv_users.Id)
                    };
                    //if (mem.Id == AppInstance.getInstance().GetUser().Id)
                    //{
                    //    mem.AllowDelete = false;
                    //}
                    if (mem.Id != ConversationHost)
                    {
                        mem.AllowToapprove = true;
                    }
                    Users.Add(mem);
                }
            }
            lvUser.ItemsSource = Users;
        }
Beispiel #9
0
        private async void SendImage(string path)
        {
            Resource res = ImageSupportInstance.getInstance().UploadImage(path, 720, 640);


            MessageSend mess = new MessageSend()
            {
                Content        = res.Id.ToString(),
                ConversationId = this.ConversationId,
                Type           = 2
            };

            using (HttpClient client = new HttpClient())
            {
                string url = Ultils.getUrl();
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                HttpResponseMessage response = client.PostAsJsonAsync("/api/Messages", mess).Result;
                if (!response.IsSuccessStatusCode)
                {
                    System.Windows.MessageBox.Show("Lỗi khi gửi tin");
                }
            }
            messTextbox.Text = "";



            //send to hub
            Message hubmess = new Message()
            {
                ArrivalTime    = DateTimeOffset.Now,
                Content        = mess.Content,
                ConversationId = mess.ConversationId,
                Id             = 0,
                SenderId       = AppInstance.getInstance().GetUser().Id,
                Type           = mess.Type
            };

            string json = JsonConvert.SerializeObject(hubmess);

            try
            {
                await connection.InvokeAsync("SendMessage", "mess", json);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }
Beispiel #10
0
        private async void LoadHub()
        {
            string url = Ultils.url + "callhub";

            connection = new HubConnectionBuilder()
                         .WithUrl(url)
                         .WithAutomaticReconnect()
                         .Build();
            connection.Closed += async(error) =>
            {
                await Task.Delay(new Random().Next(0, 5) * 1000);

                await connection.StartAsync();
            };
            connection.Reconnecting += error =>
            {
                return(Task.CompletedTask);
            };

            connection.On <string>("ReceiveMessage", (message) =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    string id   = message.Split('\0')[0];
                    string mess = message.Split('\0')[1];
                    if (long.Parse(id) != AppInstance.getInstance().GetUser().Id)
                    {
                        mainCall.Source = ImageSupportInstance.getInstance().ConvertFromBaseString(mess);
                    }
                });
            });

            try
            {
                await connection.StartAsync();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }

            await connection.InvokeAsync("AddToGroup", ConversationId.ToString());
        }
Beispiel #11
0
        public MenuControl()
        {
            User        = "******";
            NotifiBadge = 0;
            InitializeComponent();
            this.DataContext = this;

            SetupHubConnectionAsync();
            userFullName.Content = AppInstance.getInstance().GetUser().FullName;

            string basestr = ImageSupportInstance.getInstance().getUserBase64Image(AppInstance.getInstance().GetUser().Id);

            if (!basestr.Equals(""))
            {
                Useravatar = ImageSupportInstance.getInstance().ConvertFromBaseString(basestr);
            }

            notifiupdateWorker                     = new BackgroundWorker();
            notifiupdateWorker.DoWork             += NotifiupdateWorker_DoWork;
            notifiupdateWorker.RunWorkerCompleted += NotifiupdateWorker_RunWorkerCompleted;
            notifiupdateWorker.RunWorkerAsync();
        }
Beispiel #12
0
        private void btUpdateAvatar_Click(object sender, RoutedEventArgs e)
        {
            string path = ImageSupportInstance.getInstance().OpenChooseImageDialogBox();

            if (!path.Equals(""))
            {
                Resource res         = ImageSupportInstance.getInstance().UploadImage(path, 360, 360);
                User     currentuser = AppInstance.getInstance().GetUser();
                currentuser.Avatar = res.Id;
                AppInstance.getInstance().SetUser(currentuser);

                UserSignup user = new UserSignup()
                {
                    Avatar   = currentuser.Avatar,
                    FullName = currentuser.FullName,
                    Password = null,
                    Username = null
                };
                using (HttpClient client = new HttpClient())
                {
                    string url = Ultils.getUrl();
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                    HttpResponseMessage response = client.PutAsJsonAsync("/api/Users/Owner", user).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        UpdateIconEventhandler(this, new EventArgs());
                    }
                    else
                    {
                        _404Mess mess = response.Content.ReadAsAsync <_404Mess>().Result;
                        System.Windows.MessageBox.Show(mess.Message);
                    }
                }
            }
        }
Beispiel #13
0
        public MessageBox(string Title, string Text, string arriveTime, long userId, Side side)
        {
            InitializeComponent();

            this.Text       = Text;
            this.Title      = Title;
            TileMess.Text   = Title + "    " + arriveTime;
            TextMess.Text   = Text;
            Avatar          = ImageSupportInstance.getInstance().GetUserImageFromId(userId);
            ImgMess1.Source = Avatar;
            ImgMess2.Source = Avatar;
            if (side == Side.User)
            {
                ImgMess1.Visibility          = Visibility.Hidden;
                TextMess.Background          = new SolidColorBrush(Color.FromArgb(100, 210, 222, 228));
                TextMess.HorizontalAlignment = HorizontalAlignment.Right;
                TileMess.HorizontalAlignment = HorizontalAlignment.Right;
                TileMess.Text = arriveTime;
            }
            else
            {
                ImgMess2.Visibility = Visibility.Hidden;
            }
        }
Beispiel #14
0
        private void ConversationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string url = Ultils.getUrl();
            List <Conversation> ConversationList = new List <Conversation>();
            ObservableCollection <ConversationsView> conversationsViewsList = new ObservableCollection <ConversationsView>();

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                    HttpResponseMessage response = client.GetAsync("/api/Users/Owner/Conversations", HttpCompletionOption.ResponseContentRead).Result;
                    ConversationList = response.Content.ReadAsAsync <List <Conversation> >().Result;
                    if (response.IsSuccessStatusCode)
                    {
                        AppInstance.getInstance().SetConversation(ConversationList);
                    }
                }
            }
            catch (Exception ee)
            {
            }


            foreach (Conversation conver in ConversationList)
            {
                string lastMess       = "";
                string time           = "";
                long   lastMessUserId = 0;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token);
                    HttpResponseMessage response = client.GetAsync("/api/Conversations/Messages/Last?id=" + conver.Id, HttpCompletionOption.ResponseContentRead).Result;
                    Message             mess     = response.Content.ReadAsAsync <Message>().Result;
                    if (response.IsSuccessStatusCode)
                    {
                        lastMess = mess.Content;
                    }

                    if (mess.Type == 2)
                    {
                        lastMess = "Send a picture";
                    }
                    time = mess.ArrivalTime.ToString("hh:mm dd/MM");
                    if (time.Equals("12:00 01/01"))
                    {
                        time = "";
                    }
                    lastMessUserId = mess.SenderId;
                }

                conversationsViewsList.Add(new ConversationsView()
                {
                    Pk_seq     = conver.Id,
                    Text       = conver.Name,
                    Mess       = lastMess,
                    MessUserId = lastMessUserId,
                    Date       = time,
                    Avatar     = ImageSupportInstance.getInstance().GetUserImageFromId(lastMessUserId)
                });;
            }
            e.Result = conversationsViewsList;
        }