Skip to content

Commit

Permalink
Allowing async drivers (#1084)
Browse files Browse the repository at this point in the history
* Allowing async drivers

* New.Foo() is async

* Fixing unit tests

* Removing Task.Run

* count() to count
  • Loading branch information
sebastienros authored and Jetski5822 committed Oct 12, 2017
1 parent b14174c commit fc23bfc
Show file tree
Hide file tree
Showing 93 changed files with 531 additions and 454 deletions.
17 changes: 10 additions & 7 deletions src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using OrchardCore.DisplayManagement;
Expand All @@ -6,7 +7,7 @@

namespace OrchardCore.Admin
{
public class AdminMenuFilter : IResultFilter
public class AdminMenuFilter : IAsyncResultFilter
{
private readonly INavigationManager _navigationManager;
private readonly ILayoutAccessor _layoutAccessor;
Expand All @@ -22,40 +23,42 @@ public class AdminMenuFilter : IResultFilter
_shapeFactory = shapeFactory;
}

public void OnResultExecuting(ResultExecutingContext filterContext)
public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next)
{
// Should only run on a full view rendering result
if (!(filterContext.Result is ViewResult))
{
await next();
return;
}

// Should only run on the Admin
if (!AdminAttribute.IsApplied(filterContext.HttpContext))
{
await next();
return;
}

// Don't create the menu if the status code is 3xx
var statusCode = filterContext.HttpContext.Response.StatusCode;
if (statusCode >= 300 && statusCode < 400)
{
await next();
return;
}

// Populate main nav
IShape menuShape = _shapeFactory.Create("Navigation",
IShape menuShape = await _shapeFactory.CreateAsync("Navigation",
Arguments.From(new
{
MenuName = "admin",
RouteData = filterContext.RouteData,
}));

_layoutAccessor.GetLayout().Navigation.Add(menuShape);
}
dynamic layout = await _layoutAccessor.GetLayoutAsync();
layout.Navigation.Add(menuShape);

public void OnResultExecuted(ResultExecutedContext filterContext)
{
await next();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Metadata;
Expand Down Expand Up @@ -42,15 +42,13 @@ public AliasPartSettings GetAliasPartSettings(AliasPart part)
return settings;
}

private Task BuildViewModel(AliasPartViewModel model, AliasPart part)
private void BuildViewModel(AliasPartViewModel model, AliasPart part)
{
var settings = GetAliasPartSettings(part);

model.Alias = part.Alias;
model.AliasPart = part;
model.Settings = settings;

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDef
model.Pattern = settings.Pattern;
model.AliasPartSettings = settings;
return Task.CompletedTask;
}).Location("Content");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDef
model.Pattern = settings.Pattern;
model.ShowHomepageOption = settings.ShowHomepageOption;
model.AutoroutePartSettings = settings;
return Task.CompletedTask;
}).Location("Content");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDef
model.Editor = settings.Editor;
model.BodyPartSettings = settings;
return Task.CompletedTask;
}).Location("Content");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<select asp-for="Editor" class="form-control">
@foreach (var bodyEditorShape in bodyEditorShapes)
{
dynamic shape = Factory.Create(bodyEditorShape);
dynamic shape = await Factory.CreateAsync(bodyEditorShape);
shape.Editor = Model.Editor;
@await DisplayAsync(shape)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
@if (!Context.Items.ContainsKey("Media_Modal__Body"))
{
Context.Items["Media_Modal__Body"] = new object();
@await DisplayAsync(New.Media_Modal__Body())
@await DisplayAsync(await New.Media_Modal__Body())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model OrchardCore.ContentFields.Settings.BooleanFieldSettings
@model OrchardCore.ContentFields.Settings.BooleanFieldSettings


@inject OrchardCore.DisplayManagement.Theming.IThemeManager ThemeManager
Expand All @@ -24,7 +24,7 @@
<select asp-for="Editor" class="form-control">
@foreach (var editorShape in editorShapes)
{
dynamic shape = Factory.Create(editorShape);
dynamic shape = await Factory.CreateAsync(editorShape);
shape.Editor = Model.Editor;
@await DisplayAsync(shape)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<select asp-for="Editor" class="form-control">
@foreach (var editorShape in editorShapes)
{
dynamic shape = Factory.Create(editorShape);
dynamic shape = await Factory.CreateAsync(editorShape);
shape.Editor = Model.Editor;
@await DisplayAsync(shape)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model OrchardCore.ContentFields.Settings.NumericFieldSettings
@model OrchardCore.ContentFields.Settings.NumericFieldSettings
@using System.Globalization

@inject OrchardCore.DisplayManagement.Theming.IThemeManager ThemeManager
Expand Down Expand Up @@ -29,7 +29,7 @@
<select asp-for="Editor" class="form-control">
@foreach (var editorShape in editorShapes)
{
dynamic shape = Factory.Create(editorShape);
dynamic shape = await Factory.CreateAsync(editorShape);
shape.Editor = Model.Editor;
@await DisplayAsync(shape)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<select asp-for="Editor" class="form-control">
@foreach (var editorShape in editorShapes)
{
dynamic shape = Factory.Create(editorShape);
dynamic shape = await Factory.CreateAsync(editorShape);
shape.Editor = Model.Editor;
@await DisplayAsync(shape)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Modules;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -36,7 +36,7 @@ public Task BuildTypeEditorAsync(ContentTypeDefinition model, BuildEditorContext
{
var result = await contentDisplay.BuildEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -46,7 +46,7 @@ public Task UpdateTypeEditorAsync(ContentTypeDefinition model, UpdateTypeEditorC
{
var result = await contentDisplay.UpdateEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -56,7 +56,7 @@ public Task BuildTypePartEditorAsync(ContentTypePartDefinition model, BuildEdito
{
var result = await contentDisplay.BuildEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -66,7 +66,7 @@ public Task UpdateTypePartEditorAsync(ContentTypePartDefinition model, UpdateTyp
{
var result = await contentDisplay.UpdateEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -76,7 +76,7 @@ public Task BuildPartEditorAsync(ContentPartDefinition model, BuildEditorContext
{
var result = await contentDisplay.BuildEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -86,7 +86,7 @@ public Task UpdatePartEditorAsync(ContentPartDefinition model, UpdatePartEditorC
{
var result = await contentDisplay.UpdateEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -96,7 +96,7 @@ public Task BuildPartFieldEditorAsync(ContentPartFieldDefinition model, BuildEdi
{
var result = await contentDisplay.BuildEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}

Expand All @@ -106,7 +106,7 @@ public Task UpdatePartFieldEditorAsync(ContentPartFieldDefinition model, UpdateP
{
var result = await contentDisplay.UpdateEditorAsync(model, context);
if (result != null)
result.Apply(context);
await result.ApplyAsync(context);
}, Logger);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public override IDisplayResult Edit(ContentPartDefinition contentPartDefinition)
model.Description = settings.Description;
model.DisplayName = settings.DisplayName;
model.ContentPartDefinition = contentPartDefinition;
return Task.CompletedTask;
}).Location("Content");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public override IDisplayResult Edit(ContentTypeDefinition contentTypeDefinition)
model.Draftable = settings.Draftable;
model.Securable = settings.Securable;
model.Stereotype = settings.Stereotype;
return Task.CompletedTask;
}).Location("Content:5");
}

Expand Down

0 comments on commit fc23bfc

Please sign in to comment.