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


C# ConcurrentDictionary.SelectMany方法代码示例

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


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

示例1: GetDocumentDiagnosticsToFixAsync

        public static async Task<ImmutableDictionary<Document, ImmutableArray<Diagnostic>>> GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)
        {
            var allDiagnostics = ImmutableArray<Diagnostic>.Empty;
            var projectsToFix = ImmutableArray<Project>.Empty;

            var document = fixAllContext.Document;
            var project = fixAllContext.Project;

            switch (fixAllContext.Scope)
            {
            case FixAllScope.Document:
                if (document != null)
                {
                    var documentDiagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);
                    return ImmutableDictionary<Document, ImmutableArray<Diagnostic>>.Empty.SetItem(document, documentDiagnostics);
                }

                break;

            case FixAllScope.Project:
                projectsToFix = ImmutableArray.Create(project);
                allDiagnostics = await GetAllDiagnosticsAsync(fixAllContext, project).ConfigureAwait(false);
                break;

            case FixAllScope.Solution:
                projectsToFix = project.Solution.Projects
                    .Where(p => p.Language == project.Language)
                    .ToImmutableArray();

                var diagnostics = new ConcurrentDictionary<ProjectId, ImmutableArray<Diagnostic>>();
                var tasks = new Task[projectsToFix.Length];
                for (int i = 0; i < projectsToFix.Length; i++)
                {
                    fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                    var projectToFix = projectsToFix[i];
                    tasks[i] = Task.Run(
                        async () =>
                        {
                            var projectDiagnostics = await GetAllDiagnosticsAsync(fixAllContext, projectToFix).ConfigureAwait(false);
                            diagnostics.TryAdd(projectToFix.Id, projectDiagnostics);
                        }, fixAllContext.CancellationToken);
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);
                allDiagnostics = allDiagnostics.AddRange(diagnostics.SelectMany(i => i.Value.Where(x => fixAllContext.DiagnosticIds.Contains(x.Id))));
                break;
            }

            if (allDiagnostics.IsEmpty)
            {
                return ImmutableDictionary<Document, ImmutableArray<Diagnostic>>.Empty;
            }

            return await GetDocumentDiagnosticsToFixAsync(allDiagnostics, projectsToFix, fixAllContext.CancellationToken).ConfigureAwait(false);
        }
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:55,代码来源:FixAllContextHelper.cs

示例2: Index

        public IActionResult Index(string repoSet)
        {
            var gitHubAccessToken = Context.Session.GetString("GitHubAccessToken");
            var gitHubName = Context.Session.GetString("GitHubName");

            // If session state didn't have our data, either there's no one logged in, or they just logged in
            // but the claims haven't yet been read.
            if (string.IsNullOrEmpty(gitHubAccessToken))
            {
                if (!User.Identity.IsAuthenticated)
                {
                    // Not authenticated at all? Go to GitHub to authorize the app
                    return new ChallengeResult("GitHub", new AuthenticationProperties { RedirectUri = "/" + repoSet });
                }

                // Authenticated but haven't read the claims? Process the claims
                gitHubAccessToken = Context.User.FindFirst("access_token")?.Value;
                gitHubName = Context.User.Identity.Name;
                Context.Session.SetString("GitHubAccessToken", gitHubAccessToken);
                Context.Session.SetString("GitHubName", gitHubName);
            }

            // Authenticated and all claims have been read

            var repos =
                RepoSets.HasRepoSet(repoSet ?? string.Empty)
                ? RepoSets.GetRepoSet(repoSet)
                : RepoSets.GetAllRepos();

            var allIssuesByRepo = new ConcurrentDictionary<string, Task<IReadOnlyList<Issue>>>();
            var allPullRequestsByRepo = new ConcurrentDictionary<string, Task<IReadOnlyList<PullRequest>>>();

            Parallel.ForEach(repos, repo => allIssuesByRepo[repo] = GetIssuesForRepo(repo, GetGitHubClient(gitHubAccessToken)));
            Parallel.ForEach(repos, repo => allPullRequestsByRepo[repo] = GetPullRequestsForRepo(repo, GetGitHubClient(gitHubAccessToken)));

            Task.WaitAll(allIssuesByRepo.Select(x => x.Value).ToArray());
            Task.WaitAll(allPullRequestsByRepo.Select(x => x.Value).ToArray());

            var allIssues = allIssuesByRepo.SelectMany(
                issueList => issueList.Value.Result.Select(
                    issue => new IssueWithRepo
                    {
                        Issue = issue,
                        RepoName = issueList.Key,
                    })).ToList();

            var allPullRequests = allPullRequestsByRepo.SelectMany(
                pullRequestList => pullRequestList.Value.Result.Select(
                    pullRequest => new PullRequestWithRepo
                    {
                        PullRequest = pullRequest,
                        RepoName = pullRequestList.Key,
                    }))
                    .OrderBy(pullRequestWithRepo => pullRequestWithRepo.PullRequest.CreatedAt)
                    .ToList();

            return View(new HomeViewModel
            {
                TotalIssues = allIssues.Count,

                Name = gitHubName,

                GroupByAssignee = new GroupByAssigneeViewModel
                {
                    Assignees =
                        allIssues
                            .GroupBy(issue => issue.Issue.Assignee?.Login)
                            .Select(group =>
                                new GroupByAssigneeAssignee
                                {
                                    Assignee = group.Key,
                                    Issues = group.ToList().AsReadOnly(),
                                })
                            .OrderBy(group => group.Assignee, StringComparer.OrdinalIgnoreCase)
                            .ToList()
                            .AsReadOnly()
                },

                GroupByMilestone = new GroupByMilestoneViewModel
                {
                    Milestones =
                        allIssues
                            .GroupBy(issue => issue.Issue.Milestone?.Title)
                            .Select(group =>
                                new GroupByMilestoneMilestone
                                {
                                    Milestone = group.Key,
                                    Issues = group.ToList().AsReadOnly(),
                                })
                            .OrderBy(group => group.Milestone, StringComparer.OrdinalIgnoreCase)
                            .ToList()
                            .AsReadOnly()
                },

                GroupByRepo = new GroupByRepoViewModel
                {
                    Repos =
                        allIssues
                            .GroupBy(issue => issue.RepoName)
                            .Select(group =>
//.........这里部分代码省略.........
开发者ID:muratg,项目名称:ProjectKIssueList,代码行数:101,代码来源:IssueListController.cs

示例3: Run

        public void Run(int queries, int threads, int prepared)
        {
            Console.WriteLine("Preparing...");
            _queries = queries;
            _manager = new CartManager();
            _times = new ConcurrentDictionary<string, LinkedList<long>>();
            _stopwatch = new Stopwatch();
            _count = 0;
            _groups = Enumerable.Range(0, 9).Select(n => "group_" + n).ToArray();


            //pregenerate carts
            _manager.PrepareDbAsync().Wait();
            var cartTasks = new Task<Cart>[prepared];
            int groupId = 0;
            for (int i = 0; i < prepared; i++)
            {
                cartTasks[i] = _manager.AddCartAsync(_groups[groupId]);
                groupId = (groupId + 1) % _groups.Length;
            }

            Task.WaitAll(cartTasks);
            var carts = cartTasks.Select(t => t.Result).ToArray();

            Console.WriteLine("Executing...");

            //execute!
            _stopwatch.Start();
            var doTasks = new LinkedList<Task>();

            for (int i = 0; i < threads; i++)
            {
                doTasks.AddLast(DoAddCarts());
                doTasks.AddLast(DoAddItems(carts));
                //doTasks.AddLast(DoFindByGroupId());
                doTasks.AddLast(DoGetItems(carts));
                doTasks.AddLast(DoUpdateCarts(carts));
            }

            Task.WaitAll(doTasks.ToArray());

            _stopwatch.Stop();

            //print results
            Console.WriteLine("Total tasks run: {0} in {1} ({2} req/s)", _count, _stopwatch.Elapsed,
                              DoubleString((double)queries / _stopwatch.ElapsedMilliseconds * 1000));

#if debug
            Console.WriteLine(MemoryPool.Instance);
#endif
            Console.WriteLine();
            WriteRow("", "Calls", "Avg", "Median", "Min", "Max");
            WriteStatistics("Total", _times.SelectMany(vls => vls.Value));
            Console.WriteLine(new string('-', 60));
            foreach (var call in _times)
            {
                WriteStatistics(call.Key, call.Value);
            }
        }
开发者ID:priyaparul,项目名称:CqlSharp,代码行数:59,代码来源:Program.cs


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