本文整理汇总了C#中IExecutionContext.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.GetDocument方法的具体用法?C# IExecutionContext.GetDocument怎么用?C# IExecutionContext.GetDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExecutionContext
的用法示例。
在下文中一共展示了IExecutionContext.GetDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
protected override IEnumerable<IDocument> Execute(object content, IDocument input, IExecutionContext context)
{
if (content == null)
{
content = string.Empty;
}
if (string.IsNullOrEmpty(_search))
{
return new[] { context.GetDocument(input, content.ToString()) };
}
return new[] { context.GetDocument(input, content.ToString().Replace(_search, input.Content)) };
}
示例2: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
DotlessConfiguration config = DotlessConfiguration.GetDefault();
config.Logger = typeof (LessLogger);
EngineFactory engineFactory = new EngineFactory(config);
FileSystemReader fileSystemReader = new FileSystemReader(context.FileSystem);
return inputs.AsParallel().Select(input =>
{
Trace.Verbose("Processing Less for {0}", input.SourceString());
ILessEngine engine = engineFactory.GetEngine();
// TODO: Get rid of RefelectionMagic and this ugly hack as soon as dotless gets better external DI support
engine.AsDynamic().Underlying.Cache = new LessCache(context.ExecutionCache);
engine.AsDynamic().Underlying.Underlying.Parser.Importer.FileReader = fileSystemReader;
FilePath path = input.FilePath(Keys.RelativeFilePath);
string fileName = null;
if (path != null)
{
engine.CurrentDirectory = path.Directory.FullPath;
fileName = path.FileName.FullPath;
}
else
{
engine.CurrentDirectory = string.Empty;
fileName = Path.GetRandomFileName();
}
string content = engine.TransformToCss(input.Content, fileName);
return context.GetDocument(input, content);
});
}
示例3: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return inputs.AsParallel().SelectMany(input =>
{
object existingValue;
var hasExistingKey = input.TryGetValue(_fromKey, out existingValue);
if (hasExistingKey)
{
if (_format != null)
{
if (existingValue is DateTime)
{
existingValue = ((DateTime)existingValue).ToString(_format);
}
else
{
existingValue = string.Format(_format, existingValue);
}
}
if (_execute != null)
{
existingValue = _execute.Invoke(existingValue.ToString());
}
return new[] { context.GetDocument(input, new[] { new KeyValuePair<string, object>(_toKey, existingValue) }) };
}
else
{
return new[] { input };
}
});
}
示例4: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
foreach (IDocument input in inputs)
{
FilePath sidecarPath = _sidecarPath.Invoke<FilePath>(input, context);
if (sidecarPath != null)
{
IFile sidecarFile = context.FileSystem.GetInputFile(sidecarPath.FullPath);
if (sidecarFile.Exists)
{
string sidecarContent = sidecarFile.ReadAllText();
foreach (IDocument result in context.Execute(_modules, new[] { context.GetDocument(input, sidecarContent) }))
{
yield return context.GetDocument(input, result);
}
}
else
{
yield return input;
}
}
else
{
yield return input;
}
}
}
示例5: Minify
public IEnumerable<IDocument> Minify(IReadOnlyList<IDocument> inputs, IExecutionContext context, Func<string, MinificationResultBase> minify, string minifierType)
{
return inputs.AsParallel().Select(input =>
{
try
{
MinificationResultBase result = minify(input.Content);
if (result.Errors.Count > 0)
{
Trace.Error("{0} errors found while minifying {4} for {1}:{2}{3}", result.Errors.Count, input.Source, Environment.NewLine, string.Join(Environment.NewLine, result.Errors.Select(x => MinificationErrorInfoToString(x))), minifierType);
return input;
}
if (result.Warnings.Count > 0)
{
Trace.Warning("{0} warnings found while minifying {4} for {1}:{2}{3}", result.Warnings.Count, input.Source, Environment.NewLine, string.Join(Environment.NewLine, result.Warnings.Select(x => MinificationErrorInfoToString(x))), minifierType);
}
return context.GetDocument(input, result.MinifiedContent);
}
catch (Exception ex)
{
Trace.Error("Exception while minifying {2} for {0}: {1}", input.Source, ex.Message, minifierType);
return input;
}
});
}
示例6: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return inputs
.AsParallel()
.SelectMany(input =>
{
List<Dictionary<string, object>> documentMetadata = new List<Dictionary<string, object>>();
using (TextReader contentReader = new StringReader(input.Content))
{
YamlStream yamlStream = new YamlStream();
yamlStream.Load(contentReader);
foreach (YamlDocument document in yamlStream.Documents)
{
// If this is a sequence, get a document for each item
YamlSequenceNode rootSequence = document.RootNode as YamlSequenceNode;
if (rootSequence != null)
{
documentMetadata.AddRange(rootSequence.Children.Select(GetDocumentMetadata));
}
else
{
// Otherwise, just get a single set of metadata
documentMetadata.Add(GetDocumentMetadata(document.RootNode));
}
}
}
return documentMetadata.Select(metadata => context.GetDocument(input, metadata));
})
.Where(x => x != null);
}
示例7: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
IDocument result = null;
foreach (IDocument input in inputs)
{
result = result == null ? input : context.GetDocument(result, result.Content + input.Content, input);
}
return new[] { result };
}
示例8: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
// If ApplicationInput is empty, return nothing
if(string.IsNullOrWhiteSpace(context.ApplicationInput))
{
return new IDocument[0];
}
return new IDocument[] { context.GetDocument(context.ApplicationInput) };
}
示例9: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
if (_modules != null && _modules.Length > 0)
{
// Execute the modules for each input document
if (_forEachDocument)
{
return inputs.SelectMany(input =>
context.Execute(_modules, new[] {input})
.Select(result => context.GetDocument(input, result.Content, result.Metadata))
);
}
// Execute the modules once and apply to each input document
List<IDocument> results = context.Execute(_modules).ToList();
return inputs.SelectMany(input =>
results.Select(result => context.GetDocument(input, result.Content, result.Metadata)));
}
return inputs;
}
示例10: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
int sourceCount = 0;
ExecuteCount++;
foreach (IDocument input in inputs)
{
InputCount++;
for (int c = 0; c < AdditionalOutputs + 1; c++)
{
OutputCount++;
Value++;
if(CloneSource)
{
yield return context.GetDocument(input, ValueKey + sourceCount++, input.Content == null ? Value.ToString() : input.Content + Value,
new Dictionary<string, object> { { ValueKey, Value } });
}
else
{
yield return context.GetDocument(input, input.Content == null ? Value.ToString() : input.Content + Value,
new Dictionary<string, object> { { ValueKey, Value } });
}
}
}
}
示例11: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
ImmutableArray<IGrouping<object, IDocument>> groupings
= context.Execute(_modules, inputs).GroupBy(x => _key(x, context)).ToImmutableArray();
if (groupings.Length == 0)
{
return inputs;
}
return inputs.SelectMany(input =>
{
return groupings.Select(x => context.GetDocument(input,
new MetadataItems
{
{Keys.GroupDocuments, x.ToImmutableArray()},
{Keys.GroupKey, x.Key}
})
);
});
}
示例12: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return inputs
.AsParallel()
.Select(input =>
{
try
{
JsonSerializer serializer = new JsonSerializer();
Dictionary<string, object> items = new Dictionary<string, object>();
ExpandoObject json;
using (TextReader contentReader = new StringReader(input.Content))
{
using (JsonReader jsonReader = new JsonTextReader(contentReader))
{
json = serializer.Deserialize<ExpandoObject>(jsonReader);
}
}
if (json != null)
{
if (!string.IsNullOrEmpty(_key))
{
items[_key] = json;
}
if (_flatten)
{
foreach (KeyValuePair<string, object> item in json)
{
items[item.Key] = item.Value;
}
}
return context.GetDocument(input, items);
}
}
catch (Exception ex)
{
Trace.Error("Error processing JSON for {0}: {1}", input.SourceString(), ex.ToString());
}
return input;
})
.Where(x => x != null);
}
示例13: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return inputs.AsParallel().Select(input =>
{
try
{
using (var stream = input.GetStream())
{
Tabular.Table table = Tabular.Excel.ReadFrom(stream, Tabular.ExcelFormat.Excel2007);
Tabular.Csv csv = Tabular.Csv.ToCsv(table);
return context.GetDocument(input, csv.Data);
}
}
catch (Exception e)
{
Trace.Error($"An {e.ToString()} occurred ({input.Source}): {e.Message}");
return null;
}
}).Where(x => x != null);
}
示例14: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return inputs.AsParallel().Select(input =>
{
try
{
Tabular.Csv csv = new Tabular.Csv() { Data = input.Content };
Tabular.Table table = Tabular.Csv.FromCsv(csv);
StringBuilder builder = new StringBuilder();
bool firstLine = true;
builder.AppendLine("<table>");
foreach (var row in table.Rows)
{
builder.AppendLine("<tr>");
foreach (var cell in row)
{
if (_firstLineHeader && firstLine)
{
builder.AppendLine($"<th>{cell.Value}</th>");
}
else
{
builder.AppendLine($"<td>{cell.Value}</td>");
}
}
builder.AppendLine("</tr>");
firstLine = false;
}
builder.Append("</table>");
return context.GetDocument(input, builder.ToString());
}
catch (Exception e)
{
Trace.Error($"An {e.ToString()} occurred ({input.SourceString()}): {e.Message}");
return null;
}
}).Where(x => x != null);
}
示例15: GetCommitDocuments
protected ImmutableArray<IDocument> GetCommitDocuments(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
using (Repository repository = new Repository(GetRepositoryLocation(context)))
{
return repository.Commits
.OrderByDescending(x => x.Author.When)
.Select(x => context.GetDocument(new MetadataItems
{
new MetadataItem(GitKeys.Sha, x.Sha),
new MetadataItem(GitKeys.Parents, x.Parents.Select(y => y.Sha).ToImmutableArray()),
new MetadataItem(GitKeys.AuthorName, x.Author.Name),
new MetadataItem(GitKeys.AuthorEmail, x.Author.Email),
new MetadataItem(GitKeys.AuthorWhen, x.Author.When),
new MetadataItem(GitKeys.CommitterName, x.Committer.Name),
new MetadataItem(GitKeys.CommitterEmail, x.Committer.Email),
new MetadataItem(GitKeys.CommitterWhen, x.Committer.When),
new MetadataItem(GitKeys.Message, x.Message),
new MetadataItem(GitKeys.Entries,
CompareTrees(repository, x).ToImmutableDictionary(y => y.Path, y => y.Status.ToString()))
}))
.ToImmutableArray();
}
}