Ejemplo n.º 1
0
        public bool LoadRegex(string apiBase)
        {
            try
            {
                using (var client = new OTWebClient()
                {
                    Timeout = 1000
                })
                    using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(client.DownloadData(apiBase + "regex.json"), XmlDictionaryReaderQuotas.Max))
                    {
                        var xElm = XElement.Load(jsonReader);

                        lock (this.LockObj)
                        {
                            this.UrlRegex = xElm.Elements("item")
                                            .Select(e => new Regex(e.Element("regex").Value, RegexOptions.IgnoreCase))
                                            .ToArray();

                            this.ApiBase = apiBase;
                        }
                    }

                return(true);
            }
            catch (WebException) { }

            return(false);
        }
Ejemplo n.º 2
0
        public override ThumbnailInfo GetThumbnailInfo(string url, PostClass post)
        {
            var apiUrl = base.ReplaceUrl(url);

            if (apiUrl == null)
            {
                return(null);
            }

            using (var client = new OTWebClient())
                using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(client.DownloadData(apiUrl), XmlDictionaryReaderQuotas.Max))
                {
                    var xElm = XElement.Load(jsonReader);

                    var thumbUrlElm = xElm.XPathSelectElement("/response/post/thumb_url");
                    if (thumbUrlElm == null)
                    {
                        return(null);
                    }

                    var textElm = xElm.XPathSelectElement("/response/post/text");

                    return(new ThumbnailInfo()
                    {
                        ImageUrl = url,
                        ThumbnailUrl = thumbUrlElm.Value,
                        TooltipText = textElm == null ? null : textElm.Value,
                    });
                }
        }
 protected virtual string FetchImageUrl(string url)
 {
     using (var client = new OTWebClient())
     {
         return client.DownloadString(url);
     }
 }
 protected virtual string FetchImageUrl(string url)
 {
     using (var client = new OTWebClient())
     {
         return(client.DownloadString(url));
     }
 }
Ejemplo n.º 5
0
        public override ThumbnailInfo GetThumbnailInfo(string url, PostClass post)
        {
            var apiUrl = base.ReplaceUrl(url);
            if (apiUrl == null) return null;

            using (var client = new OTWebClient())
            using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(client.DownloadData(apiUrl), XmlDictionaryReaderQuotas.Max))
            {
                var xElm = XElement.Load(jsonReader);

                var thumbUrlElm = xElm.XPathSelectElement("/response/post/thumb_url");
                if (thumbUrlElm == null)
                {
                    return null;
                }

                var textElm = xElm.XPathSelectElement("/response/post/text");

                return new ThumbnailInfo()
                {
                    ImageUrl = url,
                    ThumbnailUrl = thumbUrlElm.Value,
                    TooltipText = textElm == null ? null : textElm.Value,
                };
            }
        }
Ejemplo n.º 6
0
 protected virtual byte[] FetchRegex(string apiBase)
 {
     using (var client = new OTWebClient()
     {
         Timeout = 1000
     })
     {
         return(client.DownloadData(apiBase + "regex.json"));
     }
 }
Ejemplo n.º 7
0
        public virtual Task<MemoryImage> LoadThumbnailImageAsync(CancellationToken token)
        {
            var client = new OTWebClient();

            var task = client.DownloadDataAsync(new Uri(this.ThumbnailUrl), token)
                .ContinueWith(t => MemoryImage.CopyFromBytes(t.Result), TaskScheduler.Default);

            task.ContinueWith(_ => client.Dispose(), TaskScheduler.Default);

            return task;
        }
Ejemplo n.º 8
0
            public override Task<MemoryImage> LoadThumbnailImageAsync(CancellationToken token)
            {
                var client = new OTWebClient();

                client.UserAgent = MyCommon.GetUserAgentString(fakeMSIE: true);
                client.Headers[HttpRequestHeader.Referer] = this.ImageUrl;

                var task = client.DownloadDataAsync(new Uri(this.ThumbnailUrl), token)
                    .ContinueWith(t => MemoryImage.CopyFromBytes(t.Result), TaskScheduler.Default);

                task.ContinueWith(_ => client.Dispose(), TaskScheduler.Default);

                return task;
            }
Ejemplo n.º 9
0
        protected virtual string FetchThumbnailUrl(string url)
        {
            using (var client = new OTWebClient())
            {
                var content = client.DownloadString(url);
                var matches = MetaThumbnailService.metaPattern.Matches(content);

                foreach (Match match in matches)
                {
                    var propertyName = match.Groups["property"].Value;
                    if (MetaThumbnailService.propertyNames.Contains(propertyName))
                    {
                        return(match.Groups["content"].Value);
                    }
                }

                return(null);
            }
        }
Ejemplo n.º 10
0
        protected virtual string FetchThumbnailUrl(string url)
        {
            using (var client = new OTWebClient())
            {
                var content = client.DownloadString(url);
                var matches = MetaThumbnailService.metaPattern.Matches(content);

                foreach (Match match in matches)
                {
                    var propertyName = match.Groups["property"].Value;
                    if (MetaThumbnailService.propertyNames.Contains(propertyName))
                    {
                        return match.Groups["content"].Value;
                    }
                }

                return null;
            }
        }
Ejemplo n.º 11
0
        public bool LoadRegex(string apiBase)
        {
            try
            {
                using (var client = new OTWebClient() { Timeout = 1000 })
                using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(client.DownloadData(apiBase + "regex.json"), XmlDictionaryReaderQuotas.Max))
                {
                    var xElm = XElement.Load(jsonReader);

                    lock (this.LockObj)
                    {
                        this.UrlRegex = xElm.Elements("item")
                            .Select(e => new Regex(e.Element("regex").Value, RegexOptions.IgnoreCase))
                            .ToArray();

                        this.ApiBase = apiBase;
                    }
                }

                return true;
            }
            catch (WebException) { }

            return false;
        }
Ejemplo n.º 12
0
 protected virtual byte[] FetchRegex(string apiBase)
 {
     using (var client = new OTWebClient() { Timeout = 1000 })
     {
         return client.DownloadData(apiBase + "regex.json");
     }
 }