Beispiel #1
0
        private MockEmailAttachment[] GetAttachments(IEmployer employer, ICollection <Guid> attachmentIds)
        {
            if (attachmentIds == null || attachmentIds.Count == 0)
            {
                return(null);
            }

            var attachments    = _employerMemberContactsQuery.GetMessageAttachments(employer, attachmentIds);
            var fileReferences = _filesQuery.GetFileReferences(from a in attachments select a.FileReferenceId, new Range());

            return((from f in fileReferences select new MockEmailAttachment {
                Name = f.FileName, MediaType = f.MediaType
            }).ToArray());
        }
        private void Validate(Guid employerId, IEnumerable <Guid> existingAttachmentIds, FileContents fileContents, string fileName)
        {
            // Must have appropriate file extension.

            var extension = Path.GetExtension(fileName).ToLower();

            if (!Constants.ValidFileExtensions.Contains(extension))
            {
                throw new InvalidFileNameException {
                          FileName = fileName, ValidFileExtensions = Constants.ValidFileExtensions
                }
            }
            ;

            // Must not be too large.

            if (fileContents.Length > Constants.MaxAttachmentFileSize)
            {
                throw new FileTooLargeException {
                          MaxFileSize = Constants.MaxAttachmentFileSize
                }
            }
            ;

            // The total mmust not be too large.

            var attachments = _repository.GetMessageAttachments(employerId, existingAttachmentIds);

            if (attachments.Count > 0)
            {
                var fileReferences = _filesQuery.GetFileReferences(from a in attachments select a.FileReferenceId, new Range());
                var totalSize      = attachments.Sum(a => (from f in fileReferences where f.Id == a.FileReferenceId select f).Single().FileData.ContentLength);
                if (totalSize + fileContents.Length > Constants.MaxAttachmentTotalFileSize)
                {
                    throw new TotalFilesTooLargeException {
                              MaxTotalFileSize = Constants.MaxAttachmentTotalFileSize
                    }
                }
                ;
            }
        }
    }
}
Beispiel #3
0
        void IMessagesHandler.OnMessageSent(Guid fromId, Guid toId, Guid?representativeId, MemberMessage message)
        {
            var member   = _membersQuery.GetMember(toId);
            var employer = _employersQuery.GetEmployer(fromId);

            IList <FileReference> fileReferences = null;

            if (message.AttachmentIds != null && message.AttachmentIds.Count > 0)
            {
                var messageAttachments = _employerMemberContactsQuery.GetMessageAttachments(employer, message.AttachmentIds);
                fileReferences = _filesQuery.GetFileReferences(from a in messageAttachments select a.FileReferenceId, new Range());
            }

            // Create the email to send to the member and send it.

            TemplateEmail email;

            if (representativeId == null)
            {
                email = new ContactCandidateEmail(member, message.From, employer, message.Subject, GetMemberBody(message.Body, member));
            }
            else
            {
                var representative = _membersQuery.GetMember(representativeId.Value);
                email = new RepresentativeContactCandidateEmail(representative, message.From, employer, member, message.Subject, GetMemberBody(message.Body, member));
            }

            AddAttachments(email, fileReferences);
            _emailsCommand.TrySend(email);

            // Create the email to the employer and send it.

            if (message.SendCopy)
            {
                // Need the view.

                var view = _employerMemberViewsQuery.GetProfessionalView(employer, member);
                var confirmationEmail = new EmployerContactCandidateConfirmationEmail(message.From, employer, member.Id, view.GetFullNameDisplayText(), message.Subject, GetEmployerBody(message.Body, view));
                AddAttachments(confirmationEmail, fileReferences);
                _emailsCommand.TrySend(confirmationEmail);
            }
        }