Skip to content

Commit 1aeb201

Browse files
committed
Lots of controller refactoring (reduce redundancy, perf etc.)
1 parent 4b4e10e commit 1aeb201

82 files changed

Lines changed: 561 additions & 739 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
* _Repliable_ Emails now have customer's email as ReplyTo address
5252
* #140 Import all plugin resources after adding a language
5353
* #45 Smarter logging. Save same log notifications only once including its frequency.
54-
* jQuery Mobile is updated to 1.3.2
54+
* Updated jQuery Mobile to version 1.3.2
55+
* Updated TinyMCE html editor to version 4
5556
* Mobile: Only the first product pictures is now displayed in the product-detail-view the others are available by navigation or swiping
5657
* Mobile: Shop logo is now displayed at the top of the mobile page
5758
* Mobile: legal hints are shown in the footer

src/Libraries/SmartStore.Core/Infrastructure/DependencyManagement/AutofacLifetimeScopeProvider.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ public ILifetimeScope ApplicationContainer
3333

3434
public void EndLifetimeScope()
3535
{
36-
ILifetimeScope lifetimeScope = LifetimeScope;
37-
if (lifetimeScope != null)
36+
try
3837
{
39-
lifetimeScope.Dispose();
38+
ILifetimeScope lifetimeScope = LifetimeScope;
39+
if (lifetimeScope != null)
40+
{
41+
lifetimeScope.Dispose();
42+
}
4043
}
44+
catch { }
4145
}
4246

4347
public ILifetimeScope GetLifetimeScope(Action<ContainerBuilder> configurationAction)

src/Libraries/SmartStore.Services/CommonServices.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class CommonServices : ICommonServices
1919
private readonly Lazy<IWorkContext> _workContext;
2020
private readonly Lazy<IEventPublisher> _eventPublisher;
2121
private readonly Lazy<ILocalizationService> _localization;
22-
private readonly Lazy<ILogger> _logger;
2322
private readonly Lazy<ICustomerActivityService> _customerActivity;
2423

2524
public CommonServices(
@@ -30,7 +29,6 @@ public CommonServices(
3029
Lazy<IWorkContext> workContext,
3130
Lazy<IEventPublisher> eventPublisher,
3231
Lazy<ILocalizationService> localization,
33-
Lazy<ILogger> logger,
3432
Lazy<ICustomerActivityService> customerActivity)
3533
{
3634
this._cache = cache("static");
@@ -40,7 +38,6 @@ public CommonServices(
4038
this._workContext = workContext;
4139
this._eventPublisher = eventPublisher;
4240
this._localization = localization;
43-
this._logger = logger;
4441
this._customerActivity = customerActivity;
4542
}
4643

@@ -100,14 +97,6 @@ public ILocalizationService Localization
10097
}
10198
}
10299

103-
public ILogger Logger
104-
{
105-
get
106-
{
107-
return _logger.Value;
108-
}
109-
}
110-
111100
public ICustomerActivityService CustomerActivity
112101
{
113102
get

src/Libraries/SmartStore.Services/ICommonServices.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ ILocalizationService Localization
4848
get;
4949
}
5050

51-
ILogger Logger
52-
{
53-
get;
54-
}
55-
5651
ICustomerActivityService CustomerActivity
5752
{
5853
get;

src/Plugins/Api.WebApi/Controllers/WebApiController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private bool HasPermission(bool notify = true)
4444
bool hasPermission = _permissionService.Authorize(WebApiPermissionProvider.ManageWebApi);
4545

4646
if (notify && !hasPermission)
47-
this.AddNotificationMessage(NotifyType.Error, _localizationService.GetResource("Admin.AccessDenied.Description"), true);
47+
this.Notify(NotifyType.Error, _localizationService.GetResource("Admin.AccessDenied.Description"), true);
4848

4949
return hasPermission;
5050
}

src/Plugins/Feed.Froogle/Controllers/FeedFroogleController.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ namespace SmartStore.Plugin.Feed.Froogle.Controllers
1414
public class FeedFroogleController : PluginControllerBase
1515
{
1616
private readonly IGoogleService _googleService;
17-
private readonly ILogger _logger;
1817
private readonly ISettingService _settingService;
1918

2019
public FeedFroogleController(
2120
IGoogleService googleService,
22-
ILogger logger,
2321
ISettingService settingService)
2422
{
2523
this._googleService = googleService;
26-
this._logger = logger;
2724
this._settingService = settingService;
2825
}
2926

@@ -50,7 +47,7 @@ public ActionResult Configure(FeedFroogleModel model)
5047

5148
_googleService.Helper.ScheduleTaskUpdate(model.TaskEnabled, model.GenerateStaticFileEachMinutes * 60);
5249

53-
SuccessNotification(_googleService.Helper.Resource("ConfigSaveNote"), true);
50+
NotifySuccess(_googleService.Helper.Resource("ConfigSaveNote"), true);
5451

5552
_googleService.SetupModel(model);
5653

@@ -72,8 +69,7 @@ public ActionResult GenerateFeed(FeedFroogleModel model)
7269
}
7370
catch (Exception exc)
7471
{
75-
ErrorNotification(exc.Message, true);
76-
_logger.Error(exc.Message, exc);
72+
NotifyError(exc.Message, true);
7773
}
7874

7975
_googleService.SetupModel(model, _googleService.Helper.ScheduledTask);

src/Plugins/Payments.PayPalStandard/Controllers/PaymentPayPalStandardController.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class PaymentPayPalStandardController : PaymentControllerBase
2727
private readonly IOrderProcessingService _orderProcessingService;
2828
private readonly IStoreContext _storeContext;
2929
private readonly IWorkContext _workContext;
30-
private readonly ILogger _logger;
3130
private readonly IWebHelper _webHelper;
3231
private readonly PayPalStandardPaymentSettings _paypalStandardPaymentSettings;
3332
private readonly PaymentSettings _paymentSettings;
@@ -37,7 +36,7 @@ public PaymentPayPalStandardController(ISettingService settingService,
3736
IOrderProcessingService orderProcessingService,
3837
IStoreContext storeContext,
3938
IWorkContext workContext,
40-
ILogger logger, IWebHelper webHelper,
39+
IWebHelper webHelper,
4140
PayPalStandardPaymentSettings paypalStandardPaymentSettings,
4241
PaymentSettings paymentSettings)
4342
{
@@ -47,7 +46,6 @@ public PaymentPayPalStandardController(ISettingService settingService,
4746
this._orderProcessingService = orderProcessingService;
4847
this._storeContext = storeContext;
4948
this._workContext = workContext;
50-
this._logger = logger;
5149
this._webHelper = webHelper;
5250
this._paypalStandardPaymentSettings = paypalStandardPaymentSettings;
5351
this._paymentSettings = paymentSettings;
@@ -147,7 +145,7 @@ public ActionResult PDTHandler(FormCollection form)
147145
}
148146
catch (Exception exc)
149147
{
150-
_logger.Error(_helper.Resource("FailedGetGross"), exc);
148+
Logger.Error(_helper.Resource("FailedGetGross"), exc);
151149
}
152150

153151
string payer_status = string.Empty;
@@ -186,7 +184,7 @@ public ActionResult PDTHandler(FormCollection form)
186184
//validate order total
187185
if (_paypalStandardPaymentSettings.PdtValidateOrderTotal && !Math.Round(total, 2).Equals(Math.Round(order.OrderTotal, 2)))
188186
{
189-
_logger.Error(_helper.Resource("UnequalTotalOrder").FormatWith(total, order.OrderTotal));
187+
Logger.Error(_helper.Resource("UnequalTotalOrder").FormatWith(total, order.OrderTotal));
190188

191189
return RedirectToAction("Index", "Home", new { area = "" });
192190
}
@@ -338,11 +336,11 @@ public ActionResult IPNHandler()
338336
}
339337

340338
//this.OrderService.InsertOrderNote(newOrder.OrderId, sb.ToString(), DateTime.UtcNow);
341-
_logger.Information(_helper.Resource("IpnLogInfo"), new SmartException(sb.ToString()));
339+
Logger.Information(_helper.Resource("IpnLogInfo"), new SmartException(sb.ToString()));
342340
}
343341
else
344342
{
345-
_logger.Error(_helper.Resource("IpnOrderNotFound"), new SmartException(sb.ToString()));
343+
Logger.Error(_helper.Resource("IpnOrderNotFound"), new SmartException(sb.ToString()));
346344
}
347345
}
348346
#endregion
@@ -416,7 +414,7 @@ public ActionResult IPNHandler()
416414
}
417415
else
418416
{
419-
_logger.Error(_helper.Resource("IpnOrderNotFound"), new SmartException(sb.ToString()));
417+
Logger.Error(_helper.Resource("IpnOrderNotFound"), new SmartException(sb.ToString()));
420418
}
421419
}
422420
#endregion
@@ -425,7 +423,7 @@ public ActionResult IPNHandler()
425423
}
426424
else
427425
{
428-
_logger.Error(_helper.Resource("IpnFailed"), new SmartException(strRequest));
426+
Logger.Error(_helper.Resource("IpnFailed"), new SmartException(strRequest));
429427
}
430428

431429
//nothing should be rendered to visitor

src/Plugins/Widgets.GoogleAnalytics/Controllers/WidgetsGoogleAnalyticsController.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,26 @@
1818

1919
namespace SmartStore.Plugin.Widgets.GoogleAnalytics.Controllers
2020
{
21-
//[UnitOfWork]
22-
public class WidgetsGoogleAnalyticsController : Controller
21+
22+
public class WidgetsGoogleAnalyticsController : SmartController
2323
{
2424
private readonly IWorkContext _workContext;
2525
private readonly IStoreContext _storeContext;
2626
private readonly IStoreService _storeService;
2727
private readonly ISettingService _settingService;
2828
private readonly IOrderService _orderService;
29-
private readonly ILogger _logger;
3029
private readonly ICategoryService _categoryService;
3130

3231
public WidgetsGoogleAnalyticsController(IWorkContext workContext,
3332
IStoreContext storeContext, IStoreService storeService,
34-
ISettingService settingService, IOrderService orderService, ILogger logger,
33+
ISettingService settingService, IOrderService orderService,
3534
ICategoryService categoryService)
3635
{
3736
this._workContext = workContext;
3837
this._storeContext = storeContext;
3938
this._storeService = storeService;
4039
this._settingService = settingService;
4140
this._orderService = orderService;
42-
this._logger = logger;
4341
this._categoryService = categoryService;
4442
}
4543

@@ -114,7 +112,7 @@ public ActionResult PublicInfo(string widgetZone)
114112
}
115113
catch (Exception ex)
116114
{
117-
_logger.InsertLog(SmartStore.Core.Domain.Logging.LogLevel.Error, "Error creating scripts for google ecommerce tracking", ex.ToString());
115+
Logger.InsertLog(SmartStore.Core.Domain.Logging.LogLevel.Error, "Error creating scripts for google ecommerce tracking", ex.ToString());
118116
}
119117
return Content(globalScript);
120118
//return View("SmartStore.Plugin.Widgets.GoogleAnalytics.Views.WidgetsGoogleAnalytics.PublicInfo", model);

src/Plugins/Widgets.TrustedShopsSeal/Controllers/TrustedShopsSealController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace SmartStore.Plugin.Widgets.TrustedShopsSeal.Controllers
1313
{
1414

15-
public class TrustedShopsSealController : Controller
15+
public class TrustedShopsSealController : SmartController
1616
{
1717
private readonly IWorkContext _workContext;
1818
private readonly IStoreContext _storeContext;
@@ -103,9 +103,9 @@ public ActionResult Configure(ConfigurationModel model, FormCollection form)
103103
isTrustedShopIdValid = IsTrustedShopIdValid(model);
104104

105105
if (isTrustedShopIdValid)
106-
this.AddNotificationMessage(NotifyType.Success, _localizationService.GetResource("Plugins.Widgets.TrustedShopsSeal.CheckIdSuccess"), true);
106+
NotifySuccess(_localizationService.GetResource("Plugins.Widgets.TrustedShopsSeal.CheckIdSuccess"), true);
107107
else
108-
this.AddNotificationMessage(NotifyType.Error, _localizationService.GetResource("Plugins.Widgets.TrustedShopsSeal.CheckIdError"), true);
108+
NotifyError(_localizationService.GetResource("Plugins.Widgets.TrustedShopsSeal.CheckIdError"), true);
109109
}
110110

111111
if (isTrustedShopIdValid) //save settings

src/Presentation/SmartStore.Web.Framework/Controllers/ContollerExtensions.cs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using SmartStore.Services.Common;
77
using SmartStore.Core;
88
using SmartStore.Core.Domain.Customers;
9+
using SmartStore.Collections;
910

1011
namespace SmartStore.Web.Framework.Controllers
1112
{
@@ -61,36 +62,60 @@ public static string RenderPartialViewToString(this Controller controller, strin
6162
}
6263
}
6364

65+
///// <summary>
66+
///// Pushes a message to the notification queue
67+
///// </summary>
68+
///// <param name="type">Notification type</param>
69+
///// <param name="message">Message</param>
70+
///// <param name="durable">A value indicating whether a message should be persisted for the next request</param>
71+
//public static void Notify(this ControllerBase controller, NotifyType type, string message, bool durable)
72+
//{
73+
// if (message.IsEmpty())
74+
// return;
75+
76+
// var storage = (durable ? (IDictionary<string, object>)controller.TempData : (IDictionary<string, object>)controller.ViewData);
77+
78+
// ICollection<string> messages = null;
79+
// string key = string.Format("sm.notifications.{0}", type);
80+
81+
// if (!storage.ContainsKey(key))
82+
// {
83+
// storage[key] = new HashSet<string>();
84+
// }
85+
86+
// messages = storage[key] as ICollection<string>;
87+
88+
// if (messages != null)
89+
// {
90+
// messages.Add(message);
91+
// }
92+
//}
93+
6494
/// <summary>
65-
/// Display notification
95+
/// Pushes a message to the notification queue
6696
/// </summary>
67-
/// <remarks>codehint: sm-add</remarks>
6897
/// <param name="type">Notification type</param>
6998
/// <param name="message">Message</param>
70-
/// <param name="persistForTheNextRequest">A value indicating whether a message should be persisted for the next request</param>
71-
public static void AddNotificationMessage(this ControllerBase controller, NotifyType type, string message, bool persistForTheNextRequest)
99+
/// <param name="durable">A value indicating whether a message should be persisted for the next request</param>
100+
public static void Notify(this ControllerBase controller, NotifyType type, string message, bool durable)
72101
{
73-
if (message.IsNullOrEmpty())
102+
if (message.IsEmpty())
74103
return;
75104

76-
List<string> lst = null;
77-
string dataKey = string.Format("sm.notifications.{0}", type);
105+
var storage = (durable ? (IDictionary<string, object>)controller.TempData : (IDictionary<string, object>)controller.ViewData);
106+
107+
Multimap<NotifyType, string> messages = null;
108+
string key = "sm.notifications.all";
78109

79-
if (persistForTheNextRequest)
110+
if (!storage.ContainsKey(key))
80111
{
81-
if (controller.TempData[dataKey] == null)
82-
controller.TempData[dataKey] = new List<string>();
83-
lst = (List<string>)controller.TempData[dataKey];
112+
storage[key] = messages = new Multimap<NotifyType, string>();
84113
}
85-
else
114+
115+
if (messages != null && !messages.ContainsValue(type, message))
86116
{
87-
if (controller.ViewData[dataKey] == null)
88-
controller.ViewData[dataKey] = new List<string>();
89-
lst = (List<string>)controller.ViewData[dataKey];
117+
messages.Add(type, message);
90118
}
91-
92-
if (lst != null && !lst.Exists(m => m == message))
93-
lst.Add(message);
94119
}
95120

96121
/// <summary>

0 commit comments

Comments
 (0)