예제 #1
0
        private void EmailList_AddNewEmailAddress(object sender, EventArgs e)
        {
            NewEmailAddress newEmail = new NewEmailAddress(_parent);

            newEmail.ReadyButtonClicked += (s, ea) =>
            {
                if (ea.UseLoginPassword)
                {
                    ea.Login    = CryptographyHelper.EncodeString(ea.Login);
                    ea.Password = CryptographyHelper.EncodeString(ea.Password);

                    RegistryHelper.AddRegistryValue(CryptographyHelper.HashString(ea.Address, 0), ea.Password);
                }
                else
                {
                    ea.Login    = "";
                    ea.Password = "";
                }

                _parent.Client.AddNewEmailAddress(ea);

                _parent.mainCanvas.Children.Remove(newEmail);
                _parent.Darkened = false;
            };

            newEmail.CancelButtonClicked += (s, ea) =>
            {
                _parent.mainCanvas.Children.Remove(newEmail);
                _parent.Darkened = false;
            };

            _parent.Darkened = true;
            _parent.mainCanvas.Children.Add(newEmail);
        }
예제 #2
0
        public async Task TestCreate_LikeContactEmailAddress()
        {
            var userId    = 1;
            var user      = new User(userId);
            var email1    = "*****@*****.**";
            var fullName  = "Full Name";
            var position  = "Star Lord";
            var isPrimary = true;

            var newEmail1 = new NewEmailAddress(user, EmailAddressType.Business.Id, email1, isPrimary);

            var additionalPointOfContact = new AdditionalPointOfContact(user, fullName, position, new List <NewEmailAddress> {
                newEmail1
            }, new List <NewPhoneNumber>());

            Action beforeTester = () =>
            {
                Assert.AreEqual(0, context.PhoneNumbers.Count());
                Assert.AreEqual(1, context.EmailAddresses.Count());
                Assert.AreEqual(0, context.Contacts.Count());
            };
            Action <AdditionalPointOfContactValidationEntity> validationEntityTester = (entity) =>
            {
                Assert.AreEqual(fullName, entity.FullName);
                Assert.AreEqual(position, entity.Position);
            };
            Action afterTester = () =>
            {
                Assert.AreEqual(1, context.Contacts.Count());
            };

            context.SetupActions.Add(() =>
            {
                context.EmailAddresses.Add(new EmailAddress
                {
                    ContactId = 1,
                    Address   = email1
                });
            });
            validator.Setup(x => x.ValidateCreate(It.IsAny <AdditionalPointOfContactValidationEntity>())).Callback(validationEntityTester);
            context.Revert();
            beforeTester();
            service.Create(additionalPointOfContact);
            afterTester();

            context.Revert();
            beforeTester();
            await service.CreateAsync(additionalPointOfContact);

            afterTester();
        }
예제 #3
0
        public void TestConstructor()
        {
            var emailTypeId = EmailAddressType.Home.Id;
            var email       = "*****@*****.**";
            var isPrimary   = true;
            var user        = new User(1);
            var model       = new NewEmailAddress(user, emailTypeId, email, isPrimary);

            Assert.AreEqual(emailTypeId, model.EmailAddressTypeId);
            Assert.AreEqual(email, model.Address);
            Assert.AreEqual(isPrimary, model.IsPrimary);
            Assert.AreEqual(user.Id, model.Audit.User.Id);
            Assert.IsInstanceOfType(model.Audit, typeof(Create));
        }
예제 #4
0
        public async Task TestCreate_EmailAddressValueIsWhitespace()
        {
            var    userId    = 1;
            var    user      = new User(userId);
            string email1    = String.Empty;
            var    fullName  = "Full Name";
            var    position  = "Star Lord";
            var    isPrimary = true;

            var newEmail1 = new NewEmailAddress(user, EmailAddressType.Business.Id, email1, isPrimary);
            var additionalPointOfContact = new AdditionalPointOfContact(user, fullName, position, new List <NewEmailAddress> {
                newEmail1
            }, new List <NewPhoneNumber>());

            Action beforeTester = () =>
            {
                Assert.AreEqual(0, context.PhoneNumbers.Count());
                Assert.AreEqual(0, context.EmailAddresses.Count());
                Assert.AreEqual(0, context.Contacts.Count());
            };
            Action afterTester = () =>
            {
                Assert.AreEqual(1, context.Contacts.Count());
                Assert.AreEqual(0, context.EmailAddresses.Count());
            };

            context.Revert();
            beforeTester();
            service.Create(additionalPointOfContact);
            afterTester();

            context.Revert();
            beforeTester();
            await service.CreateAsync(additionalPointOfContact);

            afterTester();
        }
예제 #5
0
        public async Task TestCreate_CheckProperties()
        {
            var userId          = 1;
            var user            = new User(userId);
            var phoneNumber1    = "555-555-1212";
            var phoneNumber1ext = "123";
            var phoneNumber2    = "123-456-7890";
            var phoneNumber2ext = "123";
            var email1          = "*****@*****.**";
            var email2          = "*****@*****.**";
            var fullName        = "Full Name";
            var position        = "Star Lord";
            var isPrimaryEmail  = true;
            var isPrimaryPhone  = true;

            var newEmail1 = new NewEmailAddress(user, EmailAddressType.Business.Id, email1, isPrimaryEmail);
            var newEmail2 = new NewEmailAddress(user, EmailAddressType.Home.Id, email2, false);

            var newPhone1 = new NewPhoneNumber(user, PhoneNumberType.Cell.Id, phoneNumber1, phoneNumber1ext, isPrimaryPhone);
            var newPhone2 = new NewPhoneNumber(user, PhoneNumberType.Home.Id, phoneNumber2, phoneNumber2ext, false);

            var additionalPointOfContact = new AdditionalPointOfContact(user, fullName, position, new List <NewEmailAddress> {
                newEmail1, newEmail2
            }, new List <NewPhoneNumber> {
                newPhone1, newPhone2
            });

            Action beforeTester = () =>
            {
                Assert.AreEqual(0, context.PhoneNumbers.Count());
                Assert.AreEqual(0, context.EmailAddresses.Count());
                Assert.AreEqual(0, context.Contacts.Count());
            };
            Action <AdditionalPointOfContactValidationEntity> validationEntityTester = (entity) =>
            {
                Assert.AreEqual(fullName, entity.FullName);
                Assert.AreEqual(position, entity.Position);
                Assert.AreEqual(1, entity.NumberOfPrimaryEmailAddresses);
                Assert.AreEqual(1, entity.NumberOfPrimaryPhoneNumbers);
            };
            Action afterTester = () =>
            {
                Assert.AreEqual(1, context.Contacts.Count());
                Assert.AreEqual(2, context.EmailAddresses.Count());
                Assert.AreEqual(2, context.PhoneNumbers.Count());

                var pointOfContact = context.Contacts.First();
                Assert.AreEqual(fullName, pointOfContact.FullName);
                Assert.AreEqual(position, pointOfContact.Position);
                Assert.AreEqual(userId, pointOfContact.History.CreatedBy);
                Assert.AreEqual(userId, pointOfContact.History.RevisedBy);
                DateTimeOffset.Now.Should().BeCloseTo(pointOfContact.History.CreatedOn, 20000);
                DateTimeOffset.Now.Should().BeCloseTo(pointOfContact.History.RevisedOn, 20000);
                Assert.AreEqual(2, pointOfContact.EmailAddresses.Count);
                Assert.AreEqual(2, pointOfContact.PhoneNumbers.Count);

                var firstEmail  = pointOfContact.EmailAddresses.First();
                var secondEmail = pointOfContact.EmailAddresses.Last();
                Assert.IsTrue(context.EmailAddresses.Contains(firstEmail));
                Assert.IsTrue(context.EmailAddresses.Contains(secondEmail));
                Assert.AreEqual(newEmail1.EmailAddressTypeId, firstEmail.EmailAddressTypeId);
                Assert.AreEqual(newEmail1.Address, firstEmail.Address);
                Assert.IsTrue(firstEmail.IsPrimary.Value);
                Assert.AreEqual(newEmail2.EmailAddressTypeId, secondEmail.EmailAddressTypeId);
                Assert.AreEqual(newEmail2.Address, secondEmail.Address);
                Assert.IsFalse(secondEmail.IsPrimary.Value);

                Assert.AreEqual(userId, firstEmail.History.CreatedBy);
                Assert.AreEqual(userId, firstEmail.History.RevisedBy);
                DateTimeOffset.Now.Should().BeCloseTo(firstEmail.History.CreatedOn, 20000);
                DateTimeOffset.Now.Should().BeCloseTo(firstEmail.History.RevisedOn, 20000);

                Assert.AreEqual(userId, secondEmail.History.CreatedBy);
                Assert.AreEqual(userId, secondEmail.History.RevisedBy);
                DateTimeOffset.Now.Should().BeCloseTo(secondEmail.History.CreatedOn, 20000);
                DateTimeOffset.Now.Should().BeCloseTo(secondEmail.History.RevisedOn, 20000);

                var firstPhone  = pointOfContact.PhoneNumbers.First();
                var secondPhone = pointOfContact.PhoneNumbers.Last();
                Assert.IsTrue(context.PhoneNumbers.Contains(firstPhone));
                Assert.IsTrue(context.PhoneNumbers.Contains(secondPhone));
                Assert.AreEqual(newPhone1.PhoneNumberTypeId, firstPhone.PhoneNumberTypeId);
                Assert.AreEqual(newPhone1.Number, firstPhone.Number);
                Assert.AreEqual(newPhone1.Extension, firstPhone.Extension);
                Assert.IsTrue(firstPhone.IsPrimary.Value);
                Assert.AreEqual(newPhone2.PhoneNumberTypeId, secondPhone.PhoneNumberTypeId);
                Assert.AreEqual(newPhone2.Number, secondPhone.Number);
                Assert.AreEqual(newPhone2.Extension, secondPhone.Extension);
                Assert.IsFalse(secondPhone.IsPrimary.Value);

                Assert.AreEqual(userId, firstPhone.History.CreatedBy);
                Assert.AreEqual(userId, firstPhone.History.RevisedBy);
                DateTimeOffset.Now.Should().BeCloseTo(firstPhone.History.CreatedOn, 20000);
                DateTimeOffset.Now.Should().BeCloseTo(firstPhone.History.RevisedOn, 20000);

                Assert.AreEqual(userId, secondPhone.History.CreatedBy);
                Assert.AreEqual(userId, secondPhone.History.RevisedBy);
                DateTimeOffset.Now.Should().BeCloseTo(secondPhone.History.CreatedOn, 20000);
                DateTimeOffset.Now.Should().BeCloseTo(secondPhone.History.RevisedOn, 20000);
            };

            validator.Setup(x => x.ValidateCreate(It.IsAny <AdditionalPointOfContactValidationEntity>())).Callback(validationEntityTester);
            context.Revert();
            beforeTester();
            service.Create(additionalPointOfContact);
            afterTester();

            context.Revert();
            beforeTester();
            await service.CreateAsync(additionalPointOfContact);

            afterTester();
        }
예제 #6
0
        public void Receiver()
        {
            try
            {
                string conversationId       = "";
                string id                   = "";
                bool   notifyContactPersons = false;
                string emailId              = "";
                string emailAddress         = "";
                while (_client.Connected)
                {
                    byte response = _reader.ReadByte();
                    switch (response)
                    {
                    case MessageDictionary.NewNotification:
                        _writer.Write(MessageDictionary.OK);

                        List <string> referenceFields = new List <string>();

                        string   notificationId   = _reader.ReadString();
                        string   notificationText = _reader.ReadString();
                        DateTime notificationDate = DateTime.ParseExact(_reader.ReadString(), "dd-MM-yyyy HH:mm:ss",
                                                                        CultureInfo.InvariantCulture);
                        int referenceFieldCount = _reader.ReadInt32();

                        for (int i = 0; i < referenceFieldCount; i++)
                        {
                            referenceFields.Add(_reader.ReadString());
                        }

                        if (_reader.Read() == MessageDictionary.EndOfMessage)
                        {
                            switch (_reader.ReadByte())
                            {
                                #region NewMessage

                            case MessageDictionary.NewMessage:
                                id             = _reader.ReadString();
                                conversationId = _reader.ReadString();
                                string authorId          = _reader.ReadString();
                                string authorFrom        = _reader.ReadString();
                                string initialDateString = _reader.ReadString();

                                byte[] previewData = ReceiveFile();

                                List <string> attachmentIds = new List <string>();

                                int attachmentCount = _reader.ReadInt32();

                                for (int j = 0; j < attachmentCount; j++)
                                {
                                    attachmentIds.Add(_reader.ReadString());
                                }

                                MemoryStream stream = new MemoryStream(previewData);

                                BitmapImage previewImage = new BitmapImage();
                                previewImage.BeginInit();
                                previewImage.StreamSource = stream;
                                previewImage.EndInit();
                                previewImage.Freeze();

                                byte type = _reader.ReadByte();

                                DateTime initialDate = DateTime.ParseExact(initialDateString,
                                                                           "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                                ConversationMessageModel message = new ConversationMessageModel(id,
                                                                                                conversationId,
                                                                                                authorId,
                                                                                                authorFrom, initialDate, true, previewImage, false, attachmentIds);

                                switch (type)
                                {
                                case MessageDictionary.MessageTypeEmail:
                                    string subject = _reader.ReadString();
                                    string content = _reader.ReadString();

                                    ConversationEmailMessageModel emailMessage =
                                        new ConversationEmailMessageModel(message,
                                                                          subject, content);
                                    message = emailMessage;
                                    break;

                                case MessageDictionary.MessageTypePhoneCall:
                                    string recipientPhoneNumber = _reader.ReadString();
                                    string description          = _reader.ReadString();
                                    bool   answered             = _reader.ReadBoolean();

                                    ConversationPhoneMessageModel phoneMessage =
                                        new ConversationPhoneMessageModel(message, recipientPhoneNumber,
                                                                          description, answered);
                                    message = phoneMessage;
                                    break;
                                }

                                NewConversationMessageArrived?.Invoke(this,
                                                                      new NewConversationMessageArrivedEventArgs()
                                {
                                    Message      = message,
                                    Notification =
                                        new NotificationModel(notificationId, notificationText,
                                                              referenceFields,
                                                              notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RenameConversation

                            case MessageDictionary.RenameConversation:
                                conversationId = _reader.ReadString();
                                string oldName = _reader.ReadString();
                                string newName = _reader.ReadString();

                                ConversationRenamed?.Invoke(this, new ConversationRenamedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    OldName        = oldName,
                                    NewName        = newName,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RenameFile

                            case MessageDictionary.RenameFile:
                                conversationId = _reader.ReadString();
                                oldName        = _reader.ReadString();
                                newName        = _reader.ReadString();

                                FileRenamed?.Invoke(this, new FileRenamedEventArgs()
                                {
                                    FileId       = conversationId,
                                    OldName      = oldName,
                                    NewName      = newName,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region AddConversationMembers

                            case MessageDictionary.AddConversationMembers:
                                conversationId = _reader.ReadString();
                                string personId    = _reader.ReadString();
                                string personColor = _reader.ReadString();

                                ConversationMembersAdded?.Invoke(this,
                                                                 new ConversationMembersAddedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    PersonId       = personId,
                                    PersonColor    = personColor,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RemoveConversationMember

                            case MessageDictionary.RemoveConversationMember:
                                conversationId = _reader.ReadString();
                                personId       = _reader.ReadString();

                                ConversationMemberRemoved?.Invoke(this,
                                                                  new ConversationMemberRemovedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    PersonId       = personId,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;

                                #endregion

                                #region ConversationSettingsChanged

                            case MessageDictionary.ChangeConversationSettings:
                                conversationId       = _reader.ReadString();
                                notifyContactPersons = _reader.ReadBoolean();
                                ConversationSettingsChanged?.Invoke(this,
                                                                    new ConversationSettingsChangedEventArgs()
                                {
                                    ConversationId       = conversationId,
                                    NotifyContactPersons = notifyContactPersons,
                                    Notification         = new NotificationModel(notificationId, notificationText,
                                                                                 referenceFields,
                                                                                 notificationDate, false)
                                });
                                break;

                                #endregion

                                #region NewCompany

                            case MessageDictionary.NewCompany:
                                string companyId   = _reader.ReadString();
                                string companyName = _reader.ReadString();

                                NewCompanyArrived?.Invoke(this, new NewCompanyEventArgs()
                                {
                                    Company      = new CompanyModel(companyId, companyName),
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RenameCompany

                            case MessageDictionary.RenameCompany:
                                companyId = _reader.ReadString();
                                newName   = _reader.ReadString();

                                CompanyRenamed?.Invoke(this, new CompanyRenamedEventArgs()
                                {
                                    CompanyId    = companyId,
                                    NewName      = newName,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RemoveCompanyEvent

                            case MessageDictionary.RemoveCompany:
                                companyId = _reader.ReadString();

                                CompanyRemoved?.Invoke(this, new CompanyRemovedEventArgs()
                                {
                                    CompanyId    = companyId,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region UpdatePersonDetails

                            case MessageDictionary.UpdatePersonDetails:

                                string PersonId         = _reader.ReadString();
                                string PersonFirstName  = _reader.ReadString();
                                string PersonLastName   = _reader.ReadString();
                                string PersonGenderCode = _reader.ReadString();
                                string PersonCompanyId  = _reader.ReadString();

                                Gender PersonGender = (Gender)Convert.ToInt32(PersonGenderCode);

                                PersonModel contactPerson = new PersonModel(PersonId, PersonFirstName, PersonLastName,
                                                                            PersonGender,
                                                                            PersonCompanyId, true);

                                int emailAddressCount = _reader.ReadInt32();

                                for (int j = 0; j < emailAddressCount; j++)
                                {
                                    emailId = _reader.ReadString();
                                    string emailName = _reader.ReadString();
                                    emailAddress = _reader.ReadString();

                                    EmailAddressModel emailAddressModel = new EmailAddressModel(emailId,
                                                                                                emailAddress,
                                                                                                emailName);
                                    contactPerson.EmailAddresses.Add(emailAddressModel);
                                }

                                int phoneNumberCount = _reader.ReadInt32();

                                for (int j = 0; j < phoneNumberCount; j++)
                                {
                                    string phoneNumberId = _reader.ReadString();
                                    string phoneName     = _reader.ReadString();
                                    string phoneNumber   = _reader.ReadString();

                                    PhoneNumberModel phoneNumberModel = new PhoneNumberModel(phoneNumberId, phoneNumber,
                                                                                             phoneName);
                                    contactPerson.PhoneNumbers.Add(phoneNumberModel);
                                }

                                ContactDetailsUpdated?.Invoke(this, new ContactDetailsUpdatedEventArgs()
                                {
                                    NewData      = contactPerson,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region NewExternalContact

                            case MessageDictionary.NewExternalContact:
                                _writer.Write(MessageDictionary.OK);

                                PersonId         = _reader.ReadString();
                                PersonFirstName  = _reader.ReadString();
                                PersonLastName   = _reader.ReadString();
                                PersonGenderCode = _reader.ReadString();
                                PersonCompanyId  = _reader.ReadString();

                                PersonGender = (Gender)Convert.ToInt32(PersonGenderCode);

                                contactPerson = new PersonModel(PersonId, PersonFirstName, PersonLastName,
                                                                PersonGender,
                                                                PersonCompanyId, true);

                                emailAddressCount = _reader.ReadInt32();

                                for (int j = 0; j < emailAddressCount; j++)
                                {
                                    emailId = _reader.ReadString();
                                    string emailName = _reader.ReadString();
                                    emailAddress = _reader.ReadString();

                                    EmailAddressModel emailAddressModel = new EmailAddressModel(emailId, emailAddress,
                                                                                                emailName);
                                    contactPerson.EmailAddresses.Add(emailAddressModel);
                                }

                                phoneNumberCount = _reader.ReadInt32();

                                for (int j = 0; j < phoneNumberCount; j++)
                                {
                                    string phoneNumberId = _reader.ReadString();
                                    string phoneName     = _reader.ReadString();
                                    string phoneNumber   = _reader.ReadString();

                                    PhoneNumberModel phoneNumberModel = new PhoneNumberModel(phoneNumberId, phoneNumber,
                                                                                             phoneName);
                                    contactPerson.PhoneNumbers.Add(phoneNumberModel);
                                }

                                NewExternalContact?.Invoke(this, new NewExternalContactEventArgs()
                                {
                                    NewData      = contactPerson,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region NewExternalContact

                            case MessageDictionary.RemoveExternalContact:

                                personId = _reader.ReadString();

                                ExternalContactRemoved?.Invoke(this, new ExternalContactRemovedEventArgs()
                                {
                                    PersonId     = personId,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;
                                #endregion

                                #region RemoveConversation
                            case MessageDictionary.RemoveConversation:
                                _writer.Write(MessageDictionary.OK);
                                conversationId = _reader.ReadString();

                                ConversationRemoved?.Invoke(this, new ConversationRemovedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;
                                #endregion
                            }
                        }
                        break;

                        #region NewFiles

                    case MessageDictionary.NewFiles:
                        List <FileModel> files = new List <FileModel>();
                        files.Clear();
                        _writer.Write(MessageDictionary.OK);
                        int fileCount = _reader.ReadInt32();

                        for (int i = 0; i < fileCount; i++)
                        {
                            conversationId = _reader.ReadString();
                            id             = _reader.ReadString();
                            string    name        = _reader.ReadString();
                            string    contentType = _reader.ReadString();
                            long      size        = _reader.ReadInt64();
                            string    dateAdded   = _reader.ReadString();
                            FileModel file        = new FileModel(id, name, new ContentType(contentType), size,
                                                                  DateTime.ParseExact(dateAdded, "dd-MM-yyyy", CultureInfo.InvariantCulture))
                            {
                                ConversationId = conversationId
                            };

                            files.Add(file);
                        }

                        NewFilesArrived?.Invoke(this, new NewFilesArrivedEventArgs()
                        {
                            Files = files
                        });
                        break;

                        #endregion

                        #region NewConversation

                    case MessageDictionary.NewConversation:
                        _writer.Write(MessageDictionary.OK);

                        conversationId = _reader.ReadString();
                        string conversationName  = _reader.ReadString();
                        string visibleId         = _reader.ReadString();
                        string dateCreatedString = _reader.ReadString();
                        notifyContactPersons = _reader.ReadBoolean();


                        DateTime dateCreated = DateTime.ParseExact(dateCreatedString, "dd-MM-yyyy HH:mm:ss",
                                                                   CultureInfo.InvariantCulture);

                        int memberCount = _reader.ReadInt32();

                        List <string> memberIds    = new List <string>();
                        List <string> memberColors = new List <string>();
                        for (int j = 0; j < memberCount; j++)
                        {
                            string memberId    = _reader.ReadString();
                            string memberColor = _reader.ReadString();

                            memberIds.Add(memberId);
                            memberColors.Add(memberColor);
                        }

                        List <ConversationMessageModel> messages = new List <ConversationMessageModel>();

                        if (_reader.Read() == MessageDictionary.OK)
                        {
                            int messageCount = _reader.ReadInt32();
                            for (int i = 0; i < messageCount; i++)
                            {
                                id = _reader.ReadString();
                                string  authorId          = _reader.ReadString();
                                string  authorFrom        = _reader.ReadString();
                                string  initialDateString = _reader.ReadString();
                                Boolean received          = _reader.ReadBoolean();

                                byte[] previewData = ReceiveFile();

                                List <string> attachmentIds = new List <string>();

                                int attachmentCount = _reader.ReadInt32();

                                for (int j = 0; j < attachmentCount; j++)
                                {
                                    attachmentIds.Add(_reader.ReadString());
                                }

                                MemoryStream stream       = new MemoryStream(previewData);
                                BitmapImage  previewImage = new BitmapImage();
                                previewImage.BeginInit();
                                previewImage.StreamSource = stream;
                                previewImage.EndInit();

                                previewImage.Freeze();

                                DateTime initialDate = DateTime.ParseExact(initialDateString, "dd-MM-yyyy HH:mm:ss",
                                                                           CultureInfo.InvariantCulture);
                                ConversationMessageModel message = new ConversationMessageModel(id, conversationId,
                                                                                                authorId,
                                                                                                authorFrom, initialDate, received, previewImage, false, attachmentIds);

                                byte type = _reader.ReadByte();

                                if (type == MessageDictionary.MessageTypeEmail)
                                {
                                    string subject = _reader.ReadString();
                                    string content = _reader.ReadString();

                                    ConversationEmailMessageModel emailMessage =
                                        new ConversationEmailMessageModel(message,
                                                                          subject, content);
                                    message = emailMessage;
                                }
                                else if (type == MessageDictionary.MessageTypePhoneCall)
                                {
                                    string recipientPhoneNumber = _reader.ReadString();
                                    string callDescription      = _reader.ReadString();
                                    bool   callAnswered         = _reader.ReadBoolean();
                                    ConversationPhoneMessageModel phoneMessage =
                                        new ConversationPhoneMessageModel(message, recipientPhoneNumber,
                                                                          callDescription, callAnswered);
                                    message = phoneMessage;
                                }

                                if (message != null)
                                {
                                    messages.Add(message);
                                }
                            }

                            if (_reader.Read() == MessageDictionary.EndOfMessage)
                            {
                                ConversationModel conversation = new ConversationModel(conversationId,
                                                                                       conversationName, visibleId, dateCreated,
                                                                                       memberIds, memberColors, notifyContactPersons);
                                messages.ForEach(obj => conversation.AddMessage(obj));
                                NewConversationArrived?.Invoke(this,
                                                               new NewConversationArrivedEventArgs()
                                {
                                    Conversation = conversation
                                });
                            }
                        }
                        break;

                        #endregion

                        #region RemoveConversation

                    case MessageDictionary.RemoveConversation:
                        _writer.Write(MessageDictionary.OK);
                        conversationId = _reader.ReadString();
                        ConversationRemoved?.Invoke(this,
                                                    new ConversationRemovedEventArgs()
                        {
                            ConversationId = conversationId
                        });
                        break;

                        #endregion

                        #region NewEmailAddress

                    case MessageDictionary.AddEmailAddress:
                        _writer.Write(MessageDictionary.OK);

                        emailId      = _reader.ReadString();
                        emailAddress = _reader.ReadString();
                        string login       = _reader.ReadString();
                        string imapHost    = _reader.ReadString();
                        int    imapPort    = _reader.ReadInt32();
                        bool   imapUseSel  = _reader.ReadBoolean();
                        string smtpHost    = _reader.ReadString();
                        int    smtpPort    = _reader.ReadInt32();
                        bool   smtpUseSsl  = _reader.ReadBoolean();
                        string addressName = _reader.ReadString();

                        NewEmailAddress?.Invoke(this, new NewEmailAddressEventArgs()
                        {
                            Id         = emailId,
                            Login      = login,
                            Address    = emailAddress,
                            ImapHost   = imapHost,
                            ImapPort   = imapPort,
                            ImapUseSsl = imapUseSel,
                            SmtpHost   = smtpHost,
                            SmtpPort   = smtpPort,
                            SmtpUseSsl = smtpUseSsl,
                            Name       = addressName
                        });

                        break;

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
                ErrorHelper.LogError(ex);
                Logout();
            }
        }