Ejemplo n.º 1
0
        public async Task <RequestEngineResult> ApproveAlbum(AlbumRequest request)
        {
            if (request == null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = "Request does not exist"
                });
            }

            request.MarkedAsApproved = DateTime.Now;
            request.Approved         = true;
            request.Denied           = false;
            await MusicRepository.Update(request);


            var canNotify = await RunSpecificRule(request, SpecificRules.CanSendNotification);

            if (canNotify.Success)
            {
                NotificationHelper.Notify(request, NotificationType.RequestApproved);
            }

            if (request.Approved)
            {
                var result = await _musicSender.Send(request);

                if (result.Success && result.Sent)
                {
                    return(new RequestEngineResult
                    {
                        Result = true
                    });
                }

                if (!result.Success)
                {
                    Logger.LogWarning("Tried auto sending album but failed. Message: {0}", result.Message);
                    return(new RequestEngineResult
                    {
                        Message = result.Message,
                        ErrorMessage = result.Message,
                        Result = false
                    });
                }

                // If there are no providers then it's successful but movie has not been sent
            }

            return(new RequestEngineResult
            {
                Result = true
            });
        }
Ejemplo n.º 2
0
        public async Task Start()
        {
            // Get all the failed ones!
            var failedRequests = _requestQueue.GetAll().Where(x => !x.Completed.HasValue);

            foreach (var request in failedRequests)
            {
                if (request.Type == RequestType.Movie)
                {
                    var movieRequest = await _movieRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _movieSender.Send(movieRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.TvShow)
                {
                    var tvRequest = await _tvRequestRepository.GetChild().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _tvSender.Send(tvRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.Album)
                {
                    var musicRequest = await _musicRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _musicSender.Send(musicRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public async Task Execute(IJobExecutionContext job)
        {
            // Get all the failed ones!
            var failedRequests = _requestQueue.GetAll().Where(x => x.Completed == null);

            foreach (var request in failedRequests)
            {
                if (request.Type == RequestType.Movie)
                {
                    var movieRequest = await _movieRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (movieRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _movieSender.Send(movieRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.TvShow)
                {
                    var tvRequest = await _tvRequestRepository.GetChild().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (tvRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _tvSender.Send(tvRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.Album)
                {
                    var musicRequest = await _musicRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (musicRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _musicSender.Send(musicRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
            }
        }