Ejemplo n.º 1
0
        // Token: 0x0600194C RID: 6476 RVA: 0x000580F0 File Offset: 0x000562F0
        public static DataProviderInformation ProcessResponseStream(Uri responseUri, Encoding responseHeaderEncoding, MemoryStream memoryStream, RequestDetailsLogger logger)
        {
            byte[]   buffer          = memoryStream.GetBuffer();
            string   @string         = WebPageDataProvider.GetString(responseHeaderEncoding, buffer);
            Encoding webPageEncoding = WebPageDataProvider.GetWebPageEncoding(@string, logger);

            if (webPageEncoding != null && !responseHeaderEncoding.Equals(webPageEncoding))
            {
                @string = WebPageDataProvider.GetString(webPageEncoding, buffer);
                logger.Set(GetLinkPreviewMetadata.WebPageEncodingUsed, 1);
            }
            return(new WebPageInformation
            {
                Text = @string,
                ResponseUri = responseUri
            });
        }
        public static LinkPreviewDataProvider GetDataProvider(GetLinkPreviewRequest request, RequestDetailsLogger logger, bool activeViewsConvergenceEnabled)
        {
            Uri uri = LinkPreviewDataProvider.CreateUri(request.Url);
            LinkPreviewDataProvider result;
            Uri uri2;

            if (activeViewsConvergenceEnabled && OEmbedVideoPreviewBuilder.IsOEmbedVideoUri(uri, logger))
            {
                result = new OEmbedDataProvider(uri, request, logger);
            }
            else if (WikipediaLinkPreviewBuilder.TryGetWikipediaServiceUri(uri, out uri2))
            {
                result = new WikipediaDataProvider(uri2, request, logger);
            }
            else
            {
                result = new WebPageDataProvider(uri, request, logger);
            }
            return(result);
        }
Ejemplo n.º 3
0
        // Token: 0x0600194F RID: 6479 RVA: 0x00058208 File Offset: 0x00056408
        private static Encoding GetWebPageEncoding(string webPageString, RequestDetailsLogger logger)
        {
            Encoding  result    = null;
            string    text      = null;
            int       num       = 0;
            Stopwatch stopwatch = Stopwatch.StartNew();

            text = WebPageDataProvider.GetWebPageEncoding(webPageString, WebPageDataProvider.GetXmlEncodingRegEx, "xml encoding");
            num++;
            if (text == null)
            {
                text = WebPageDataProvider.GetWebPageEncoding(webPageString, WebPageDataProvider.GetMetaEncodingRegEx, "meta encoding");
                num++;
            }
            if (text == null)
            {
                text = WebPageDataProvider.GetWebPageEncoding(webPageString, WebPageDataProvider.GetMeta5EncodingRegEx, "meta encoding");
                num++;
            }
            if (text != null)
            {
                try
                {
                    result = Encoding.GetEncoding(text);
                }
                catch (ArgumentException)
                {
                    GetLinkPreview.ThrowInvalidRequestException("GetEncodingFailed", string.Format("Get encoding failed for {0}", text));
                }
            }
            stopwatch.Stop();
            long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            logger.Set(GetLinkPreviewMetadata.EncodingRegExCount, num);
            logger.Set(GetLinkPreviewMetadata.ElapsedTimeToGetWebPageEncoding, elapsedMilliseconds);
            return(result);
        }