public void Constructor_LoadStores_MaintainOrder()
 {
     MultiStorageProvider p = new MultiStorageProvider(new HttpRuntimeCacheStorage(new TimeSpan(1, 0, 0)), new SqlServerStorage(""));
     Assert.AreEqual(2, p.Stores.Count);
     Assert.IsTrue(p.Stores[0].GetType() == typeof(HttpRuntimeCacheStorage));
     Assert.IsTrue(p.Stores[1].GetType() == typeof(SqlServerStorage));
 }
Example #2
0
        public void Constructor_LoadStores_MaintainOrder()
        {
            var p = new MultiStorageProvider(new MemoryCacheStorage(new TimeSpan(1, 0, 0)), new SqlServerStorage(string.Empty));

            Assert.Equal(2, p.Stores.Count);
            Assert.True(p.Stores[0].GetType() == typeof(MemoryCacheStorage));
            Assert.True(p.Stores[1].GetType() == typeof(SqlServerStorage));
        }
        public void Constructor_LoadStores_MaintainOrder()
        {
            MultiStorageProvider p = new MultiStorageProvider(new HttpRuntimeCacheStorage(new TimeSpan(1, 0, 0)), new SqlServerStorage(""));

            Assert.AreEqual(2, p.Stores.Count);
            Assert.IsTrue(p.Stores[0].GetType() == typeof(HttpRuntimeCacheStorage));
            Assert.IsTrue(p.Stores[1].GetType() == typeof(SqlServerStorage));
        }
 public void Constructor_LoadWithNullStores_ThrowsError()
 {
     bool errorCaught = false;
     try
     {
         MultiStorageProvider p = new MultiStorageProvider(null, null);
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("stores", ex.ParamName, "wrong exception param");
         errorCaught = true;
     }
     Assert.IsTrue(errorCaught, "No Error caught");
 }
Example #5
0
        public void Constructor_LoadWithNullStores_ThrowsError()
        {
            bool errorCaught = false;

            try
            {
                var p = new MultiStorageProvider(null, null);
            }
            catch (ArgumentNullException ex)
            {
                Assert.Equal("stores", ex.ParamName); // wrong exception param
                errorCaught = true;
            }
            Assert.True(errorCaught, "No Error caught");
        }
        public void Constructor_LoadWithNoStores_ThrowsError()
        {
            bool errorCaught = false;

            try
            {
                MultiStorageProvider p = new MultiStorageProvider();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("stores", ex.ParamName, "wrong exception param");
                errorCaught = true;
            }
            Assert.IsTrue(errorCaught, "No Error caught");
        }
Example #7
0
        /// <summary>
        /// Customize aspects of the MiniProfiler.
        /// </summary>
        private void InitProfilerSettings()
        {
            // a powerful feature of the MiniProfiler is the ability to share links to results with other developers.
            // by default, however, long-term result caching is done in HttpRuntime.Cache, which is very volatile.
            //
            // let's rig up serialization of our profiler results to a database, so they survive app restarts.

            // Setting up a MultiStorage provider. This will store results in the HttpRuntimeCache (normally the default) and in SqlLite as well.
            MultiStorageProvider multiStorage = new MultiStorageProvider(
                new HttpRuntimeCacheStorage(new TimeSpan(1, 0, 0)),
                new SqliteMiniProfilerStorage(ConnectionString));

            MiniProfiler.Settings.Storage = multiStorage;

            // different RDBMS have different ways of declaring sql parameters - SQLite can understand inline sql parameters just fine
            // by default, sql parameters won't be displayed
            MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();

            // these settings are optional and all have defaults, any matching setting specified in .RenderIncludes() will
            // override the application-wide defaults specified here, for example if you had both:
            //    MiniProfiler.Settings.PopupRenderPosition = RenderPosition.Right;
            //    and in the page:
            //    @MiniProfiler.RenderIncludes(position: RenderPosition.Left)
            // then the position would be on the left that that page, and on the right (the app default) for anywhere that doesn't
            // specified position in the .RenderIncludes() call.
            MiniProfiler.Settings.PopupRenderPosition  = RenderPosition.Right; // defaults to left
            MiniProfiler.Settings.PopupMaxTracesToShow = 10;                   // defaults to 15
            MiniProfiler.Settings.RouteBasePath        = "~/profiler";         // e.g. /profiler/mini-profiler-includes.js

            // optional settings to control the stack trace output in the details pane
            // the exclude methods are not thread safe, so be sure to only call these once per appdomain
            MiniProfiler.Settings.ExcludeType("SessionFactory"); // Ignore any class with the name of SessionFactory
            MiniProfiler.Settings.ExcludeAssembly("NHibernate"); // Ignore any assembly named NHibernate
            MiniProfiler.Settings.ExcludeMethod("Flush");        // Ignore any method with the name of Flush
            // MiniProfiler.Settings.ShowControls = true;
            MiniProfiler.Settings.StackMaxLength = 256;          // default is 120 characters

            // because profiler results can contain sensitive data (e.g. sql queries with parameter values displayed), we
            // can define a function that will authorize clients to see the json or full page results.
            // we use it on http://stackoverflow.com to check that the request cookies belong to a valid developer.
            MiniProfiler.Settings.Results_Authorize = request =>
            {
                // you may implement this if you need to restrict visibility of profiling on a per request basis

                // for example, for this specific path, we'll only allow profiling if a query parameter is set
                if ("/Home/ResultsAuthorization".Equals(request.Url.LocalPath, StringComparison.OrdinalIgnoreCase))
                {
                    return((request.Url.Query).ToLower().Contains("isauthorized"));
                }

                // all other paths can check our global switch
                return(!DisableProfilingResults);
            };

            // the list of all sessions in the store is restricted by default, you must return true to alllow it
            MiniProfiler.Settings.Results_List_Authorize = request =>
            {
                // you may implement this if you need to restrict visibility of profiling lists on a per request basis
                return(true); // all requests are kosher
            };
        }