-
-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathAsyncMvcHostControl.cs
More file actions
86 lines (73 loc) · 2.79 KB
/
AsyncMvcHostControl.cs
File metadata and controls
86 lines (73 loc) · 2.79 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Web.Mvc
{
using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.UI.Modules;
using DotNetNuke.Web.Mvc.Routing;
public class AsyncMvcHostControl : MvcHostControl, IAsyncModuleControl
{
public AsyncMvcHostControl()
: base()
{
}
public AsyncMvcHostControl(string controlKey)
: base(controlKey)
{
}
protected override void OnInitInternal(EventArgs e)
{
if (this.ExecuteModuleImmediately)
{
this.Page.RegisterAsyncTask(new PageAsyncTask(this.ExecuteModuleAsync));
}
}
protected override void OnPreRenderInternal(EventArgs e)
{
// We need to defer execution to after the async task registered in OnInitInternal above, which will only get executed at the WebForms async point, just before PreRenderComplete.
this.Page.RegisterAsyncTask(new PageAsyncTask(this.OnPreRenderAsync));
}
protected async Task ExecuteModuleAsync(CancellationToken cancellationToken)
{
try
{
HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
var moduleExecutionEngine = GetModuleExecutionEngine();
this.Result = await moduleExecutionEngine.ExecuteModuleAsync(this.GetModuleRequestContext(httpContext), cancellationToken);
this.ModuleActions = this.LoadActions(this.Result);
httpContext.SetModuleRequestResult(this.Result);
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private Task OnPreRenderAsync(CancellationToken cancellationToken)
{
try
{
if (this.Result == null)
{
return Task.CompletedTask;
}
var mvcString = RenderModule(this.Result);
if (!string.IsNullOrEmpty(Convert.ToString(mvcString, CultureInfo.InvariantCulture)))
{
this.Controls.Add(new LiteralControl(Convert.ToString(mvcString, CultureInfo.InvariantCulture)));
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
return Task.CompletedTask;
}
}
}