Esempio n. 1
0
        /// <summary>
        /// Gets a rich text box that show the syntax highlighted source code of the example.
        /// </summary>
        /// <returns></returns>
        protected virtual NWidget GetExampleSource()
        {
            NRichTextView richText = new NRichTextView();

            richText.HRuler.Visibility = ENVisibility.Collapsed;
            richText.VRuler.Visibility = ENVisibility.Collapsed;
            richText.ReadOnly          = true;

            try
            {
                // Decompress the source code of the example
                Type exampleType = Schema.DomType.Type;
                NSourceCodeDecompressor decompressor = new NSourceCodeDecompressor(exampleType);
                SourceCodeStream.Position = 0;
                NCompression.DecompressZip(SourceCodeStream, decompressor);

                // Highlight the decompressed source code
                NSyntaxHighlighter syntaxHighlighter = new NSyntaxHighlighter();

                MemoryStream decompressedStream = decompressor.GetSourceCodeStream();
                if (decompressedStream != null)
                {
                    Stream htmlStream = syntaxHighlighter.Highlight(decompressedStream);

                    // Load the colorized source code in the source code rich text view
                    richText.LoadFromStream(htmlStream, new NHtmlTextFormat());
                }
            }
            catch (Exception ex)
            {
                NTrace.WriteException("Failed to get example source.", ex);
            }

            return(richText);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the example description.
        /// </summary>
        /// <returns></returns>
        protected virtual NWidget CreateExampleDescription()
        {
            NRichTextView richTextView = new NRichTextView();

            richTextView.Padding = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

            richTextView.HRuler.Visibility = ENVisibility.Collapsed;
            richTextView.VRuler.Visibility = ENVisibility.Collapsed;
            richTextView.ReadOnly          = true;

            byte[] descriptionData = NEncoding.UTF8.GetBytes(GetExampleDescription());
            using (MemoryStream stream = new MemoryStream(descriptionData))
            {
                richTextView.LoadFromStream(stream, new NHtmlTextFormat());
            }

            richTextView.Content.Padding = new NMargins(NDesign.HorizontalSpacing * 2, NDesign.VerticalSpacing);

            NGroupBox groupBox = new NGroupBox("Description");

            groupBox.Content = richTextView;
            return(groupBox);
        }