Example #1
0
    public void BuildText(Site site, PageResources allResources, MarkdownPipeline markdownPipeline)
    {
        switch (Type)
        {
        case ResourceType.None:
            SetHtmlTextAsEmpty();
            return;

        case ResourceType.Markdown:
            BuildMarkdown(site, allResources, markdownPipeline);
            break;

        case ResourceType.RichText:
            try
            {
                HtmlText = RtfUtility.RtfToHtml(File.ReadAllText(FullPath));
            }
            catch (Exception e)
            {
                throw new BuildException(e, $"Error when parsing \"{FullPath}\" into RTF");
            }

            break;

        case ResourceType.Html:
            try
            {
                HtmlText = HtmlUtility.Parse(File.ReadAllText(FullPath));
            }
            catch (Exception e)
            {
                throw new BuildException(e, $"Error when parsing HTML at \"{FullPath}\"");
            }

            break;

        case ResourceType.Generator:
            // Generators are processed during the gather stage.
            return;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Example #2
0
 /// <summary>
 /// Sends the pending results to anyone listening to the event
 /// </summary>
 /// <param name="searchFinished">Has the searched finished.</param>
 void sendPendingResults(bool searchFinished)
 {
     if (HandleResults != null && mSearchParams != null && (!mSearchParams.SortByFile || searchFinished))
     {
         StringBuilder           builder      = new StringBuilder();
         List <SearchResultList> readyResults = null;
         lock (mPendingResults)
         {
             if (mPendingResults.Count > 0)
             {
                 if (mSearchParams.SortByFile)
                 {
                     readyResults = mPendingResults.OrderBy(resultList => resultList.FileName).ToList();
                 }
                 else
                 {
                     readyResults = mPendingResults;
                 }
                 Logger.get().AddDataFormat(mPendingResults, "PendingResults", "Pending results sent for {0} files.", mPendingResults.Count);
                 mPendingResults = new List <SearchResultList>();
             }
         }
         if (readyResults != null && readyResults.Count > 0)
         {
             readyResults.ForEach(result =>
             {
                 String rtf = RtfUtility.createRtf(result, mSearchParams.FileNameSearch, mRegex);
                 builder.AppendLine(rtf);
             });
             if (HandleResults != null)
             {
                 HandleResults(builder.ToString());
             }
             lock (Stats)
             {
                 Stats.ResultsSent += readyResults.Count;
             }
             readyResults.Clear();
         }
     }
 }
Example #3
0
        void Colorize()
        {
#if PARSER
            if (_colorizing)
            {
                return;
            }
            _colorizing = true;
            var text = EditBox.Text;
            var sel  = EditBox.SelectionStart;
            EditBox.Clear();
            var sb = new StringBuilder();
            sb.Append("{\\rtf1");
            sb.Append(RtfUtility.ToColorTable(
                          Color.Black,
                          Color.DarkGreen,
                          Color.DarkRed,
                          Color.DarkOliveGreen,
                          Color.Blue,
                          Color.DarkCyan,
                          Color.BlueViolet,
                          Color.DarkGray));
            var p    = new EbnfParser(ParseContext.Create(text));
            var pos  = 0L;
            var cols = new Stack <int>();
            cols.Push(0);
            while (p.Read())
            {
                switch (p.NodeType)
                {
                case LLNodeType.NonTerminal:
                    switch (p.SymbolId)
                    {
                    case EbnfParser.attribute:
                        cols.Push(3);
                        break;

                    case EbnfParser.symbol:
                    case EbnfParser.expressions:
                        cols.Push(4);
                        break;

                    default:
                        cols.Push(0);
                        break;
                    }
                    break;

                case LLNodeType.EndNonTerminal:
                    cols.Pop();
                    break;

                case LLNodeType.Terminal:
                case LLNodeType.Error:
                    if (p.Position > pos)
                    {
                        sb.Append("\\cf1 ");
                        sb.Append(RtfUtility.Escape(text.Substring((int)pos, (int)(p.Position - pos))));
                    }
                    if (LLNodeType.Error == p.NodeType)
                    {
                        sb.Append("\\cf2");
                    }
                    else
                    {
                        sb.Append("\\cf");

                        switch (p.SymbolId)
                        {
                        case EbnfParser.literal:
                            sb.Append(5);
                            break;

                        case EbnfParser.regex:
                            sb.Append(6);
                            break;


                        default:
                            sb.Append(cols.Peek());
                            break;
                        }
                    }
                    sb.Append(RtfUtility.Escape(p.Value));
                    pos = p.Position + p.Value.Length;
                    break;
                }
            }
            sb.Append("}");
            System.Diagnostics.Debug.WriteLine(sb.ToString());
            EditBox.Rtf            = sb.ToString();
            EditBox.SelectionStart = sel;
            _colorizing            = false;
#endif
        }