- EngineContext.Current.Resolve<IConfigurationProvider<StoreInformationSettings>>()
- .SaveSettings(new StoreInformationSettings()
- {
- StoreName = "Your store name",
- StoreUrl = "http://www.yourStore.com/",
- StoreClosed = false,
- StoreClosedAllowForAdmins = false,
- DefaultStoreTheme = "DarkOrange",
- AllowCustomerToSelectTheme = false,
- DisplayMiniProfilerInPublicStore = false,
- });
關於Mvc-Mini-Profiler
Mini-Profile的本意是用於Asp.NETMVC和Asp.nET程序Profile的簡單工具,它本身不Hook到每一個線程,並不注重解決重要的Performance問題,相反:
. 適用與ADO.NET,LINQ to SQL.EF甚至EF-code first的性能監測
. 通過代碼來Profile指定代碼段的性能
我們來看一下Nop是怎麼使用到Profiler的:
在Front web的_root.cshtml中
var displayMiniProfiler = EngineContext.Current.Resolve<Nop.Core.Domain.StoreInformationSettings>().DisplayMiniProfilerInPublicStore; }
理論上,後臺應該在商店信息部分設置是否要顯示性能分析數據(這個對於分析網站的性能是有幫助的,但如何僅針對管理員還需要進一步討論,例如寫數據到Log,或者Table,而不是顯示在Page上):
public class StoreInformationSettings : ISettings { public string StoreName { get; set; } public string StoreUrl { get; set; } public bool StoreClosed { get; set; } public bool StoreClosedAllowForAdmins { get; set; } public string DefaultStoreTheme { get; set; } public bool AllowCustomerToSelectTheme { get; set; } public bool DisplayMiniProfilerInPublicStore { get; set; } }
在InstallationService當中,我們DisplayMiniProfilerInPublicStore = false,
<head>中注入Miniprofile的腳本以及輸出內容的CSS
@if (displayMiniProfiler) { @MvcMiniProfiler.MiniProfiler.RenderIncludes(); }
在Global.asax.cs
AreaRegistration.RegisterAllAreas(); if (DataSettingsHelper.DatabaseIsInstalled() && EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore) { GlobalFilters.Filters.Add(new ProfilingActionFilter()); }
在Global.asax中,Web程序EndRequest中,Profile功能的關閉:
- protected void Application_EndRequest(object sender, EventArgs e)
- {
- if (DataSettingsHelper.DatabaseIsInstalled() &&
- EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore)
- {
- //stop as early as you can, even earlier with MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
- MiniProfiler.Stop();
- }
- }
使用步驟:
1. 下載MVC Mini profiler,添加引用
2. 一般而言,選擇在Layout root文件中Head增加
@MvcMiniProfiler.MiniProfiler.RenderIncludes() </head>
3. 在Global.asax.cs Application_BeginRequest:
其實在這裏可以增加邏輯判斷,例如僅本地登陸啓動Profile;特定用戶Profile,Nop Commerce在這個方面可以改進一下:
if (Request.IsLocal) MvcMiniProfiler.MiniProfiler.Start();
。。。。 。。。。
protected void Application_End() { MvcMiniProfiler.MiniProfiler.Stop(); }
在後臺某個View-Controller中:
using MvcMiniProfiler;
...
var profiler = MiniProfiler.Current; // it's ok if this is null
using (profiler.Step("Set page title"))
{
ViewBag.Title = "Home Page";
}
using (profiler.Step("Doing complexstuff"))
{
using (profiler.Step("Step A"))
{ // something more interestinghere
Thread.Sleep(100);
}
using (profiler.Step("Step B"))
{ // and here
Thread.Sleep(250);
}
}
更多信息,請參考:
http://code.google.com/p/mvc-mini-profiler/