private string GetContentType(string fileName) { string contentType = String.Empty; string ext = Path.GetExtension(fileName).ToLower(); if (_contentTypes.ContainsKey(ext)) { return(_contentTypes[ext]); } RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(ext); if (regKey != null && regKey.GetValue("Content Type") != null) { string mimeType = regKey.GetValue("Content Type").ToString(); if (mimeType.StartsWith("text")) { contentType = String.Format("{0}; charset=utf-8", mimeType); } else { contentType = mimeType; } _contentTypes[ext] = contentType; } return(contentType); }
private void ParseProjectOutput() { ProjectOutputList items = ProjectOutput; SortedFileList <bool> localCopyItems = new SortedFileList <bool>(); SortedFileList <TargetType> keys = new SortedFileList <TargetType>(); ProjectOutput.BaseDirectory = ProjectPath; localCopyItems.BaseDirectory = ProjectPath; keys.BaseDirectory = ProjectPath; SortedList <string, bool> copyKeys = new SortedList <string, bool>(); foreach (string v in GetParameters("SharedItems", Parameters.SharedItems, "")) { if (!keys.ContainsKey(v)) { keys.Add(v, TargetType.SharedItem); } } foreach (string v in GetParameters("LocalItems", Parameters.LocalItems, "")) { if (!keys.ContainsKey(v)) { keys.Add(v, TargetType.Item); } } foreach (string v in GetParameters("CopyItems", Parameters.LocalItems, "None;Compile;Content;EmbeddedResource")) { if (!copyKeys.ContainsKey(v)) { copyKeys.Add(v, true); } } string primaryTarget = QQnPath.Combine(OutputPath, TargetName + TargetExt); string itemTarget = primaryTarget; items.Add(new TargetItem(itemTarget, QQnPath.Combine(IntermediateOutputPath, TargetName + TargetExt), TargetType.Item)); if (BuildProperties.ContainsKey("_SGenDllCreated") && GetProperty("_SGenDllCreated") == "true" && BuildProperties.ContainsKey("_SGenDllName")) { string dllName = GetProperty("_SGenDllName"); itemTarget = QQnPath.Combine(OutputPath, dllName); items.Add(new TargetItem(itemTarget, QQnPath.Combine(IntermediateOutputPath, dllName), TargetType.Item)); } if (BuildProperties.ContainsKey("_DebugSymbolsProduced") && GetProperty("_DebugSymbolsProduced") == "true") { string pdbName = GetProperty("TargetName") + ".pdb"; DebugSrc = pdbName; itemTarget = QQnPath.Combine(OutputPath, pdbName); items.Add(new TargetItem(itemTarget, QQnPath.Combine(IntermediateOutputPath, pdbName), TargetType.Item)); } foreach (ProjectItem pi in BuildItems) { if (string.IsNullOrEmpty(pi.Include)) { continue; } TargetType type = TargetType.None; switch (pi.Name) { // TODO: Rewrite to a per-language infrastructure case "IntermediateAssembly": case "AddModules": case "DocFileItem": case "IntermediateSatelliteAssembliesWithTargetPath": type = TargetType.Item; break; case "ContentWithTargetPath": case "AllItemsFullPathWithTargetPath": case "ReferenceCopyLocal": string condition; if (pi.TryGetMetaData("CopyToOutputDirectory", out condition)) { switch (condition) { case "Always": case "PreserveNewest": type = TargetType.SharedCopy; break; default: break; } } if (type == TargetType.None) { goto default; } break; case "ReferenceComWrappersToCopyLocal": case "ResolvedIsolatedComModules": case "_DeploymentLooseManifestFile": case "ReferenceCopyLocalPaths": case "NativeReferenceFile": string fusionName = pi.GetMetadata("FusionName"); if (!string.IsNullOrEmpty(fusionName)) { References.Add(new AssemblyReference(fusionName, pi, this)); } type = TargetType.SharedItem; break; default: if (!keys.TryGetValue(pi.Name, out type)) { type = TargetType.None; } break; } if (type != TargetType.None) { string target = CalculateTarget(pi); if (!items.ContainsKey(target)) { items.Add(new TargetItem(EnsureRelativePath(target), EnsureRelativePath(pi.Include), type, pi)); } } if (copyKeys.ContainsKey(pi.Name)) { string copyCondition; if (pi.TryGetMetaData("CopyToOutputDirectory", out copyCondition)) { switch (copyCondition) { case "Always": case "PreserveNewest": { localCopyItems[pi.Include] = true; } break; } } } } foreach (TargetItem ti in items.Values) { if (ti.Type == TargetType.SharedCopy) { if (localCopyItems.ContainsKey(ti.Include)) { ti.Type = TargetType.Copy; } } } }
private void WriteReflections() { BuildGroupContext groupContext = this.Context.GroupContexts[this.Group.Id]; if (groupContext == null) { throw new BuildException( "The group context is not provided, and it is required by the build system."); } string reflectionFile = Path.Combine( Path.GetDirectoryName(_tocFilePath), groupContext["$ReflectionFile"]); if (!File.Exists(reflectionFile)) { return; } XmlDocument document = new XmlDocument(); document.Load(reflectionFile); XPathNavigator documentNavigator = document.CreateNavigator(); XPathNavigator rootNavigator = documentNavigator.SelectSingleNode( "reflection/apis"); if (rootNavigator == null) { return; } XmlWriter writer = rootNavigator.AppendChild(); for (int i = 0; i < _undocumentedNodes.Count; i++) { KeyValuePair <string, HierarchicalTocNode> keyValue = _undocumentedNodes[i]; string fileName = keyValue.Key; HierarchicalTocNode node = keyValue.Value; string nodeText = node.FullText; string topicId = "N:" + nodeText; // This simulates a root namespace group or container, allowing // the transformations to create a list of namespaces with syntax // section added. The only issue is that the title include tag is // set to <include item="rootTopicTitle"/>, which we can change // to <include item="namespaceTopicTitle"/> using build components. writer.WriteStartElement("api"); // start: api writer.WriteAttributeString("id", topicId); writer.WriteStartElement("topicdata"); // start: topicdata writer.WriteAttributeString("name", nodeText); writer.WriteAttributeString("group", "root"); writer.WriteEndElement(); // end: topicdata writer.WriteStartElement("apidata"); // start: apidata writer.WriteAttributeString("name", nodeText); writer.WriteAttributeString("group", "namespace"); writer.WriteEndElement(); // end: apidata writer.WriteStartElement("elements"); // start: elements XPathNavigator tocExcludedNode = null; if (_dicTocExcludedNamespaces != null && _dicTocExcludedNamespaces.ContainsKey(topicId)) { tocExcludedNode = rootNavigator.SelectSingleNode( "api[@id='" + topicId + "']"); if (tocExcludedNode != null) { string topicFile = _dicTocExcludedNamespaces[topicId]; if (!String.IsNullOrEmpty(topicFile)) { XPathNavigator fileNode = tocExcludedNode.SelectSingleNode("file"); if (fileNode != null && fileNode.MoveToAttribute( "name", String.Empty)) { fileNode.SetValue(topicFile); if (tocExcludedNode.MoveToAttribute("id", String.Empty)) { tocExcludedNode.SetValue(GetTocExcludedTopic(topicId)); } } } } } if (node.HasChildren) { IList <HierarchicalTocNode> children = node.Children; for (int j = 0; j < children.Count; j++) { HierarchicalTocNode child = children[j]; writer.WriteStartElement("element"); // start: element writer.WriteAttributeString("api", "N:" + child.FullText); writer.WriteEndElement(); // end: element } } writer.WriteEndElement(); // end: elements writer.WriteStartElement("file"); // start: file writer.WriteAttributeString("name", fileName); writer.WriteEndElement(); // end: file writer.WriteEndElement(); // end: api } writer.Close(); if (!String.IsNullOrEmpty(_projectName)) { XPathNavigator navigator = rootNavigator.SelectSingleNode( "api[starts-with(@id, 'R:')]"); if (navigator != null && navigator.MoveToChild("elements", String.Empty)) { writer = navigator.AppendChild(); for (int i = 0; i < _undocumentedNodes.Count; i++) { KeyValuePair <string, HierarchicalTocNode> keyValue = _undocumentedNodes[i]; HierarchicalTocNode node = keyValue.Value; string topicId = "N:" + node.FullText; if (_dicTocExcludedNamespaces != null && _dicTocExcludedNamespaces.ContainsKey(topicId)) { continue; } writer.WriteStartElement("element"); // start: element writer.WriteAttributeString("api", topicId); writer.WriteEndElement(); // end: element } writer.Close(); } } document.Save(reflectionFile); }
public virtual void Initialize(BuildContext context) { BuildExceptions.NotNull(context, "context"); base.Initialize(context.Logger); BuildSettings settings = context.Settings; if (settings == null) { this.IsInitialized = false; return; } _context = context; _sandcastleDir = context.SandcastleDirectory; _sandcastleAssistDir = settings.SandAssistDirectory; // Make sure the default component handlers are added... //Keyword: "$(SandcastleComponent)"; if (!_dicConfigMap.ContainsKey("SandcastleComponent")) { string sandcastleComponents = null; if (context.IsDirectSandcastle) { if (!String.IsNullOrEmpty(_sandcastleAssistDir) || Directory.Exists(_sandcastleAssistDir)) { sandcastleComponents = Path.Combine(_sandcastleAssistDir, "Sandcastle.BuildAssembler.dll"); } } else { if (!String.IsNullOrEmpty(_sandcastleDir) || Directory.Exists(_sandcastleDir)) { sandcastleComponents = Path.Combine(_sandcastleDir, @"ProductionTools\BuildComponents.dll"); } } if (!String.IsNullOrEmpty(sandcastleComponents) && File.Exists(sandcastleComponents)) { _dicConfigMap.Add("SandcastleComponent", sandcastleComponents); } } //Keyword: "$(SandAssistComponent)"; if (_dicConfigMap.ContainsKey("SandAssistComponent") == false) { if (String.IsNullOrEmpty(_sandcastleAssistDir) == false || Directory.Exists(_sandcastleAssistDir)) { // If the Sandcastle Assist component assembly is in the same // directory as the Sandcastle Helpers... string assistComponents = Path.Combine(_sandcastleAssistDir, "Sandcastle.Components.dll"); if (File.Exists(assistComponents)) { _dicConfigMap.Add("SandAssistComponent", assistComponents); } else { // Otherwise, if in the "Components" sub-directory... assistComponents = Path.Combine(_sandcastleAssistDir, @"Components\Sandcastle.Components.dll"); if (File.Exists(assistComponents)) { _dicConfigMap.Add("SandAssistComponent", assistComponents); } } } } this.IsInitialized = true; }