protected static IList <CodeSnippetContent> GetSnippetContents(BuildGroup group)
        {
            if (group == null)
            {
                return(null);
            }

            IList <CodeSnippetContent> listSnippets = group.SnippetContents;

            if (listSnippets == null || listSnippets.Count == 0)
            {
                return(null);
            }

            int itemCount = listSnippets.Count;
            List <CodeSnippetContent> validSnippets = new List <CodeSnippetContent>(
                itemCount);

            for (int i = 0; i < itemCount; i++)
            {
                CodeSnippetContent content = listSnippets[i];
                if (content != null && content.IsEmpty == false)
                {
                    if (content.Count == 0)
                    {
                        validSnippets.Add(content);
                    }
                    else
                    {
                        //TODO: Grab the items and serialize them to a file...
                    }
                }
            }

            return(validSnippets);
        }
Beispiel #2
0
        /// <summary>
        /// The creates the configuration information or settings required by the
        /// target component for the build process.
        /// </summary>
        /// <param name="group">
        /// A build group, <see cref="BuildGroup"/>, representing the documentation
        /// target for configuration.
        /// </param>
        /// <param name="writer">
        /// An <see cref="XmlWriter"/> object used to create one or more new
        /// child nodes at the end of the list of child nodes of the current node.
        /// </param>
        /// <returns>
        /// Returns <see langword="true"/> for a successful configuration;
        /// otherwise, it returns <see langword="false"/>.
        /// </returns>
        /// <remarks>
        /// The <see cref="XmlWriter"/> writer passed to this configuration object
        /// may be passed on to other configuration objects, so do not close or
        /// dispose it.
        /// </remarks>
        public override bool Configure(BuildGroup group, XmlWriter writer)
        {
            BuildExceptions.NotNull(group, "group");
            BuildExceptions.NotNull(writer, "writer");

            if (!this.Enabled || !this.IsInitialized)
            {
                return(false);
            }

            Debug.Assert(_settings != null, "The settings object is required.");
            if (_settings == null || _context == null)
            {
                return(false);
            }
            BuildStyle buildStyle = _settings.Style;

            Debug.Assert(buildStyle != null, "The style object cannot be null (or Nothing).");
            if (buildStyle == null)
            {
                return(false);
            }

            //<component type="Sandcastle.Components.ReferenceCodeComponent" assembly="$(SandAssistComponent)">
            //    <options mode="IndirectIris" tabSize="4" lineNumbers="true" outlining="false" storage="Sqlite" separator="..."/>
            //
            //    <!--The following options are for processing codeReference tags in the
            //    reference help.
            //    It is a replacement of the ExampleComponent, providing better coloring,
            //    minimum memory usage etc.
            //
            //    $codeSnippets
            //      @storage: * Indicates where the code snippets should be stored after loading
            //                * Possible values are
            //                     - Memory: the snippets are stored in memory similar to
            //                               the ExampleComponent.
            //                     - Database: the snippets are stored in Sqlite database.
            //                * Default: Database
            //      @separator: * For multi-parts snippets, this defines the separator...
            //                  * Default: ...-->
            //
            //    <!--<codeSnippets>
            //        <codeSnippet source=".\CodeSnippetSample.xml" format="Sandcastle" />
            //    </codeSnippets>-->
            //    <SandcastleItem name="%CodeSnippets%" />
            //</component>

            writer.WriteStartElement("options");  //start: options
            writer.WriteAttributeString("mode", _highlightMode);
            writer.WriteAttributeString("tabSize", _tabSize.ToString());
            writer.WriteAttributeString("lineNumbers", _showLineNumbers.ToString());
            writer.WriteAttributeString("outlining", _showOutlining.ToString());
            writer.WriteAttributeString("storage", _snippetStorage.ToString());
            writer.WriteAttributeString("separator", _snippetSeparator);
            writer.WriteEndElement();             //end: options

            IList <CodeSnippetContent> listSnippets = group.SnippetContents;

            if (listSnippets != null && listSnippets.Count != 0)
            {
                writer.WriteStartElement("codeSnippets");  // start - codeSnippets

                int contentCount = listSnippets.Count;
                for (int i = 0; i < contentCount; i++)
                {
                    CodeSnippetContent snippetContent = listSnippets[i];
                    if (snippetContent == null || snippetContent.IsEmpty)
                    {
                        continue;
                    }
                    writer.WriteStartElement("codeSnippet"); // start - codeSnippet
                    writer.WriteAttributeString("source", snippetContent.ContentFile);
                    writer.WriteAttributeString("format", "Sandcastle");
                    writer.WriteEndElement();                // end - codeSnippet
                }

                writer.WriteEndElement();                  // end - codeSnippets
            }

            SnippetContent snippets = buildStyle.Snippets;

            if (snippets != null && snippets.Count != 0)
            {
                writer.WriteStartElement("codeSources");  // start - codeSources

                for (int i = 0; i < snippets.Count; i++)
                {
                    SnippetItem snippetItem = snippets[i];
                    if (snippetItem == null || snippetItem.IsEmpty)
                    {
                        continue;
                    }
                    writer.WriteStartElement("codeSource"); // start - codeSource
                    writer.WriteAttributeString("source", snippetItem.Source);
                    writer.WriteAttributeString("format", "Sandcastle");
                    writer.WriteEndElement();                // end - codeSource
                }

                // The excludedUnits is required by the SnippetComponent,
                // we maintain that...
                writer.WriteStartElement("excludedUnits"); // start - excludedUnits
                IList <string> excludedUnits = snippets.ExcludedUnitFolders;
                if (excludedUnits != null && excludedUnits.Count != 0)
                {
                    for (int i = 0; i < excludedUnits.Count; i++)
                    {
                        string unitFolder = excludedUnits[i];
                        if (String.IsNullOrEmpty(unitFolder))
                        {
                            continue;
                        }
                        writer.WriteStartElement("unitFolder"); // start - unitFolder
                        writer.WriteAttributeString("name", unitFolder);
                        writer.WriteEndElement();               // end - unitFolder
                    }
                }
                writer.WriteEndElement();              // end - excludedUnits

                writer.WriteStartElement("languages"); // start - languages
                IList <SnippetLanguage> languages = snippets.Languages;
                if (languages != null && languages.Count != 0)
                {
                    for (int i = 0; i < languages.Count; i++)
                    {
                        SnippetLanguage language = languages[i];
                        if (!language.IsValid)
                        {
                            continue;
                        }
                        writer.WriteStartElement("language"); // start - language
                        writer.WriteAttributeString("unit", language.Unit);
                        writer.WriteAttributeString("languageId", language.LanguageId);
                        writer.WriteAttributeString("extension", language.Extension);
                        writer.WriteEndElement();               // end - language
                    }
                }
                writer.WriteEndElement();              // end - languages

                writer.WriteEndElement();              // end - codeSources
            }

            return(true);
        }