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


C# ExecutionContext.Clone方法代码示例

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


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

示例1: Execute

        // This executes the specified modules with the specified input documents
        public IReadOnlyList<IDocument> Execute(ExecutionContext context, IEnumerable<IModule> modules, ImmutableArray<IDocument> documents)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(Pipeline));
            }
            
            foreach (IModule module in modules.Where(x => x != null))
            {
                string moduleName = module.GetType().Name;
                Stopwatch stopwatch = Stopwatch.StartNew();
                using(_engine.Trace.WithIndent().Verbose("Executing module {0} with {1} input document(s)", moduleName, documents.Length))
                {
                    try
                    {
                        // Execute the module
                        IEnumerable<IDocument> outputs = module.Execute(documents, context.Clone(module));
                        documents = outputs?.Where(x => x != null).ToImmutableArray() ?? ImmutableArray<IDocument>.Empty;

                        // Remove any documents that were previously processed (checking will also mark the cache entry as hit)
                        if (_previouslyProcessedCache != null)
                        {
                            ImmutableArray<IDocument>.Builder newDocuments = ImmutableArray.CreateBuilder<IDocument>();
                            foreach (IDocument document in documents)
                            {
                                if (_processedSources.ContainsKey(document.Source))
                                {
                                    // We've seen this source before and already added it to the processed cache
                                    newDocuments.Add(document);
                                }
                                else
                                {
                                    List<Document> processedDocuments;
                                    if (!_previouslyProcessedCache.TryGetValue(document, out processedDocuments))
                                    {
                                        // This document was not previously processed, so add it to the current result and set up a list to track final results
                                        newDocuments.Add(document);
                                        processedDocuments = new List<Document>();
                                        _previouslyProcessedCache.Set(document, processedDocuments);
                                        _processedSources.Add(document.Source, processedDocuments);
                                    }
                                    // Otherwise, this document was previously processed so don't add it to the results
                                }
                            }
                            if (newDocuments.Count != documents.Length)
                            {
                                _engine.Trace.Verbose("Removed {0} previously processed document(s)", documents.Length - newDocuments.Count);
                            }
                            documents = newDocuments.ToImmutable();
                        }

                        // Set results in engine and trace
                        _engine.DocumentCollection.Set(Name, documents);
                        stopwatch.Stop();
                        _engine.Trace.Verbose("Executed module {0} in {1} ms resulting in {2} output document(s)", 
                            moduleName, stopwatch.ElapsedMilliseconds, documents.Length);
                    }
                    catch (Exception ex)
                    {
                        _engine.Trace.Error("Error while executing module {0}: {1}", moduleName, ex.ToString());
                        documents = ImmutableArray<IDocument>.Empty;
                        _engine.DocumentCollection.Set(Name, documents);
                        break;
                    }
                }
            }
            return documents;
        }
开发者ID:JasonKoopmans,项目名称:Wyam,代码行数:69,代码来源:Pipeline.cs


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