当前位置: 首页>>代码示例>>C#>>正文


C# IExecutionContext.Execute方法代码示例

本文整理汇总了C#中IExecutionContext.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.Execute方法的具体用法?C# IExecutionContext.Execute怎么用?C# IExecutionContext.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IExecutionContext的用法示例。


在下文中一共展示了IExecutionContext.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            if (_modules != null)
            {
                Dictionary<string, object> metadata = new Dictionary<string, object>();

                // Execute the modules for each input document
                if (_forEachDocument)
                {
                    return inputs.Select(input =>
                    {
                        foreach (IDocument result in context.Execute(_modules, new[] { input }))
                        {
                            foreach (KeyValuePair<string, object> kvp in result)
                            {
                                metadata[kvp.Key] = kvp.Value;
                            }
                        }
                        return input.Clone(metadata);
                    });
                }

                // Execute the modules once and apply to each input document
                foreach (IDocument result in context.Execute(_modules))
                {
                    foreach (KeyValuePair<string, object> kvp in result)
                    {
                        metadata[kvp.Key] = kvp.Value;
                    }
                }
                return inputs.Select(input => input.Clone(metadata));
            }

            return inputs.Select(x => x.Clone(new [] { new KeyValuePair<string, object>(_key, _metadata(x, context)) }));
        }
开发者ID:mgnslndh,项目名称:Wyam,代码行数:35,代码来源:Meta.cs

示例2: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     if (_modules != null)
     {
         if (_forEachDocument)
         {
             return inputs.SelectMany(input => context.Execute(_modules, new[] { input }).SelectMany(result => Execute(result.Content, input, context)));
         }
         return context.Execute(_modules, null).SelectMany(result => inputs.SelectMany(input => Execute(result.Content, input, context)));
     }
     return inputs.SelectMany(x => Execute(_content(x), x, context));
 }
开发者ID:Rohansi,项目名称:Wyam,代码行数:12,代码来源:ContentModule.cs

示例3: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            List<IDocument> results = new List<IDocument>();
            IEnumerable<IDocument> documents = inputs;
            foreach (Tuple<DocumentConfig, IModule[]> condition in _conditions)
            {
                // Split the documents into ones that satisfy the predicate and ones that don't
                List<IDocument> handled = new List<IDocument>();
                List<IDocument> unhandled = new List<IDocument>();
                foreach (IDocument document in documents)
                {
                    if (condition.Item1 == null || condition.Item1.Invoke<bool>(document, context))
                    {
                        handled.Add(document);
                    }
                    else
                    {
                        unhandled.Add(document);
                    }
                }

                // Run the modules on the documents that satisfy the predicate
                results.AddRange(context.Execute(condition.Item2, handled));

                // Continue with the documents that don't satisfy the predicate
                documents = unhandled;
            }

            // Add back any documents that never matched a predicate
            results.AddRange(documents);

            return results;
        }
开发者ID:ibebbs,项目名称:Wyam,代码行数:33,代码来源:If.cs

示例4: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     foreach (IDocument input in inputs)
     {
         List<string> inputLines = input.Content.Split(new[] { '\n' }, StringSplitOptions.None).ToList();
         int delimiterLine = inputLines.FindIndex(x =>
         {
             string trimmed = x.TrimEnd();
             return trimmed.Length > 0 && (_repeated ? trimmed.All(y => y == _delimiter[0]) : trimmed == _delimiter);
         });
         if (delimiterLine != -1)
         {
             string frontMatter = string.Join("\n", inputLines.Take(delimiterLine)) + "\n";
             inputLines.RemoveRange(0, delimiterLine + 1);
             string content = string.Join("\n", inputLines);
             foreach (IDocument result in context.Execute(_modules, new[] { input.Clone(frontMatter) }))
             {
                 yield return result.Clone(content);
             }
         }
         else
         {
             yield return input;
         }
     }
 }
开发者ID:st1pps,项目名称:Wyam,代码行数:26,代码来源:FrontMatter.cs

示例5: 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;
         }
     }
 }
开发者ID:ibebbs,项目名称:Wyam,代码行数:27,代码来源:Sidecar.cs

示例6: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     if (_modules != null)
     {
         return context.Execute(_modules, inputs.Count == 1 ? inputs : null).SelectMany(x => inputs.SelectMany(y => Execute(x.Content, y, context)));
     }
     return inputs.SelectMany(x => Execute(_content.GetValue(x, context), x, context));
 }
开发者ID:martinvobr,项目名称:Wyam,代码行数:8,代码来源:ContentModule.cs

示例7: 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;
        }
开发者ID:ibebbs,项目名称:Wyam,代码行数:21,代码来源:Merge.cs

示例8: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            return inputs.AsParallel().Select(input =>
            {
                try
                {
                    XslCompiledTransform xslt = new XslCompiledTransform();

                    if (_xsltPath != null)
                    {
                        FilePath path = _xsltPath.Invoke<FilePath>(input, context);
                        if (path != null)
                        {
                            IFile file = context.FileSystem.GetInputFile(path);
                            if (file.Exists)
                            {
                                using (Stream fileStream = file.OpenRead())
                                {
                                    xslt.Load(XmlReader.Create(fileStream));
                                }
                            }
                        }
                    }
                    else if (_xsltGeneration != null)
                    {
                        IDocument xsltDocument = context.Execute(_xsltGeneration, new[] {input}).Single();
                        using (Stream stream = xsltDocument.GetStream())
                        {
                            xslt.Load(XmlReader.Create(stream));
                        }
                    }
                    using (Stream stream = input.GetStream())
                    {
                        StringWriter str = new StringWriter();
                        using (XmlTextWriter writer = new XmlTextWriter(str))
                        {
                            xslt.Transform(XmlReader.Create(stream), writer);
                        }
                        return context.GetDocument(input, str.ToString());
                    }

                }
                catch (Exception e)
                {
                    Trace.Error($"An {e.GetType().Name} occurred: {e.Message}");
                    return null;
                }
            }).Where(x => x != null);
        }
开发者ID:ibebbs,项目名称:Wyam,代码行数:49,代码来源:Xslt.cs

示例9: 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 => input.Clone(
             new Dictionary<string, object>
             {
                 {MetadataKeys.GroupDocuments, x.ToImmutableArray()},
                 {MetadataKeys.GroupKey, x.Key}
             })
         );
     });
 }
开发者ID:st1pps,项目名称:Wyam,代码行数:19,代码来源:GroupBy.cs

示例10: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            return inputs.AsParallel().Select(x =>
            {
                try
                {
                    XslCompiledTransform xslt = new XslCompiledTransform();

                    if (_xsltPath != null)
                    {
                        string path = _xsltPath.Invoke<string>(x, context);
                        path = Path.Combine(context.InputFolder, PathHelper.NormalizePath(path));
                        xslt.Load(path);
                    }
                    else if (_xsltGeneration != null)
                    {
                        IDocument xsltDocument = context.Execute(_xsltGeneration, new [] { x }).Single();
                        using (Stream stream = xsltDocument.GetStream())
                        {
                            xslt.Load(System.Xml.XmlReader.Create(stream));
                        }
                    }
                    using (Stream stream = x.GetStream())
                    {
                        StringWriter str = new System.IO.StringWriter();
                        using (XmlTextWriter writer = new System.Xml.XmlTextWriter(str))
                        {
                            xslt.Transform(System.Xml.XmlReader.Create(stream), writer);
                        }
                        return x.Clone(str.ToString());
                    }

                }
                catch (Exception e)
                {
                    context.Trace.Error($"An {e.GetType().Name} occurred: {e.Message}");
                    return null;
                }
            }).Where(x => x != null);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:40,代码来源:Xslt.cs

示例11: Execute

        public IValue Execute(IExecutionContext context)
        {
            this.returnValue = null;
            this.cancel = false;
            this.fault = false;

            IValue last = GenericValue<object>.Default;
            foreach(ICodeBlock code in this.CodeBlocks)
            {
                last = context.Execute(code);

                if (returnValue != null)
                    return returnValue;

                if (this.cancel)
                    break;

                if (this.fault)
                    throw new FaultException("Execution fault (fault break)");
            }

            return last;
        }
开发者ID:redxdev,项目名称:DScript,代码行数:23,代码来源:Executable.cs

示例12: Execute

 protected override IValue Execute(IExecutionContext ctx)
 {
     return ctx.Execute(this.Executable);
 }
开发者ID:redxdev,项目名称:DScript,代码行数:4,代码来源:ExecutableArgument.cs

示例13: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     return inputs.Concat(context.Execute(_modules));
 }
开发者ID:martinvobr,项目名称:Wyam,代码行数:4,代码来源:Concat.cs

示例14: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     return inputs.SelectMany(x => context.Execute(_modules, new[] { x }));
 }
开发者ID:JasonKoopmans,项目名称:Wyam,代码行数:4,代码来源:ForEach.cs

示例15: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            if (inputs == null)
            {
                throw new ArgumentNullException("inputs");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var processedDocuments = context.Execute(_modules, inputs);
            foreach (IDocument document in processedDocuments)
            {
                Dictionary<string, object> processedMetadata = document.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                dynamic borogroveObject = document.Get(_key);
                if (borogroveObject == null)
                {
                    continue;
                }

                Dictionary<string, object> borogroveDictionary = borogroveObject;
                foreach (KeyValuePair<string, object> keyValuePair in borogroveDictionary)
                {
                    string canonicalizedKey = CanonicalizeString(keyValuePair.Key);
                    dynamic value = keyValuePair.Value;
                    string stringValue = (string)value;
                    switch (canonicalizedKey)
                    {
                        case Identifier:
                        case Parent:
                        case Previous:
                        case Next:
                        case DraftOf:
                        case ArtifactOf:
                        case CommentsOn:
                            processedMetadata.Add(canonicalizedKey, Guid.Parse(stringValue));
                            continue;

                        case Title:
                        case Description:
                        case DraftIdentifier:
                            processedMetadata.Add(canonicalizedKey, stringValue);
                            continue;

                        case Creator:
                            var creators = new List<Model.Creator>();
                            foreach (var creator in value.Children)
                            {
                                var creatorObject = new Model.Creator()
                                {
                                    Role = Model.RoleUtilities.ParseFriendlyName((string)creator["role"]),
                                    Text = (string)creator["text"],
                                    FileAs = (string)creator["file-as"],
                                };
                                creators.Add(creatorObject);
                            }
                            processedMetadata.Add(Creator, creators);
                            continue;

                        case CreatedDate:
                        case ModifiedDate:
                        case PublishedDate:
                            processedMetadata.Add(canonicalizedKey, DateTime.Parse(stringValue));
                            continue;

                        case Rights:
                        case License:
                            processedMetadata.Add(Rights, stringValue);
                            Model.License parsedLicense;
                            if (Model.LicenseUtilities.TryParseLicense(stringValue, out parsedLicense))
                            {
                                processedMetadata.Add(License, parsedLicense);
                            }
                            else
                            {
                                context.Trace.Warning($"Unable to parse license: {stringValue}");
                            }
                            continue;

                        case Language:
                            processedMetadata.Add(Language, CultureInfo.GetCultureInfo(stringValue));
                            continue;

                        case WorkType:
                            processedMetadata.Add(WorkType, Model.WorkTypeUtilities.ParseFriendlyName(stringValue));
                            continue;

                        case ContentRating:
                            processedMetadata.Add(ContentRating, Model.ContentRatingUtilities.ParseShortName(stringValue));
                            continue;

                        case ContentDescriptors:
                            processedMetadata.Add(ContentDescriptors, Model.ContentDescriptorUtilities.ParseContentDescriptor(stringValue));
                            continue;

                        default:
                            if (processedMetadata.ContainsKey(keyValuePair.Key))
//.........这里部分代码省略.........
开发者ID:foobardog,项目名称:Borogove,代码行数:101,代码来源:WorkMetadataYamlUnpacker.cs


注:本文中的IExecutionContext.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。