Ejemplo n.º 1
0
        private void RemoveConv(RemoveConvTemplate rconvT)
        {
            ContactUI rConv = null;

            foreach (ContactUI i in mainPageViewModel.ContactsTab.Contacts)
            {
                if (i.ChatId == rconvT.ChatId)
                {
                    rConv = i;
                    break;
                }
            }

            if (rConv != null)
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    if (mainPageViewModel.ContactsTab.SelectedContact != null &&
                        mainPageViewModel.ContactsTab.SelectedContact.Equals(rConv))
                    {
                        mainPageViewModel.CurrentChatMessages.Clear();
                        mainPageViewModel.ContactsTab.SelectedContact = null;
                    }

                    mainPageViewModel.ContactsTab.Contacts.Remove(rConv);
                }
                                                                 ));
            }
        }
Ejemplo n.º 2
0
        private void RemoveConvTarget(RemoveConvTemplate rconvtT)
        {
            ContactUI rConv = null;

            foreach (ContactUI i in mainPageViewModel.ContactsTab.Contacts)
            {
                if (i.ChatId == rconvtT.ChatId)
                {
                    rConv = i;
                    break;
                }
            }

            if (rConv != null)
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    rConv.ContactLastMessage = (rConv.ConvMembers.Count - 1).ToString() + ' ' + (string)Application.Current.FindResource("l_Members");
                }
                                                                 ));
            }
        }
Ejemplo n.º 3
0
        void NotifyHandling()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                while (true)
                {
                    try
                    {
                        memoryStream.Flush();
                        memoryStream.Position = 0;

                        do
                        {
                            byte[] buffer = new byte[256];
                            int    bytes;

                            bytes = clientStream.Read(buffer, 0, buffer.Length);
                            memoryStream.Write(buffer, 0, bytes);

                            buffer = new byte[256];
                        }while (clientStream.DataAvailable);

                        memoryStream.Position = 0;
                        RRTemplate serverResponse = formatter.Deserialize(memoryStream) as RRTemplate;

                        if (serverResponse != null)
                        {
                            switch (serverResponse.RRType)
                            {
                            case RRType.AddContact:
                                AddRemoveContactTemplate aContT = serverResponse.RRObject as AddRemoveContactTemplate;
                                if (aContT != null)
                                {
                                    AddContact(aContT);
                                }
                                break;

                            case RRType.RemoveContact:
                                AddRemoveContactTemplate rContT = serverResponse.RRObject as AddRemoveContactTemplate;
                                if (rContT != null)
                                {
                                    RemoveContact(rContT);
                                }
                                break;

                            case RRType.RefreshContacts:
                                RefreshContactsTemplate refrC = serverResponse.RRObject as RefreshContactsTemplate;
                                if (refrC != null)
                                {
                                    RefreshContacts(refrC);
                                }
                                break;

                            case RRType.SearchOutContacts:
                                SearchOutContactsTemplate searchOutC = serverResponse.RRObject as SearchOutContactsTemplate;
                                if (searchOutC != null)
                                {
                                    SearchOutContacts(searchOutC);
                                }
                                break;

                            case RRType.SendMessage:
                                SendMessageTemplate sMessT = serverResponse.RRObject as SendMessageTemplate;
                                if (sMessT != null)
                                {
                                    SendMessageReceive(sMessT);
                                }
                                break;

                            case RRType.RefreshContactStatus:
                                RefreshContactStatusTemplate refrContStT = serverResponse.RRObject as RefreshContactStatusTemplate;
                                if (refrContStT != null)
                                {
                                    RefreshContactStatus(refrContStT);
                                }
                                break;

                            case RRType.AddContactTarget:
                                AddRemoveContactTargetTemplate aconttT = serverResponse.RRObject as AddRemoveContactTargetTemplate;
                                if (aconttT != null)
                                {
                                    AddContactTarget(aconttT);
                                }
                                break;

                            case RRType.RemoveContactTarget:
                                AddRemoveContactTargetTemplate rconttT = serverResponse.RRObject as AddRemoveContactTargetTemplate;
                                if (rconttT != null)
                                {
                                    RemoveContactTarget(rconttT);
                                }
                                break;

                            case RRType.RefreshMessageState:
                                RefreshMessageStateTemplate refrmsT = serverResponse.RRObject as RefreshMessageStateTemplate;
                                if (refrmsT != null)
                                {
                                    RefreshMessageState(refrmsT);
                                }
                                break;

                            case RRType.CreateConv:
                                CreateConvTemplate crconvT = serverResponse.RRObject as CreateConvTemplate;
                                if (crconvT != null)
                                {
                                    AddConv(crconvT);
                                }
                                break;

                            case RRType.RemoveConv:
                                RemoveConvTemplate rconvT = serverResponse.RRObject as RemoveConvTemplate;
                                if (rconvT != null)
                                {
                                    RemoveConv(rconvT);
                                }
                                break;

                            case RRType.RemoveConvTarget:
                                RemoveConvTemplate rconvtT = serverResponse.RRObject as RemoveConvTemplate;
                                if (rconvtT != null)
                                {
                                    RemoveConvTarget(rconvtT);
                                }
                                break;

                            case RRType.BlockUnblockUserTarget:
                                BlockUnblockUserTemplate bunbUT = serverResponse.RRObject as BlockUnblockUserTemplate;
                                if (bunbUT != null)
                                {
                                    ChangeBlockUserStatusTarget(bunbUT);
                                }
                                break;

                            default:
                                if (client.Connected)
                                {
                                    mainPageViewModel.MainViewModel.ErrorService(new ErrorReportTemplate(ErrorType.Other, new Exception("Unknown problem")));
                                }
                                else
                                {
                                    return;
                                }
                                break;
                            }
                        }
                        else
                        {
                            if (client.Connected)
                            {
                                mainPageViewModel.MainViewModel.ErrorService(new ErrorReportTemplate(ErrorType.UnCorrectServerResponse, new Exception("Uncorrect server response")));
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    catch (SocketException ex)
                    {
                        if (client.Connected)
                        {
                            mainPageViewModel.MainViewModel.ErrorService(new ErrorReportTemplate(ErrorType.NoConnectionWithServer, ex));
                        }
                        else
                        {
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (client.Connected)
                        {
                            mainPageViewModel.MainViewModel.ErrorService(new ErrorReportTemplate(ErrorType.Other, ex));
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }