public void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener(new Dictionary <string, string>());

            string   basePath = this.GetType().Namespace + ".Templates." + this.Template;
            Assembly asm      = Assembly.GetExecutingAssembly();

            string[] names = asm.GetManifestResourceNames();

            foreach (string name in names)
            {
                if (!name.StartsWith(basePath))
                {
                    continue;
                }


                string outputPath =
                    System.IO.Path.GetFullPath(
                        System.IO.Path.Combine(
                            this.Path, name.Substring(basePath.Length + 1)));
                string outputDir = System.IO.Path.GetDirectoryName(outputPath);
                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }
                using (Stream inputStream = asm.GetManifestResourceStream(name))
                    using (Stream fileStream = File.OpenWrite(outputPath))
                        inputStream.CopyTo(fileStream);
            }
        }
        public void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener(new Dictionary<string, string>());

            string basePath = this.GetType().Namespace + ".Templates." + this.Template;
            Assembly asm = Assembly.GetExecutingAssembly();
            string[] names = asm.GetManifestResourceNames();

            foreach (string name in names)
            {
                if (!name.StartsWith(basePath))
                    continue;


                string outputPath =
                    System.IO.Path.GetFullPath(
                                               System.IO.Path.Combine(
                                                                      this.Path, name.Substring(basePath.Length + 1)));
                string outputDir = System.IO.Path.GetDirectoryName(outputPath);
                if (!Directory.Exists(outputDir))
                    Directory.CreateDirectory(outputDir);
                using (Stream inputStream = asm.GetManifestResourceStream(name))
                using (Stream fileStream = File.OpenWrite(outputPath))
                    inputStream.CopyTo(fileStream);
            }
        }
示例#3
0
        public void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener(new Dictionary<string, string>
                                                                         {
                                                                             {"LostDoc.Core.DocGenerator", "Build"},
                                                                         });

            TraceSources.GeneratorSource.Listeners.Add(traceListener);

            try
            {
                SetTraceLevel();
                
                if (!File.Exists(this.Path))
                {
                    Console.WriteLine("File not found: '{0}'", this.Path);
                    return;
                }

                this.Output = BuildOutputFilePath();

                DocGenerator gen = new DocGenerator(container);

                gen.AssetFilters.AddRange(
                    BuildAssetFilters());

                gen.Enrichers.AddRange(
                    BuildEnrichers());

                gen.AddAssembly(this.Path);
                
                XDocument rawDoc = gen.Generate();

                
                //StringWriter output = new StringWriter();
                //try
                //{
                //    using (
                //        XmlWriter writer = XmlWriter.Create(output,
                //                                            new XmlWriterSettings
                //                                                {
                //                                                    CheckCharacters = true,
                //                                                    Encoding = Encoding.ASCII
                //                                                }))
                //        rawDoc.Save(writer);
                //}
                //catch
                //{
                    
                //}

                rawDoc.Save(this.Output);

            }
            finally
            {
                TraceSources.GeneratorSource.Listeners.Remove(traceListener);
            }
        }
示例#4
0
        public void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener(new Dictionary <string, string>
            {
                { "LostDoc.Core.DocGenerator", "Build" },
            });

            TraceSources.GeneratorSource.Listeners.Add(traceListener);

            try
            {
                SetTraceLevel();

                if (!File.Exists(this.Path))
                {
                    Console.WriteLine("File not found: '{0}'", this.Path);
                    return;
                }

                this.Output = BuildOutputFilePath();

                DocGenerator gen = new DocGenerator(container);

                gen.AssetFilters.AddRange(
                    BuildAssetFilters());

                gen.Enrichers.AddRange(
                    BuildEnrichers());

                gen.AddAssembly(this.Path);

                XDocument rawDoc = gen.Generate();


                //StringWriter output = new StringWriter();
                //try
                //{
                //    using (
                //        XmlWriter writer = XmlWriter.Create(output,
                //                                            new XmlWriterSettings
                //                                                {
                //                                                    CheckCharacters = true,
                //                                                    Encoding = Encoding.ASCII
                //                                                }))
                //        rawDoc.Save(writer);
                //}
                //catch
                //{

                //}

                rawDoc.Save(this.Output);
            }
            finally
            {
                TraceSources.GeneratorSource.Listeners.Remove(traceListener);
            }
        }
示例#5
0
        public void Invoke()
        {
            var traceListener = new ConsolidatedConsoleTraceListener(new Dictionary<string, string>
                                                                         {
                                                                             {"LostDoc.Core.DocGenerator", "Build"},
                                                                         });

            TraceSources.GeneratorSource.Listeners.Add(traceListener);

            try
            {
                if (this.Quiet.IsPresent)
                {
                    const SourceLevels quietLevel = SourceLevels.Error | SourceLevels.Warning | SourceLevels.Critical;
                    TraceSources.GeneratorSource.Switch.Level = quietLevel;
                }
                else  if (this.Verbose.IsPresent)
                {
                    const SourceLevels verboseLevel = SourceLevels.All;
                    TraceSources.GeneratorSource.Switch.Level = verboseLevel;
                }
                else
                {
                    const SourceLevels normalLevel = SourceLevels.Information |
                                                     SourceLevels.Warning |
                                                     SourceLevels.Error |
                                                     SourceLevels.Critical |
                                                     SourceLevels.ActivityTracing;
                    TraceSources.GeneratorSource.Switch.Level = normalLevel;
                }

                DocGenerator gen = new DocGenerator();
                gen.AssetFilters.Add(new ComObjectTypeFilter());
                gen.AssetFilters.Add(new CompilerGeneratedFilter());
                if (!this.IncludeNonPublic.IsPresent)
                    gen.AssetFilters.Add(new PublicTypeFilter());

                gen.AssetFilters.Add(new PrivateImplementationDetailsFilter());
                gen.AssetFilters.Add(new DynamicallyInvokableAttributeFilter());
                gen.AssetFilters.Add(new CompilerGeneratedFilter());
                gen.AssetFilters.Add(new LogicalMemberInfoVisibilityFilter());
                gen.AssetFilters.Add(new SpecialNameMemberInfoFilter());

                if (!string.IsNullOrWhiteSpace(this.Filter))
                    gen.AssetFilters.Add(new AssetGlobFilter { Include = this.Filter });

                XmlDocEnricher docEnricher = new XmlDocEnricher();
                gen.Enrichers.Add(docEnricher);


                if (!string.IsNullOrEmpty(this.NamespaceDocPath))
                {
                    var namespaceEnricher = new ExternalNamespaceDocEnricher();
                    if (System.IO.Path.IsPathRooted(this.NamespaceDocPath))
                        namespaceEnricher.Load(this.NamespaceDocPath);
                    else if (
                        File.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path),
                                                           this.NamespaceDocPath)))
                        namespaceEnricher.Load(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path),
                                                                      this.NamespaceDocPath));
                    else
                        namespaceEnricher.Load(this.NamespaceDocPath);

                    gen.Enrichers.Add(namespaceEnricher);
                }


                if (!File.Exists(this.Path))
                {
                    Console.WriteLine("File not found: '{0}'", this.Path);
                    return;
                }

                if (this.IncludeBclDocComments.IsPresent)
                {
                    string winPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                    string bclDocPath = System.IO.Path.Combine(winPath, @"microsoft.net\framework\",
                                                               string.Format("v{0}.{1}.{2}",
                                                                             Environment.Version.Major,
                                                                             Environment.Version.Minor,
                                                                             Environment.Version.Build),
                                                               @"en\");


                    docEnricher.AddPath(bclDocPath);

                    bclDocPath = System.IO.Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                        @"Reference Assemblies\Microsoft\Framework\.NETFramework",
                        string.Format("v{0}.{1}",
                                      Environment.Version.Major,
                                      Environment.Version.Minor));

                    docEnricher.AddPath(bclDocPath);
                }

                gen.AddAssembly(this.Path);


                var assemblyName = AssemblyName.GetAssemblyName(this.Path);

                XDocument rawDoc = gen.Generate();
                string fileName = System.IO.Path.Combine(this.Output ?? System.IO.Path.GetDirectoryName(this.Path),
                                                         string.Format("{0}_{1}.ldoc",
                                                                       System.IO.Path.GetFileName(this.Path),
                                                                       assemblyName.Version));

                this.Output = System.IO.Path.GetFullPath(fileName);

                if (!Directory.Exists(System.IO.Path.GetDirectoryName(fileName)))
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fileName));
                //StringWriter output = new StringWriter();
                //try
                //{
                //    using (
                //        XmlWriter writer = XmlWriter.Create(output,
                //                                            new XmlWriterSettings
                //                                                {
                //                                                    CheckCharacters = true,
                //                                                    Encoding = Encoding.ASCII
                //                                                }))
                //        rawDoc.Save(writer);
                //}
                //catch
                //{
                    
                //}

                rawDoc.Save(fileName);

            }
            finally
            {
                TraceSources.GeneratorSource.Listeners.Remove(traceListener);
            }
        }
示例#6
0
        public void Invoke()
        {
            var traceListener = new ConsolidatedConsoleTraceListener(
                new Dictionary<string, string>
                    {
                        {
                            "LostDoc.Core.Template",
                            "Template"
                        },
                        {
                            "LostDoc.Core.Bundle",
                            "Bundle"
                        },
                        {
                            "LostDoc.Core.Template.AssetResolver",
                            "Resolve"
                        }
                    });

            
            TraceSources.TemplateSource.Listeners.Add(traceListener);
            TraceSources.AssetResolverSource.Listeners.Add(traceListener);
            try
            {
                if (this.Verbose.IsPresent)
                {
                    const SourceLevels verboseLevel = SourceLevels.All;
                    TraceSources.TemplateSource.Switch.Level = verboseLevel;
                    TraceSources.AssetResolverSource.Switch.Level = verboseLevel;
                    TraceSources.BundleSource.Listeners.Add(traceListener);
                }
                else
                {
                    const SourceLevels normalLevel = SourceLevels.Information | SourceLevels.Warning | SourceLevels.Error | SourceLevels.ActivityTracing;
                    TraceSources.TemplateSource.Switch.Level = normalLevel;
                    TraceSources.AssetResolverSource.Switch.Level = normalLevel;
                }

                LinkedList<FileInfo> includedFiles = new LinkedList<FileInfo>();

                if (File.Exists(this.Path))
                    includedFiles.AddLast(new FileInfo(this.Path));
                else if (Directory.Exists(this.Path))
                {
                    Directory.GetFiles(this.Path, "*.ldoc", SearchOption.AllDirectories)
                             .Aggregate(includedFiles,
                                        (l, f) => l.AddLast(new FileInfo(f)).List);
                }
                else
                    throw new FileNotFoundException(System.IO.Path.GetFullPath(this.Path));


                Bundle bundle = new Bundle(this.IgnoreVersionComponent);

                TraceSources.TemplateSource.TraceInformation("Merging LostDoc files into bundle.");

                var xmlSettings = new XmlReaderSettings
                {
                    CheckCharacters = false
                };

                foreach (FileInfo file in includedFiles)
                {
                    TraceSources.TemplateSource.TraceEvent(TraceEventType.Information, 0, "Path: {0}", file.Name);
                    XDocument fileDoc;
                    using (var reader = XmlReader.Create(file.FullName, xmlSettings))
                        fileDoc = XDocument.Load(reader);

                    bundle.Add(fileDoc);
                }

                // find template
                string appDir = Assembly.GetExecutingAssembly().Location;
                string cwDir = Directory.GetCurrentDirectory();


                IFileProvider fsProvider = new DirectoryFileProvider();
                IFileProvider resourceProvider = new ResourceFileProvider("LBi.LostDoc.ConsoleApplication.Templates");

                IFileProvider selectedFileProvider = null;
                string templatePath = null;

                if (System.IO.Path.IsPathRooted(this.Template) &&
                    fsProvider.FileExists(System.IO.Path.Combine(this.Template, "template.xml")))
                {
                    selectedFileProvider = fsProvider;
                    templatePath = this.Template;
                }
                else if (!System.IO.Path.IsPathRooted(this.Template))
                {
                    string tmp = System.IO.Path.Combine(cwDir, this.Template, "template.xml");
                    if (fsProvider.FileExists(tmp))
                    {
                        selectedFileProvider = fsProvider;
                        templatePath = tmp;
                    }
                    else
                    {
                        tmp = System.IO.Path.Combine(appDir, this.Template, "template.xml");
                        if (fsProvider.FileExists(tmp))
                        {
                            selectedFileProvider = fsProvider;
                            templatePath = tmp;
                        }
                        else
                        {
                            tmp = System.IO.Path.Combine(this.Template, "template.xml");
                            if (resourceProvider.FileExists(tmp))
                            {
                                selectedFileProvider = resourceProvider;
                                templatePath = tmp;
                            }
                        }
                    }
                }

                if (templatePath == null)
                    throw new FileNotFoundException(this.Template);

                string outputDir = this.Output
                                   ?? (Directory.Exists(this.Path)
                                           ? this.Path
                                           : System.IO.Path.GetDirectoryName(this.Path));

                Template template = new Template(selectedFileProvider);

                template.Load(templatePath);
                AssetRedirectCollection assetRedirects;
                XDocument mergedDoc = bundle.Merge(out assetRedirects);
                var templateData = new TemplateData
                                       {
                                           OverwriteExistingFiles = this.Force.IsPresent,
                                           AssetRedirects = assetRedirects,
                                           Document = mergedDoc,
                                           IgnoredVersionComponent = this.IgnoreVersionComponent,
                                           Arguments = this.Arguments,
                                           TargetDirectory = outputDir
                                       };

                template.Generate(templateData);
            }
            finally
            {
                TraceSources.TemplateSource.Listeners.Remove(traceListener);
                TraceSources.AssetResolverSource.Listeners.Remove(traceListener);
            }
        }
示例#7
0
        public void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener(
                new Dictionary <string, string>
            {
                {
                    "LostDoc.Core.Template",
                    "Template"
                },
                {
                    "LostDoc.Core.Bundle",
                    "Bundle"
                },
                {
                    "LostDoc.Core.Template.AssetResolver",
                    "Resolve"
                }
            });


            TraceSources.TemplateSource.Listeners.Add(traceListener);
            TraceSources.AssetResolverSource.Listeners.Add(traceListener);
            try
            {
                if (this.Quiet.IsPresent)
                {
                    const SourceLevels quietLevel = SourceLevels.Error | SourceLevels.Warning | SourceLevels.Critical;
                    TraceSources.TemplateSource.Switch.Level      = quietLevel;
                    TraceSources.AssetResolverSource.Switch.Level = quietLevel;
                    TraceSources.BundleSource.Listeners.Add(traceListener);
                }
                else if (this.Verbose.IsPresent)
                {
                    const SourceLevels verboseLevel = SourceLevels.All;
                    TraceSources.TemplateSource.Switch.Level      = verboseLevel;
                    TraceSources.AssetResolverSource.Switch.Level = verboseLevel;
                    TraceSources.BundleSource.Listeners.Add(traceListener);
                }
                else
                {
                    const SourceLevels normalLevel = SourceLevels.Information | SourceLevels.Warning | SourceLevels.Error | SourceLevels.ActivityTracing;
                    TraceSources.TemplateSource.Switch.Level      = normalLevel;
                    TraceSources.AssetResolverSource.Switch.Level = normalLevel;
                }

                LinkedList <FileInfo> includedFiles = new LinkedList <FileInfo>();

                if (File.Exists(this.Path))
                {
                    includedFiles.AddLast(new FileInfo(this.Path));
                }
                else if (Directory.Exists(this.Path))
                {
                    Directory.GetFiles(this.Path, "*.ldoc", SearchOption.AllDirectories)
                    .Aggregate(includedFiles,
                               (l, f) => l.AddLast(new FileInfo(f)).List);
                }
                else
                {
                    throw new FileNotFoundException(System.IO.Path.GetFullPath(this.Path));
                }


                Bundle bundle = new Bundle(this.IgnoreVersionComponent);

                TraceSources.TemplateSource.TraceInformation("Merging LostDoc files into bundle.");

                foreach (FileInfo file in includedFiles)
                {
                    TraceSources.TemplateSource.TraceEvent(TraceEventType.Information, 0, "Source: {0}", file.Name);
                    XDocument fileDoc = XDocument.Load(file.FullName);

                    bundle.Add(fileDoc);
                }

                var lazyProviders = container.GetExports <IFileProvider>(ContractNames.TemplateProvider);
                var realProviders = lazyProviders.Select(lazy => lazy.Value);
                TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray());

                Template template = new Template(container);
                template.Load(templateResolver, this.Template);

                string outputDir = this.Output
                                   ?? (Directory.Exists(this.Path)
                                           ? this.Path
                                           : System.IO.Path.GetDirectoryName(this.Path));
                AssetRedirectCollection assetRedirects;
                XDocument mergedDoc = bundle.Merge(out assetRedirects);

                var templateData = new TemplateData(mergedDoc)
                {
                    AssetRedirects          = assetRedirects,
                    OverwriteExistingFiles  = this.Force.IsPresent,
                    IgnoredVersionComponent = this.IgnoreVersionComponent,
                    Arguments          = this.Arguments,
                    OutputFileProvider = new ScopedFileProvider(new DirectoryFileProvider(), outputDir)
                };

                template.Generate(templateData);
            }
            finally
            {
                TraceSources.TemplateSource.Listeners.Remove(traceListener);
                TraceSources.AssetResolverSource.Listeners.Remove(traceListener);
            }
        }
        public override void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener
                                {
                                    { TraceSources.TemplateSource, "Template" },
                                    { TraceSources.BundleSource, "Bundle" },
                                    { TraceSources.AssetResolverSource, "Resolve" }
                                };

            using (traceListener)
            {
                this.ConfigureTraceLevels(traceListener);

                LinkedList<FileInfo> includedFiles = new LinkedList<FileInfo>();

                if (File.Exists(this.Path))
                    includedFiles.AddLast(new FileInfo(this.Path));
                else if (Directory.Exists(this.Path))
                {
                    Directory.GetFiles(this.Path, "*.ldoc", SearchOption.AllDirectories)
                             .Aggregate(includedFiles, (l, f) => l.AddLast(new FileInfo(f)).List);
                }
                else
                    throw new FileNotFoundException(System.IO.Path.GetFullPath(this.Path));


                Bundle bundle = new Bundle(this.IgnoreVersionComponent);

                TraceSources.TemplateSource.TraceInformation("Merging LostDoc files into bundle.");

                foreach (FileInfo file in includedFiles)
                {
                    TraceSources.TemplateSource.TraceEvent(TraceEventType.Information, 0, "Source: {0}", file.Name);
                    XDocument fileDoc = XDocument.Load(file.FullName);

                    bundle.Add(fileDoc);
                }

                var lazyProviders = container.GetExports<IFileProvider>(ContractNames.TemplateProvider);
                var realProviders = lazyProviders.Select(lazy => lazy.Value);
                TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray());
                TemplateInfo templateInfo = templateResolver.Resolve(this.Template);
                Template template = templateInfo.Load(container);

                string outputDir = this.Output
                                   ?? (Directory.Exists(this.Path)
                                           ? this.Path
                                           : System.IO.Path.GetDirectoryName(this.Path));
                AssetRedirectCollection assetRedirects;
                XDocument mergedDoc = bundle.Merge(out assetRedirects);

                var templateData = new TemplateData(mergedDoc)
                                       {
                                           AssetRedirects = assetRedirects,
                                           OverwriteExistingFiles = this.Force.IsPresent,
                                           IgnoredVersionComponent = this.IgnoreVersionComponent,
                                           Arguments = this.Arguments,
                                           OutputFileProvider = new ScopedFileProvider(new DirectoryFileProvider(), outputDir)
                                       };

                template.Generate(templateData);
            }

        }
示例#9
0
        public void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener(
                new Dictionary<string, string>
                    {
                        {
                            "LostDoc.Core.Template",
                            "Template"
                        },
                        {
                            "LostDoc.Core.Bundle",
                            "Bundle"
                        },
                        {
                            "LostDoc.Core.Template.AssetResolver",
                            "Resolve"
                        }
                    });

            
            TraceSources.TemplateSource.Listeners.Add(traceListener);
            TraceSources.AssetResolverSource.Listeners.Add(traceListener);
            try
            {
                if (this.Quiet.IsPresent)
                {
                    const SourceLevels quietLevel = SourceLevels.Error | SourceLevels.Warning | SourceLevels.Critical;
                    TraceSources.TemplateSource.Switch.Level = quietLevel;
                    TraceSources.AssetResolverSource.Switch.Level = quietLevel;
                    TraceSources.BundleSource.Listeners.Add(traceListener);
                }
                else if (this.Verbose.IsPresent)
                {
                    const SourceLevels verboseLevel = SourceLevels.All;
                    TraceSources.TemplateSource.Switch.Level = verboseLevel;
                    TraceSources.AssetResolverSource.Switch.Level = verboseLevel;
                    TraceSources.BundleSource.Listeners.Add(traceListener);
                }
                else
                {
                    const SourceLevels normalLevel = SourceLevels.Information | SourceLevels.Warning | SourceLevels.Error | SourceLevels.ActivityTracing;
                    TraceSources.TemplateSource.Switch.Level = normalLevel;
                    TraceSources.AssetResolverSource.Switch.Level = normalLevel;
                }

                LinkedList<FileInfo> includedFiles = new LinkedList<FileInfo>();

                if (File.Exists(this.Path))
                    includedFiles.AddLast(new FileInfo(this.Path));
                else if (Directory.Exists(this.Path))
                {
                    Directory.GetFiles(this.Path, "*.ldoc", SearchOption.AllDirectories)
                             .Aggregate(includedFiles,
                                        (l, f) => l.AddLast(new FileInfo(f)).List);
                }
                else
                    throw new FileNotFoundException(System.IO.Path.GetFullPath(this.Path));


                Bundle bundle = new Bundle(this.IgnoreVersionComponent);

                TraceSources.TemplateSource.TraceInformation("Merging LostDoc files into bundle.");

                foreach (FileInfo file in includedFiles)
                {
                    TraceSources.TemplateSource.TraceEvent(TraceEventType.Information, 0, "Source: {0}", file.Name);
                    XDocument fileDoc = XDocument.Load(file.FullName);

                    bundle.Add(fileDoc);
                }

                var lazyProviders = container.GetExports<IFileProvider>(ContractNames.TemplateProvider);
                var realProviders = lazyProviders.Select(lazy => lazy.Value);
                TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray());

                Template template = new Template(container);
                template.Load(templateResolver, this.Template);

                string outputDir = this.Output
                                   ?? (Directory.Exists(this.Path)
                                           ? this.Path
                                           : System.IO.Path.GetDirectoryName(this.Path));
                AssetRedirectCollection assetRedirects;
                XDocument mergedDoc = bundle.Merge(out assetRedirects);

                var templateData = new TemplateData(mergedDoc)
                                       {
                                           AssetRedirects = assetRedirects,
                                           OverwriteExistingFiles = this.Force.IsPresent,
                                           IgnoredVersionComponent = this.IgnoreVersionComponent,
                                           Arguments = this.Arguments,
                                           OutputFileProvider = new ScopedFileProvider(new DirectoryFileProvider(), outputDir)
                                       };

                template.Generate(templateData);
            }
            finally
            {
                TraceSources.TemplateSource.Listeners.Remove(traceListener);
                TraceSources.AssetResolverSource.Listeners.Remove(traceListener);
            }
        }
        public override void Invoke(CompositionContainer container)
        {
            var traceListener = new ConsolidatedConsoleTraceListener
                                {
                                    { TraceSources.GeneratorSource, "Build" },
                                    { TraceSources.AssemblyLoader, "Loader" },
                                    { TraceSources.AssetResolverSource, "Resolver" },
                                };

            using (traceListener)
            {
                this.ConfigureTraceLevels(traceListener);

                DocGenerator gen = new DocGenerator(container);
                gen.AssetFilters.Add(new ComObjectTypeFilter());
                gen.AssetFilters.Add(new CompilerGeneratedFilter());
                if (!this.IncludeNonPublic.IsPresent)
                    gen.AssetFilters.Add(new PublicTypeFilter());

                gen.AssetFilters.Add(new PrivateImplementationDetailsFilter());
                gen.AssetFilters.Add(new DynamicallyInvokableAttributeFilter());
                gen.AssetFilters.Add(new CompilerGeneratedFilter());
                gen.AssetFilters.Add(new LogicalMemberInfoVisibilityFilter());
                gen.AssetFilters.Add(new SpecialNameMemberInfoFilter());

                if (!string.IsNullOrWhiteSpace(this.Filter))
                    gen.AssetFilters.Add(new AssetGlobFilter { Include = this.Filter });

                XmlDocEnricher docEnricher = new XmlDocEnricher();
                gen.Enrichers.Add(docEnricher);


                if (!string.IsNullOrEmpty(this.NamespaceDocPath))
                {
                    var namespaceEnricher = new ExternalNamespaceDocEnricher();
                    if (System.IO.Path.IsPathRooted(this.NamespaceDocPath))
                        namespaceEnricher.Load(this.NamespaceDocPath);
                    else if (
                        File.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path),
                                                           this.NamespaceDocPath)))
                        namespaceEnricher.Load(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path),
                                                                      this.NamespaceDocPath));
                    else
                        namespaceEnricher.Load(this.NamespaceDocPath);

                    gen.Enrichers.Add(namespaceEnricher);
                }


                if (!File.Exists(this.Path))
                {
                    Console.WriteLine("File not found: '{0}'", this.Path);
                    return;
                }

                if (this.IncludeBclDocComments.IsPresent)
                {
                    string winPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                    string bclDocPath = System.IO.Path.Combine(winPath, @"microsoft.net\framework\",
                                                               string.Format("v{0}.{1}.{2}",
                                                                             Environment.Version.Major,
                                                                             Environment.Version.Minor,
                                                                             Environment.Version.Build),
                                                               @"en\");


                    docEnricher.AddPath(bclDocPath);

                    bclDocPath = System.IO.Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                        @"Reference Assemblies\Microsoft\Framework\.NETFramework",
                        string.Format("v{0}.{1}",
                                      Environment.Version.Major,
                                      Environment.Version.Minor));

                    docEnricher.AddPath(bclDocPath);
                }


                var assemblyName = AssemblyName.GetAssemblyName(this.Path);

                XDocument rawDoc = gen.Generate(this.Path);

                string fileName = System.IO.Path.Combine(this.Output ?? System.IO.Path.GetDirectoryName(this.Path),
                                                         string.Format("{0}_{1}.ldoc",
                                                                       System.IO.Path.GetFileName(this.Path),
                                                                       assemblyName.Version));

                this.Output = System.IO.Path.GetFullPath(fileName);

                if (!Directory.Exists(System.IO.Path.GetDirectoryName(fileName)))
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fileName));

                rawDoc.Save(fileName);

            }

        }
示例#11
0
        public void Invoke()
        {
            var traceListener = new ConsolidatedConsoleTraceListener(new Dictionary<string, string>
                                                                         {
                                                                             {"LostDoc.Core.DocGenerator", "Build"},
                                                                         });

            TraceSources.GeneratorSource.Listeners.Add(traceListener);

            try
            {

                if (this.Verbose.IsPresent)
                {
                    const SourceLevels verboseLevel = SourceLevels.All;
                    TraceSources.GeneratorSource.Switch.Level = verboseLevel;
                }
                else
                {
                    const SourceLevels normalLevel = SourceLevels.Information | SourceLevels.Warning | SourceLevels.Error | SourceLevels.ActivityTracing;
                    TraceSources.GeneratorSource.Switch.Level = normalLevel;
                }

                DocGenerator gen = new DocGenerator();

                gen.AssetFilters.Add(new CompilerGeneratedFilter());
                if (!this.IncludeNonPublic.IsPresent)
                    gen.AssetFilters.Add(new PublicTypeFilter());

                gen.AssetFilters.Add(new CompilerGeneratedFilter());
                gen.AssetFilters.Add(new LogicalMemberInfoVisibilityFilter());
                gen.AssetFilters.Add(new SpecialNameMemberInfoFilter());

                if (!string.IsNullOrWhiteSpace(this.Filter))
                    gen.AssetFilters.Add(new TypeNameGlobFilter {Include = this.Filter});

                XmlDocEnricher docEnricher = new XmlDocEnricher();
                gen.Enrichers.Add(docEnricher);


                if (!string.IsNullOrEmpty(this.NamespaceDocPath))
                {
                    var namespaceEnricher = new ExternalNamespaceDocEnricher();
                    if (System.IO.Path.IsPathRooted(this.NamespaceDocPath))
                        namespaceEnricher.Load(this.NamespaceDocPath);
                    else if (
                        File.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path),
                                                           this.NamespaceDocPath)))
                        namespaceEnricher.Load(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path),
                                                                      this.NamespaceDocPath));
                    else
                        namespaceEnricher.Load(this.NamespaceDocPath);

                    gen.Enrichers.Add(namespaceEnricher);
                }


                if (!File.Exists(this.Path))
                {
                    Console.WriteLine("File not found: '{0}'", this.Path);
                    return;
                }

                if (this.IncludeBclDocComments.IsPresent)
                {
                    string winPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                    string bclDocPath = System.IO.Path.Combine(winPath, @"microsoft.net\framework\",
                                                               string.Format("v{0}.{1}.{2}",
                                                                             Environment.Version.Major,
                                                                             Environment.Version.Minor,
                                                                             Environment.Version.Build),
                                                               @"en\");


                    docEnricher.AddPath(bclDocPath);

                    bclDocPath = System.IO.Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                        @"Reference Assemblies\Microsoft\Framework\.NETFramework",
                        string.Format("v{0}.{1}",
                                      Environment.Version.Major,
                                      Environment.Version.Minor));

                    docEnricher.AddPath(bclDocPath);
                }

                gen.AddAssembly(this.Path);

                Assembly assembly;

                try
                {
                    assembly = Assembly.ReflectionOnlyLoadFrom(this.Path);
                }
                catch (FileLoadException)
                {
                    var assemblyName = AssemblyName.GetAssemblyName(this.Path);
                    var fullName = assemblyName.FullName;
                    var loadedAssemblies = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies();
                    assembly =
                        loadedAssemblies.Single(a => StringComparer.Ordinal.Equals(a.GetName().FullName, fullName));
                }

                XDocument rawDoc = gen.Generate();
                string fileName = System.IO.Path.Combine(this.Output ?? System.IO.Path.GetDirectoryName(this.Path),
                                                         string.Format("{0}_{1}.ldoc",
                                                                       System.IO.Path.GetFileName(this.Path),
                                                                       assembly.GetName().Version));

                this.Output = System.IO.Path.GetFullPath(fileName);

                if (!Directory.Exists(System.IO.Path.GetDirectoryName(fileName)))
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fileName));

                using (var writer = XmlWriter.Create(fileName, _xmlSettings))
                    rawDoc.Save(writer);
            }
            finally
            {
                TraceSources.GeneratorSource.Listeners.Remove(traceListener);
            }
        }