コード例 #1
0
ファイル: TriageDb.cs プロジェクト: jango2015/corefx-tools
 public static async Task AddDumpAsync(Dump dump)
 {
     using (var context = new TriageDbContext(s_connStr))
     {
         await context.SaveChangesAsync();
     }
 }
コード例 #2
0
        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();
            }
        }