Exemplo n.º 1
0
        /// <summary>
        /// This writes the current state or attributes of this object,
        /// in the <c>XML</c> format, to the media or storage accessible by the given writer.
        /// </summary>
        /// <param name="writer">
        /// The <c>XML</c> writer with which the <c>XML</c> format of this object's state
        /// is written.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void WriteXml(XmlWriter writer)
        {
            BuildExceptions.NotNull(writer, "writer");

            if (!this.IsValid)
            {
                return;
            }

            writer.WriteStartElement(TagName);  // start - TagName
            writer.WriteAttributeString("name", this.Name);

            writer.WriteStartElement("propertyGroup");  // start - propertyGroup
            writer.WriteAttributeString("name", "General");
            writer.WritePropertyElement("Title", this.Title);
            writer.WritePropertyElement("Id", _sourceId);
            writer.WritePropertyElement("LinkType", _linkType.ToString());
            writer.WritePropertyElement("FrameworkType", _frameworkType.ToString());
            writer.WriteEndElement();                   // end - propertyGroup

            // 3. The reference items defining the API content
            writer.WriteComment(" The reference items defining the API content ");
            writer.WriteStartElement("referenceItems");  // start - referenceItems
            for (int i = 0; i < _listItems.Count; i++)
            {
                ReferenceItem item = _listItems[i];
                if (item != null && !item.IsEmpty)
                {
                    item.WriteXml(writer);
                }
            }
            writer.WriteEndElement();                    // end - referenceItems

            // Write the user-defined contents...
            this.WriteContents(writer);

            // Write the filters...
            this.WriteFilters(writer);

            writer.WriteEndElement();           // end - TagName
        }
        /// <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");

            IBuildNamedList <BuildGroupContext> groupContexts = _context.GroupContexts;

            if (groupContexts == null || groupContexts.Count == 0)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            ReferenceGroupContext groupContext = groupContexts[group.Id]
                                                 as ReferenceGroupContext;

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

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

            BuildFramework     framework = groupContext.Framework;
            BuildFrameworkKind kind      = framework.FrameworkType.Kind;

            ReferenceEngineSettings referenceSettings = _settings.EngineSettings[
                BuildEngineType.Reference] as ReferenceEngineSettings;
            BuildSpecialSdkType webSdkType = referenceSettings.WebMvcSdkType;

            writer.WriteStartElement("options");   // start - options
            writer.WriteAttributeString("locale",
                                        _settings.CultureInfo.Name.ToLower());
            if (kind == BuildFrameworkKind.Silverlight)
            {
                writer.WriteAttributeString("version", "VS.95");
            }
            else if (kind == BuildFrameworkKind.Compact)
            {
                // The framework 3.5 is the last version of Windows CE...
                writer.WriteAttributeString("version", "VS.90");
            }
            if (webSdkType != BuildSpecialSdkType.Null &&
                webSdkType != BuildSpecialSdkType.None)
            {
                switch (webSdkType.Value)
                {
                case 10:        // ASP.NET MVC 1.0: Supported in .NET 3.5
                    writer.WriteAttributeString("mvcVersion", "VS.90");
                    break;

                case 20:        // ASP.NET MVC 2.0: Supported in .NET 3.5 SP1
                    // This is currently the default documentation for
                    // the ASP.NET MVC Framework...
                    writer.WriteAttributeString("mvcVersion", "");
                    break;

                case 30:        // ASP.NET MVC 3.0: Supported in .NET 4.0
                    writer.WriteAttributeString("mvcVersion", "VS.98");
                    break;

                case 40:        // ASP.NET MVC 4.0: Supported in .NET 4.5
                    writer.WriteAttributeString("mvcVersion", "VS.108");
                    break;
                }
            }
            writer.WriteAttributeString("linkTarget",
                                        "_" + _format.ExternalLinkTarget.ToString().ToLower());
            writer.WriteEndElement();              // end - options

            bool   isEmbeddedGroup    = false;
            bool   frameworkAvailable = false;
            bool   isEmbeddedScript   = groupContext.IsEmbeddedGroup;
            string tempText           = _context["$EmbeddedScriptSharp"];

            if (!String.IsNullOrEmpty(tempText))
            {
                isEmbeddedScript = Convert.ToBoolean(tempText);
            }

            List <DataSource> dataSources = new List <DataSource>();

            if (kind == BuildFrameworkKind.Silverlight)
            {
                string silverlightDir = groupContext["$SilverlightDataDir"];

                if (!String.IsNullOrEmpty(silverlightDir) &&
                    Directory.Exists(silverlightDir))
                {
                    frameworkAvailable = true;

                    writer.WriteStartElement("targets");
                    writer.WriteAttributeString("base", silverlightDir);
                    writer.WriteAttributeString("recurse", "false");
                    writer.WriteAttributeString("system", "true");
                    writer.WriteAttributeString("files", "*.xml");
                    writer.WriteAttributeString("type",
                                                _format.ExternalLinkType.ToString().ToLower());

                    // Write the data source...
                    Version latestVersion = BuildFrameworks.LatestSilverlightVersion;
                    if (latestVersion == null)
                    {
                        latestVersion = framework.Version;
                    }
                    this.WriteDataSource(writer, DataSourceType.Silverlight,
                                         silverlightDir, latestVersion, true, true, dataSources);

                    writer.WriteEndElement();
                }
            }
            else if (kind == BuildFrameworkKind.Portable)
            {
                string portableDir = groupContext["$PortableDataDir"];

                if (!String.IsNullOrEmpty(portableDir) && Directory.Exists(portableDir))
                {
                    frameworkAvailable = true;

                    writer.WriteStartElement("targets");
                    writer.WriteAttributeString("base", portableDir);
                    writer.WriteAttributeString("recurse", "false");
                    writer.WriteAttributeString("system", "true");
                    writer.WriteAttributeString("files", "*.xml");
                    writer.WriteAttributeString("type",
                                                _format.ExternalLinkType.ToString().ToLower());

                    // Write the data source...
                    Version latestVersion = BuildFrameworks.LatestPortableVersion;
                    if (latestVersion == null)
                    {
                        latestVersion = framework.Version;
                    }
                    this.WriteDataSource(writer, DataSourceType.Portable,
                                         portableDir, latestVersion, true, false, dataSources);

                    writer.WriteEndElement();
                }
            }
            else if (kind == BuildFrameworkKind.ScriptSharp)
            {
                string scriptSharpDir = groupContext["$ScriptSharpDataDir"];

                if (!String.IsNullOrEmpty(scriptSharpDir) && Directory.Exists(scriptSharpDir))
                {
                    frameworkAvailable = true;

                    if (!isEmbeddedGroup)
                    {
                        writer.WriteStartElement("targets");
                        writer.WriteAttributeString("base", scriptSharpDir);
                        writer.WriteAttributeString("recurse", "false");
                        writer.WriteAttributeString("system", "true");
                        writer.WriteAttributeString("files", "*.xml");

                        if (isEmbeddedScript)
                        {
                            writer.WriteAttributeString("type",
                                                        BuildLinkType.Local.ToString().ToLower());
                        }
                        else
                        {
                            writer.WriteAttributeString("type",
                                                        BuildLinkType.None.ToString().ToLower());
                        }

                        // Write the data source...
                        Version latestVersion = BuildFrameworks.LatestScriptSharpVersion;
                        if (latestVersion == null)
                        {
                            latestVersion = framework.Version;
                        }
                        this.WriteDataSource(writer, DataSourceType.ScriptSharp,
                                             scriptSharpDir, latestVersion, true, false, dataSources);

                        writer.WriteEndElement();
                    }
                }
            }

            // If not specialized framework, then write the default...
            if (!frameworkAvailable || kind == BuildFrameworkKind.None ||
                kind == BuildFrameworkKind.DotNet || kind == BuildFrameworkKind.Compact)
            {
                string dotNetDataDir = Path.GetFullPath(
                    Environment.ExpandEnvironmentVariables(ReferenceEngine.ReflectionDirectory));

                writer.WriteStartElement("targets");
                writer.WriteAttributeString("base", dotNetDataDir);
                writer.WriteAttributeString("recurse", "true");
                writer.WriteAttributeString("system", "true");
                writer.WriteAttributeString("files", "*.xml");
                writer.WriteAttributeString("type",
                                            _format.ExternalLinkType.ToString().ToLower());

                // Write the data source...
                this.WriteDataSource(writer, DataSourceType.Framework,
                                     dotNetDataDir, ReferenceEngine.ReflectionVersion, true,
                                     false, dataSources);

                writer.WriteEndElement();
            }

            // The Portable and ScriptSharp do not support Blend...
            if (kind != BuildFrameworkKind.Portable &&
                kind != BuildFrameworkKind.Compact &&
                kind != BuildFrameworkKind.ScriptSharp)
            {
                string blendDir = groupContext["$BlendDataDir"];

                if (!String.IsNullOrEmpty(blendDir) && Directory.Exists(blendDir))
                {
                    writer.WriteStartElement("targets");
                    writer.WriteAttributeString("base", blendDir);
                    writer.WriteAttributeString("recurse", "false");
                    writer.WriteAttributeString("system", "true");
                    writer.WriteAttributeString("files", "*.xml");
                    writer.WriteAttributeString("type",
                                                _format.ExternalLinkType.ToString().ToLower());

                    // Write the data source...
                    BuildSpecialSdk latestBlendSdk = null;
                    if (kind == BuildFrameworkKind.Silverlight)
                    {
                        latestBlendSdk = BuildSpecialSdks.LatestBlendSilverlightSdk;
                    }
                    else
                    {
                        latestBlendSdk = BuildSpecialSdks.LatestBlendWpfSdk;
                    }
                    Version latestVersion = (latestBlendSdk == null) ?
                                            null : latestBlendSdk.Version;
                    if (latestVersion == null)
                    {
                        latestVersion = framework.Version;
                    }
                    this.WriteDataSource(writer, DataSourceType.Blend, blendDir,
                                         latestVersion, true, kind == BuildFrameworkKind.Silverlight,
                                         dataSources);

                    writer.WriteEndElement();
                }
            }

            IList <string> linkDirs = _context.GetValue(
                "$ReferenceLinkDirectories") as IList <string>;
            IList <ReferenceLinkSource> linkSources = _context.GetValue(
                "$ReferenceLinkSources") as IList <ReferenceLinkSource>;

            if ((linkDirs != null && linkDirs.Count != 0) &&
                (linkSources != null && linkSources.Count == linkDirs.Count))
            {
                for (int i = 0; i < linkDirs.Count; i++)
                {
                    ReferenceLinkSource linkSource     = linkSources[i];
                    BuildLinkType       sourceLinkType = linkSource.LinkType;

                    writer.WriteStartElement("targets");
                    writer.WriteAttributeString("base", linkDirs[i]);
                    writer.WriteAttributeString("recurse", "true");
                    writer.WriteAttributeString("system", "false");
                    writer.WriteAttributeString("files", "*.xml");
                    writer.WriteAttributeString("type",
                                                sourceLinkType.ToString().ToLower());

                    writer.WriteEndElement();
                }
            }

            BuildLinkType linkType     = _format.LinkType;
            string        linkTypeText = linkType.ToString().ToLower();

            // For the embedded group, we will not link to the other groups...
            if (!isEmbeddedGroup)
            {
                for (int i = 0; i < groupContexts.Count; i++)
                {
                    ReferenceGroupContext aContext = groupContexts[i]
                                                     as ReferenceGroupContext;

                    if (aContext == null || aContext.IsLinkGroup)
                    {
                        continue;
                    }

                    if (aContext.GroupType != BuildGroupType.Reference ||
                        aContext == groupContext)
                    {
                        continue;
                    }

                    string linkFile = aContext["$ReflectionFile"];
                    if (!String.IsNullOrEmpty(linkFile))
                    {
                        writer.WriteStartElement("targets");

                        writer.WriteAttributeString("base", @".\");
                        writer.WriteAttributeString("recurse", "false");
                        writer.WriteAttributeString("system", "false");
                        writer.WriteAttributeString("files", @".\" + linkFile);
                        writer.WriteAttributeString("type", linkTypeText);
                        writer.WriteEndElement();
                    }
                }
            }

            //<targets base=".\" recurse="false"
            //   files=".\reflection.xml" type="local" />
            writer.WriteStartElement("targets");
            writer.WriteAttributeString("base", @".\");
            writer.WriteAttributeString("recurse", "false");
            writer.WriteAttributeString("system", "false");
            writer.WriteAttributeString("files", @".\" + groupContext["$ReflectionFile"]);

            if (isEmbeddedGroup)
            {
                writer.WriteAttributeString("type",
                                            BuildLinkType.Local.ToString().ToLower());
            }
            else
            {
                writer.WriteAttributeString("type", linkTypeText);
            }

            writer.WriteEndElement();

            // Provide the information for the MSDN link resolvers...
            writer.WriteStartElement("linkResolver"); // start - linkResolver
            writer.WriteAttributeString("storage", _linkStorage.ToString().ToLower());
            writer.WriteAttributeString("cache", _cacheLinks ? "true" : "false");
            if (dataSources != null && dataSources.Count != 0)
            {
                for (int i = 0; i < dataSources.Count; i++)
                {
                    DataSource dataSource = dataSources[i];

                    this.WriteDataSource(writer, dataSource.SourceType,
                                         dataSource.InputDir, dataSource.Version,
                                         dataSource.IsDatabase, dataSource.IsSilverlight, true);
                }
            }
            writer.WriteEndElement();                 // end - linkResolver

            // Finally, provide the information for the conceptual links
            // in reference documents, if any...
            bool hasConceptualContext = _settings.BuildConceptual;

            if (hasConceptualContext)
            {
                hasConceptualContext = false;

                for (int i = 0; i < groupContexts.Count; i++)
                {
                    BuildGroupContext aContext = groupContexts[i];
                    if (aContext.GroupType == BuildGroupType.Conceptual)
                    {
                        hasConceptualContext = true;
                        break;
                    }
                }
            }

            if (hasConceptualContext)
            {
                ConceptualEngineSettings conceptualSettings = _settings.EngineSettings[
                    BuildEngineType.Conceptual] as ConceptualEngineSettings;
                Debug.Assert(conceptualSettings != null,
                             "The settings does not include the reference engine settings.");
                if (conceptualSettings == null)
                {
                    return(false);
                }
                ConceptualLinkConfiguration linkConfig =
                    conceptualSettings.ConceptualLinks;
                Debug.Assert(linkConfig != null,
                             "There is no conceptual link configuration available.");
                if (linkConfig == null)
                {
                    return(false);
                }

                writer.WriteStartElement("conceptualLinks");  //start: conceptualLinks
                writer.WriteAttributeString("enabled", "true");
                writer.WriteAttributeString("showText",
                                            linkConfig.ShowLinkText.ToString());
                writer.WriteAttributeString("showBrokenLinkText",
                                            linkConfig.ShowBrokenLinkText.ToString());
                writer.WriteAttributeString("type", linkTypeText);

                for (int i = 0; i < groupContexts.Count; i++)
                {
                    BuildGroupContext aContext = groupContexts[i];
                    if (aContext.GroupType == BuildGroupType.Conceptual)
                    {
                        writer.WriteStartElement("conceptualTargets");  // start - conceptualTargets
                        writer.WriteAttributeString("base", String.Format(
                                                        @".\{0}", aContext["$DdueXmlCompDir"]));
                        writer.WriteAttributeString("type", linkTypeText);
                        writer.WriteEndElement();                       // end - conceptualTargets
                    }
                }
                writer.WriteEndElement();                     //end: conceptualLinks
            }

            return(true);
        }
Exemplo n.º 3
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
        /// is created as a new child specifically for this object, and will not
        /// be passed onto other configuration objects.
        /// </remarks>
        public override bool Configure(BuildGroup group, XmlWriter writer)
        {
            BuildExceptions.NotNull(group, "group");
            BuildExceptions.NotNull(writer, "writer");

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

            BuildSettings settings = _context.Settings;

            writer.WriteStartElement("options");   // start - options
            writer.WriteAttributeString("locale",
                                        settings.CultureInfo.Name.ToLower());
            writer.WriteAttributeString("linkTarget",
                                        "_" + _format.ExternalLinkTarget.ToString().ToLower());
            writer.WriteEndElement();              // end - options

            List <DataSource> dataSources = new List <DataSource>();

            // For now, lets simply write the default...
            //writer.WriteStartElement("targets");    // start - targets
            //writer.WriteAttributeString("base", @"%DXROOT%\Data\Reflection\");
            //writer.WriteAttributeString("recurse", "true");
            //writer.WriteAttributeString("files", "*.xml");
            //writer.WriteAttributeString("type",
            //    _format.ExternalLinkType.ToString().ToLower());
            //writer.WriteEndElement();               // end - targets
            string dotNetDataDir = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(ReferenceEngine.ReflectionDirectory));

            writer.WriteStartElement("targets");  // start - targets
            writer.WriteAttributeString("base", dotNetDataDir);
            writer.WriteAttributeString("recurse", "true");
            writer.WriteAttributeString("system", "true");
            writer.WriteAttributeString("files", "*.xml");
            writer.WriteAttributeString("type",
                                        _format.ExternalLinkType.ToString().ToLower());

            // Write the data source...
            this.WriteDataSource(writer, DataSourceType.Framework,
                                 dotNetDataDir, ReferenceEngine.ReflectionVersion, true,
                                 false, dataSources);

            writer.WriteEndElement();             // end - targets

            // Write Silverlight framework too...
            Version latestVersion = BuildFrameworks.LatestSilverlightVersion;
            string  reflectionDir = _context.ReflectionDataDirectory;

            if (latestVersion != null && (!String.IsNullOrEmpty(reflectionDir) &&
                                          Directory.Exists(reflectionDir)))
            {
                string silverlightDir = Path.Combine(reflectionDir,
                                                     @"Silverlight\v" + latestVersion.ToString(2));

                // If it exits and not empty, we assume the reflection data
                // is already created..
                if (Directory.Exists(silverlightDir) &&
                    !DirectoryUtils.IsDirectoryEmpty(silverlightDir))
                {
                    writer.WriteStartElement("targets");
                    writer.WriteAttributeString("base", silverlightDir);
                    writer.WriteAttributeString("recurse", "false");
                    writer.WriteAttributeString("system", "true");
                    writer.WriteAttributeString("files", "*.xml");
                    writer.WriteAttributeString("type",
                                                _format.ExternalLinkType.ToString().ToLower());

                    // Write the data source...
                    this.WriteDataSource(writer, DataSourceType.Silverlight,
                                         silverlightDir, latestVersion, true, true, dataSources);

                    writer.WriteEndElement();
                }
            }
            latestVersion = null;
            bool isSilverlight = false;

            // Write Blend SDK...
            BuildSpecialSdk latestBlendSdk      = null;
            BuildSpecialSdk silverlightBlendSdk = BuildSpecialSdks.LatestBlendSilverlightSdk;
            BuildSpecialSdk wpfBlendSdk         = BuildSpecialSdks.LatestBlendWpfSdk;

            if (silverlightBlendSdk != null && wpfBlendSdk != null)
            {
                // In this case we use the latest version, most likely to
                // have improved API...
                latestBlendSdk = wpfBlendSdk;
                if (silverlightBlendSdk.Version > wpfBlendSdk.Version)
                {
                    isSilverlight  = true;
                    latestBlendSdk = silverlightBlendSdk;
                }
            }
            else if (silverlightBlendSdk != null)
            {
                isSilverlight  = true;
                latestBlendSdk = silverlightBlendSdk;
            }
            else if (wpfBlendSdk != null)
            {
                latestBlendSdk = wpfBlendSdk;
            }

            latestVersion = (latestBlendSdk == null) ?
                            null : latestBlendSdk.Version;

            if (latestVersion != null && (!String.IsNullOrEmpty(reflectionDir) &&
                                          Directory.Exists(reflectionDir)))
            {
                string blendDir = null;
                if (isSilverlight)
                {
                    blendDir = Path.Combine(reflectionDir,
                                            @"Blend\Silverlight\v" + latestVersion.ToString(2));
                }
                else
                {
                    blendDir = Path.Combine(reflectionDir,
                                            @"Blend\Wpf\v" + latestVersion.ToString(2));
                }

                // If it exits and not empty, we assume the reflection data
                // is already created..
                if (Directory.Exists(blendDir) &&
                    !DirectoryUtils.IsDirectoryEmpty(blendDir))
                {
                    writer.WriteStartElement("targets");
                    writer.WriteAttributeString("base", blendDir);
                    writer.WriteAttributeString("recurse", "false");
                    writer.WriteAttributeString("system", "true");
                    writer.WriteAttributeString("files", "*.xml");
                    writer.WriteAttributeString("type",
                                                _format.ExternalLinkType.ToString().ToLower());

                    // Write the data source...
                    this.WriteDataSource(writer, DataSourceType.Blend,
                                         blendDir, latestVersion, true, isSilverlight, dataSources);

                    writer.WriteEndElement();
                }
            }

            // Provide the information for the MSDN link resolvers...
            writer.WriteStartElement("linkResolver"); // start - linkResolver
            writer.WriteAttributeString("storage", "database");
            writer.WriteAttributeString("cache", "false");
            if (dataSources != null && dataSources.Count != 0)
            {
                for (int i = 0; i < dataSources.Count; i++)
                {
                    DataSource dataSource = dataSources[i];

                    this.WriteDataSource(writer, dataSource.SourceType,
                                         dataSource.InputDir, dataSource.Version,
                                         dataSource.IsDatabase, dataSource.IsSilverlight, true);
                }
            }
            writer.WriteEndElement();                 // end - linkResolver

            BuildLinkType linkType     = _format.LinkType;
            string        linkTypeText = linkType.ToString().ToLower();

            IBuildNamedList <BuildGroupContext> groupContexts = _context.GroupContexts;

            if (groupContexts != null && groupContexts.Count != 0)
            {
                for (int i = 0; i < groupContexts.Count; i++)
                {
                    BuildGroupContext groupContext = groupContexts[i];

                    if (groupContext.GroupType != BuildGroupType.Reference)
                    {
                        continue;
                    }

                    string linkFile = groupContext["$ReflectionFile"];
                    if (!String.IsNullOrEmpty(linkFile))
                    {
                        writer.WriteStartElement("targets");

                        writer.WriteAttributeString("base", @".\");
                        writer.WriteAttributeString("recurse", "false");
                        writer.WriteAttributeString("files",
                                                    @".\" + groupContext["$ReflectionFile"]);
                        writer.WriteAttributeString("type", linkTypeText);

                        writer.WriteEndElement();
                    }
                }
            }

            return(true);
        }