本文整理汇总了C#中ConcurrentDictionary.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.OrderBy方法的具体用法?C# ConcurrentDictionary.OrderBy怎么用?C# ConcurrentDictionary.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.OrderBy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadSymbols
void LoadSymbols()
{
MarketSymbols = new ConcurrentDictionary<string, string>();
resourceName = new []
{
"Windows.Controls.Resources.NYSE.csv",
"Windows.Controls.Resources.NASDAQ.csv",
"Windows.Controls.Resources.AMEX.csv"
};
var asm = Assembly.GetExecutingAssembly();
Parallel.ForEach(resourceName, (s) => ReadResourceSymbolFile(s, asm));
if (!MarketSymbols.Any())
return;
Symbols = MarketSymbols.OrderBy(x => x.Key).ToDictionary(k => k.Key, v => v.Value);
for (int i = 0; i < Symbols.Count; i++)
{
var itm = Symbols.ElementAt(i);
var idx = int.Parse(itm.Value.Substring(0, 1));
// Stripping the market index char
var val = itm.Value.Substring(1);
Symbols[itm.Key] = val;
this.AppendValues(itm.Key, val, icon[idx]);
}
}
示例2: Count
public async Task<HttpResponseMessage> Count()
{
// For each partition client, keep track of partition information and the number of words
ConcurrentDictionary<Int64RangePartitionInformation, long> totals = new ConcurrentDictionary<Int64RangePartitionInformation, long>();
IList<Task> tasks = new List<Task>();
foreach (Int64RangePartitionInformation partition in await this.GetServicePartitionKeysAsync())
{
try
{
ServicePartitionClient<HttpCommunicationClient> partitionClient
= new ServicePartitionClient<HttpCommunicationClient>(communicationFactory, serviceUri, new ServicePartitionKey(partition.LowKey));
await partitionClient.InvokeWithRetryAsync(
async (client) =>
{
HttpResponseMessage response = await client.HttpClient.GetAsync(new Uri(client.Url, "Count"));
string content = await response.Content.ReadAsStringAsync();
totals[partition] = Int64.Parse(content.Trim());
});
}
catch (Exception ex)
{
// Sample code: print exception
ServiceEventSource.Current.OperationFailed(ex.Message, "Count - run web request");
}
}
StringBuilder sb = new StringBuilder();
sb.Append("<h1> Total:");
sb.Append(totals.Aggregate<KeyValuePair<Int64RangePartitionInformation, long>, long>(0, (total, next) => next.Value + total));
sb.Append("</h1>");
sb.Append("<table><tr><td>Partition ID</td><td>Key Range</td><td>Total</td></tr>");
foreach (KeyValuePair<Int64RangePartitionInformation, long> partitionData in totals.OrderBy(partitionData => partitionData.Key.LowKey))
{
sb.Append("<tr><td>");
sb.Append(partitionData.Key.Id);
sb.Append("</td><td>");
sb.AppendFormat("{0} - {1}", partitionData.Key.LowKey, partitionData.Key.HighKey);
sb.Append("</td><td>");
sb.Append(partitionData.Value);
sb.Append("</td></tr>");
}
sb.Append("</table>");
return new HttpResponseMessage()
{
Content = new StringContent(sb.ToString(), Encoding.UTF8, "text/html")
};
}
示例3: HandleLocalFileChanges
public void HandleLocalFileChanges(ConcurrentDictionary<string, string> localFileChanges)
{
string localChangesFilePath = $"{ConfigurationManager.AppSettings["LocalWikiRootPath"].ToString()}Changes.txt";
Dictionary<string, string> orderedLocalFileChanges = localFileChanges.OrderBy(x => x.Key).ToDictionary(d => d.Key, d => d.Value);
_consoleManager.WritePaddedText("The following changes were made to the local wiki files: ");
using (StreamWriter streamWriter = File.CreateText(localChangesFilePath))
{
foreach (string change in orderedLocalFileChanges.Values)
{
_consoleManager.WriteTextLine(change);
streamWriter.WriteLine(change);
}
}
}
示例4: Count
public async Task<HttpResponseMessage> Count()
{
// Get the list of representative service partition clients.
IList<ServicePartitionClient<CommunicationClient>> partitionClients = await this.GetServicePartitionClientsAsync();
// For each partition client, keep track of partition information and the number of words
ConcurrentDictionary<Int64RangePartitionInformation, long> totals = new ConcurrentDictionary<Int64RangePartitionInformation, long>();
IList<Task> tasks = new List<Task>(partitionClients.Count);
foreach (ServicePartitionClient<CommunicationClient> partitionClient in partitionClients)
{
// partitionClient internally resolves the address and retries on transient errors based on the configured retry policy.
tasks.Add(
partitionClient.InvokeWithRetryAsync(
client =>
{
Uri serviceAddress = new Uri(client.BaseAddress, "Count");
HttpWebRequest request = WebRequest.CreateHttp(serviceAddress);
request.Method = "GET";
request.Timeout = (int) client.OperationTimeout.TotalMilliseconds;
request.ReadWriteTimeout = (int) client.ReadWriteTimeout.TotalMilliseconds;
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
totals[client.ResolvedServicePartition.Info as Int64RangePartitionInformation] = Int64.Parse(reader.ReadToEnd().Trim());
}
return Task.FromResult(true);
}));
}
try
{
await Task.WhenAll(tasks);
}
catch (Exception ex)
{
// Sample code: print exception
ServiceEventSource.Current.OperationFailed(ex.Message, "Count - run web request");
}
StringBuilder sb = new StringBuilder();
sb.Append("<h1> Total:");
sb.Append(totals.Aggregate<KeyValuePair<Int64RangePartitionInformation, long>, long>(0, (total, next) => next.Value + total));
sb.Append("</h1>");
sb.Append("<table><tr><td>Partition ID</td><td>Key Range</td><td>Total</td></tr>");
foreach (KeyValuePair<Int64RangePartitionInformation, long> partitionData in totals.OrderBy(partitionData => partitionData.Key.LowKey))
{
sb.Append("<tr><td>");
sb.Append(partitionData.Key.Id);
sb.Append("</td><td>");
sb.AppendFormat("{0} - {1}", partitionData.Key.LowKey, partitionData.Key.HighKey);
sb.Append("</td><td>");
sb.Append(partitionData.Value);
sb.Append("</td></tr>");
}
sb.Append("</table>");
HttpResponseMessage message = new HttpResponseMessage();
message.Content = new StringContent(sb.ToString(), Encoding.UTF8, "text/html");
return message;
}
示例5: Count
public async Task<CountResponse> Count()
{
// Get the list of representative service partition clients.
IList<ServicePartitionClient<CommunicationClient>> partitionClients =
await this.GetServicePartitionClientsAsync();
// For each partition client, keep track of partition information and the number of words
ConcurrentDictionary<Int64RangePartitionInformation, long> totals = new ConcurrentDictionary<Int64RangePartitionInformation, long>();
IList<Task> tasks = new List<Task>(partitionClients.Count);
foreach (ServicePartitionClient<CommunicationClient> partitionClient in partitionClients)
{
// partitionClient internally resolves the address and retries on transient errors based on the configured retry policy.
tasks.Add(
partitionClient.InvokeWithRetryAsync(
client =>
{
Uri serviceAddress = new Uri(client.BaseAddress, "Count");
HttpWebRequest request = WebRequest.CreateHttp(serviceAddress);
request.Method = "GET";
request.Timeout = (int)client.OperationTimeout.TotalMilliseconds;
request.ReadWriteTimeout = (int)client.ReadWriteTimeout.TotalMilliseconds;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
totals[client.ResolvedServicePartition.Info as Int64RangePartitionInformation] = Int64.Parse(reader.ReadToEnd().Trim());
}
return Task.FromResult(true);
}));
}
try
{
await Task.WhenAll(tasks);
}
catch (Exception ex)
{
// Sample code: print exception
ServiceEventSource.Current.OperationFailed(ex.Message, "Count - run web request");
}
var retVal = new CountResponse();
retVal.Total = totals.Aggregate<KeyValuePair<Int64RangePartitionInformation, long>, long>(0, (total, next) => next.Value + total);
foreach (KeyValuePair<Int64RangePartitionInformation, long> partitionData in totals.OrderBy(partitionData => partitionData.Key.LowKey))
{
var info = new Info();
info.Id = partitionData.Key.Id;
info.LowKey = partitionData.Key.LowKey;
info.HighKey = partitionData.Key.HighKey;
info.Hits = partitionData.Value;
retVal.Infos.Add(info);
}
return retVal;
}
示例6: order
/// <summary>
/// Orders the clients map
/// </summary>
public Dictionary<UInt64, string> order(ConcurrentDictionary<UInt64, string> cDict)
{
IEnumerable<KeyValuePair<UInt64, string>> orderedMap = cDict.OrderBy(element => element.Key);
Dictionary<UInt64, string> dict = orderedMap.ToDictionary(el => el.Key, el => el.Value);
return dict;
}
示例7: SortFilesByLineNumbers
private string[] SortFilesByLineNumbers(
ConcurrentDictionary<string, int> files)
{
var sortedFiles = new string[files.Count];
var count = 0;
foreach(var file in files.OrderBy(x => x.Value))
sortedFiles[count++] = file.Key;
return sortedFiles;
}
示例8: 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();
//.........这里部分代码省略.........
示例9: ValidateThenSuggestEntities
//.........这里部分代码省略.........
//If it is empty assume the Start Date
if (string.IsNullOrEmpty(val))
repeat.FrequencyDetailAsWeeklyFrequencyDetail = new[] { startDayOfWeek };
else
{
var dayStrings = val.Split(',');
var daysOfWeek = new List<DayOfWeek>();
if (dayStrings.Any(s => s == "s" || s == "su" || s == "sun" || s == "sunday"))
daysOfWeek.Add(DayOfWeek.Sunday);
if (dayStrings.Any(s => s == "m" || s == "mo" || s == "mon" || s == "monday"))
daysOfWeek.Add(DayOfWeek.Monday);
if (dayStrings.Any(s => s == "t" || s == "tu" || s == "tue" || s == "tues" || s == "tuesday"))
daysOfWeek.Add(DayOfWeek.Tuesday);
if (dayStrings.Any(s => s == "w" || s == "we" || s == "wed" || s == "wednesday"))
daysOfWeek.Add(DayOfWeek.Wednesday);
if (dayStrings.Any(s => s == "r" || s == "th" || s == "tr" || s == "thur" || s == "thurs" || s == "thursday"))
daysOfWeek.Add(DayOfWeek.Thursday);
if (dayStrings.Any(s => s == "f" || s == "fr" || s == "fri" || s == "friday"))
daysOfWeek.Add(DayOfWeek.Friday);
if (dayStrings.Any(s => s == "s" || s == "sa" || s == "sat" || s == "saturday"))
daysOfWeek.Add(DayOfWeek.Saturday);
//Make sure the days include the startdate
if (!daysOfWeek.Contains(startDayOfWeek))
daysOfWeek.Add(startDayOfWeek);
repeat.FrequencyDetailAsWeeklyFrequencyDetail = daysOfWeek.OrderBy(e => (int)e).ToArray();
}
}
if (repeat.Frequency == Frequency.Monthly)
{
if (string.IsNullOrEmpty(val) || val == "date")
{
repeat.FrequencyDetailAsMonthlyFrequencyDetail = MonthlyFrequencyDetail.OnDayInMonth;
}
else if (val == "day")
{
var detailsAvailable = repeat.AvailableMonthlyFrequencyDetailTypes.ToList();
if (detailsAvailable.Count() > 1)
detailsAvailable.Remove(MonthlyFrequencyDetail.OnDayInMonth);
repeat.FrequencyDetailAsMonthlyFrequencyDetail = detailsAvailable.First();
}
}
#endregion
repeat.StatusInt = repeat.RepeatEveryTimes == null || repeat.FrequencyInt == null || setError
? (int)ImportStatus.Error
: (int)ImportStatus.New;
importRow.Repeat = repeat;
}
#endregion
#region Contact Info
//Create label and value dictionaries for Phone Number contact information
示例10: GetHitsCount
public async Task<HitsCountResponse> GetHitsCount()
{
// Get the list of representative service partition clients.
var partitionClients = await this.GetServicePartitionClientsAsync();
// For each partition client, keep track of partition information and the number of words
var totals = new ConcurrentDictionary<Int64RangePartitionInformation, Task<long>>();
IList<Task> tasks = new List<Task>(partitionClients.Count);
foreach (var partitionClient in partitionClients)
{
// partitionClient internally resolves the address and retries on transient errors based on the configured retry policy.
Task<long> tt = partitionClient.beanCache.GetHitsCount();
tasks.Add(tt);
totals[partitionClient.part as Int64RangePartitionInformation] = tt;
}
try
{
await Task.WhenAll(tasks);
}
catch (Exception ex)
{
// Sample code: print exception
ServiceEventSource.Current.Message(ex.Message, "Count - run web request");
throw ex;
}
var response = new HitsCountResponse();
response.Total = totals.Aggregate(0, (total, next) => (int)next.Value.Result + total);
foreach (var partitionData in totals.OrderBy(partitionData => partitionData.Key.LowKey))
{
var cachInfo = new CacheInfo();
cachInfo.Id = partitionData.Key.Id;
cachInfo.LowKey = partitionData.Key.LowKey;
cachInfo.HighKey = partitionData.Key.HighKey;
cachInfo.Hits = partitionData.Value.Result;
response.CacheInfo.Add(cachInfo);
}
return response;
}