Exemplo n.º 1
0
		/// <summary>
		/// Constructs a new instance of HtmlFactory
		/// </summary>
		/// <param name="tempFileName">NDoc generated temp xml file</param>
		/// <param name="outputDirectory">The directory to write the Html files to</param>
		/// <param name="htmlProvider">Object the provides additional Html content</param>
		/// <param name="config"></param>
		public HtmlFactory( string tempFileName, string outputDirectory, ExternalHtmlProvider htmlProvider, NativeHtmlHelp2Config config )
		{
			Debug.WriteLine("mem before doc load " + GC.GetTotalMemory(true).ToString());
			// Load the XML documentation.
			xmlDocumentation = new XmlDocument();
			Stream tempFile=null;
			try
			{
				tempFile=File.Open(tempFileName,FileMode.Open,FileAccess.Read);

				FilteringXmlTextReader fxtr = new FilteringXmlTextReader(tempFile);
				xmlDocumentation.Load(fxtr);

				tempFile.Seek(0,SeekOrigin.Begin);

				XmlTextReader reader = new XmlTextReader(tempFile);
				xPathDocumentation = new XPathDocument(reader,XmlSpace.Preserve);

			}
			finally
			{
				if (tempFile!=null) tempFile.Close();
				if (File.Exists(tempFileName)) File.Delete(tempFileName);
			}

			//check if there is anything to document
			XmlNodeList typeNodes = xmlDocumentation.SelectNodes("/ndoc/assembly/module/namespace/*[name()!='documentation']");
			if ( typeNodes.Count == 0 )			
				throw new DocumenterException("There are no documentable types in this project.\n\nAny types that exist in the assemblies you are documenting have been excluded by the current visibility settings.\nFor example, you are attempting to document an internal class, but the 'DocumentInternals' visibility setting is set to False.\n\nNote: C# defaults to 'internal' if no accessibilty is specified, which is often the case for Console apps created in VS.NET...");

			if ( !Directory.Exists( outputDirectory ) )
				throw new Exception( string.Format( "The output directory {0}, does not exist", outputDirectory ) );

			_outputDirectory = outputDirectory;
			documentedNamespaces = new ArrayList();
		


			string NSName="";
			string FrameworkVersion="";
			if ( config.SdkDocVersion == SdkVersion.SDK_v1_0 )
			{
				NSName = "ms-help://MS.NETFrameworkSDK";
				FrameworkVersion="1.0";
			}
			else if ( config.SdkDocVersion == SdkVersion.SDK_v1_1 )
			{
				NSName = "ms-help://MS.NETFrameworkSDKv1.1";
				FrameworkVersion="1.1";
			}
            else if (config.SdkDocVersion == SdkVersion.SDK_v2_0)
            {
                NSName = "ms-help://MS.NETFrameworkSDKv2.0";
                FrameworkVersion = "2.0";
            }
			else
				Debug.Assert( false );		// remind ourselves to update this list when new framework versions are supported

			string DocLangCode = Enum.GetName(typeof(SdkLanguage),config.SdkDocLanguage).Replace("_","-");
			if (DocLangCode != "en")
				NSName = NSName + "." + DocLangCode;

			nsMapper = new NamespaceMapper( Path.Combine( Directory.GetParent( _outputDirectory ).ToString(), "NamespaceMap.xml" ) );
			nsMapper.SetSystemNamespace(NSName);

			fileNameMapper = new FileNameMapper(xmlDocumentation);
			_htmlProvider = htmlProvider;
			_utilities = new MsdnXsltUtilities( this.nsMapper, this.fileNameMapper );

			this.Arguments = new XsltArgumentList();
			this.Arguments.AddExtensionObject( "urn:ndoc-sourceforge-net:documenters.NativeHtmlHelp2.xsltUtilities", _utilities );
			this.Arguments.AddExtensionObject( "urn:NDocExternalHtml", _htmlProvider );

			// add properties passed to the stylesheets
			this.Arguments.AddParam( "ndoc-title", "", config.Title );
			this.Arguments.AddParam( "ndoc-document-attributes", "", config.DocumentAttributes );
			this.Arguments.AddParam( "ndoc-net-framework-version", "", FrameworkVersion );
			this.Arguments.AddParam( "ndoc-version", "", config.Version );

			XPathDocument DocumenterSpecificXml = GetDocumenterSpecificXmlData(config);
			XPathNodeIterator it = DocumenterSpecificXml.CreateNavigator().Select("*");
			this.Arguments.AddParam( "documenter-specific-xml", "", it );
			
		}
Exemplo n.º 2
0
		/// <summary>See <see cref="IDocumenter"/>.</summary>
		public override void Build(Project project)
		{
			if ( !HxObject.HxCompIsInstalled )
				throw new DocumenterException( "Could not find Html Help 2 compiler. Please make sure VSHIK 2003 is properly installed" );

			try
			{
#if DEBUG
				int start = Environment.TickCount;
#endif
				OnDocBuildingStep( 0, "Initializing..." );

				Workspace workspace = new NativeHtmlHelp2Workspace( WorkingPath );
				workspace.Clean();
				workspace.Prepare();

				UnPackResources( workspace );

				// set up the includes file
				IncludeFile includes = IncludeFile.CreateFrom( Path.Combine( workspace.ResourceDirectory, "includes.hxf" ), "includes" );
				// attach to this event so resource directories get included in the include file
				workspace.ContentDirectoryAdded += new ContentEventHandler( includes.AddDirectory ); 

				// create and save the named url index
				CreateNamedUrlIndex( workspace );

				// save the includes file
				includes.Save( workspace.WorkingDirectory );

				// set up the table of contents
				TOCFile toc = TOCFile.CreateFrom( Path.Combine( workspace.ResourceDirectory, "project.HxT" ), MyConfig.HtmlHelpName );
				toc.LangId = MyConfig.LangID;

				// set up the project file
				ProjectFile HxProject = CreateProjectFile( workspace );
				HxProject.TOCFile = toc.FileName;
				HxProject.Save( workspace.WorkingDirectory );

				// get the ndoc xml
				OnDocBuildingStep( 10, "Merging XML documentation..." );

				// Will hold the name of the file name containing the XML doc
				string tempFileName = null;

				HtmlFactory factory = null;

				try 
				{
					// determine temp file name
					tempFileName = Path.GetTempFileName();
					// Let the Documenter base class do it's thing.
					MakeXmlFile(project, tempFileName);

					GC.Collect();
					GC.WaitForPendingFinalizers();
					GC.Collect();

					// create and intialize a HtmlFactory
					ExternalHtmlProvider htmlProvider = new ExternalHtmlProvider(
						MyConfig.HeaderHtml, MyConfig.FooterHtml);
					factory = new HtmlFactory(tempFileName, 
						workspace.ContentDirectory, htmlProvider, MyConfig);
				} 
				finally 
				{
					if (tempFileName != null && File.Exists(tempFileName)) 
					{
						File.Delete(tempFileName);
					}
				}

				// generate all the html content - builds the toc along the way
				using( new TOCBuilder( toc, factory ) )
					MakeHtml( workspace, factory );

				toc.Save( workspace.WorkingDirectory );

				//then compile the HxC into an HxS
				OnDocBuildingStep( 65, "Compiling Html Help 2 Files..." );
				CompileHxCFile( workspace );

				// copy outputs to the final build location
				workspace.SaveOutputs( "*.Hxs" );
				workspace.SaveOutputs( "*.HxI" );

				// do clean up and final registration steps
				OnDocBuildingStep( 95, "Finishing up..." );

				if ( MyConfig.RegisterTitleWithNamespace )
					RegisterTitleWithCollection( workspace );
				else if ( MyConfig.RegisterTitleAsCollection )
					RegisterTitleAsCollection( workspace );

				// create collection level files
				if( MyConfig.GenerateCollectionFiles )
					CreateCollectionFiles( workspace );

				workspace.RemoveResourceDirectory();
				if ( MyConfig.CleanIntermediates )
					workspace.CleanIntermediates();

#if DEBUG
				Trace.WriteLine( string.Format( "It took a total of {0} seconds", ( Environment.TickCount - start ) / 1000 ) );
#endif
				Trace.WriteLine( "Build complete" );
			}
			catch ( Exception e )
			{
				throw new DocumenterException( "An error occured while creating the documentation", e );
			}
		}