Exemple #1
0
        public static string GetSimpleImageFromUrl(string url)
        {
            try
            {
                var uri = new Uri(url);

                string filename = Path.GetFileName(uri.LocalPath);

                if (filename.EndsWith(".jpg") || filename.EndsWith(".png") || filename.EndsWith(".jpeg") || filename.EndsWith(".gif"))
                {
                    return(url);
                }
                else
                {
                    var             domain    = HttpClientUtility.GetDomainFromUrl(url).ToLower();
                    IAcquisitionAPI simpleApi = null;
                    if (_simpleAPIs.TryGetValue(domain, out simpleApi))
                    {
                        return(simpleApi.GetImageFromUri(uri));
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
            }
            catch
            {
                return(string.Empty);
            }
        }
Exemple #2
0
        public static async Task <IEnumerable <Tuple <string, string> > > GetImagesFromUrl(string title, string url, IResourceNetworkLayer networkLayer, IProgress <float> progress, CancellationToken token)
        {
            try
            {
                var uri = new Uri(url);

                string filename = Path.GetFileName(uri.LocalPath);

                if (filename.EndsWith(".jpg") || filename.EndsWith(".png") || filename.EndsWith(".jpeg") || filename.EndsWith(".gif"))
                {
                    return new Tuple <string, string>[] { Tuple.Create(title, url) }
                }
                ;
                else
                {
                    var domain = HttpClientUtility.GetDomainFromUrl(url).ToLower();

                    IAsyncAcquisitionAPI asyncApi  = null;
                    IAcquisitionAPI      simpleApi = null;
                    if (_simpleAPIs.TryGetValue(domain, out simpleApi))
                    {
                        return(new Tuple <string, string>[] { Tuple.Create(title, simpleApi.GetImageFromUri(uri)) });
                    }
                    else if (_asyncAPIs.TryGetValue(domain, out asyncApi))
                    {
                        return(await asyncApi.GetImagesFromUri(title, uri, networkLayer, progress, token));
                    }
                    else
                    {
                        return(Enumerable.Empty <Tuple <string, string> >());
                    }
                }
            }
            catch
            {
                return(Enumerable.Empty <Tuple <string, string> >());
            }
        }