files tree made better.
This commit is contained in:
parent
ffbf032480
commit
ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions
39
src/Yavsc/Extensions/AppBuilderExtensions.cs
Normal file
39
src/Yavsc/Extensions/AppBuilderExtensions.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Yavsc.Extensions {
|
||||
public static class AppBuilderExtensions {
|
||||
public static IApplicationBuilder UseWhen(this IApplicationBuilder app,
|
||||
Func<HttpContext, bool> condition, Action<IApplicationBuilder> configuration) {
|
||||
if (app == null) {
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
|
||||
if (condition == null) {
|
||||
throw new ArgumentNullException(nameof(condition));
|
||||
}
|
||||
|
||||
if (configuration == null) {
|
||||
throw new ArgumentNullException(nameof(configuration));
|
||||
}
|
||||
|
||||
var builder = app.New();
|
||||
configuration(builder);
|
||||
|
||||
return app.Use(next => {
|
||||
builder.Run(next);
|
||||
|
||||
var branch = builder.Build();
|
||||
|
||||
return context => {
|
||||
if (condition(context)) {
|
||||
return branch(context);
|
||||
}
|
||||
|
||||
return next(context);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
88
src/Yavsc/Extensions/EnumExtensions.cs
Normal file
88
src/Yavsc/Extensions/EnumExtensions.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Yavsc.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds select items from an enum type
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="SR"></param>
|
||||
/// <param name="valueSelected"></param>
|
||||
/// <returns></returns>
|
||||
public static List<SelectListItem> GetSelectList (Type type, IStringLocalizer SR, Enum valueSelected)
|
||||
{
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
var values = Enum.GetValues(type).Cast<Enum>();
|
||||
var items = new List<SelectListItem>();
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
items.Add(new SelectListItem {
|
||||
Text = SR[GetDescription(value, typeInfo)],
|
||||
Value = value.ToString(),
|
||||
Selected = value == valueSelected
|
||||
});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
public static List<SelectListItem> GetSelectList (Type type, IStringLocalizer SR, string selectedValue = null)
|
||||
{
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
var values = Enum.GetValues(type).Cast<Enum>();
|
||||
var items = new List<SelectListItem>();
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
var strval = value.ToString();
|
||||
|
||||
items.Add(new SelectListItem {
|
||||
Text = SR[GetDescription(value, typeInfo)],
|
||||
Value = strval,
|
||||
Selected = strval == selectedValue
|
||||
});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
public static string GetDescription(this Enum value, TypeInfo typeInfo )
|
||||
{
|
||||
var declaredMember = typeInfo.DeclaredMembers.FirstOrDefault(i => i.Name == value.ToString());
|
||||
var attribute = declaredMember?.GetCustomAttribute<DisplayAttribute>();
|
||||
return attribute == null ? value.ToString() : attribute.Description ?? attribute.Name;
|
||||
}
|
||||
public static string GetDescription(this Enum value)
|
||||
{
|
||||
var type = value.GetType();
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
return GetDescription(value, typeInfo);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetDescriptions(Type type)
|
||||
{
|
||||
var values = Enum.GetValues(type).Cast<Enum>();
|
||||
var descriptions = new List<string>();
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
descriptions.Add(value.GetDescription());
|
||||
}
|
||||
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
public static Enum GetEnumFromDescription(string description, Type enumType)
|
||||
{
|
||||
var enumValues = Enum.GetValues(enumType).Cast<Enum>();
|
||||
var descriptionToEnum = enumValues.ToDictionary(k => k.GetDescription(), v => v);
|
||||
return descriptionToEnum[description];
|
||||
}
|
||||
}
|
||||
}
|
||||
60
src/Yavsc/Extensions/OAuthAuthorizationServerExtensions.cs
Normal file
60
src/Yavsc/Extensions/OAuthAuthorizationServerExtensions.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using OAuth.AspNet.AuthServer;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods to add Authorization Server capabilities to an OWIN pipeline
|
||||
/// </summary>
|
||||
public static class OAuthAuthorizationServerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds OAuth2 Authorization Server capabilities to an OWIN web application. This middleware
|
||||
/// performs the request processing for the Authorize and Token endpoints defined by the OAuth2 specification.
|
||||
/// See also http://tools.ietf.org/html/rfc6749
|
||||
/// </summary>
|
||||
/// <param name="app">The web application builder</param>
|
||||
/// <param name="options">Options which control the behavior of the Authorization Server.</param>
|
||||
/// <returns>The application builder</returns>
|
||||
public static IApplicationBuilder UseOAuthAuthorizationServer(this IApplicationBuilder app, OAuthAuthorizationServerOptions options)
|
||||
{
|
||||
if (app == null)
|
||||
throw new NullReferenceException($"The extension method {nameof(OAuthAuthorizationServerExtensions.UseOAuthAuthorizationServer)} was called on a null reference to a {nameof(IApplicationBuilder)}");
|
||||
|
||||
if (options == null)
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
|
||||
|
||||
|
||||
return app.UseMiddleware<OAuthAuthorizationServerMiddleware>(options);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds OAuth2 Authorization Server capabilities to an OWIN web application. This middleware
|
||||
/// performs the request processing for the Authorize and Token endpoints defined by the OAuth2 specification.
|
||||
/// See also http://tools.ietf.org/html/rfc6749
|
||||
/// </summary>
|
||||
/// <param name="app">The web application builder</param>
|
||||
/// <param name="configureOptions">Options which control the behavior of the Authorization Server.</param>
|
||||
/// <returns>The application builder</returns>
|
||||
public static IApplicationBuilder UseOAuthAuthorizationServer(this IApplicationBuilder app, Action<OAuthAuthorizationServerOptions> configureOptions)
|
||||
{
|
||||
if (app == null)
|
||||
throw new NullReferenceException($"The extension method {nameof(OAuthAuthorizationServerExtensions.UseOAuthAuthorizationServer)} was called on a null reference to a {nameof(IApplicationBuilder)}");
|
||||
|
||||
if (configureOptions == null)
|
||||
throw new ArgumentNullException(nameof(configureOptions));
|
||||
|
||||
|
||||
var options = new OAuthAuthorizationServerOptions();
|
||||
if (configureOptions != null)
|
||||
|
||||
configureOptions(options);
|
||||
|
||||
return app.UseOAuthAuthorizationServer(options);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
46
src/Yavsc/Extensions/SignalRBuilderExtension.cs
Normal file
46
src/Yavsc/Extensions/SignalRBuilderExtension.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.Owin.Builder;
|
||||
using Owin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
using Microsoft.AspNet.SignalR;
|
||||
using AppFunc = Func<IDictionary<string, object>, Task>;
|
||||
|
||||
public static class BuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseAppBuilder(
|
||||
this IApplicationBuilder app,
|
||||
Action<IAppBuilder> configure)
|
||||
{
|
||||
app.UseOwin(addToPipeline =>
|
||||
{
|
||||
addToPipeline(next =>
|
||||
{
|
||||
var appBuilder = new AppBuilder();
|
||||
appBuilder.Properties["builder.DefaultApp"] = next;
|
||||
|
||||
configure(appBuilder);
|
||||
|
||||
return appBuilder.Build<AppFunc>();
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
public static void UseSignalR(this IApplicationBuilder app, string path = "/signalr")
|
||||
{
|
||||
app.UseAppBuilder(appBuilder => appBuilder.MapSignalR(
|
||||
path,
|
||||
new HubConfiguration() {
|
||||
EnableDetailedErrors = true,
|
||||
EnableJSONP = true
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue