Ejemplo n.º 1
0
 bool IResourceTextProvider.ProcessResourceText(IResource resource, IResourceTextConsumer consumer)
 {
     try
     {
         StreamReader reader = Core.FileResourceManager.GetStreamReader(resource);
         if (reader != null)
         {
             using ( reader )
             {
                 // for weblinks, detect & set charset if it is not set
                 IResource source = resource.GetLinkProp("Source");
                 if (source != null)
                 {
                     string charset = source.GetPropText(Core.FileResourceManager.PropCharset);
                     if (charset.Length == 0)
                     {
                         charset = HtmlTools.DetectCharset(reader);
                         new ResourceProxy(source).SetPropAsync(Core.FileResourceManager.PropCharset, charset);
                         reader.BaseStream.Position = 0;
                     }
                 }
                 ProcessResourceStream(resource, source, reader, consumer);
             }
         }
     }
     catch (ObjectDisposedException)
     {
         Core.TextIndexManager.QueryIndexing(resource.Id);
     }
     return(true);
 }
Ejemplo n.º 2
0
        private TextReader OpenHTMLReader(Stream readStream, string charset)
        {
            if (charset == null)
            {
                readStream.Seek(0, SeekOrigin.Begin);
                charset = HtmlTools.DetectCharset(new StreamReader(readStream));
            }
            readStream.Seek(0, SeekOrigin.Begin);
            Encoding enc;

            try
            {
                enc = Encoding.GetEncoding(charset);
            }
            catch (Exception)
            {
                enc = Encoding.Default;
            }

            return(new StreamReader(readStream, enc));
        }