コード例 #1
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);
 }
コード例 #2
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);
        }
コード例 #3
0
ファイル: HtmlIndexerTests.cs プロジェクト: mo5h/omeo
        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;"));
        }
コード例 #4
0
ファイル: HtmlIndexerTests.cs プロジェクト: mo5h/omeo
        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"));
        }
コード例 #5
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;
        }
コード例 #6
0
 private static void ProcessHTMLFragment(IResource res, IResourceTextConsumer consumer)
 {
     HtmlIndexer.IndexHtml(res, res.GetPropText(Core.Props.LongBody), consumer, null);
 }