Exemplo n.º 1
0
        public async Task <IList <FileModel> > SaveVideoAsync(IEnumerable <HttpPostedFileBase> files, string path = null)
        {
            var fileList = new List <FileModel>();

            if (files == null)
            {
                return(fileList);
            }
            foreach (var file in files)
            {
                // var validationFormat = await _videoValidator.GetFormatAsync(file);
                //var validationResolution = await _videoValidator.GetResolutionAsync(file);



                //if (validationResolution != null)
                //    throw new ArgumentNullException(nameof(validationResolution));
                //if (validationSize != null)
                //    throw new ArgumentNullException(nameof(validationSize));
                if (path == null)
                {
                    path = FileConst.VideosWebPath;
                }

                var fileSaved = new FileModel()
                {
                    Id        = SequentialGuidGenerator.NewSequentialGuid(),
                    Name      = SequentialGuidGenerator.NewSequentialGuid() + Path.GetExtension(file.FileName),
                    Type      = FileConst.FileType,
                    Extension = Path.GetExtension(file.FileName),
                    Size      = file.ContentLength,
                    Path      = path
                };
                //if (validationFormat != null)
                //    throw new ArgumentNullException(nameof(validationFormat));
                //var name = path + Path.GetFileName(fileSaved.Name);
                //var validationSize = await _videoValidator.GetSizeAsync(name);
                //if (validationSize != null)
                //    throw new ArgumentNullException(nameof(validationFormat));

                var byteFile = await ConvertToByteArrayAsync(file);

                var pathToSave = Path.Combine(path, fileSaved.Name);
                await CreateFileAsync(byteFile, fileSaved.Name, path);

                var thumbPath       = HttpContext.Current.Server.MapPath(FileConst.ThumbPath);
                var pathThumbToSave = Path.Combine(thumbPath, fileSaved.Name);
                await _videoManager.ResolveMetadataAsync(pathToSave);

                // if(_configurationManager.VideoWaterMark.ToBoolean() == true)
                //await _videoManager.WatermarkWithCustomTextAsync(pathToSave);
                await _videoManager.GenerateThumbnailAsync(pathToSave);

                //ToDo UnComment When Needed
                // await _videoManager.CutDownAsync(pathToSave);
                // await _videoManager.WatermarkMediaAsync(pathToSave, string.Empty, VideoEnums.WatermarkType.NovinakAndCompanyName, VideoEnums.WatermarkPosition.BottomRight, string.Empty);

                fileList.Add(fileSaved);
            }
            return(fileList);
        }
Exemplo n.º 2
0
        public async Task <IList <FileModel> > SaveImageAsync(IEnumerable <HttpPostedFileBase> files, string path = null, ImageProcessType imageType = ImageProcessType.Nan)
        {
            var fileList = new List <FileModel>();

            if (files == null)
            {
                return(fileList);
            }
            foreach (var file in files)
            {
                if (imageType == ImageProcessType.Attachment)
                {
                    var validationFormat = await _imageValidation.GetFormatAttachment(file);

                    if (validationFormat != null)
                    {
                        throw new ArgumentNullException(nameof(validationFormat));
                    }
                }
                else
                {
                    var validationFormat = await _imageValidation.GetFormatImage(file);

                    if (validationFormat != null)
                    {
                        throw new ArgumentNullException(nameof(validationFormat));
                    }
                }

                if (path == null)
                {
                    path = FileConst.ImagesWebPath;
                }
                var fileSaved = new FileModel()
                {
                    Id        = SequentialGuidGenerator.NewSequentialGuid(),
                    Name      = SequentialGuidGenerator.NewSequentialGuid() + Path.GetExtension(file.FileName),
                    Type      = FileConst.FileType,
                    Extension = Path.GetExtension(file.FileName),
                    Size      = file.ContentLength,
                    Path      = path
                };
                var byteFile = await ConvertToByteArrayAsync(file);

                var pathToSave = Path.Combine(path, fileSaved.Name);
                await CreateFileAsync(byteFile, fileSaved.Name, path);

                if (imageType != ImageProcessType.Attachment)
                {
                    var thumbPath       = HttpContext.Current.Server.MapPath(FileConst.ThumbPath);
                    var pathThumbToSave = Path.Combine(thumbPath, fileSaved.Name);
                }

                fileList.Add(fileSaved);
                switch (imageType)
                {
                case ImageProcessType.ProductImage:
                    await _imageBuilder.ProductImageProcessAsync(pathToSave);

                    break;

                case ImageProcessType.CompanyCoverFileName:
                    await _imageBuilder.CompanyCoverFileProcessAsync(pathToSave);

                    break;

                case ImageProcessType.LogoFileName:
                    await _imageBuilder.LogoProcessAsync(pathToSave);

                    break;

                case ImageProcessType.CompanyImages:
                    await _imageBuilder.CompanyImagesFileProcessAsync(pathToSave);

                    break;

                case ImageProcessType.ProductImages:
                    await _imageBuilder.ProductImageProcessAsync(pathToSave);

                    break;
                }
            }
            return(fileList);
        }