Skip to content

Commit 1f792d9

Browse files
committed
* More provider cleanup
* Added DependentWidgetsAttribute
1 parent 700ad0f commit 1f792d9

30 files changed

Lines changed: 244 additions & 556 deletions

src/Libraries/SmartStore.Core/Plugins/PluginDescriptor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ public bool IsInKnownGroup
160160
[DataMember]
161161
public bool Installed { get; set; }
162162

163+
/// <summary>
164+
/// Gets or sets the value indicating whether the plugin is configurable
165+
/// </summary>
166+
/// <remarks>
167+
/// A plugin is configurable when it implements the <see cref="IConfigurable"/> interface
168+
/// </remarks>
169+
[DataMember]
170+
public bool IsConfigurable { get; set; }
171+
163172
/// <summary>
164173
/// Gets or sets the root key of string resources.
165174
/// </summary>

src/Libraries/SmartStore.Core/Plugins/PluginManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ private static LoadPluginResult LoadPluginFromFolder(string pluginFolderPath, IL
282282
if (typeof(IPlugin).IsAssignableFrom(t) && !t.IsInterface && t.IsClass && !t.IsAbstract)
283283
{
284284
descriptor.PluginType = t;
285+
descriptor.IsConfigurable = typeof(IConfigurable).IsAssignableFrom(t);
285286
pluginFound = true;
286287
}
287288
else if (descriptor.Installed && typeof(IPreApplicationStart).IsAssignableFrom(t) && !t.IsInterface && t.IsClass && !t.IsAbstract && t.HasDefaultConstructor())
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SmartStore.Core.Plugins
8+
{
9+
/// <summary>
10+
/// Enables provider developers to specify one or many widgets, which
11+
/// should automatically get (de)activated when the provider gets (de)activated.
12+
/// Useful in scenarios where separate widgets are responsible for the displaying of provider data.
13+
/// </summary>
14+
/// <remarks>
15+
/// A widget should definitely NOT depend on multiple providers as the activation
16+
/// only occurs on a single item base.
17+
/// </remarks>
18+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
19+
public class DependentWidgetsAttribute : Attribute
20+
{
21+
public DependentWidgetsAttribute(params string[] widgetSystemNames)
22+
{
23+
WidgetSystemNames = widgetSystemNames;
24+
}
25+
26+
public string[] WidgetSystemNames { get; private set; }
27+
}
28+
}

src/Libraries/SmartStore.Core/Plugins/Providers/IProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public bool IsValueCreated
3535
get { return _lazy.IsValueCreated; }
3636
}
3737

38+
public Lazy<TProvider, ProviderMetadata> ToLazy()
39+
{
40+
return _lazy;
41+
}
42+
3843
public override string ToString()
3944
{
4045
return _lazy.Metadata.SystemName;

src/Libraries/SmartStore.Core/Plugins/Providers/ProviderMetadata.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public class ProviderMetadata
6767
/// </remarks>
6868
public bool IsEditable { get; set; }
6969

70+
/// <summary>
71+
/// Gets or sets an array of widget system names, which depend on the current provider
72+
/// </summary>
73+
/// <remarks>
74+
/// Dependent widgets get automatically (de)activated when their parent providers get (de)activated
75+
/// </remarks>
76+
public string[] DependentWidgets { get; set; }
77+
7078
/// <summary>
7179
/// Gets or sets the <see cref="PluginDescriptor"/> instance in which the provider is implemented
7280
/// </summary>

src/Libraries/SmartStore.Core/SmartStore.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<Compile Include="Collections\QuerystringBuilder.cs" />
154154
<Compile Include="IActivatable.cs" />
155155
<Compile Include="Plugins\IConfigurable.cs" />
156+
<Compile Include="Plugins\Providers\DependentWidgetsAttribute.cs" />
156157
<Compile Include="Plugins\Providers\DisplayOrderAttribute.cs" />
157158
<Compile Include="Plugins\Providers\IUserEditable.cs" />
158159
<Compile Include="Plugins\Providers\IProvider.cs" />

src/Libraries/SmartStore.Data/Migrations/201406262150229_Providers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
138138
builder.AddOrUpdate("Common.SystemName").Value("System name").Value("de", "Systemname");
139139
builder.AddOrUpdate("Common.DisplayOrder").Value("Display order").Value("de", "Reihenfolge");
140140
builder.AddOrUpdate("Admin.Common.Deactivate").Value("Deactivate").Value("de", "Deaktivieren");
141+
builder.Delete("Admin.Configuration.Plugins.Fields.IsEnabled");
141142

142143
// Tax providers
143144
string prefix = "Admin.Configuration.Tax.Providers.";

src/Libraries/SmartStore.Services/Cms/WidgetExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ public static class WidgetExtensions
1010
public static bool IsWidgetActive(this Provider<IWidget> widget, WidgetSettings widgetSettings)
1111
{
1212
Guard.ArgumentNotNull(() => widget);
13+
14+
return widget.ToLazy().IsWidgetActive(widgetSettings);
15+
}
16+
17+
public static bool IsWidgetActive(this Lazy<IWidget, ProviderMetadata> widget, WidgetSettings widgetSettings)
18+
{
19+
Guard.ArgumentNotNull(() => widget);
1320
Guard.ArgumentNotNull(() => widgetSettings);
1421

1522
if (widgetSettings.ActiveWidgetSystemNames == null)
@@ -18,6 +25,6 @@ public static bool IsWidgetActive(this Provider<IWidget> widget, WidgetSettings
1825
}
1926

2027
return widgetSettings.ActiveWidgetSystemNames.Contains(widget.Metadata.SystemName, StringComparer.OrdinalIgnoreCase);
21-
}
28+
}
2229
}
2330
}

src/Libraries/SmartStore.Services/Configuration/SettingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public virtual Setting GetSettingById(int settingId)
234234
var settingsByKey = settings[key];
235235
var setting = settingsByKey.FirstOrDefault(x => x.StoreId == storeId);
236236

237-
//load shared value?
237+
// load shared value?
238238
if (setting == null && storeId > 0 && loadSharedValueIfNotFound)
239239
setting = settingsByKey.FirstOrDefault(x => x.StoreId == 0);
240240

src/Libraries/SmartStore.Services/Payments/PaymentExtentions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public static class PaymentExtentions
1616
/// <param name="paymentMethod">Payment method</param>
1717
/// <param name="paymentSettings">Payment settings</param>
1818
/// <returns>Result</returns>
19-
public static bool IsPaymentMethodActive(
20-
this Provider<IPaymentMethod> paymentMethod,
21-
PaymentSettings paymentSettings)
19+
public static bool IsPaymentMethodActive(this Provider<IPaymentMethod> paymentMethod, PaymentSettings paymentSettings)
2220
{
2321
if (paymentMethod == null)
2422
throw new ArgumentNullException("paymentMethod");

0 commit comments

Comments
 (0)