forked from smartstore/SmartStoreNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevToolsPlugin.cs
More file actions
105 lines (88 loc) · 3 KB
/
Copy pathDevToolsPlugin.cs
File metadata and controls
105 lines (88 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using SmartStore.Core.Logging;
using SmartStore.Core.Plugins;
using SmartStore.Data;
using SmartStore.Data.Setup;
using SmartStore.Services.Configuration;
using SmartStore.Core.Caching;
namespace SmartStore.DevTools
{
[DisplayOrder(10)]
[SystemName("Widgets.DevToolsDemo")]
[FriendlyName("Dev-Tools Demo Widget")]
public class DevToolsPlugin : BasePlugin, IConfigurable //, IWidget
{
private readonly ISettingService _settingService;
private readonly ICacheableRouteRegistrar _cacheableRouteRegistrar;
public DevToolsPlugin(ISettingService settingService,
ICacheableRouteRegistrar cacheAbleRouteRegistrar)
{
_settingService = settingService;
_cacheableRouteRegistrar = cacheAbleRouteRegistrar;
this.Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
//public IList<string> GetWidgetZones() => new List<string> { "home_page_top" };
//public void GetDisplayWidgetRoute(string widgetZone, object model, int storeId, out string actionName, out string controllerName, out RouteValueDictionary routeValues)
//{
// actionName = "MyDemoWidget";
// controllerName = "DevTools";
// routeValues = new RouteValueDictionary
// {
// { "Namespaces", "SmartStore.DevTools.Controllers" },
// { "area", "SmartStore.DevTools" }
// };
//}
public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
actionName = "Configure";
controllerName = "DevTools";
routeValues = new RouteValueDictionary() { { "area", "SmartStore.DevTools" } };
}
public override void Install()
{
// Example for how to add a route to the output cache
//_cacheableRouteRegistrar.RegisterCacheableRoute("SmartStore.DevTools/DevTools/PublicInfo");
_settingService.SaveSetting(new ProfilerSettings());
base.Install();
Logger.Info(string.Format("Plugin installed: SystemName: {0}, Version: {1}, Description: '{2}'", PluginDescriptor.SystemName, PluginDescriptor.Version, PluginDescriptor.FriendlyName));
}
/// <summary>
/// Uninstall plugin
/// </summary>
public override void Uninstall()
{
// Example for how to remove a route from the output cache
//_cacheableRouteRegistrar.RemoveCacheableRoute("SmartStore.DevTools/DevTools/PublicInfo");
_settingService.DeleteSetting<ProfilerSettings>();
base.Uninstall();
}
private static bool? _hasPendingMigrations;
internal static bool HasPendingMigrations()
{
bool result = true;
if (_hasPendingMigrations == null)
{
try
{
var migrator = new DbSeedingMigrator<SmartObjectContext>();
result = migrator.GetPendingMigrations().Any();
if (result == false)
{
// Don't check again
_hasPendingMigrations = false;
}
}
catch { }
}
else
{
result = _hasPendingMigrations.Value;
}
return result;
}
}
}