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


C# ConcurrentDictionary.Distinct方法代码示例

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


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

示例1: SuggestEntites

        /// <summary>
        /// Suggests other potential options based on the entities passed
        /// </summary>
        /// <param name="rows">The rows being imported</param>
        /// <returns>Entites with suggestions</returns>
        public Suggestions SuggestEntites(ImportRow[] rows)
        {
            var rowSuggestionsConcurrentDictionary = new ConcurrentDictionary<int, RowSuggestions>();

            var suggestionsToReturn = new Suggestions();
            var clients = new ConcurrentDictionary<Guid, FoundOps.Api.Models.Client>();
            var locations = new ConcurrentDictionary<Guid, FoundOps.Api.Models.Location>();
            var contactInfoSets = new ConcurrentDictionary<Guid, FoundOps.Api.Models.ContactInfo>();

            Parallel.For((long)0, rows.Count(), rowIndex =>
            {
                var row = rows[rowIndex];

                var rowSuggestions = new RowSuggestions();

                #region Location

                if (row.Location != null)
                {
                    //Find all the Locations to be suggested by finding all Locations for the Client of the row
                    var locationSuggestions = row.Client != null
                        ? _locations.Where(l => l.Value.ClientId == row.Client.Id).ToArray()
                        : null;

                    if (locationSuggestions != null)
                    {
                        //Add any of the suggestions to the rows suggestions
                        rowSuggestions.LocationSuggestions.AddRange(locationSuggestions.Select(l => l.Key));
                        var convertedLocationSuggestions = locationSuggestions.Select(l => l.Value).Select(FoundOps.Api.Models.Location.ConvertModel);

                        //Add all suggested Locations to the list of Locations to be returned
                        foreach (var location in convertedLocationSuggestions)
                            locations.GetOrAdd(location.Id, location);
                    }

                    //Add the matched/new location as the first suggestion
                    rowSuggestions.LocationSuggestions.Add(row.Location.Id);

                    //Add the location passed to the list of location entites
                    locations.GetOrAdd(row.Location.Id, row.Location);
                }

                #endregion

                #region Client

                if (row.Client != null)
                {
                    //Find all the Clients to be suggested by finding all Clients for the Location of the row
                    var clientSuggestions = row.Location != null
                        ? _clients.Where(c => c.Key == row.Location.ClientId).ToArray()
                        : null;

                    if (clientSuggestions != null)
                    {
                        //Add any of the suggestions to the rows suggestions
                        rowSuggestions.ClientSuggestions.AddRange(clientSuggestions.Select(c => c.Key));
                        var convertedClientSuggestions = clientSuggestions.Select(c => c.Value).Select(FoundOps.Api.Models.Client.ConvertModel);

                        //Add all suggested Clients to the list of Clients to be returned
                        foreach (var client in convertedClientSuggestions)
                            clients.GetOrAdd(client.Id, client);
                    }

                    //Add the matched/new client as the first suggestion
                    rowSuggestions.ClientSuggestions.Add(row.Client.Id);

                    //Add the Client passed to the list of client entites
                    clients.GetOrAdd(row.Client.Id, row.Client);
                }

                #endregion

                //Repeat
                if (row.Repeat != null)
                    rowSuggestions.Repeats.Add(row.Repeat);

                //Contact Info
                if (row.ContactInfoSet.Count != 0)
                {
                    rowSuggestions.ContactInfoSuggestions.AddRange(row.ContactInfoSet.Select(ci => ci.Id));

                    foreach (var contactInfoSet in row.ContactInfoSet)
                        contactInfoSets.GetOrAdd(contactInfoSet.Id, contactInfoSet);
                }

                //Add this row's suggestions to the list to be returned
                rowSuggestionsConcurrentDictionary.GetOrAdd((int)rowIndex, rowSuggestions);
            });

            //Order the row suggestions by rowIndex
            suggestionsToReturn.RowSuggestions.AddRange(rowSuggestionsConcurrentDictionary.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value));

            //Only add distinct Clients
            var distinctClients = clients.Distinct();
//.........这里部分代码省略.........
开发者ID:FoundOPS,项目名称:server,代码行数:101,代码来源:SuggestionsController.cs


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