public static TriageData FromDictionary(Dictionary<string, string> triageData) { if (triageData == null) throw new ArgumentNullException("triageData"); var data = new TriageData(); data.LoadFromStringDictionary(triageData); return data; }
public static TriageData FromDictionary(Dictionary <string, string> triageData) { if (triageData == null) { throw new ArgumentNullException("triageData"); } var data = new TriageData(); data.LoadFromStringDictionary(triageData); return(data); }
public static async Task UpdateDumpTriageInfo(int dumpId, TriageData triageData) { if (triageData == null) { throw new ArgumentNullException("triageData"); } Dump dump = null; using (var context = new TriageDbContext(s_connStr)) { //find the dump to update dump = await context.Dumps.FindAsync(dumpId); if (dump == null) { throw new ArgumentException($"Could not update dump. No dump was found with id {dumpId}", "dumpId"); } await UpdateUniquelyNamedEntitiesAsync(context, triageData); //if the bucket id is set on the triage data and it is different than the dump id //update the bucket of the dump with the new triage data bucket if (triageData.BucketId.HasValue && dump.BucketId != triageData.BucketId) { dump.Bucket = null; dump.BucketId = triageData.BucketId; } //if the triage info contains the thread information delete the previous threads and frames if (triageData.Threads.Count > 0) { //remove all the dump frames from the context before updating //this is needed because frame has a required FK to dumpId so //frames without an associated dump are not allowed var frames = dump.Threads.SelectMany(t => t.Frames).ToArray(); context.Frames.RemoveRange(frames); context.Threads.RemoveRange(dump.Threads); dump.Threads.Clear(); //add the new threads to the dump foreach (var t in triageData.Threads) { dump.Threads.Add(t); } } //if there are more properties specified in the triage data if (triageData.Properties.Count > 0) { //load the existing properties into a dictionary keyed by property name var existingProps = dump.Properties.ToDictionary(p => p.Name); //add or update the properties of the dump foreach (var p in triageData.Properties) { //if a property with the same name already exists update it, otherwise add it //NOTE: currently this only supports adding or updating properties. It's possible we will // want to update this later on to support removing properties by passing null or empty // string as the value if (existingProps.ContainsKey(p.Name)) { existingProps[p.Name].Value = p.Value; } else { dump.Properties.Add(p); } } } await context.SaveChangesAsync(); } }
public static async Task UpdateDumpTriageInfo(int dumpId, Dictionary <string, string> triageData) { await UpdateDumpTriageInfo(dumpId, TriageData.FromDictionary(triageData)); }
private static async Task UpdateUniquelyNamedEntitiesAsync(TriageDbContext context, TriageData triageData) { //add or update the bucket if it exists if (triageData.Bucket != null && triageData.Bucket.BucketId == 0) { triageData.Bucket = await GetUniquelyNamedEntityAsync(context, context.Buckets, triageData.Bucket); } var addedModules = triageData.Threads.Where(t => t.ThreadId == 0).SelectMany(t => t.Frames).Select(f => f.Module).Where(m => m.ModuleId == 0).OrderBy(m => m.Name).ToArray(); for (int i = 0; i < addedModules.Length; i++) { if (i > 0 && addedModules[i].Name == addedModules[i - 1].Name) { addedModules[i].ModuleId = addedModules[i - 1].ModuleId; } else { addedModules[i].ModuleId = (await GetUniquelyNamedEntityAsync(context, context.Modules, addedModules[i])).ModuleId; } } var addedRoutines = triageData.Threads.Where(t => t.ThreadId == 0).SelectMany(t => t.Frames).Select(f => f.Routine).Where(r => r.RoutineId == 0).OrderBy(r => r.Name).ToArray(); for (int i = 0; i < addedRoutines.Length; i++) { if (i > 0 && addedRoutines[i].Name == addedRoutines[i - 1].Name) { addedRoutines[i].RoutineId = addedRoutines[i - 1].RoutineId; } else { addedRoutines[i].RoutineId = (await GetUniquelyNamedEntityAsync(context, context.Routines, addedRoutines[i])).RoutineId; } } foreach (var frame in triageData.Threads.SelectMany(t => t.Frames)) { frame.ModuleId = frame.Module.ModuleId; frame.Module = null; frame.RoutineId = frame.Routine.RoutineId; frame.Routine = null; } }