Api Filter on constructs tagged with .Net Attributes

Topics: Developer Forum, Project Management Forum, User Forum
Nov 21, 2007 at 3:50 PM
Edited Apr 8, 2008 at 11:45 AM
Hi,

I'd like to be able to construct a help file that only contains methods, classes, etc... tagged with a certain .Net Attribute. Is this possible?

Thanks

Christophe
Coordinator
Nov 21, 2007 at 4:07 PM
The API filter works by name so it isn't possible to exclude items by attribute. You could create a plug-in that runs after the GenerateReflectionInfo step that loads the XML file and purges all items marked with a given set of attributes.

Eric
Nov 21, 2007 at 4:23 PM
Eric,

That is the pointer I needed!

Thanks

Christophe
Mar 25, 2008 at 12:03 PM
Edited Mar 25, 2008 at 12:09 PM
Hi Eric,

I now created a plugin that filters the reflection.org after the GenerateReflectionInfo build step using an xslt transform. However, I cannot replace the original reflection.org with the filtered one because the former is locked (by Sandcastle?). Is there a way or a build step where the reflection.org is no more locked so that I can replace it with the filtered one? Hereunder the relevant sections of my plugin:

public ExecutionPointCollection ExecutionPoints {
get {
if (executionPoints == null) {
executionPoints = new ExecutionPointCollection();

executionPoints.Add(
new ExecutionPoint(
BuildStep.GenerateReflectionInfo,
ExecutionBehaviors.After
)
);
}

return executionPoints;
}
}

public void Initialize(BuildProcess buildProcess, XPathNavigator configuration) {
builder = buildProcess;
}


public void Execute(ExecutionContext context) {

builder.ReportProgress("ShfbPlugIn.Execute(): Entering");
builder.ReportProgress("ShfbPlugIn.Execute(): ReflectionInfoFileName: {0}", Builder.ReflectionInfoFilename);

try {
string styleSheetPath = Path.Combine(builder.HelpFileBuilderFolder, "Plugins");
styleSheetPath = Path.Combine(styleSheetPath, "ExternalApiFilter.xslt");

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(styleSheetPath);
xslt.Transform(builder.ReflectionInfoFilename, builder.ReflectionInfoFilename);
}
catch (Exception e) {
builder.ReportProgress("ShfbPlugIn.Execute(): Got exception: {0}", e);
}

builder.ReportProgress("ShfbPlugIn.Execute(): Leaving");
}


Thanks

Christophe
Coordinator
Mar 25, 2008 at 4:13 PM
Edited Mar 25, 2008 at 4:16 PM
Hi Christophe,

SHFB doesn't open the reflection file until after the GenerateReflectionInfo build step. I think the problem is that you are trying to transform the file from and to the same name. I had a similar issue when I added the code to transform the .topic files. You need to transform the file to a different filename and you have to use a reader and a writer each with settings that tell them to close after they are done. Here's the general flow based on the topic file transformation I do:

XmlReader reader = null;
XmlWriter writer = null;
XsltSettings settings;
XmlReaderSettings readerSettings;
XmlWriterSettings writerSettings;
 
try
{
    readerSettings = new XmlReaderSettings();
    readerSettings.CloseInput = true;
 
    xslTransform = new XslCompiledTransform();
    settings = new XsltSettings(true, true);
 
    xslTransform.Load(XmlReader.Create(xslStylesheet,
        readerSettings), settings, new XmlUrlResolver());
 
    this.ReportProgress("Applying XSL transformation '{0}' to " +
        "'{1}'.", xslStylesheet, sourceFile);
 
    reader = XmlReader.Create(sourceFile, readerSettings);
    writerSettings = xslTransform.OutputSettings.Clone();
    writerSettings.CloseOutput = true;
 
    writer = XmlWriter.Create(destFile, writerSettings);
 
    xslTransform.Transform(reader, null, writer);
}
catch(Exception ex)
{
    // Handle exception or rethrow
}
finally
{
    if(reader != null)
        reader.Close();
 
    if(writer != null)
    {
        writer.Flush();
        writer.Close();
    }
}
 
// Rename the file when done
File.Delete(sourceFile);
File.Move(destFile, sourceFile);

Eric
Mar 26, 2008 at 10:43 AM
Hi Eric,

This makes sense! I didn't think about that. I'll let you know how it goes!

Thanks

Christophe
Mar 26, 2008 at 1:07 PM
Hi Eric,

It works! Thanks! But now it appears that I need to improve my stylesheet a little bit :-)

Cheers

Christophe