Skip to content

Commit

Permalink
Merge from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed Oct 18, 2016
2 parents 847c6d9 + 0c7ce21 commit d55a9bd
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 62 deletions.
5 changes: 5 additions & 0 deletions VirtoCommerce.Platform.Core/Modularity/IModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace VirtoCommerce.Platform.Core.Modularity
/// </summary>
public interface IModule
{
/// <summary>
/// Contain module manifest information
/// </summary>
ManifestModuleInfo ModuleInfo { get; set; }

/// <summary>
/// Allows module to configure database.
/// This method is called before Initialize().
Expand Down
2 changes: 2 additions & 0 deletions VirtoCommerce.Platform.Core/Modularity/ModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public abstract class ModuleBase : IModule
{
public ManifestModuleInfo ModuleInfo { get; set; }

public virtual void SetupDatabase()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria
{
query = query.Where(n => n.ObjectTypeId == criteria.ObjectTypeId);
}

if (criteria.IsActive)
{
query = query.Where(n => n.IsActive && n.SentDate == null && (n.LastFailAttemptDate == null || DbFunctions.AddHours(n.LastFailAttemptDate, criteria.RepeatHoursIntervalForFail) < DateTime.UtcNow));
{
query = query.Where(n => n.IsActive && n.SentDate == null && (n.LastFailAttemptDate == null || DbFunctions.AddHours(n.LastFailAttemptDate, criteria.RepeatHoursIntervalForFail) < DateTime.UtcNow)
&& (n.StartSendingDate == null || n.StartSendingDate < DateTime.UtcNow));
}
retVal.TotalCount = query.Count();
retVal.Notifications = query.OrderBy(n => n.CreatedDate)
Expand Down
22 changes: 22 additions & 0 deletions VirtoCommerce.Platform.Web/App_Start/AiExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.ApplicationInsights;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.ExceptionHandling;

namespace VirtoCommerce.Platform.Web.App_Start
{
public class AiExceptionHandler : ExceptionHandler
{
public override void Handle(ExceptionHandlerContext context)
{
if (context != null && context.Exception != null)
{
var ai = new TelemetryClient();
ai.TrackException(context.Exception);
}
base.Handle(context);
}
}
}
1 change: 1 addition & 0 deletions VirtoCommerce.Platform.Web/App_Start/BundleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static void RegisterBundles(BundleCollection bundles)
var moduleCatalog = ServiceLocator.Current.GetInstance<IModuleCatalog>();
var allModules = moduleCatalog.Modules.OfType<ManifestModuleInfo>().ToArray();
var manifestModules = moduleCatalog.CompleteListWithDependencies(allModules)
.Where(x => x.State == ModuleState.Initialized)
.OfType<ManifestModuleInfo>()
.ToArray();

Expand Down
5 changes: 4 additions & 1 deletion VirtoCommerce.Platform.Web/App_Start/FilterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using System.Web.Mvc;
using VirtoCommerce.Platform.Web.Controllers;

namespace VirtoCommerce.Platform.Web
{
Expand All @@ -10,7 +11,9 @@ public class FilterConfig
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
System.Web.Http.GlobalConfiguration.Configuration.Filters.Add(new ResponseTimeHeaderFilter());
filters.Add(new AiHandleErrorAttribute());

System.Web.Http.GlobalConfiguration.Configuration.Filters.Add(new ResponseTimeHeaderFilter());
}
}
/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion VirtoCommerce.Platform.Web/App_Start/WebApiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Newtonsoft.Json.Serialization;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.Platform.Core.Web.Security;
using System.Web.Http.ExceptionHandling;
using VirtoCommerce.Platform.Web.App_Start;

namespace VirtoCommerce.Platform.Web
{
Expand Down Expand Up @@ -46,6 +48,8 @@ public static void Register(HttpConfiguration config)
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
//config.EnableQuerySupport();
config.AddODataQueryFilter();
}

config.Services.Replace(typeof(IExceptionHandler), new AiExceptionHandler());
}
}
}
50 changes: 50 additions & 0 deletions VirtoCommerce.Platform.Web/Controllers/AiHandleErrorAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.ApplicationInsights;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace VirtoCommerce.Platform.Web.Controllers
{
/// <summary>
/// If the custom errors configuration is Off, then exceptions will be available for the HTTPModule to collect.
/// However, if it is RemoteOnly (default), or On – then the exception will be cleared and not available for us to automatically collect.
/// You can fix that by adding an attribute derived from HandleErrorAttribute and then registering it as global filter as shown below.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class AiHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
{
//If customError is Off, then AI HTTPModule will report the exception
//if (filterContext.HttpContext.IsCustomErrorEnabled)
//{
// Note: A single instance of telemetry client is sufficient to track multiple telemetry items.
var ai = new TelemetryClient();

var properties = new Dictionary<string, string>();
if(filterContext.HttpContext!=null)
FillFormProperties(filterContext.HttpContext.Request, properties);

ai.TrackException(filterContext.Exception, properties);
//}
}
base.OnException(filterContext);
}

private void FillFormProperties(HttpRequestBase request, Dictionary<string, string> dictionary)
{
if (request.Form == null) return;

var items = request.Form.AllKeys.SelectMany(request.Form.GetValues, (k, v) => new { key = k, value = v });
foreach (var item in items)
{
dictionary.Add(item.key, item.value);
}
}

}
}
27 changes: 27 additions & 0 deletions VirtoCommerce.Platform.Web/Modularity/ManifestModuleCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Core.Properties;

Expand Down Expand Up @@ -71,6 +72,32 @@ protected override void InnerLoad()
}
}

public override void Validate()
{

base.Validate();

var modules = Modules.OfType<ManifestModuleInfo>();
//Dependencies and platform version validation
foreach (var module in modules)
{
//Check platform version
if (!module.PlatformVersion.IsCompatibleWith(PlatformVersion.CurrentVersion))
{
module.Errors.Add(string.Format("module platform version {0} is incompatible with current {1}", module.PlatformVersion, PlatformVersion.CurrentVersion));
}

foreach (var declaredDependency in module.Dependencies)
{
var installedDependency = modules.First(x => x.Id.EqualsInvariant(declaredDependency.Id));
if (!declaredDependency.Version.IsCompatibleWithBySemVer(installedDependency.Version))
{
module.Errors.Add(string.Format("module dependency {0} is incompatible with installed {1}", declaredDependency, installedDependency.Version));
}
}
}
}

private IDictionary<string, ModuleManifest> GetModuleManifests()
{
var result = new Dictionary<string, ModuleManifest>();
Expand Down
31 changes: 20 additions & 11 deletions VirtoCommerce.Platform.Web/Modularity/ModuleInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using Common.Logging;
using Microsoft.Practices.ServiceLocation;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Core.Modularity.Exceptions;
using VirtoCommerce.Platform.Core.PushNotifications;
Expand Down Expand Up @@ -56,17 +57,22 @@ public void Initialize(ModuleInfo moduleInfo)
if (moduleInfo == null)
throw new ArgumentNullException("moduleInfo");

try
var manifestModuleInfo = moduleInfo as ManifestModuleInfo;
//Do not initialize modules with errors
if (manifestModuleInfo.Errors.IsNullOrEmpty())
{
var moduleInstance = CreateModule(moduleInfo);
moduleInfo.ModuleInstance = moduleInstance;
moduleInstance.SetupDatabase();
moduleInstance.Initialize();
moduleInfo.State = ModuleState.Initialized;
}
catch (Exception ex)
{
HandleModuleInitializationError(moduleInfo, ex);
try
{
var moduleInstance = CreateModule(moduleInfo);
moduleInfo.ModuleInstance = moduleInstance;
moduleInstance.SetupDatabase();
moduleInstance.Initialize();
moduleInfo.State = ModuleState.Initialized;
}
catch (Exception ex)
{
HandleModuleInitializationError(moduleInfo, ex);
}
}
}

Expand Down Expand Up @@ -139,7 +145,10 @@ protected virtual IModule CreateModule(ModuleInfo moduleInfo)
{
if (moduleInfo == null)
throw new ArgumentNullException("moduleInfo");
return CreateModule(moduleInfo.ModuleType);
var result = CreateModule(moduleInfo.ModuleType);

result.ModuleInfo = moduleInfo as ManifestModuleInfo;
return result;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ angular.module('platformWebApp')
var blade = $('.blade:last', mainContent);
var offset = parseInt(blade.offset().left);

$timeout(function () {
offset = parseInt(blade.width())
}, 50, false);

if (!scope.blade.disableOpenAnimation) {
blade.css('margin-left', '-' + blade.width() + 'px').addClass('__animate');

Expand All @@ -67,9 +63,8 @@ angular.module('platformWebApp')
}

$timeout(function () {
if (offset > mainContent.scrollLeft()) {
mainContent.animate({ scrollLeft: offset + 'px' }, 500);
}
var scrollAdjustment = (offset >= mainContent.scrollLeft()) ? blade.width() : mainContent.scrollLeft();
mainContent.animate({ scrollLeft: offset + scrollAdjustment + 'px' }, 500);
}, 0, false);

scope.bladeMaximize = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
var currentEntities;

blade.refresh = function (parentRefresh) {
if (blade.isApiSave) {
settings.get({ id: blade.currentEntityId }, function (setting) {
if (parentRefresh && blade.parentRefresh) {
blade.parentRefresh(setting.arrayValues);
}

setting.arrayValues = _.map(setting.arrayValues, function (x) { return { value: x }; });
blade.origEntity = angular.copy(setting.arrayValues);
initializeBlade(setting);
},
function (error) { bladeNavigationService.setError('Error ' + error.status, blade); });
}
settings.get({ id: blade.currentEntityId }, function (setting) {
if (parentRefresh && blade.parentRefresh) {
blade.parentRefresh(setting.arrayValues);
}

setting.arrayValues = _.map(setting.arrayValues, function (x) { return { value: x }; });
blade.origEntity = angular.copy(setting.arrayValues);
initializeBlade(setting);
});
}

function initializeBlade(data) {
Expand Down Expand Up @@ -107,6 +104,14 @@
},
canExecuteMethod: isDirty,
});
blade.refresh();
} else {
$scope.$watch('blade.parentBlade.currentEntities', function (data) {
if (data) {
var allEntities = _.flatten(_.map(data, _.values));
initializeBlade(_.findWhere(allEntities, { name: blade.currentEntityId }));
}
});
}

$scope.checkAll = function () {
Expand All @@ -124,30 +129,22 @@
}

function deleteChecked() {
var dialog = {
id: "confirmDeleteItem",
title: "platform.dialogs.settings-value-delete.title",
message: "platform.dialogs.settings-value-delete.message",
callback: function (remove) {
if (remove) {
var selection = _.where(currentEntities, { _selected: true });
angular.forEach(selection, function (listItem) {
$scope.delete(currentEntities.indexOf(listItem));
});
}
}
}
dialogService.showConfirmationDialog(dialog);
//var dialog = {
// id: "confirmDeleteItem",
// title: "platform.dialogs.settings-value-delete.title",
// message: "platform.dialogs.settings-value-delete.message",
// callback: function (remove) {
// if (remove) {
var selection = _.where(currentEntities, { _selected: true });
angular.forEach(selection, function (listItem) {
$scope.delete(currentEntities.indexOf(listItem));
});
// }
// }
//}
//dialogService.showConfirmationDialog(dialog);
}

$scope.$watch('blade.parentBlade.currentEntities', function (data) {
if (data) {
var allEntities = _.flatten(_.map(data, _.values));
initializeBlade(_.findWhere(allEntities, { name: blade.currentEntityId }));
}
});

// on load
resetNewValue();
blade.refresh();
}]);
Loading

0 comments on commit d55a9bd

Please sign in to comment.