Exemplo n.º 1
0
 public static async Task AddDumpAsync(Dump dump)
 {
     using (var context = new TriageDbContext(s_connStr))
     {
         await context.SaveChangesAsync();
     }
 }
Exemplo n.º 2
0
        public static async Task <int> AddDumpAsync(Dump dump)
        {
            using (var context = new TriageDbContext(s_connStr))
            {
                context.Dumps.Add(dump);

                await context.SaveChangesAsync();
            }

            return(dump.DumpId);
        }
Exemplo n.º 3
0
        private static async Task <T> GetUniquelyNamedEntityAsync <T>(TriageDbContext context, IDbSet <T> set, T entity) where T : UniquelyNamedEntity
        {
            if (entity.Name.Length > 450)
            {
                entity.Name = entity.Name.Substring(0, 450);
            }

            T tempEntity = await set.FirstOrDefaultAsync(e => e.Name == entity.Name);

            if (tempEntity != null)
            {
                return(tempEntity);
            }

            set.Add(entity);

            await context.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 4
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();
            }
        }