Skip to content

Commit 0a69e99

Browse files
committed
on data processed event basic infrastructure added
1 parent e0c77dd commit 0a69e99

File tree

7 files changed

+57
-1
lines changed

7 files changed

+57
-1
lines changed

src/Examples/Examples.Mvc/Controllers/CustomersController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Web.Mvc;
55
using Examples.Data;
66
using Examples.Mvc.ViewModels;
7+
using JQDT.Models;
78
using JQDT.MVC;
89

910
public class CustomersController : Controller
@@ -21,7 +22,7 @@ public ActionResult Index()
2122
return View();
2223
}
2324

24-
[JQDataTable]
25+
[CustomJQDataTable]
2526
public ActionResult GetCustomersData()
2627
{
2728
var data = this.context.Customers.Select(x => new CustomerViewModel
@@ -42,4 +43,14 @@ public ActionResult GetCustomersData()
4243
return this.View(data);
4344
}
4445
}
46+
47+
public class CustomJQDataTableAttribute : JQDataTableAttribute
48+
{
49+
public override void OnDataProcessed(object data, RequestInfoModel requestInfoModel)
50+
{
51+
var processedData = ((IQueryable<CustomerViewModel>)data).Where(x => x.CustomerID > 10 && x.CustomerID < 20);
52+
var list = processedData.ToList();
53+
data = list;
54+
}
55+
}
4556
}

src/Examples/Examples.Mvc/Examples.Mvc.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@
282282
<Project>{d845ab6d-1887-4597-9256-148ad0a11459}</Project>
283283
<Name>JQDT.MVC</Name>
284284
</ProjectReference>
285+
<ProjectReference Include="..\..\JQDT\JQDT.csproj">
286+
<Project>{C82E4675-88AB-4B78-8475-F1521BDAE330}</Project>
287+
<Name>JQDT</Name>
288+
</ProjectReference>
285289
<ProjectReference Include="..\Examples.Data\Examples.Data.csproj">
286290
<Project>{082A75A9-D2AE-4BA6-84EF-606852B1B88A}</Project>
287291
<Name>Examples.Data</Name>

src/JQDT.MVC/JQDataTableAttribute.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,22 @@ public override void OnActionExecuted(ActionExecutedContext filterContext)
3535
}
3636
}
3737

38+
/// <summary>
39+
/// Called when [data processed].
40+
/// </summary>
41+
/// <param name="data">The data.</param>
42+
/// <param name="requestInfoModel">The request information model.</param>
43+
public virtual void OnDataProcessed(object data, RequestInfoModel requestInfoModel)
44+
{
45+
}
46+
3847
private void PerformOnActionExecuted(ActionExecutedContext filterContext)
3948
{
4049
var dataCollectionType = filterContext.Controller.ViewData.Model.GetType();
4150
var dependencyResolver = new DI.DependencyResolver();
4251
var applicationInitizlizationFunction = ExecuteFunctionProvider<ActionExecutedContext>.GetAppInicializationFunc(dataCollectionType, typeof(ApplicationMvc<>));
4352
var mvcApplication = applicationInitizlizationFunction(filterContext, dependencyResolver);
53+
this.SubscribeToEvents(mvcApplication);
4454
var result = (ResultModel)mvcApplication.Execute();
4555

4656
filterContext.Result = this.FormatResult(new
@@ -55,6 +65,11 @@ private void PerformOnActionExecuted(ActionExecutedContext filterContext)
5565
base.OnActionExecuted(filterContext);
5666
}
5767

68+
private void SubscribeToEvents(IApplicationBase application)
69+
{
70+
application.OnDataProcessed += this.OnDataProcessed;
71+
}
72+
5873
private ActionResult FormatResult(object resultModel)
5974
{
6075
var jsonResult = new JsonResult

src/JQDT/Application/ApplicationBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using JQDT.DataProcessing;
8+
using JQDT.Delegates;
89
using JQDT.DI;
910
using JQDT.ModelBinders;
1011
using JQDT.Models;
@@ -27,6 +28,11 @@ public ApplicationBase(IDependencyResolver dependencyResolver)
2728
this.dependencyResolver = dependencyResolver;
2829
}
2930

31+
/// <summary>
32+
/// Occurs when [on data processed].
33+
/// </summary>
34+
public event DataProcessorEventHandler OnDataProcessed;
35+
3036
/// <summary>
3137
/// Application entry point method. Executes all data processors.
3238
/// </summary>
@@ -46,6 +52,8 @@ public ResultModel Execute()
4652
var dataProcessChain = this.GetDataProcessChain(requestModel.Helpers.DataCollectionType);
4753
var processedData = dataProcessChain.ProcessData(data, requestModel);
4854

55+
this.OnDataProcessed(processedData, requestModel);
56+
4957
result.Data = processedData.ToList().Select(x => (object)x).ToList();
5058
result.Draw = requestModel.TableParameters.Draw;
5159
result.RecordsTotal = data.Count();

src/JQDT/Application/IApplicationBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
namespace JQDT.Application
22
{
3+
using JQDT.Delegates;
34
using JQDT.Models;
45

56
/// <summary>
67
/// Base interface for <see cref="ApplicationBase{T}"/>
78
/// </summary>
89
public interface IApplicationBase
910
{
11+
/// <summary>
12+
/// Occurs when [on data processed].
13+
/// </summary>
14+
event DataProcessorEventHandler OnDataProcessed;
15+
1016
/// <summary>
1117
/// Application entry point method. Executes all data processors.
1218
/// </summary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace JQDT.Delegates
2+
{
3+
using JQDT.Models;
4+
5+
/// <summary>
6+
/// Occurs on data process event
7+
/// </summary>
8+
/// <param name="data">The data.</param>
9+
/// <param name="requestInfoModel">The request information model.</param>
10+
public delegate void DataProcessorEventHandler(object data, RequestInfoModel requestInfoModel);
11+
}

src/JQDT/JQDT.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="DataProcessing\IDataProcessChain.cs" />
8181
<Compile Include="DataProcessing\SortDataProcessing\SortDataProcessor.cs" />
8282
<Compile Include="DataProcessing\PagingDataProcessing\PagingDataProcessor.cs" />
83+
<Compile Include="Delegates\DataProcessorEventHandler.cs" />
8384
<Compile Include="DI\DependencyResolver.cs" />
8485
<Compile Include="DI\IDependencyResolver.cs" />
8586
<Compile Include="Enumerations\OperationTypesEnum.cs" />

0 commit comments

Comments
 (0)