示例#1
0
        private static void TestMain(BuildDocumenter documenter,
                                     TestOptions options, ReferenceEngineSettings engineSettings)
        {
            // Decide which version information to use...
            ReferenceVersionType versionType = ReferenceVersionType.Advanced;

            string libraryDir = Path.Combine(sampleDir, @"SampleLibrary\");

            string outputDir  = Path.Combine(libraryDir, @"Output\");
            string projectDoc = Path.Combine(outputDir, "Project.xml");

            ReferenceGroup apiGroup = new ReferenceGroup(
                "Test API References", TestGroupIds.TestLibGroupId);

            apiGroup.RunningHeaderText = "Sandcastle Helpers: Test API Reference";

            if (engineSettings != null && engineSettings.RootNamespaceContainer)
            {
                apiGroup.RootNamespaceTitle = "SampleLibrary Test References";
            }

            ReferenceContent apiContent = apiGroup.Content;

            apiContent.FrameworkType = BuildFrameworkType.Framework35;
            apiContent.AddItem(projectDoc, null);
            apiContent.AddItem(Path.Combine(outputDir, "TestLibrary.xml"),
                               Path.Combine(outputDir, "TestLibrary.dll"));

            apiGroup.AddSnippet(new CodeSnippetContent(Path.Combine(
                                                           libraryDir, "CodeSnippetSample.snippets")));

            string helpTestDir = Path.Combine(sampleDir, @"SampleTopics\");
            string mediaLinks  = Path.Combine(helpTestDir, "MediaContent.media");

            apiGroup.AddMedia(new MediaContent(mediaLinks,
                                               Path.Combine(helpTestDir, "Media")));

            // Create and add an API filter...
            ReferenceNamespaceFilter namespaceFilter =
                new ReferenceNamespaceFilter("TestLibrary", true);

            namespaceFilter.Add(new ReferenceTypeFilter("Point3D", false, false));

            apiContent.TypeFilters.Add(namespaceFilter);

            documenter.AddGroup(apiGroup);

            ReferenceVersionInfo versionInfo = null;

            if (versionType == ReferenceVersionType.Advanced)
            {
                libraryDir = Path.Combine(sampleDir, @"SampleLibraryVersion\");
                outputDir  = Path.Combine(libraryDir, @"Output\");

                apiContent = new ReferenceContent();
                apiContent.FrameworkType = BuildFrameworkType.Framework20;
                apiContent.AddItem(Path.Combine(outputDir, "TestLibrary.xml"),
                                   Path.Combine(outputDir, "TestLibrary.dll"));

                versionInfo = new ReferenceVersionInfo();
                versionInfo.PlatformFilters = true;
                //versionInfo.PlatformId = "netfw";
                versionInfo.PlatformTitle = ".NET Framework";
                //versionInfo.VersionId = "netfw20";
                versionInfo.VersionLabel = "2.0";

                ReferenceVersionSource source = new ReferenceVersionSource();
                //source.VersionId    = "netfw10";
                source.VersionLabel = "1.0";
                source.Content      = apiContent;

                versionInfo.AddSource(source);

                apiGroup.VersionType = versionType;
                apiGroup.VersionInfo = versionInfo;
            }

            if (versionType == ReferenceVersionType.Advanced &&
                versionInfo != null)
            {
                libraryDir = Path.Combine(sampleDir, @"SampleLibrarySilverlight\");
                outputDir  = Path.Combine(libraryDir, @"Output\");

                apiContent = new ReferenceContent();
                apiContent.FrameworkType = BuildFrameworkType.Silverlight40;
                apiContent.AddItem(Path.Combine(outputDir, "TestLibrary.xml"),
                                   Path.Combine(outputDir, "TestLibrary.dll"));

                ReferenceVersionRelated relatedVersion = new ReferenceVersionRelated();
                relatedVersion.PlatformId = "silverlight_mobile";
                //relatedVersion.PlatformTitle = "Silverlight for Windows Phone";

                ReferenceVersionSource source = new ReferenceVersionSource();
                source.VersionId = "silverlight_mobile_v1";
                //source.VersionLabel = "Windows Phone OS 7.0";
                source.Content = apiContent;

                relatedVersion.Add(source);

                versionInfo.AddRelated(relatedVersion);
            }
        }
        private bool OnBeginMultiple(BuildContext context)
        {
            BuildLogger logger = context.Logger;

            ReferenceGroupContext groupContext =
                context.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.");
            }

            string apiVersionsDir = Path.Combine(context.WorkingDirectory,
                                                 groupContext["$ApiVersionsFolder"]);

            if (!Directory.Exists(apiVersionsDir))
            {
                Directory.CreateDirectory(apiVersionsDir);
            }

            _listVersions = new BuildKeyedList <ReferenceVersions>();

            ReferenceVersionInfo versionInfo = _group.VersionInfo;

            // For the main version information...
            ReferenceVersions versions = new ReferenceVersions(versionInfo.PlatformId,
                                                               versionInfo.PlatformTitle);
            ReferenceVersionSource mainSource = new ReferenceVersionSource(
                versionInfo.VersionId);

            mainSource.Content      = _group.Content;
            mainSource.VersionLabel = versionInfo.VersionLabel;

            versions.Add(mainSource);
            for (int i = 0; i < versionInfo.Count; i++)
            {
                ReferenceVersionSource source = versionInfo[i];
                if (source != null && source.IsValid)
                {
                    versions.Add(source);
                }
            }

            _listVersions.Add(versions);

            // For the related versions information...
            IList <ReferenceVersionRelated> listRelated = versionInfo.RelatedVersions;

            if (listRelated != null && listRelated.Count != 0)
            {
                for (int j = 0; j < listRelated.Count; j++)
                {
                    ReferenceVersionRelated related = listRelated[j];

                    if (related == null || related.IsEmpty)
                    {
                        continue;
                    }

                    versions = new ReferenceVersions(related.PlatformId, related.PlatformTitle);
                    for (int i = 0; i < related.Count; i++)
                    {
                        ReferenceVersionSource source = related[i];
                        if (source != null && source.IsValid)
                        {
                            versions.Add(source);
                        }
                    }

                    _listVersions.Add(versions);
                }
            }

            // Now, we prepare the various platforms and contexts...
            for (int i = 0; i < _listVersions.Count; i++)
            {
                versions = _listVersions[i];
                string indexText = String.Empty;
                if (_listVersions.Count > 1)
                {
                    indexText = (i + 1).ToString();
                }

                string versionsDir = Path.Combine(apiVersionsDir,
                                                  "Platform" + indexText);

                if (!Directory.Exists(versionsDir))
                {
                    Directory.CreateDirectory(versionsDir);
                }

                versions.PlatformDir = versionsDir;

                int itemCount = versions.Count;
                for (int j = 0; j < itemCount; j++)
                {
                    ReferenceVersionSource source = versions[j];

                    ReferenceGroupContext versionsContext =
                        new ReferenceGroupContext(_group, source.SourceId);

                    indexText = String.Empty;
                    if (itemCount > 1)
                    {
                        indexText = (j + 1).ToString();
                    }

                    string workingDir = Path.Combine(versionsDir, "Version" + indexText);
                    if (!Directory.Exists(workingDir))
                    {
                        Directory.CreateDirectory(workingDir);
                    }
                    versions.VersionDirs.Add(workingDir);

                    versionsContext["$GroupIndex"]    = groupContext["$GroupIndex"];
                    versionsContext["$VersionsIndex"] = indexText;
                    versionsContext["$VersionsDir"]   = versionsDir;
                    versionsContext["$WorkingDir"]    = workingDir;

                    versionsContext.CreateProperties(String.Empty);

                    groupContext.Add(versionsContext);
                }
            }

            groupContext.Versions = _listVersions;

            return(true);
        }