public override ReferenceContent Create(BuildGroupContext groupContext) { BuildExceptions.NotNull(groupContext, "groupContext"); BuildContext context = groupContext.Context; BuildLogger logger = null; if (context != null) { logger = context.Logger; } if (!this.IsInitialized) { throw new BuildException(String.Format( "The content source '{0}' is not yet initialized.", this.Title)); } if (!this.IsValid) { if (logger != null) { logger.WriteLine(String.Format( "The content group source '{0}' is invalid.", this.Title), BuildLoggerLevel.Warn); } return(null); } string searchPattern = _searchPattern; if (String.IsNullOrEmpty(searchPattern)) { searchPattern = "*.dll"; } string[] fullPaths = Directory.GetFiles(_sourcePath.Path, searchPattern, _isRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); if (fullPaths == null || fullPaths.Length == 0) { return(null); } HashSet <string> dependencyDirs = new HashSet <string>( StringComparer.OrdinalIgnoreCase); Dictionary <string, string> assemblies = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (string fullPath in fullPaths) { string fileName = Path.GetFileName(fullPath); if (assemblies.ContainsKey(fileName) || (_excludeSet.Count != 0 && _excludeSet.Contains(fileName))) { continue; } // We will not use the assemblies without comments as // dependencies, since we cannot verify these are .NET DLLs. string commentFile = Path.ChangeExtension(fullPath, ".xml"); if (!File.Exists(commentFile)) { continue; } string dependencyDir = Path.GetDirectoryName(fullPath); if (!dependencyDir.EndsWith("\\")) { dependencyDir += "\\"; } dependencyDirs.Add(dependencyDir); assemblies[fileName] = fullPath; } if (assemblies.Count == 0) { return(null); } ReferenceContent content = new ReferenceContent(); // Set the framework version... if (_frameworkType == BuildFrameworkType.Null || _frameworkType == BuildFrameworkType.None) { BuildFramework framework = BuildFrameworks.LatestFramework; if (framework == null) { // If not successful, use the default... framework = BuildFrameworks.DefaultFramework; } content.FrameworkType = framework.FrameworkType; } else { content.FrameworkType = _frameworkType; } foreach (KeyValuePair <string, string> pair in assemblies) { string assemblyFile = pair.Value; string commentFile = Path.ChangeExtension(assemblyFile, ".xml"); content.AddItem(commentFile, assemblyFile); } // Provide the dependency information for the content... DependencyContent depContents = content.Dependencies; foreach (string dependencyDir in dependencyDirs) { depContents.Paths.Add(new BuildDirectoryPath(dependencyDir)); } // Provide other user-supplied information to the content... content.Comments = this.Comments; content.HierarchicalToc = this.HierarchicalToc; content.TypeFilters = this.TypeFilters; content.AttributeFilters = this.AttributeFilters; return(content); }
private void CreateLinkGroups(BuildContext context) { context["$EmbeddedScriptSharp"] = Boolean.FalseString; if (_listGroups == null || _listGroups.Count == 0) { return; } BuildLogger logger = context.Logger; List <ReferenceGroup> buildGroups = new List <ReferenceGroup>(); IList <BuildGroupContext> groupContexts = context.GroupContexts; bool hasScriptSharp = false; BuildFrameworkType latestScriptSharp = BuildFrameworkType.None; int itemCount = _listGroups.Count; int index = 0; for (int i = 0; i < itemCount; i++) { ReferenceGroup group = _listGroups[i]; ReferenceContent content = group.Content; if (content != null) { BuildFrameworkType frameworkType = content.FrameworkType; if (frameworkType.Kind == BuildFrameworkKind.ScriptSharp) { hasScriptSharp = true; if (frameworkType > latestScriptSharp) { latestScriptSharp = frameworkType; } } } } // Include contents from the Script# framework for correct // linking, since there is MSDN links for the Script#... if (hasScriptSharp && _engineSettings.EmbedScriptSharpFramework && latestScriptSharp.Kind == BuildFrameworkKind.ScriptSharp) { BuildFramework framework = BuildFrameworks.GetFramework(latestScriptSharp); if (framework == null) { framework = BuildFrameworks.LatestScriptSharp; } if (framework != null) { ReferenceGroup buildGroup = new ReferenceGroup( "Embedded ScriptSharp - " + ReferenceGroup.NextGroupName(), Guid.NewGuid().ToString()); ReferenceContent content = buildGroup.Content; string[] assemblies = Directory.GetFiles(framework.AssemblyDir, "*.dll", SearchOption.AllDirectories); for (int i = 0; i < assemblies.Length; i++) { string assembly = assemblies[i]; string comments = Path.ChangeExtension(assembly, ".xml"); if (File.Exists(comments)) { content.AddItem(comments, assembly); } } buildGroup.ExcludeToc = true; buildGroup.SyntaxType = BuildSyntaxType.CSharp | BuildSyntaxType.JavaScript; buildGroups.Add(buildGroup); // Create the group context... ReferenceGroupContext buildGroupContext = new ReferenceGroupContext(buildGroup); buildGroupContext.IsEmbeddedGroup = true; groupContexts.Add(buildGroupContext); string indexText = (itemCount + index + 1).ToString(); // Create the build dynamic properties... buildGroupContext.CreateProperties(indexText); // This has no effect, since the newly created group will // not have any content source. buildGroup.BeginSources(context); context["$EmbeddedScriptSharp"] = Boolean.TrueString; } } if (buildGroups.Count != 0) { _listGroups.Add(buildGroups); } // Process the user-provided link sources... List <ReferenceLinkSource> linkSources = null; IList <ReferenceLinkSource> listSources = _engineSettings.LinkSources as IList <ReferenceLinkSource>; if (listSources != null && listSources.Count != 0) { for (int i = 0; i < listSources.Count; i++) { ReferenceLinkSource linkSource = listSources[i]; if (linkSource == null || !linkSource.IsValid) { if (logger != null) { string title = linkSource.Title; if (title == null) { title = String.Empty; } logger.WriteLine(String.Format( "A provided reference link source titled = '{0}', at index = '{1}' is invalid.", title, i), BuildLoggerLevel.Warn); } continue; } if (linkSources == null) { linkSources = new List <ReferenceLinkSource>(); } linkSources.Add(linkSource); } } // Process the automatic link sources... BuildSpecialSdkType webMvcSdkType = _engineSettings.WebMvcSdkType; if (webMvcSdkType != BuildSpecialSdkType.None && webMvcSdkType != BuildSpecialSdkType.Null) { BuildSpecialSdk webSdk = BuildSpecialSdks.GetSdk(webMvcSdkType, BuildFrameworkKind.DotNet); if (webSdk != null) { ReferenceLinkSource linkSource = new ReferenceLinkSource(); linkSource.LinkType = BuildLinkType.Msdn; linkSource.Title = webMvcSdkType.Label; linkSource.FrameworkType = BuildFrameworks.LatestFramework.FrameworkType; string aspMVCDir = webSdk.AssemblyDir; string[] assemblyFiles = Directory.GetFiles( webSdk.AssemblyDir, "*.dll", SearchOption.TopDirectoryOnly); for (int i = 0; i < assemblyFiles.Length; i++) { string assemblyFile = assemblyFiles[i]; string commentFile = Path.ChangeExtension(assemblyFile, ".xml"); if (File.Exists(commentFile)) { ReferenceItem refItem = new ReferenceItem( commentFile, assemblyFile); refItem.XamlSyntax = false; linkSource.Add(refItem); } } if (linkSource.IsValid) { if (linkSources == null) { linkSources = new List <ReferenceLinkSource>(); } linkSources.Add(linkSource); } } } if (linkSources != null && linkSources.Count != 0) { context.SetValue("$ReferenceLinkSources", linkSources); itemCount = linkSources.Count; if (_linkGroups == null) { _linkGroups = new BuildList <ReferenceGroup>(); } for (int i = 0; i < itemCount; i++) { ReferenceLinkSource linkSource = linkSources[i]; ReferenceGroup linkGroup = new ReferenceGroup( "Reference Links - " + ReferenceGroup.NextGroupName(), linkSource.SourceId, linkSource); linkGroup.ExcludeToc = true; _linkGroups.Add(linkGroup); // Create the group context... ReferenceGroupContext linkGroupContext = new ReferenceGroupContext(linkGroup); linkGroupContext.IsLinkGroup = true; groupContexts.Add(linkGroupContext); string indexText = String.Empty; if (itemCount > 1) { indexText = (i + 1).ToString(); } // Create the build dynamic properties... linkGroupContext.CreateProperties(indexText); // This has no effect, since the newly created group will // not have any content source. linkGroup.BeginSources(context); } } }