Ejemplo n.º 1
0
        public async Task Upload(UploadRequestModel request)
        {
            var video = GetVideoFromRequest(request);

            Console.WriteLine("Requesting video upload");
            await youTubeManagerService.Upload(request.Path, video);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Upload([FromForm] UploadRequestModel model)
        {
            try
            {
                // Should probably to nest this upload code in a service, like _postService.Upload(...);
                // Right now it's only for the example
                var stream = new MemoryStream();
                await model.File.CopyToAsync(stream);

                var fileName = Guid.NewGuid().ToString() + Path.GetExtension(model.File.FileName);

                await _fileService.WriteAsync(new ()
                {
                    FileName   = fileName,
                    FileStream = stream
                });

                return(Ok(new UploadResponseModel()
                {
                    FileName = fileName
                }));
            }
            catch (FileUploadException)
            {
                return(BadRequest(new ErrorViewModel()
                {
                    ErrorKey = "upload_failed"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.ToString()));
            }
        }
Ejemplo n.º 3
0
        private static async Task RunAsync(IServiceProvider serviceProvider, string[] args)
        {
            try
            {
                var service = (IYouTubeBusinessManagerService)serviceProvider
                              .GetService(typeof(IYouTubeBusinessManagerService));

                UploadRequestModel inputData = args.Length switch
                {
                    0 => throw new ArgumentException("At least is necessary one parameter"),
                          1 => new UploadRequestModel()
                          {
                              Path = args.First()
                          },
                          _ => Dodo.Console.ConsoleManager.ParseArguments <UploadRequestModel>(args)
                };

                await service.Upload(inputData);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error");
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Execute convert input.
        /// </summary>
        /// <param name="request">RequestModel</param>
        /// <returns>DataModel</returns>
        private UploadDataModel Convert(UploadRequestModel request)
        {
            // Local variable declaration
            UploadDataModel inputObject = null;

            // Variable initialize
            inputObject = new UploadDataModel();

            // Convert data input
            DataHelper.ConvertInput(request, inputObject);

            // Return value
            return(inputObject);
        }
Ejemplo n.º 5
0
 private Video GetVideoFromRequest(UploadRequestModel request)
 {
     return(new Video()
     {
         Snippet = new VideoSnippet()
         {
             Title = request.Title ?? configuration["default:title"],
             Description = request.Description ?? configuration["default:description"],
             CategoryId = request.CategoryId ?? configuration["default:categoryId"],
             ChannelId = request.ChannelId ?? configuration["default:channelId"],
             Tags = request.Tags ?? (string[])configuration.GetValue(typeof(string[]), "default:tags")
         }
     });
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Execute processing.
        /// </summary>
        /// <param name="request">RequestModel</param>
        /// <returns>ResponseModel</returns>
        private UploadResponseModel Execute(UploadRequestModel request)
        {
            // Local variable declaration
            UploadResponseModel responseModel = null;
            UploadDataModel     inputObject   = null;
            UploadDataModel     resultObject  = null;

            // Variable initialize
            responseModel = new UploadResponseModel();

            // Execute convert input.
            inputObject = Convert(request);

            // Check infomation
            Check(inputObject);

            // Upload infomation
            resultObject = UploadInfo(inputObject);

            // Execute convert ouput.
            responseModel = Convert(resultObject);

            return(responseModel);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Upload process.
        /// </summary>
        /// <param name="request">RequestModel</param>
        /// <returns>ResponseModel</returns>
        public UploadResponseModel Invoke(UploadRequestModel request)
        {
            var response = Execute(request);

            return(response);
        }