Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Add new types
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Jun 24, 2017
1 parent 5f31116 commit bf63fe5
Show file tree
Hide file tree
Showing 28 changed files with 1,013 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
/// <summary>
/// Builds or modifies an <see cref="PageApplicationModelProviderContext"/> for Razor Page discovery.
/// Builds or modifies an <see cref="PageApplicationModel"/> for Razor Page invocation.
/// </summary>
public interface IPageApplicationModelProvider
{
Expand All @@ -30,13 +30,13 @@ public interface IPageApplicationModelProvider
int Order { get; }

/// <summary>
/// Executed for the first pass of building <see cref="PageApplicationModel"/> instances. See <see cref="Order"/>.
/// Executed for the first pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="PageApplicationModelProviderContext"/>.</param>
void OnProvidersExecuting(PageApplicationModelProviderContext context);

/// <summary>
/// Executed for the second pass of building <see cref="PageApplicationModel"/> instances. See <see cref="Order"/>.
/// Executed for the second pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="PageApplicationModelProviderContext"/>.</param>
void OnProvidersExecuted(PageApplicationModelProviderContext context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
/// <summary>
/// Allows customization of the of the <see cref="PageRouteModel"/>.
/// </summary>
public interface IPageRouteModelConvention
{
/// <summary>
/// Called to apply the convention to the <see cref="PageRouteModel"/>.
/// </summary>
/// <param name="model">The <see cref="PageRouteModel"/>.</param>
void Apply(PageRouteModel model);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
/// <summary>
/// Builds or modifies an <see cref="PageRouteModelProviderContext"/> for Razor Page routing.
/// </summary>
public interface IPageRouteModelProvider
{
/// <summary>
/// Gets the order value for determining the order of execution of providers. Providers execute in
/// ascending numeric value of the <see cref="Order"/> property.
/// </summary>
/// <remarks>
/// <para>
/// Providers are executed in an ordering determined by an ascending sort of the <see cref="Order"/> property.
/// A provider with a lower numeric value of <see cref="Order"/> will have its
/// <see cref="OnProvidersExecuting"/> called before that of a provider with a higher numeric value of
/// <see cref="Order"/>. The <see cref="OnProvidersExecuted"/> method is called in the reverse ordering after
/// all calls to <see cref="OnProvidersExecuting"/>. A provider with a lower numeric value of
/// <see cref="Order"/> will have its <see cref="OnProvidersExecuted"/> method called after that of a provider
/// with a higher numeric value of <see cref="Order"/>.
/// </para>
/// <para>
/// If two providers have the same numeric value of <see cref="Order"/>, then their relative execution order
/// is undefined.
/// </para>
/// </remarks>
int Order { get; }

/// <summary>
/// Executed for the first pass of building <see cref="PageRouteModel"/> instances. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="PageRouteModelProviderContext"/>.</param>
void OnProvidersExecuting(PageRouteModelProviderContext context);

/// <summary>
/// Executed for the second pass of building <see cref="PageRouteModel"/> instances. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="PageRouteModelProviderContext"/>.</param>
void OnProvidersExecuted(PageRouteModelProviderContext context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
Expand All @@ -16,26 +19,25 @@ public class PageApplicationModel
/// <summary>
/// Initializes a new instance of <see cref="PageApplicationModel"/>.
/// </summary>
/// <param name="relativePath">The application relative path of the page.</param>
/// <param name="viewEnginePath">The path relative to the base path for page discovery.</param>
public PageApplicationModel(string relativePath, string viewEnginePath)
public PageApplicationModel(
PageActionDescriptor actionDescriptor,
TypeInfo pageType,
TypeInfo modelType,
TypeInfo handlerType,
IReadOnlyList<object> handlerAttributes)
{
if (relativePath == null)
{
throw new ArgumentNullException(nameof(relativePath));
}

if (viewEnginePath == null)
{
throw new ArgumentNullException(nameof(viewEnginePath));
}

RelativePath = relativePath;
ViewEnginePath = viewEnginePath;
ActionDescriptor = actionDescriptor ?? throw new ArgumentNullException(nameof(actionDescriptor));
PageType = pageType;
ModelType = modelType;
HandlerType = handlerType;

Filters = new List<IFilterMetadata>();
Properties = new Dictionary<object, object>();
Selectors = new List<SelectorModel>();
Properties = new CopyOnWriteDictionary<object, object>(
actionDescriptor.Properties,
EqualityComparer<object>.Default);
Handlers = new List<PageHandlerModel>();
HandlerProperties = new List<PagePropertyModel>();
HandlerAttributes = handlerAttributes;
}

/// <summary>
Expand All @@ -49,24 +51,27 @@ public PageApplicationModel(PageApplicationModel other)
throw new ArgumentNullException(nameof(other));
}

RelativePath = other.RelativePath;
ViewEnginePath = other.ViewEnginePath;
ActionDescriptor = other.ActionDescriptor;

Filters = new List<IFilterMetadata>(other.Filters);
Properties = new Dictionary<object, object>(other.Properties);

Selectors = new List<SelectorModel>(other.Selectors.Select(m => new SelectorModel(m)));
Handlers = new List<PageHandlerModel>(other.Handlers.Select(m => new PageHandlerModel(m)));
HandlerProperties = new List<PagePropertyModel>(other.HandlerProperties.Select(p => new PagePropertyModel(p)));
HandlerAttributes = other.HandlerAttributes;
}

private PageActionDescriptor ActionDescriptor { get; }

/// <summary>
/// Gets the application root relative path for the page.
/// </summary>
public string RelativePath { get; }
public string RelativePath => ActionDescriptor.RelativePath;

/// <summary>
/// Gets the path relative to the base path for page discovery.
/// </summary>
public string ViewEnginePath { get; }
public string ViewEnginePath => ActionDescriptor.ViewEnginePath;

/// <summary>
/// Gets the applicable <see cref="IFilterMetadata"/> instances.
Expand All @@ -79,8 +84,20 @@ public PageApplicationModel(PageApplicationModel other)
public IDictionary<object, object> Properties { get; }

/// <summary>
/// Gets the <see cref="SelectorModel"/> instances.
/// Gets the <see cref="PageHandlerModel"/> instances.
/// </summary>
public IList<SelectorModel> Selectors { get; }
public IList<PageHandlerModel> Handlers { get; }

public IList<PagePropertyModel> HandlerProperties { get; }

public TypeInfo PageType { get; }

public TypeInfo ModelType { get; }

public TypeInfo HandlerType { get; }

public IReadOnlyList<object> HandlerAttributes { get; }


}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
Expand All @@ -10,9 +11,19 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
/// </summary>
public class PageApplicationModelProviderContext
{
public PageApplicationModelProviderContext(PageActionDescriptor descriptor, TypeInfo pageTypeInfo)
{
ActionDescriptor = descriptor;
PageType = pageTypeInfo;
}

public PageActionDescriptor ActionDescriptor { get; }

public TypeInfo PageType { get; }

/// <summary>
/// Gets the <see cref="PageApplicationModel"/> instances.
/// Gets or sets the <see cref="PageApplicationModel"/>.
/// </summary>
public IList<PageApplicationModel> Results { get; } = new List<PageApplicationModel>();
public PageApplicationModel PageModel { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Internal;

namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
/// <summary>
/// A type which is used to represent a property in a <see cref="PageApplicationModel"/>.
/// </summary>
[DebuggerDisplay("PageHandlerModel: Name={MethodName}")]
public class PageHandlerModel : ICommonModel
{
public PageHandlerModel(
MethodInfo handlerMethod,
IReadOnlyList<object> attributes)
{
HandlerMethod = handlerMethod ?? throw new ArgumentNullException(nameof(handlerMethod));

Attributes = attributes;
Parameters = new List<PageParameterModel>();
Properties = new Dictionary<object, object>();
}

public PageHandlerModel(PageHandlerModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}

HandlerMethod = other.HandlerMethod;
Name = other.Name;

Page = other.Page;

// These are just metadata, safe to create new collections
Attributes = new List<object>(other.Attributes);
Properties = new Dictionary<object, object>(other.Properties);

// Make a deep copy of other 'model' types.
Parameters = new List<PageParameterModel>(other.Parameters.Select(p => new PageParameterModel(p) { Handler = this }));
}

public MethodInfo HandlerMethod { get; }

public string HttpMethod { get; set; }

public string Name { get; set; }

public IList<PageParameterModel> Parameters { get; }

public PageApplicationModel Page { get; set; }

public IReadOnlyList<object> Attributes { get; }

MemberInfo ICommonModel.MemberInfo => HandlerMethod;

public IDictionary<object, object> Properties { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
[DebuggerDisplay("PageParameterModel: Name={ParameterName}")]
public class PageParameterModel : ICommonModel, IBindingModel
{
public PageParameterModel(
ParameterInfo parameterInfo,
IReadOnlyList<object> attributes)
{
ParameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo));

if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}

Properties = new Dictionary<object, object>();
Attributes = new List<object>(attributes);
}

public PageParameterModel(PageParameterModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}

Handler = other.Handler;
Attributes = new List<object>(other.Attributes);
BindingInfo = other.BindingInfo == null ? null : new BindingInfo(other.BindingInfo);
ParameterInfo = other.ParameterInfo;
ParameterName = other.ParameterName;
Properties = new Dictionary<object, object>(other.Properties);
}

public PageHandlerModel Handler { get; set; }

public IReadOnlyList<object> Attributes { get; }

public IDictionary<object, object> Properties { get; }

MemberInfo ICommonModel.MemberInfo => ParameterInfo.Member;

string ICommonModel.Name => ParameterName;

public ParameterInfo ParameterInfo { get; }

public string ParameterName { get; set; }

public BindingInfo BindingInfo { get; set; }
}
}
Loading

0 comments on commit bf63fe5

Please sign in to comment.