//===================================================================== #if DEBUG /// <summary> /// Dump the references to an XML file /// </summary> /// <param name="targetsFile">The file in which to store the targets as XML</param> /// <remarks>This is used as a debugging aid to compare the resolved references to prior versions and /// ensure that they match.</remarks> public void DumpTargetDictionary(string targetsFile) { LinkTextResolver resolver = new LinkTextResolver(this); XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(targetsFile, settings)) { writer.WriteStartDocument(); writer.WriteStartElement("References"); writer.WriteAttributeString("Count", this.Count.ToString(CultureInfo.InvariantCulture)); foreach (var td in targetDictionaries.Reverse <KeyValuePair <ReferenceLinkType, TargetDictionary> >()) { foreach (var target in td.Value) { writer.WriteStartElement("Reference"); writer.WriteAttributeString("Id", target.Key); resolver.WriteTarget(target.Value, DisplayOptions.All, writer); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteEndDocument(); } }
//===================================================================== /// <inheritdoc /> public override void Initialize(XPathNavigator configuration) { TargetDictionary newTargets; ReferenceLinkType type; string attrValue, id; targets = new TargetTypeDictionary(); resolver = new LinkTextResolver(targets); // Get the shared instances dictionary. Create it if it doesn't exist. if(BuildComponentCore.Data.ContainsKey(SharedReferenceTargetsId)) sharedTargets = BuildComponentCore.Data[SharedReferenceTargetsId] as Dictionary<string, TargetDictionary>; if(sharedTargets == null) BuildComponentCore.Data[SharedReferenceTargetsId] = sharedTargets = new Dictionary<string, TargetDictionary>(); // base-url is an xpath expression applied against the current document to pick up the save location of the // document. If specified, local links will be made relative to the base-url. string baseUrlValue = configuration.GetAttribute("base-url", String.Empty); if(!String.IsNullOrEmpty(baseUrlValue)) baseUrl = XPathExpression.Compile(baseUrlValue); // hrefFormat is a string format that is used to format the value of local href attributes. The // default is "{0}.htm" if not specified. hrefFormat = (string)configuration.Evaluate("string(hrefFormat/@value)"); if(String.IsNullOrWhiteSpace(hrefFormat)) hrefFormat = "{0}.htm"; // The container XPath can be replaced; this is useful string containerValue = configuration.GetAttribute("container", String.Empty); if(!String.IsNullOrEmpty(containerValue)) XmlTargetDictionaryUtilities.ContainerExpression = containerValue; XPathNodeIterator targetsNodes = configuration.Select("targets"); #if DEBUG this.WriteMessage(MessageLevel.Diagnostic, "Loading reference link target info"); DateTime startLoad = DateTime.Now; #endif foreach(XPathNavigator targetsNode in targetsNodes) { // Get target type attrValue = targetsNode.GetAttribute("type", String.Empty); if(String.IsNullOrEmpty(attrValue)) this.WriteMessage(MessageLevel.Error, "Each targets element must have a type attribute " + "that specifies which type of links to create"); if(!Enum.TryParse<ReferenceLinkType>(attrValue, true, out type)) this.WriteMessage(MessageLevel.Error, "'{0}' is not a supported reference link type", attrValue); // Check for shared instance by ID. If not there, create it and add it. id = targetsNode.GetAttribute("id", String.Empty); if(!sharedTargets.TryGetValue(id, out newTargets)) { this.WriteMessage(MessageLevel.Info, "Loading {0} reference link type targets", type); newTargets = this.CreateTargetDictionary(targetsNode); sharedTargets[newTargets.DictionaryId] = newTargets; } targets.Add(type, newTargets); } #if DEBUG TimeSpan loadTime = (DateTime.Now - startLoad); this.WriteMessage(MessageLevel.Diagnostic, "Load time: {0} seconds", loadTime.TotalSeconds); // Dump targets for comparison to other versions // targets.DumpTargetDictionary(Path.GetFullPath("TargetDictionary.xml")); // Serialization test // targets.SerializeDictionary(Directory.GetCurrentDirectory()); #endif // Getting the count from a database cache can be expensive so only report it if it will be seen if(this.BuildAssembler.VerbosityLevel == MessageLevel.Info) this.WriteMessage(MessageLevel.Info, "{0} total reference link targets", targets.Count); if(targets.NeedsMsdnResolver) { this.WriteMessage(MessageLevel.Info, "Creating MSDN URL resolver"); msdnResolver = this.CreateMsdnResolver(configuration); string localeValue = (string)configuration.Evaluate("string(locale/@value)"); if(msdnResolver != null && !String.IsNullOrWhiteSpace(localeValue)) msdnResolver.Locale = localeValue; } linkTarget = (string)configuration.Evaluate("string(linkTarget/@value)"); if(String.IsNullOrWhiteSpace(linkTarget)) linkTarget = "_blank"; }
internal static void WriteSimpleMemberReference(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, LinkTextResolver resolver) { string cer = member.Id; string typeCer, memberName, arguments; DecomposeMemberIdentifier(cer, out typeCer, out memberName, out arguments); if((options & DisplayOptions.ShowContainer) > 0) { SimpleTypeReference type = CreateSimpleTypeReference(typeCer); WriteSimpleTypeReference(type, options & ~DisplayOptions.ShowContainer, writer); writer.WriteString("."); } // Change this so that we deal with EII names correctly, too writer.WriteString(memberName); if((options & DisplayOptions.ShowParameters) > 0) { if(String.IsNullOrEmpty(arguments)) { Parameter[] parameters = new Parameter[0]; resolver.WriteMethodParameters(parameters, writer); } else { IList<string> parameterTypeCers = SeparateTypes(arguments); Parameter[] parameters = new Parameter[parameterTypeCers.Count]; for(int i = 0; i < parameterTypeCers.Count; i++) { TypeReference parameterType = CreateTypeReference(parameterTypeCers[i]); if(parameterType == null) parameterType = new NamedTemplateTypeReference("UAT"); parameters[i] = new Parameter(String.Empty, parameterType); } resolver.WriteMethodParameters(parameters, writer); } } }
internal static void WriteSimpleMemberReference(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, LinkTextResolver resolver) { string cer = member.Id; string typeCer, memberName, arguments; DecomposeMemberIdentifier(cer, out typeCer, out memberName, out arguments); if ((options & DisplayOptions.ShowContainer) > 0) { SimpleTypeReference type = CreateSimpleTypeReference(typeCer); WriteSimpleTypeReference(type, options & ~DisplayOptions.ShowContainer, writer); writer.WriteString("."); } // Change this so that we deal with EII names correctly, too writer.WriteString(memberName); if ((options & DisplayOptions.ShowParameters) > 0) { if (String.IsNullOrEmpty(arguments)) { Parameter[] parameters = new Parameter[0]; resolver.WriteMethodParameters(parameters, writer); } else { IList <string> parameterTypeCers = SeparateTypes(arguments); Parameter[] parameters = new Parameter[parameterTypeCers.Count]; for (int i = 0; i < parameterTypeCers.Count; i++) { TypeReference parameterType = CreateTypeReference(parameterTypeCers[i]); if (parameterType == null) { parameterType = new NamedTemplateTypeReference("UAT"); } parameters[i] = new Parameter(String.Empty, parameterType); } resolver.WriteMethodParameters(parameters, writer); } } }