/// <summary>
        /// Method that process the url
        /// </summary>
        /// <param name="request">Information sent by the browser about the request</param>
        /// <param name="response">Information that is being sent back to the client.</param>
        /// <param name="session">Session used to </param>
        /// <returns>true if this module handled the request.</returns>
        public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            Uri uri = request.Uri;

            if (!uri.AbsolutePath.StartsWith("/FanartService"))
            {
                return(false);
            }

            IFanArtService fanart = ServiceRegistration.Get <IFanArtService>(false);

            if (fanart == null)
            {
                return(false);
            }

            FanArtConstants.FanArtMediaType mediaType;
            FanArtConstants.FanArtType      fanArtType;
            int maxWidth;
            int maxHeight;

            if (!Enum.TryParse(request.Param["mediatype"].Value, out mediaType))
            {
                return(false);
            }
            if (!Enum.TryParse(request.Param["fanarttype"].Value, out fanArtType))
            {
                return(false);
            }
            string name = request.Param["name"].Value;

            if (string.IsNullOrWhiteSpace(name))
            {
                return(false);
            }

            name = name.Decode(); // For safe handling of "&" character in name

            // Both values are optional
            int.TryParse(request.Param["width"].Value, out maxWidth);
            int.TryParse(request.Param["height"].Value, out maxHeight);

            IList <FanArtImage> files = fanart.GetFanArt(mediaType, fanArtType, name, maxWidth, maxHeight, true);

            if (files == null || files.Count == 0)
            {
#if DEBUG
                ServiceRegistration.Get <ILogger>().Debug("No FanArt for {0} '{1}' of type '{2}'", name, fanArtType, mediaType);
#endif
                return(false);
            }

            using (MemoryStream memoryStream = new MemoryStream(files[0].BinaryData))
                SendWholeStream(response, memoryStream, false);
            return(true);
        }
        /// <summary>
        /// Method that process the url
        /// </summary>
        public override async Task Invoke(IOwinContext context)
        {
            var request  = context.Request;
            var response = context.Response;
            Uri uri      = request.Uri;

            if (!uri.AbsolutePath.StartsWith(ResourceHttpAccessUrlUtils.RESOURCE_SERVER_BASE_PATH) || !uri.AbsolutePath.Contains("/FanartService"))
            {
                await Next.Invoke(context);

                return;
            }

            IFanArtService fanart = ServiceRegistration.Get <IFanArtService>(false);

            if (fanart == null)
            {
                return;
            }

            string mediaType  = request.Query["mediatype"];
            string fanArtType = request.Query["fanarttype"];
            int    maxWidth;
            int    maxHeight;
            string name = request.Query["name"];

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }

            name = name.Decode(); // For safe handling of "&" character in name

            // Both values are optional
            int.TryParse(request.Query["width"], out maxWidth);
            int.TryParse(request.Query["height"], out maxHeight);

            IList <FanArtImage> files = fanart.GetFanArt(mediaType, fanArtType, name, maxWidth, maxHeight, true);

            if (files == null || files.Count == 0)
            {
#if DEBUG
                ServiceRegistration.Get <ILogger>().Debug("No FanArt for {0} '{1}' of type '{2}'", name, fanArtType, mediaType);
#endif
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            using (MemoryStream memoryStream = new MemoryStream(files[0].BinaryData))
                await SendWholeStream(response, memoryStream, false);
        }
Example #3
0
        /// <summary>
        /// Method that process the url
        /// </summary>
        /// <param name="request">Information sent by the browser about the request</param>
        /// <param name="response">Information that is being sent back to the client.</param>
        /// <param name="session">Session used to </param>
        /// <returns>true if this module handled the request.</returns>
        public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            Uri uri = request.Uri;

            if (!uri.AbsolutePath.StartsWith("/FanartService"))
            {
                return(false);
            }

            IFanArtService fanart = ServiceRegistration.Get <IFanArtService>(false);

            if (fanart == null)
            {
                return(false);
            }

            FanArtConstants.FanArtMediaType mediaType;
            FanArtConstants.FanArtType      fanArtType;
            int maxWidth;
            int maxHeight;

            if (uri.Segments.Length < 4)
            {
                return(false);
            }
            if (!Enum.TryParse(GetSegmentWithoutSlash(uri, 2), out mediaType))
            {
                return(false);
            }
            if (!Enum.TryParse(GetSegmentWithoutSlash(uri, 3), out fanArtType))
            {
                return(false);
            }
            string name = GetSegmentWithoutSlash(uri, 4);

            // Both values are optional
            int.TryParse(GetSegmentWithoutSlash(uri, 5), out maxWidth);
            int.TryParse(GetSegmentWithoutSlash(uri, 6), out maxHeight);

            IList <FanArtImage> files = fanart.GetFanArt(mediaType, fanArtType, name, maxWidth, maxHeight, true);

            if (files == null || files.Count == 0)
            {
                return(false);
            }

            using (MemoryStream memoryStream = new MemoryStream(files[0].BinaryData))
                SendWholeStream(response, memoryStream, false);
            return(true);
        }
        protected void Download_Async()
        {
            if (!_asyncStarted)
            {
                IFanArtService fanArtService = ServiceRegistration.Get <IFanArtService>(false);
                if (fanArtService == null)
                {
                    return;
                }

                IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();
                threadPool.Add(() =>
                {
                    IList <FanArtImage> possibleSources = fanArtService.GetFanArt(FanArtMediaType, FanArtType, FanArtName, MaxWidth, MaxHeight, true);
                    lock (_syncObj)
                        _possibleSources = possibleSources;
                });
                _asyncStarted = true;
            }
        }
        private UPnPError OnGetFanArt(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IFanArtService fanArtService = ServiceRegistration.Get <IFanArtService>();

            if (fanArtService == null)
            {
                return(new UPnPError(500, "FanArt service not available"));
            }

            FanArtConstants.FanArtMediaType fanArtMediaType = (FanArtConstants.FanArtMediaType)Enum.Parse(typeof(FanArtConstants.FanArtMediaType), inParams[0].ToString());
            FanArtConstants.FanArtType      fanArtType      = (FanArtConstants.FanArtType)Enum.Parse(typeof(FanArtConstants.FanArtType), inParams[1].ToString());
            string name         = inParams[2].ToString();
            int    maxWidth     = (int)inParams[3];
            int    maxHeight    = (int)inParams[4];
            bool   singleRandom = (bool)inParams[5];

            IList <FanArtImage> fanArtImages = fanArtService.GetFanArt(fanArtMediaType, fanArtType, name, maxWidth, maxHeight, singleRandom) ?? new List <FanArtImage>();

            outParams = new List <object> {
                fanArtImages
            };
            return(null);
        }