Ejemplo n.º 1
0
            public void InstantiateIn(Control c)
            {
                SourceItem container = (SourceItem)c;

                Label line = new Label();

                line.CssClass = "shl_ln";
                line.Text     = container.LineNumber.ToString();
                container.Controls.Add(line);

                container.Controls.Add(new LiteralControl(Environment.NewLine));
            }
Ejemplo n.º 2
0
            public void InstantiateIn(Control c)
            {
                SourceItem container = (SourceItem)c;

                container.Controls.Add(new LiteralControl(container.SourceLine + Environment.NewLine));
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the controls which form the code snippet.
        /// </summary>
        /// <param name="source">The source code.</param>
        /// <param name="language">The language in which the source code is written.</param>
        protected virtual void RenderCode(string source, string language)
        {
            HighlighterBase highlighter = this.GetHighlighter(language);
            string          parsedText  = highlighter.Parse(source);

            string[] lines = parsedText.Replace("\r", String.Empty).Split('\n');

            // Find the placeholders for the line numbers and source lines.
            Control templatedOutLineControl = new SourceHeaderItem(highlighter.FullName, lines.Length);

            this.Controls.Add(templatedOutLineControl);
            this.codeLayoutTemplate.InstantiateIn(templatedOutLineControl);

            PlaceHolder lineNumberPlaceHolder = this.FindLineNumberPlaceHolder(templatedOutLineControl);
            PlaceHolder sourceLinePlaceHolder = this.FindSourceLinePlaceHolder(templatedOutLineControl);

            FunctionSelector selector = FunctionSelectorFactory.Get(language);

            selector.FunctionName = FunctionName;

            if (lineNumberPlaceHolder != null || sourceLinePlaceHolder != null)
            {
                Control templatedLineNumberControl, templatedSourceLineControl, separatorControl;
                for (int i = 0; i < lines.Length; i++)
                {
                    int lineNumber = (i + 1);
                    if (lineNumber >= _StartLineNumber && lineNumber <= _EndLineNumber)
                    {
                        string line = lines[i];
                        if (selector.IsLineBelongingToRequiredFunction(line))
                        {
                            if (lineNumberPlaceHolder != null && this.lineNumberTemplate != null)
                            {
                                // Parse line number.
                                templatedLineNumberControl = new SourceItem(lineNumber, lines.Length, line);

                                this.lineNumberTemplate.InstantiateIn(templatedLineNumberControl);
                                lineNumberPlaceHolder.Controls.Add(templatedLineNumberControl);

                                if (lineNumber < lines.Length && this.separatorTemplate != null)
                                {
                                    separatorControl = new SeparatorItem();
                                    this.separatorTemplate.InstantiateIn(separatorControl);
                                    lineNumberPlaceHolder.Controls.Add(separatorControl);
                                }
                            }

                            if (sourceLinePlaceHolder != null && this.sourceLineTemplate != null)
                            {
                                // Parse source line.
                                templatedSourceLineControl = new SourceItem(lineNumber, lines.Length, line);

                                this.sourceLineTemplate.InstantiateIn(templatedSourceLineControl);
                                sourceLinePlaceHolder.Controls.Add(templatedSourceLineControl);

                                if (lineNumber < lines.Length && this.separatorTemplate != null)
                                {
                                    separatorControl = new SeparatorItem();
                                    this.separatorTemplate.InstantiateIn(separatorControl);
                                    sourceLinePlaceHolder.Controls.Add(separatorControl);
                                }
                            }
                        }
                    }
                }
            }

            templatedOutLineControl.DataBind();
        }