-
-
Notifications
You must be signed in to change notification settings - Fork 774
Async support for MVC controllers. #7193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 4 commits
d12c894
3245116
b5e7244
1a091c3
eb6c71f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // 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) | ||
| { | ||
| 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; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // 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.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using DotNetNuke.Entities.Modules; | ||
| using DotNetNuke.UI.Modules; | ||
|
|
||
| public class AsyncMvcSettingsControl : AsyncMvcHostControl, IAsyncSettingsControl | ||
| { | ||
| public AsyncMvcSettingsControl() | ||
| : base("Settings") | ||
| { | ||
| this.ExecuteModuleImmediately = false; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void LoadSettings() | ||
| { | ||
| throw new NotSupportedException("Async controls need to call LoadSettingsAsync."); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Task LoadSettingsAsync(CancellationToken cancellationToken) | ||
| { | ||
| return this.ExecuteModuleAsync(cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void UpdateSettings() | ||
| { | ||
| throw new NotSupportedException("Async controls need to call UpdateSettingsAsync."); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async Task UpdateSettingsAsync(CancellationToken cancellationToken) | ||
| { | ||
| await this.ExecuteModuleAsync(cancellationToken); | ||
|
|
||
| ModuleController.Instance.UpdateModule(this.ModuleContext.Configuration); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| namespace DotNetNuke.Web.Mvc.Framework.Controllers | ||
| { | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Threading.Tasks; | ||
| using System.Web.Mvc; | ||
| using System.Web.UI; | ||
|
|
||
|
|
@@ -24,6 +25,10 @@ public interface IDnnController : IController | |
|
|
||
| ModuleActionCollection ModuleActions { get; set; } | ||
|
|
||
| Task<ModuleActionCollection> ModuleActionsAsync { get; set; } | ||
|
|
||
| bool IsAsync { get; set; } | ||
|
|
||
|
Comment on lines
+28
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dnnsoftware/approvers do we have concerns about 3rd parties implementing this interface and being broken by this change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, as this will result in a compilation error for any upstream user of IDnnController correct since they don't implement the interface members
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new One difficult situation with this might be the |
||
| ModuleInstanceContext ModuleContext { get; set; } | ||
|
|
||
| bool ValidateRequest { get; set; } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,15 @@ | |
| namespace DotNetNuke.Web.Mvc.Framework.Modules | ||
| { | ||
| using System.IO; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| public interface IModuleExecutionEngine | ||
| { | ||
| ModuleRequestResult ExecuteModule(ModuleRequestContext moduleRequestContext); | ||
|
|
||
| Task<ModuleRequestResult> ExecuteModuleAsync(ModuleRequestContext moduleRequestContext, CancellationToken cancellationToken); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question about modifying interface
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, we could have a separate |
||
|
|
||
| void ExecuteModuleResult(ModuleRequestResult moduleResult, TextWriter writer); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.