コード例 #1
0
        public async Task <OperationStatus> AddThumbnailFor(string fileID, Stream fileStream)
        {
            var opStatus = new OperationStatus();

            AirshowUtils.ConfirmDirectoryExistsOrCreate(ImagesDirectory);
            fileStream.Seek(0, SeekOrigin.Begin);

            var pdfInput   = GeneratePathForFileIdWithExtension(fileID, "pdf");
            var jpegOutput = GeneratePathForFileIdWithExtension(fileID, "jpeg");

            using (var phyisicalFileStream = File.Create(pdfInput))
            {
                await fileStream.CopyToAsync(phyisicalFileStream);
            }

            System.Diagnostics.Process clientProcess = new Process();
            clientProcess.StartInfo.FileName  = "java";
            clientProcess.StartInfo.Arguments = @"-jar " + JarPath + " " + $"PDFThumbGenerator {pdfInput} {jpegOutput}";
            clientProcess.Start();
            clientProcess.WaitForExit();
            File.Delete(pdfInput);

            int code = clientProcess.ExitCode;

            if (code != 0)
            {
                opStatus.ErrorMessageIfAny = "An error ocurred during the generation of the image";
            }


            return(opStatus);
        }
コード例 #2
0
        public async Task <OperationResult <string> > SaveFile(Stream fileStream)
        {
            var fileId = Guid.NewGuid().ToString("N");

            fileStream.Seek(0, SeekOrigin.Begin);
            var thumbResult = await _thumbnailsRepo.AddThumbnailFor(fileId, fileStream);

            if (thumbResult.ErrorMessageIfAny != null)
            {
                return(new OperationResult <string>
                {
                    ErrorMessageIfAny = thumbResult.ErrorMessageIfAny
                });
            }


            var newFile = new PresentationFile();

            newFile.FileID = fileId;
            await _context.PresentationFiles.AddAsync(newFile);

            await _context.SaveChangesAsync();



            var filePathResult = CreatePathFor(fileId);

            if (filePathResult.ErrorMessageIfAny != null)
            {
                return(new OperationResult <string>
                {
                    ErrorMessageIfAny = filePathResult.ErrorMessageIfAny
                });
            }

            var fs = AirshowUtils.CreateFileToWriteAtPath(filePathResult.Value);

            if (fs == null)
            {
                return(new OperationResult <string>
                {
                    ErrorMessageIfAny = OperationStatus.kInvalidFileNameOrAlreadyExists
                });
            }
            fileStream.Seek(0, SeekOrigin.Begin);
            await fileStream.CopyToAsync(fs);


            fs.Dispose();

            return(new OperationResult <string>
            {
                Value = newFile.FileID
            });
        }
コード例 #3
0
        private OperationResult <string> GetOrCreateUploadsDirectory()
        {
            var directory = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "userUploads";
            var result    = AirshowUtils.ConfirmDirectoryExistsOrCreate(directory);

            if (result.ErrorMessageIfAny != null)
            {
                return(new OperationResult <string>
                {
                    ErrorMessageIfAny = result.ErrorMessageIfAny
                });
            }
            return(new OperationResult <string>
            {
                Value = directory
            });
        }