private void SaveOperationThreshold()
        {
            Guid MiniProfilerId;

            MiniProfilerId = PerformanceLabs.MiniProfiler.Id;

            //MiniProfiler.Settings.Storage.Save(PerformanceLabs.MiniProfiler);

            Type t = (PerformanceLabsConfigurations.contextType == PerformanceLabDBContextType.MainContext) ? typeof(PerformanceLabsDBContext) : typeof(Test_PerformanceLabsDBContext);

            using (IPerformanceDBProxy context = (IPerformanceDBProxy)Activator.CreateInstance(t))
            {
                //ParentId = (from mpt in context.MiniProfilerTimings
                //            join mp in context.MiniProfilers
                //            on mpt.MiniProfilerId equals mp.Id
                //            where mpt.Name != null && mpt.Name == OperationName
                //            orderby mp.Started descending, mpt.RowId descending
                //            select mpt.Id).First();

                MiniProfilerOperationThreshold mmpThreshold = new MiniProfilerOperationThreshold()
                {
                    MiniProfilerId           = MiniProfilerId,
                    OperationName            = OperationName,
                    ParentId                 = null,
                    ThresholdOperationTiming = ThresholdOperationTiming
                };

                context.MiniProfilerOperationThresholds.Add(mmpThreshold);
                context.SaveChanges();
            }
        }
 public static void SaveToDataBase()
 {
     if (DurationMilliseconds > TrivialDurationThresholdMillisecondsStopWatch)
     {
         Type t = (PerformanceLabsConfigurations.contextType == PerformanceLabDBContextType.MainContext) ? typeof(PerformanceLabsDBContext) : typeof(Test_PerformanceLabsDBContext);
         using (IPerformanceDBProxy context = (IPerformanceDBProxy)Activator.CreateInstance(t))
         {
             var parentId = (from swProfiler in context.StopWatchProfilers
                             orderby swProfiler.Started descending
                             select swProfiler.RowId).First();
             if (parentId != 0)
             {
                 StopWatchProfilerTiming swProfilerTiming = new StopWatchProfilerTiming()
                 {
                     ParentId                 = parentId,
                     Name                     = OperationName,
                     MethodRunCounts          = NumOfInvocations,
                     DurationMilliseconds     = DurationMilliseconds,
                     AvgDurationMilliseconds  = AvgDurationMilliseconds,
                     ThresholdOperationTiming = ThresholdOperationTiming
                 };
                 context.StopWatchProfilerTimings.Add(swProfilerTiming);
                 context.SaveChanges();
             }
         }
     }
 }
        public static void StartProfiler()
        {
            Type t = (PerformanceLabsConfigurations.contextType == PerformanceLabDBContextType.MainContext) ? typeof(PerformanceLabsDBContext) : typeof(Test_PerformanceLabsDBContext);

            using (IPerformanceDBProxy context = (IPerformanceDBProxy)Activator.CreateInstance(t))
            {
                StopWatchProfiler swProfiler = new StopWatchProfiler()
                {
                    ProfilerName = ProfilerName,
                    Started      = DateTime.UtcNow,
                    MachineName  = MachineName,
                    User         = User,
                    TrivialDurationThresholdMilliseconds = TrivialDurationThresholdMillisecondsStopWatch
                };

                context.StopWatchProfilers.Add(swProfiler);
                context.SaveChanges();
            }
        }