コード例 #1
0
ファイル: FilesTestExtensions.cs プロジェクト: formist/LinkMe
 public static FileReference CreateTestPhoto(this IFilesCommand filesCommand, int index, FileType fileType)
 {
     using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(FilesTestExtensions), "TestPhoto.jpg"))
     {
         return(filesCommand.SaveFile(fileType, new StreamFileContents(stream), string.Format(PhotoFileNameFormat, index)));
     }
 }
コード例 #2
0
ファイル: PreviewLogoTests.cs プロジェクト: formist/LinkMe
        private void AddLogo(JobAd jobAd)
        {
            var filePath = FileSystem.GetAbsolutePath(@"Test\Data\Photos\ProfilePhoto.jpg", RuntimeEnvironment.GetSourceFolder());

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    // Load the contents from the file.

                    using (var reader = new BinaryReader(File.OpenRead(filePath)))
                    {
                        var count  = 4096;
                        var buffer = new byte[count];
                        while ((count = reader.Read(buffer, 0, count)) > 0)
                        {
                            writer.Write(buffer, 0, count);
                        }
                    }

                    stream.Position = 0;
                    var fileReference = _filesCommand.SaveFile(FileType.CompanyLogo, new StreamFileContents(stream), Path.GetFileName(filePath));

                    jobAd.LogoId = fileReference.Id;
                    _jobAdsCommand.UpdateJobAd(jobAd);
                }
            }
        }
コード例 #3
0
ファイル: FilesTestExtensions.cs プロジェクト: formist/LinkMe
 public static FileReference CreateTestFile(this IFilesCommand filesCommand, int index, FileType fileType)
 {
     using (var stream = new MemoryStream(new ASCIIEncoding().GetBytes(string.Format(ContentsFormat, index))))
     {
         return(filesCommand.SaveFile(fileType, new StreamFileContents(stream), string.Format(FileNameFormat, index)));
     }
 }
コード例 #4
0
 protected FileReference SaveFile(FileType fileType, string contents, string fileName)
 {
     using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
     {
         return(_filesCommand.SaveFile(fileType, new StreamFileContents(stream), fileName));
     }
 }
コード例 #5
0
        private FileReference GetResumeFile(TestResume testResume)
        {
            const string fileName = "resume.doc";
            var          data     = testResume.GetData();

            using (var stream = new MemoryStream(data))
            {
                return(_filesCommand.SaveFile(FileType.Resume, new StreamFileContents(stream), fileName));
            }
        }
コード例 #6
0
        public void TestCompleteResume()
        {
            var candidate = new Candidate {
                Id = Guid.NewGuid()
            };

            _candidatesCommand.CreateCandidate(candidate);

            const string fileName = "resume.doc";
            var          data     = TestResume.Complete.GetData();

            FileReference fileReference;

            using (var stream = new MemoryStream(data))
            {
                fileReference = _filesCommand.SaveFile(FileType.Resume, new StreamFileContents(stream), fileName);
            }

            var resume = _parseResumesCommand.ParseResume(data, fileName).Resume;

            _candidateResumesCommand.CreateResume(candidate, resume, fileReference);

            AssertResume(_candidatesCommand.GetCandidate(candidate.Id), resume, fileReference);
        }
コード例 #7
0
        private Member CreateMember()
        {
            var member = CreateMember(0);

            const string  fileName = "resume.doc";
            var           data     = TestResume.Complete.GetData();
            FileReference fileReference;

            using (var stream = new MemoryStream(data))
            {
                fileReference = _filesCommand.SaveFile(FileType.Resume, new StreamFileContents(stream), fileName);
            }

            var resume    = _parseResumesCommand.ParseResume(fileReference).Resume;
            var candidate = _candidatesCommand.GetCandidate(member.Id);

            _candidateResumesCommand.CreateResume(candidate, resume);
            return(member);
        }
コード例 #8
0
        FileReference IEmployerLogosCommand.SaveLogo(FileContents fileContents, string fileName)
        {
            var extension = Path.GetExtension(fileName);

            if (string.IsNullOrEmpty(extension))
            {
                throw new InvalidImageExtensionException(extension);
            }
            extension = extension.TrimStart('.');
            if (!_imagesCommand.IsValidFileExtension(extension))
            {
                throw new InvalidImageExtensionException(extension);
            }

            // Save it after cropping it to an appropriate size.

            using (var stream = _imagesCommand.Crop(fileContents.GetStream(), Roles.JobAds.Constants.LogoMaxSize, _imagesCommand.GetFormat(extension)))
            {
                return(_filesCommand.SaveFile(FileType.CompanyLogo, new StreamFileContents(stream), fileName));
            }
        }
コード例 #9
0
        MemberMessageAttachment IEmployerMemberContactsCommand.CreateMessageAttachment(IEmployer employer, IEnumerable <Guid> existingAttachmentIds, FileContents fileContents, string fileName)
        {
            // Check first.

            Validate(employer.Id, existingAttachmentIds, fileContents, fileName);

            // Save the file.

            var fileReference = _filesCommand.SaveFile(FileType.Attachment, fileContents, fileName);

            // Create the attachment to be saved.

            var attachment = new MemberMessageAttachment {
                FileReferenceId = fileReference.Id
            };

            attachment.Prepare();
            attachment.Validate();
            _repository.CreateMessageAttachment(employer.Id, attachment);

            return(attachment);
        }
コード例 #10
0
ファイル: MemberPhotosCommand.cs プロジェクト: formist/LinkMe
        FileReference IMemberPhotosCommand.SavePhoto(FileContents fileContents, string fileName)
        {
            var extension = Path.GetExtension(fileName);

            if (string.IsNullOrEmpty(extension))
            {
                throw new InvalidImageExtensionException(extension);
            }
            extension = extension.TrimStart('.');
            if (!_imagesCommand.IsValidFileExtension(extension))
            {
                throw new InvalidImageExtensionException(extension);
            }
            fileName = Path.ChangeExtension(fileName, StorageExtension);

            // Save it after converting it to an appropriate size and format.

            using (var stream = _imagesCommand.Resize(fileContents.GetStream(), Domain.Contacts.Constants.PhotoMaxSize, StorageFormat))
            {
                return(_filesCommand.SaveFile(FileType.ProfilePhoto, new StreamFileContents(stream), fileName));
            }
        }
コード例 #11
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            try
            {
                if (file == null)
                {
                    throw new ValidationErrorsException(new RequiredValidationError("file"));
                }

                var member    = CurrentMember;
                var candidate = _candidatesQuery.GetCandidate(member.Id);

                // Do a check first.

                var fileName     = Path.GetFileName(file.FileName);
                var fileContents = new HttpPostedFileContents(file);
                _candidateResumeFilesCommand.ValidateFile(fileName, fileContents);

                // Save the file and associate it with the candidate.

                var fileReference = _filesCommand.SaveFile(FileType.Resume, fileContents, fileName);
                _candidateResumesCommand.CreateResumeFile(candidate, fileReference);

                // Must send text/plain mime type for legacy browsers.

                return(Json(new JsonResumeFileModel
                {
                    Id = fileReference.Id,
                    Name = fileName,
                    Size = file.ContentLength,
                }, MediaType.Text));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel(), MediaType.Text));
        }