本文整理汇总了C#中ConcurrentBag.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.OrderByDescending方法的具体用法?C# ConcurrentBag.OrderByDescending怎么用?C# ConcurrentBag.OrderByDescending使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.OrderByDescending方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FirstNews
public IEnumerable<INews> FirstNews()
{
var newsInstance = InterNewsBL.Instance;
var newsList = new ConcurrentBag<INews>();
try
{
var result = newsInstance.SelectTopNews();
result.AsParallel().AsOrdered().ForAll(val =>
{
newsList.Add(new News
{
NewsID = val.NewsID,
DisplayOrder = val.DisplayOrder,
Heading = val.Heading,
ImageUrl = val.ImageUrl,
ShortDesc = val.ShortDescription,
IsRss = val.IsRss,
//NewsDesc= val.NewsDescription,
DttmCreated = val.DttmCreated
});
});
}
catch (Exception)
{
throw;
}
finally
{
newsInstance.Dispose();
}
return newsList.OrderByDescending(v => v.DttmCreated);
}
示例2: NewsList
public IEnumerable<INews> NewsList(Int64 NextPage)
{
var newsInstance = InterNewsBL.Instance;
ConcurrentBag<INews> newsList = new ConcurrentBag<INews>();
try
{
var result = newsInstance.SelectAllForList(NextPage);
result.AsParallel().AsOrdered().ForAll(val =>
{
newsList.Add(new News
{
NewsID = val.NewsID,
DisplayOrder = val.DisplayOrder,
Heading = val.Heading,
ImageUrl = val.ImageUrl,
EditorID = string.Empty,
EditorName = "",
ShortDesc = val.ShortDescription,
NewsDesc = val.NewsDescription,
DttmCreated = val.DttmCreated,
IsRss = val.IsRss
});
});
}
catch (Exception)
{
throw;
}
finally
{
newsInstance.Dispose();
}
return newsList.OrderByDescending(v => v.DttmCreated);
}
示例3: SearchCategories
private void SearchCategories(coreModel.SearchCriteria criteria, coreModel.SearchResult result)
{
// TODO: optimize for performance, need to eliminate number of database queries
// 1. Catalog should either be passed or loaded using caching
// 2. Categories should be loaded by passing array of ids instead of parallel locading one by one
using (var repository = _catalogRepositoryFactory())
{
if (!String.IsNullOrEmpty(criteria.CatalogId))
{
var query = repository.Categories.OfType<dataModel.Category>().Where(x => x.CatalogId == criteria.CatalogId);
var dbCatalog = repository.GetCatalogById(criteria.CatalogId);
var isVirtual = dbCatalog is dataModel.VirtualCatalog;
if (!String.IsNullOrEmpty(criteria.Keyword))
{
query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Code.Contains(criteria.Keyword));
}
else if (!String.IsNullOrEmpty(criteria.CategoryId))
{
if (isVirtual)
{
var dbCategory = repository.GetCategoryById(criteria.CategoryId);
//Need return all linked categories also
var allLinkedPhysicalCategoriesIds = dbCategory.IncommingLinks.Select(x => x.SourceCategoryId).ToArray();
query = repository.Categories.OfType<dataModel.Category>();
if (allLinkedPhysicalCategoriesIds.Any())
{
if (criteria.HideDirectLinedCategories)
{
query = query.Where(x => x.ParentCategoryId == criteria.CategoryId || allLinkedPhysicalCategoriesIds.Contains(x.ParentCategoryId));
}
else
{
query = query.Where(x => x.ParentCategoryId == criteria.CategoryId || allLinkedPhysicalCategoriesIds.Contains(x.Id));
}
}
else
{
query = query.Where(x => x.ParentCategoryId == criteria.CategoryId);
}
}
else
{
query = query.Where(x => x.ParentCategoryId == criteria.CategoryId);
}
}
else if(!String.IsNullOrEmpty(criteria.Code))
{
query = query.Where(x => x.Code == criteria.Code);
}
else if (!String.IsNullOrEmpty(criteria.SeoKeyword))
{
var urlKeyword = _commerceService.GetSeoByKeyword(criteria.SeoKeyword).Where(x => x.ObjectType == typeof(coreModel.Category).Name).FirstOrDefault();
if(urlKeyword == null)
{
query = query.Where(x=> false);
}
else
{
query = query.Where(x => x.Id == urlKeyword.ObjectId);
}
}
else if (!String.IsNullOrEmpty(criteria.CatalogId))
{
query = query.Where(x => x.CatalogId == criteria.CatalogId && (x.ParentCategoryId == null || criteria.GetAllCategories));
if (isVirtual)
{
//Need return only catalog linked categories
var allLinkedCategoriesIds = ((dataModel.VirtualCatalog)dbCatalog).IncommingLinks
.Where(x=>x.TargetCategoryId == null)
.Select(x => x.SourceCategoryId);
//Search in all catalogs
query = repository.Categories.OfType<dataModel.Category>();
query = query.Where(x => (x.CatalogId == criteria.CatalogId && (x.ParentCategoryId == null || criteria.GetAllCategories)) || allLinkedCategoriesIds.Contains(x.Id));
}
}
var categoryIds = query.OfType<dataModel.Category>().Select(x => x.Id).ToArray();
var categories = new ConcurrentBag<coreModel.Category>();
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 10
};
Parallel.ForEach(categoryIds, parallelOptions, (x) =>
{
var category = _categoryService.GetById(x);
categories.Add(category);
});
//Must order by priority
result.Categories = categories.OrderByDescending(x => x.Priority).ThenBy(x => x.Name).ToList();
}
}
}
示例4: ParseAndSave
public void ParseAndSave(ServerLogFileContainer container)
{
if (!container.AppLogFiles.Any())
return;
foreach (AppLogFiles appLogFile in container.AppLogFiles)
{
DateTime lastEntryDate = DateTime.MinValue;
LatestLogFileInfo latestLogFileInfo = null;
if (_useSmartParsing)
{
latestLogFileInfo = _repository.GetLatestLogFileInfo(container.Environment.Name, container.Server.Name, appLogFile.Appname);
}
if (latestLogFileInfo != null)
{
lastEntryDate = latestLogFileInfo.DateTime;
LogLine("- Using smart update. Last entry for {0}/{1}/{2} was {3}", container.Environment.Name, container.Server.Name, appLogFile.Appname, lastEntryDate);
}
else
{
LogLine("- No latest date found for {0} or smart update is off.", appLogFile.Appname);
}
_appFileDates = new ConcurrentBag<DateTime>();
Parallel.ForEach(appLogFile.LogfilePaths, (filePath) =>
{
LogLine("Parsing {0} ({1})", filePath, ByteSize.FromBytes(new FileInfo(filePath).Length).ToString());
// Smart update - ignore files that are older than the most recent log file
FileInfo info = new FileInfo(filePath);
_appFileDates.Add(info.LastWriteTimeUtc);
if (_useSmartParsing)
{
if (info.LastWriteTimeUtc > lastEntryDate)
{
ParseAndSaveSingleLogFile(container.Environment.Name, container.Server.Name, appLogFile.Appname, filePath, latestLogFileInfo);
}
else
{
LogLine("Ignoring {0} as it's older than {1} (the last log entry)", filePath, lastEntryDate);
}
}
else
{
ParseAndSaveSingleLogFile(container.Environment.Name, container.Server.Name, appLogFile.Appname, filePath, null);
}
});
// Saved the newest log file date
LatestLogFileInfo cachedFileInfo = new LatestLogFileInfo()
{
Id = LatestLogFileInfo.GenerateId(container.Environment.Name, container.Server.Name, appLogFile.Appname),
DateTime = _appFileDates.OrderByDescending(x => x.ToUniversalTime()).FirstOrDefault()
};
_repository.SaveLatestLogFileInfo(cachedFileInfo);
}
}
示例5: NewsObject
private IEnumerable<ITopNews> NewsObject(XDocument xDoc, bool IsImgBreak)
{
try
{
ConcurrentBag<ITopNews> newsList = new ConcurrentBag<ITopNews>();
var items = (from x in xDoc.Descendants("item")
select new
{
Heading = x.Element("title").Value,
Link = x.Element("link").Value,
ShortDesc = x.Element("description").Value,
PubDate = x.Element("pubDate").Value,
guid = x.Element("guid").Value
});
if (items != null)
{
items.AsParallel().AsOrdered().ForAll(item =>
//items.ToList().ForEach(item =>
{
string ShortDesc = item.ShortDesc;
string imgUrl = string.Empty;
string desc = ShortDesc;
if (desc.Contains('>'))
{
var arr = desc.Split('>');
if (arr.Length > 1)
{
ShortDesc = arr[1];
imgUrl = arr[0].Split('=')[1];
}
if (IsImgBreak && !string.IsNullOrEmpty(imgUrl))
{
imgUrl = imgUrl.Replace('"', ' ').Replace('"', ' ').Remove(imgUrl.LastIndexOf('/'), 1);
}
}
newsList.Add(
new TopNews
{
TopNewsID = item.guid,
DisplayOrder = 0,
Heading = item.Heading,
ImageUrl = imgUrl,
ShortDescription = ShortDesc,
//NewsDesc= val.NewsDescription,
DttmCreated = Convert.ToDateTime(item.PubDate)
});
});
}
return newsList.OrderByDescending(v => v.DttmCreated.Date);
}
catch (Exception ex)
{
throw ex;
}
}
示例6: SearchCatalogs
private void SearchCatalogs(coreModel.SearchCriteria criteria, coreModel.SearchResult result)
{
using (var repository = _catalogRepositoryFactory())
{
var catalogIds = repository.Catalogs.Select(x => x.Id).ToArray();
var catalogs = new ConcurrentBag<coreModel.Catalog>();
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 10
};
Parallel.ForEach(catalogIds, parallelOptions, (x) =>
{
var catalog = _catalogService.GetById(x);
catalogs.Add(catalog);
});
result.Catalogs = catalogs.OrderByDescending(x => x.Name).ToList();
}
}
示例7: LoadReplays
void LoadReplays(string dir, ScrollItemWidget template)
{
using (new Support.PerfTimer("Load replays"))
{
var loadedReplays = new ConcurrentBag<ReplayMetadata>();
Parallel.ForEach(Directory.GetFiles(dir, "*.orarep"), (fileName, pls) =>
{
if (cancelLoadingReplays)
{
pls.Stop();
return;
}
var replay = ReplayMetadata.Read(fileName);
if (replay != null)
loadedReplays.Add(replay);
});
if (cancelLoadingReplays)
return;
var sortedReplays = loadedReplays.OrderByDescending(replay => replay.GameInfo.StartTimeUtc).ToList();
Game.RunAfterTick(() =>
{
replayList.RemoveChildren();
foreach (var replay in sortedReplays)
AddReplay(replay, template);
SetupReplayDependentFilters();
ApplyFilter();
});
}
}
示例8: Selection
private void Selection()
{
var tempGenerationContainer = new ConcurrentBag<Specimen>();
if (this.Elitism)
{
var elite = _currGeneration.Last();
tempGenerationContainer.Add(elite);
}
for (int i = 0; i < this.PopulationSize / 2.5; i++)
{
int pidx1 = this.PopulationSize - i - 1;
int pidx2 = pidx1;
while (pidx1 == pidx2 || _currGeneration[pidx1].IsSimilar(_currGeneration[pidx2]))
{
pidx2 = RouletteSelection();
}
var parent1 = _currGeneration[pidx1].Mutate();
var parent2 = _currGeneration[pidx2].Mutate();
//Console.WriteLine("Selected Species {0} and {1}", pidx1, pidx2);
var children = Rnd.NextDouble() < this.CrossoverRate ? parent1.Crossover(parent2) : new List<Specimen> { _currGeneration[pidx1], _currGeneration[pidx2] };
foreach (var ch in children.AsParallel())
{
if (double.IsNaN(ch.Fitness))
{
var fitness = FitnessFunction(ch);
var newChild = new Specimen
{
Genes = ch.Genes,
Length = ch.Length,
Fitness = double.IsNaN(fitness) ? 0 : (double.IsInfinity(fitness) ? 1e5 : fitness)
};
tempGenerationContainer.Add(newChild);
}
else
{
tempGenerationContainer.Add(ch);
}
}
}
_currGeneration = tempGenerationContainer.OrderByDescending(s => s.Fitness).Take(this.PopulationSize).Reverse().ToList();
_fitnessTable = new List<double>();
foreach (var spec in _currGeneration)
{
if (!_fitnessTable.Any())
{
_fitnessTable.Add(spec.Fitness);
}
else
{
_fitnessTable.Add(_fitnessTable.Last() + spec.Fitness);
}
}
TotalFitness = _currGeneration.Sum(spec => spec.Fitness);
Console.WriteLine("=== Selection Result ===\n\n");
Console.WriteLine("\n--- Top 5 ---");
var best = _currGeneration.Last();
Console.WriteLine("Best Specimen:\n{0}\n", best.Print());
int j = 1;
foreach (var spec in _currGeneration.AsEnumerable().Reverse().Take(5).Skip(1))
{
Console.WriteLine("Specimen {0} has Fitness: {1}\n", j++, spec.Fitness); // FIXME: Printout Genes
}
Console.WriteLine("Average Fitness: {0}\n", TotalFitness/PopulationSize);
}
示例9: GetItems
private async Task<IOrderedEnumerable<ToDoItem>> GetItems()
{
//await Task.Yield();
var items = new ConcurrentBag<ToDoItem>();
var projects = VBE.VBProjects.Cast<VBProject>().Where(project => project.Protection != vbext_ProjectProtection.vbext_pp_locked);
foreach(var project in projects)
{
var modules = _parser.Parse(project, this).ComponentParseResults;
foreach (var module in modules)
{
var markers = module.Comments.SelectMany(GetToDoMarkers);
foreach (var marker in markers)
{
items.Add(marker);
}
}
}
var sortedItems = items.OrderByDescending(item => item.Priority)
.ThenBy(item => item.ProjectName)
.ThenBy(item => item.ModuleName)
.ThenBy(item => item.LineNumber);
return sortedItems;
}
示例10: SearchMovie
public virtual async Task<IEnumerable<ITorrentSearchResult>> SearchMovie(string name, int? year, string imdbId, VideoQuality videoQuality = VideoQuality.Any,
string extraKeywords = null, string excludeKeywords = null,
int? minSize = null, int? maxSize = null, int? minSeed = null) {
var results = new ConcurrentBag<ITorrentSearchResult>();
var tasks = MovieProviders.RunTasks(p =>
p.SearchMovie(name, year, imdbId, videoQuality, extraKeywords, excludeKeywords, minSize, maxSize, minSeed, this)
.ContinueWith(t => results.AddRange(t.Result)),
ExceptionHandler
);
await Task.WhenAll(tasks);
return results.OrderByDescending(r => r.Seed);
}
示例11: Search
public virtual async Task<IEnumerable<ITorrentSearchResult>> Search(string query, VideoQuality videoQuality = VideoQuality.Any, string excludeKeywords = null,
int? minSize = null, int? maxSize = null, int? minSeed = null) {
var providers = ((IEnumerable<ITorrentProvider>)MovieProviders).Union(TvShowProviders);
var results = new ConcurrentBag<ITorrentSearchResult>();
var tasks = providers.RunTasks(p =>
p.Search(query, videoQuality, excludeKeywords, minSize, maxSize, minSeed, this)
.ContinueWith(t => results.AddRange(t.Result)),
ExceptionHandler
);
await Task.WhenAll(tasks);
return results.OrderByDescending(r => r.Seed);
}