public async static Task Run([BlobTrigger("input/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, [Inject] ILogger log, [Inject] IVideoService videoService)
        {
            log.LogInformation($"C# Blob trigger function Processing blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
            await videoService.AddVideo(name);

            log.LogInformation($"C# Blob trigger function Processed");
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(Guid id, VideoViewModel video)//[Bind("Id,Name,Url")] Video video)
        {
            if (ModelState.IsValid)
            {
                Video new_video = await _videService.AddVideo(id, video);

                if (new_video != null)
                {
                    return(RedirectToAction("Details", "Modules", new { id = new_video.Moduleid }));
                }
            }

            return(View(video));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(int id, VideoViewModel video)//[Bind("Id,Name,Url")] Video video)
        {
            if (ModelState.IsValid)
            {
                Video new_video = await _videService.AddVideo(id, video);

                if (new_video != null)
                {
                    return(RedirectToAction("Post", "Publication", new { id = new_video.PublicationId }));
                }
            }

            return(View(video));
        }
Esempio n. 4
0
        public async Task <ActionResult> SaveVideo(VideoViewModel model)
        {
            string virtualSrcPath = "~/Videos/" + User.Identity.Name + "/temporary/videopath/" + model.FileName;
            string srcPath        = Server.MapPath(virtualSrcPath);

            if (System.IO.File.Exists(srcPath))
            {
                if (ModelState.IsValid)
                {
                    using (IVideoService videoService = ServiceCreator.CreateVideoService(Connection))
                    {
                        string virtualDestPath = "~/Content/Videos/" + User.Identity.Name + "/" + model.PlaylistId + "/";
                        string destPath        = Server.MapPath(virtualDestPath);
                        string hashedFileName  = model.FileName.GetHashCode() + DateTime.Now.Ticks + ".mp4";;
                        bool   isExists        = Directory.Exists(destPath);
                        if (!isExists)
                        {
                            Directory.CreateDirectory(destPath);
                        }
                        destPath += hashedFileName;
                        System.IO.File.Copy(srcPath, destPath);
                        System.IO.File.Delete(srcPath);

                        VideoDTO videoDto = new VideoDTO();
                        videoDto.Name        = model.Name;
                        videoDto.IsDeleted   = false;
                        videoDto.Description = model.Description;
                        videoDto.UserName    = User.Identity.Name;
                        videoDto.Path        = virtualDestPath.Substring(1) + hashedFileName;
                        videoDto.PlaylistId  = model.PlaylistId;
                        OperationDetails operationDetail = await videoService.AddVideo(videoDto);

                        return(RedirectToAction("PlaylistConcrete", "Playlist", new { playlistId = model.PlaylistId }));
                    }
                }
                else
                {
                    return(AddVideo(model));
                }
            }
            else
            {
                ModelState.AddModelError("FileNotFound", "Can't found your file. Please try to upload it again.");
                return(AddVideo(model));
            }
        }
        public async Task <IActionResult> Post()
        {
            if (!Request.HasFormContentType)
            {
                return(BadRequest());
            }
            var model = await MultipartRequestHelper.HandleAddVideoRequest(Request, _tempFilesPath, ModelState, _allowedExtensions);

            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }
            if (!TryValidateModel(model))
            {
                return(ValidationProblem(ModelState));
            }
            await _videoService.AddVideo(model);

            return(Ok());
        }
        public async Task <ActionResult> AddVideo([FromForm] VideoAddDto model)
        {
            model.UserId = User.Identity.Name;
            var    files = HttpContext.Request.Form.Files;
            string path  = Path.Combine(Directory.GetCurrentDirectory(), "UsersContent");

            for (int i = 0; i < 2; i++)
            {
                string save = Guid.NewGuid().ToString();
                if (files[i].FileName.Contains(".jpg") || files[i].FileName.Contains(".jpeg"))
                {
                    model.PhotoPath = save + ".jpg";
                    using (var stream = System.IO.File.Create(Path.Combine(path, "VideosPhotos", model.PhotoPath)))
                    {
                        await files[i].CopyToAsync(stream);
                    }
                }
                if (files[i].FileName.Contains(".png"))
                {
                    model.PhotoPath = save + ".png";
                    using (var stream = System.IO.File.Create(Path.Combine(path, "VideosPhotos", model.PhotoPath)))
                    {
                        await files[i].CopyToAsync(stream);
                    }
                }
                if (files[i].FileName.Contains(".mp4"))
                {
                    model.VideoPath = save + ".mp4";
                    using (var stream = System.IO.File.Create(Path.Combine(path, "UsersVideos", model.VideoPath)))
                    {
                        await files[i].CopyToAsync(stream);
                    }
                }
            }

            Guid videoId = await _videoService.AddVideo(model);

            return(Ok(videoId));
        }
 public ActionResult Create(VideoDto model)
 {
     if (ModelState.IsValid)
     {
         var file = Request.Files["ImageInput"];
         if (file != null && file.ContentLength > 0)
         {
             var upload = new UploadUtility(StoreAreaForUpload.ForVideo);
             var result = upload.SharedCoverSaveAs(file);
             if (!result.Success)
             {
                 ModelState.AddModelError("UploadError", result.Message);
                 return(View(model));
             }
             model.ThumbPath = result.Message;
         }
         _videoService.AddVideo(model);
         return(RedirectToAction("Index"));
     }
     BindVideoCategory(model.Category);
     return(View(model));
 }
Esempio n. 8
0
 public ActionResult <bool> AddVideo(VideoNew videoNew)
 {
     LogContent = "新建了监控模型,参数源:" + JsonConvert.SerializeObject(videoNew);
     return(bll.AddVideo(videoNew));
 }
Esempio n. 9
0
        public async Task <IActionResult> Add([FromBody] VideoDto dto)
        {
            await _videoService.AddVideo(dto);

            return(Ok(true));
        }
Esempio n. 10
0
        public async Task <IActionResult> UploadVideo(int?id, IFormFile file)
        {
            try
            {
                if (id == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response <dynamic> {
                        Succeeded = false, Message = "آیتم مورد نظر پیدا نشد"
                    }));
                }
                var center = _centerService.GetById(id.Value);

                if (center == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response <dynamic> {
                        Succeeded = false, Message = "آیتم مورد نظر پیدا نشد"
                    }));
                }
                if (file == null || file.Length <= 0)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response <dynamic> {
                        Succeeded = false, Message = "ویدیو پیدا نشد"
                    }));
                }

                var uploadFolder = Path.Combine(Directory.GetCurrentDirectory(), "UploadedFiles", "Videos");

                if (!Directory.Exists(uploadFolder))
                {
                    Directory.CreateDirectory(uploadFolder);
                }
                var fileName  = id + "-(" + DateTime.Now.ToString("yyyy-M-d-hhmmss") + ")" + Path.GetExtension(file.FileName);
                var finalPath = Path.Combine(uploadFolder, fileName);

                await using (var fileStream = new FileStream(finalPath, FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }
                var video = _videoService.AddVideo(id.Value, fileName);

                var conversionHelper = new ConversionHelper(_videoService);
                _backgroundJob.Enqueue(() => conversionHelper.ConvertVideo(video));

                var oldVideo = _videoService.GetByCenterId(id.Value);
                if (oldVideo != null)
                {
                    _videoService.Delete(oldVideo);
                    var videoConverts = _videoService.GetVideoConverts(oldVideo.Id);
                    foreach (var item in videoConverts)
                    {
                        _videoService.DeleteVideoConvert(item.Id);
                    }
                }
                return(Ok(new Response <dynamic>(finalPath)
                {
                    Message = "ویدیو با موفقیت آپلود شد"
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response <dynamic> {
                    Succeeded = false, Message = e.ToString() + "آپلود ویدیو با خطا مواجه شد"
                }));
            }
        }
        public async Task <IActionResult> Add([FromBody] VideoDto dto)
        {
            await _videoService.AddVideo(dto);

            return(Created(this.Url.Link("GetVideoById", new { Id = dto.Id }), new { Id = dto.Id }));
        }