Beispiel #1
0
 public void Teardown()
 {
     _indexer    = null;
     _nOffset    = 0;
     _sFragments = null;
     _nOffsets   = null;
 }
Beispiel #2
0
 public void Setup()
 {
     _indexer    = new HtmlIndexer();
     _nOffset    = 0;
     _sFragments = new ArrayList();
     _nOffsets   = new ArrayList();
 }
 private void Indexing()
 {
     _indexer = new HtmlIndexer(_webSite.WebSiteIndex, _webSite.WebSiteUrl); //c:\index   http://blog.codinghorror.com/
     if (WebSite.NewIndex)
     {
         _indexer.AddDirectory(new DirectoryInfo(_webSite.WebSiteLocation), "*.htm*");   //\blog.codinghorror.com
     }
     _indexer.Close();
     _searcher     = new Searcher(_webSite.WebSiteIndex);
     SearchEnabled = true;
     BusyIndicator = false;
 }
Beispiel #4
0
 static bool ProcessResourceTextImpl(IResource res, IResourceTextConsumer consumer)
 {
     OutlookProcessor.CheckState();
     try
     {
         OutlookProcessor processor = OutlookSession.OutlookProcessor;
         if (processor != null)
         {
             MailBodyDescriptorDelegate myDelegate = CreateMailBodyDescriptor;
             MailBodyDescriptor         mailBody   = (MailBodyDescriptor)processor.RunUniqueJob(myDelegate, res);
             if (mailBody != null && Core.State != CoreState.ShuttingDown)
             {
                 //  Order of sections: Source, Subject, Body.
                 IResource resPerson  = res.GetLinkProp(Core.ContactManager.Props.LinkFrom);
                 IResource resAccount = res.GetLinkProp(PROP.EmailAccountFrom);
                 if (resPerson != null)
                 {
                     //  Construct [From] section out of contact name and its account
                     string fromText = resPerson.DisplayName;
                     if (resAccount != null)
                     {
                         fromText += " " + resAccount.DisplayName;
                     }
                     consumer.AddDocumentFragment(res.Id, fromText, DocumentSection.SourceSection);
                 }
                 consumer.AddDocumentHeading(res.Id, mailBody.Subject);
                 consumer.RestartOffsetCounting();
                 if (mailBody.IsHTML)
                 {
                     HtmlIndexer.IndexHtml(res, mailBody.Body, consumer, DocumentSection.BodySection);
                 }
                 else
                 {
                     consumer.AddDocumentFragment(res.Id, mailBody.Body.Replace("\r\n", "\n"));
                 }
             }
         }
     }
     catch (OutlookThreadTimeoutException)
     {
         if (consumer.Purpose == TextRequestPurpose.Indexing)
         {
             // retry indexing of the email later
             Guard.QueryIndexingWithCheckId(res);
         }
         return(false);
     }
     return(true);
 }
Beispiel #5
0
        bool IResourceTextProvider.ProcessResourceText(IResource res, IResourceTextConsumer consumer)
        {
            if (res != null)
            {
                int id = res.Id;
//                if (res.Type == NntpPlugin._newsArticle || res.Type == NntpPlugin._newsLocalArticle)
                if (NntpPlugin.IsNntpType(res.Type))
                {
                    string text = res.GetPropText(Core.Props.LongBody);
                    if (text.Trim().Length > 0)
                    {
                        consumer.AddDocumentFragment(id, text);
                    }
                    else
                    {
                        HtmlIndexer.IndexHtml(res, res.GetPropText(NntpPlugin._propHtmlContent), consumer, DocumentSection.BodySection);
                    }
                    consumer.RestartOffsetCounting();
                    consumer.AddDocumentHeading(id, res.GetPropText(Core.Props.Subject));

                    IResource author  = res.GetLinkProp(Core.ContactManager.Props.LinkFrom);
                    IResource account = res.GetLinkProp(Core.ContactManager.Props.LinkEmailAcctFrom);
                    if (author != null)
                    {
                        //  Construct [From] section out of contact name and its account
                        string fromText = author.DisplayName;
                        if (account != null)
                        {
                            fromText += " " + account.DisplayName;
                        }
                        consumer.AddDocumentFragment(id, fromText + " ", DocumentSection.SourceSection);
                    }
                    IResourceList groups = res.GetLinksOfType(NntpPlugin._newsGroup, NntpPlugin._propTo);
                    foreach (IResource group in groups)
                    {
                        consumer.AddDocumentFragment(id, group.GetPropText(Core.Props.Name) + " ", DocumentSection.SourceSection);
                    }
                }
                else
                {
                    IResource article = res.GetLinkProp(NntpPlugin._propAttachment);
                    if (article != null && NntpPlugin.IsNntpType(article.Type))
                    {
                        consumer.AddDocumentHeading(id, res.GetPropText(Core.Props.Name));
                    }
                }
            }
            return(true);
        }
Beispiel #6
0
        public void CheckOffsetsTags()
        {
            string sBody = "<html>Welcome</br>to <b>hell</b>&nbsp;</html>";

            HtmlIndexer.IndexHtml(0xCD, sBody, this, null);

            Assert.AreEqual(_sFragments.Count, 4);

            Assert.AreEqual(_sFragments[0], "Welcome");
            Assert.AreEqual(_sFragments[1], "to ");
            Assert.AreEqual(_sFragments[2], "hell");
            Assert.AreEqual(_sFragments[3], " ");

            Assert.AreEqual(_nOffsets[0], sBody.IndexOf("Welcome"));
            Assert.AreEqual(_nOffsets[1], sBody.IndexOf("to"));
            Assert.AreEqual(_nOffsets[2], sBody.IndexOf("hell"));
            Assert.AreEqual(_nOffsets[3], sBody.IndexOf("&nbsp;"));
        }
Beispiel #7
0
        public void CheckOffsetsSimple()
        {
            string sBody = "Here comes the &lt;nite&gt;!";

            HtmlIndexer.IndexHtml(0xCD, sBody, this, null);

            Assert.AreEqual(_sFragments.Count, 4);

            Assert.AreEqual(_sFragments[0], "Here ");
            Assert.AreEqual(_sFragments[1], "comes ");
            Assert.AreEqual(_sFragments[2], "the <");
            Assert.AreEqual(_sFragments[3], "nite>!");

            Assert.AreEqual(_nOffsets[0], sBody.IndexOf("Here"));
            Assert.AreEqual(_nOffsets[1], sBody.IndexOf("comes"));
            Assert.AreEqual(_nOffsets[2], sBody.IndexOf("the"));
            Assert.AreEqual(_nOffsets[3], sBody.IndexOf("nite"));
        }
Beispiel #8
0
        internal static void RunConverter(string fileName, IResourceTextConsumer consumer, IResource res)
        {
            Process process = CreateConverterProcess(fileName, true);

            try
            {
                if (!process.Start())
                {
                    throw new Exception();
                }
            }
            catch
            {
                return;
            }
            try
            {
                Encoding     utf8         = new UTF8Encoding(false, false);
                StreamReader outputReader = new StreamReader(process.StandardOutput.BaseStream, utf8);

                string content = Utils.StreamReaderReadToEnd(outputReader);

                consumer.RestartOffsetCounting();                       // Just in case ;)
                HtmlIndexer.IndexHtml(res, content, consumer, DocumentSection.BodySection);
            }
            finally
            {
                string stderr = Utils.StreamReaderReadToEnd(process.StandardError);
                process.WaitForExit();
                if (process.ExitCode != 0)
                {
                    throw new Exception(_converterName + " (Excel-to-HTML) has performed an invalid operation while converting \"" + fileName + "\". " + stderr);
                }
            }
            return;
        }
Beispiel #9
0
 private static void ProcessHTMLFragment(IResource res, IResourceTextConsumer consumer)
 {
     HtmlIndexer.IndexHtml(res, res.GetPropText(Core.Props.LongBody), consumer, null);
 }