本文整理汇总了C#中System.Collections.Dictionary.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.SelectMany方法的具体用法?C# Dictionary.SelectMany怎么用?C# Dictionary.SelectMany使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.SelectMany方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyPendingStoryMerges
public static void ApplyPendingStoryMerges()
{
Helpers.RunSqlStatement(Name, "update ignore StoryMerges s1 join StoryMerges s2 on s2.StoryID1=s1.StoryID2 set s2.StoryID1=s1.StoryID1", false);
//Get user-initiated merge actions. The actions are grouped as a user may have merged stories recursively.
Dictionary<long, HashSet<long>> mergeGroups = new Dictionary<long, HashSet<long>>();
Helpers.RunSelect(Name, "select StoryID1, StoryID2, IP, UserID from StoryMerges where MergedAt is null order by StoryID2 desc;",
mergeGroups,
(values, reader) =>
{
long keepID = reader.GetInt64("StoryID1");
long mergeID = reader.GetInt64("StoryID2");
if (mergeGroups.ContainsKey(mergeID))
{
HashSet<long> tmp = mergeGroups[mergeID];
tmp.Add(mergeID);
mergeGroups.Remove(mergeID);
if (mergeGroups.ContainsKey(keepID))
mergeGroups[keepID].UnionWith(tmp);
else
mergeGroups.Add(keepID, tmp);
}
else if (mergeGroups.ContainsKey(keepID))
{
mergeGroups[keepID].Add(mergeID);
}
else
{
mergeGroups.Add(keepID, new HashSet<long>());
mergeGroups[keepID].Add(mergeID);
}
long ip = reader.GetInt64("IP");
long userID = reader.GetInt64("UserID");
string sql = @"insert into StoryLog (IP, UserID, Timestamp, EventType, StoryAgeInSeconds, StoryID, MergedWithStoryID, TweetCount, RetweetCount, UserCount, TopUserCount)
select " + ip + "," + userID + ", utc_timestamp(), 12, unix_timestamp(utc_timestamp())-unix_timestamp(StartTime), StoryID, " + keepID + @", TweetCount, RetweetCount, UserCount, TopUserCount
from Story where StoryID = " + mergeID + ";";
Helpers.RunSqlStatement(Name, sql, false);
}
);
var mergeActions = mergeGroups.SelectMany(n =>
n.Value.Select(m => new MergeAction() { KeptStoryID = n.Key, MergedStoryID = m }));
//Perform merge actions
MergeStories(mergeActions, isAutomerge: false);
//Clean old actions
Helpers.RunSqlStatement(Name, "delete from StoryMerges where MergedAt is not null and MergedAt < (utc_timestamp() - interval 1 hour);", false);
}
示例2: DestroyInstances
private static void DestroyInstances(Dictionary<string, List<StaticObject>> instanceDictionary)
{
foreach (StaticObject i in instanceDictionary.SelectMany(ins => ins.Value))
{
DestroySoInstance(i);
}
}
示例3: Check
public static void Check(IEnumerable idsBlRefs, HashSet<string> ignoreBlocks)
{
curDepth = 0;
_ignoreBlocks = ignoreBlocks;
Database db = HostApplicationServices.WorkingDatabase;
_errors = new List<Error>();
attemptedblocks = new HashSet<ObjectId>();
AllDublicBlRefInfos = new List<BlockRefDublicateInfo>();
dictBlRefInfos = new Dictionary<string, Dictionary<PointTree, List<BlockRefDublicateInfo>>>();
try
{
using (var t = db.TransactionManager.StartTransaction())
{
if (idsBlRefs == null)
{
var ms = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForRead) as BlockTableRecord;
idsBlRefs = ms;
}
GetDublicateBlocks(idsBlRefs, Matrix3d.Identity, 0);
t.Commit();
}
// дублирующиеся блоки
AllDublicBlRefInfos = dictBlRefInfos.SelectMany(s => s.Value.Values).Where(w => w.Count > 1)
.SelectMany(s => s.GroupBy(g => g).Where(w => w.Skip(1).Any()))
.Select(s =>
{
var bi = s.First();
bi.CountDublic = s.Count();
bi.Dublicates = s.Skip(1).ToList();
return bi;
}).ToList();
// Добавление дубликатов в результирующий список
//AddTransformedToModelDublic(dublicBlRefInfos);
}
catch (Exception ex)
{
Logger.Log.Error(ex, $"CheckDublicateBlocks - {db.Filename}. {ex.StackTrace}");
return;
}
if (AllDublicBlRefInfos.Count == 0)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nДубликаты блоков не найдены.");
}
else
{
foreach (var dublBlRefInfo in AllDublicBlRefInfos)
{
Error err = new Error($"Дублирование блоков '{dublBlRefInfo.Name}' - {dublBlRefInfo.CountDublic} шт. в точке {dublBlRefInfo.Position.ToString()}",
dublBlRefInfo.IdBlRef, dublBlRefInfo.TransformToModel, System.Drawing.SystemIcons.Error);
err.Tag = dublBlRefInfo;
_errors.Add(err);
}
}
if (_errors.Count>0)
{
var formDublicates = new FormError(_errors, true);
formDublicates.Text = "Дублирование блоков";
formDublicates.EnableDublicateButtons();
if (Application.ShowModalDialog(formDublicates) != System.Windows.Forms.DialogResult.OK)
{
formDublicates.EnableDialog(false);
Application.ShowModelessDialog(formDublicates);
throw new Exception("Отменено пользователем.");
}
}
}