-
-
Notifications
You must be signed in to change notification settings - Fork 777
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
Open
dimarobert
wants to merge
6
commits into
dnnsoftware:develop
Choose a base branch
from
dimarobert:async-mvc-actions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+705
−226
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
868b8f6
Support for async execution of MVC Controller Actions.
dimarobert 103fee6
Better separate Async and non-async module hosts.
dimarobert 165cb2f
MVC: Improve error messages when view template is not found by writin…
dimarobert cee5c2a
NullReferenceException fixes.
dimarobert 6adcc6b
Throw if ModuleActions is accessed to early.
dimarobert dea3a25
Async execution of ModuleActionItemsAttribute ActionFilterAttribute.
dimarobert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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; | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
DNN Platform/DotNetNuke.Web.Mvc/AsyncMvcSettingsControl.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.