本文整理汇总了C#中Bundle.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Bundle.Add方法的具体用法?C# Bundle.Add怎么用?C# Bundle.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bundle
的用法示例。
在下文中一共展示了Bundle.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
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);
}
}
示例2: Build
/// <summary>
/// This method will construct a three folder structure inside <paramref name="targetDirectory"/> containing: Html, Index, and Source
/// </summary>
/// <param name="sourceDirectory">
/// Directory containing ldoc files
/// </param>
/// <param name="targetDirectory">
/// Output directory
/// </param>
public void Build(string sourceDirectory, string targetDirectory)
{
if (Directory.Exists(targetDirectory) && Directory.EnumerateFileSystemEntries(targetDirectory).Any())
throw new InvalidOperationException("Target path is not empty.");
this.OnStateChanged(State.Preparing);
string htmlRoot = Path.Combine(targetDirectory, "Html");
string indexRoot = Path.Combine(targetDirectory, "Index");
string sourceRoot = Path.Combine(targetDirectory, "Source");
string logRoot = Path.Combine(targetDirectory, "Logs");
DirectoryInfo htmlDir = Directory.CreateDirectory(htmlRoot);
DirectoryInfo indexDir = Directory.CreateDirectory(indexRoot);
DirectoryInfo sourceDir = Directory.CreateDirectory(sourceRoot);
DirectoryInfo logDir = Directory.CreateDirectory(logRoot);
var sourceFiles = Directory.EnumerateFiles(sourceDirectory, "*.ldoc", SearchOption.TopDirectoryOnly);
// copy all source files to output directory and add to bundle
Bundle bundle = new Bundle(this.IgnoreVersionComponent);
foreach (var sourceFile in sourceFiles)
{
string targetFile = Path.Combine(sourceDir.FullName, Path.GetFileName(sourceFile));
File.Copy(sourceFile, targetFile);
bundle.Add(XDocument.Load(targetFile));
}
TemplateOutput templateOutput;
// wire up logging
string templateLogFile = Path.Combine(logDir.FullName,
string.Format("template_{0:yyyy'_'MM'_'dd'__'HH'_'mm'_'ss}.log", DateTime.Now));
using (TextWriterTraceListener traceListener = new TextWriterTraceListener(templateLogFile))
{
// log everything
traceListener.Filter = new EventTypeFilter(SourceLevels.All);
LostDoc.Diagnostics.TraceSources.TemplateSource.Switch.Level = SourceLevels.All;
LostDoc.Diagnostics.TraceSources.BundleSource.Switch.Level = SourceLevels.All;
LostDoc.Diagnostics.TraceSources.AssetResolverSource.Switch.Level = SourceLevels.All;
LostDoc.Diagnostics.TraceSources.TemplateSource.Listeners.Add(traceListener);
LostDoc.Diagnostics.TraceSources.BundleSource.Listeners.Add(traceListener);
LostDoc.Diagnostics.TraceSources.AssetResolverSource.Listeners.Add(traceListener);
// merge ldoc files
this.OnStateChanged(State.Merging);
AssetRedirectCollection assetRedirects;
var mergedDoc = bundle.Merge(out assetRedirects);
// generate output
var templateData = new TemplateData(mergedDoc)
{
AssetRedirects = assetRedirects,
IgnoredVersionComponent = this.IgnoreVersionComponent,
OutputFileProvider =
new ScopedFileProvider(new DirectoryFileProvider(), htmlDir.FullName),
//TargetDirectory = htmlDir.FullName,
Arguments = new Dictionary<string, object> { { "SearchUri", "/search/" } },
KeepTemporaryFiles = true,
TemporaryFilesPath = Path.Combine(logDir.FullName, "temp")
};
this.OnStateChanged(State.Templating);
templateOutput = this.Template.Generate(templateData);
LostDoc.Diagnostics.TraceSources.TemplateSource.Listeners.Remove(traceListener);
LostDoc.Diagnostics.TraceSources.BundleSource.Listeners.Remove(traceListener);
LostDoc.Diagnostics.TraceSources.AssetResolverSource.Listeners.Remove(traceListener);
}
this.OnStateChanged(State.Indexing);
string indexLogFile = Path.Combine(logDir.FullName,
string.Format("index_{0:yyyy'_'MM'_'dd'__'HH'_'mm'_'ss}.log", DateTime.Now));
using (TextWriterTraceListener traceListener = new TextWriterTraceListener(indexLogFile))
{
// log everything
traceListener.Filter = new EventTypeFilter(SourceLevels.All);
TraceSources.ContentBuilderSource.Switch.Level = SourceLevels.All;
TraceSources.ContentBuilderSource.Listeners.Add(traceListener);
// one stop-word per line
StringReader stopWordsReader = new StringReader(@"missing");
// index output
using (var directory = FSDirectory.Open(indexDir))
using (stopWordsReader)
{
Analyzer analyzer = new StandardAnalyzer(global::Lucene.Net.Util.Version.LUCENE_30, stopWordsReader);
Analyzer titleAnalyzer = new TitleAnalyzer();
IDictionary<string, Analyzer> fieldAnalyzers = new Dictionary<string, Analyzer>
//.........这里部分代码省略.........
示例3: Invoke
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);
//.........这里部分代码省略.........