Skip to content

Commit

Permalink
1.给数据查询增加NotContains的比较方式,用于判断字符串不包含片断字符串
Browse files Browse the repository at this point in the history
2.修复Api路由器优先级不足无法正常解析的问题
  • Loading branch information
gmf520 committed Nov 18, 2015
1 parent b1f6ead commit d6eae77
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 38 deletions.
2 changes: 1 addition & 1 deletion OSharp.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnknownCssClass/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNameofExpression/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNullPropagation/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=OSharp_4EE3_7801_683C_5F0F/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="OSharp代码格式"&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;CSArrangeThisQualifier&gt;True&lt;/CSArrangeThisQualifier&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;CAN_CHANGE_TO_EXPLICIT&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;ALWAYS_EXPLICIT&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_EXPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsFormatDocComments&gt;True&lt;/JsFormatDocComments&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=OSharp_4EE3_7801_683C_5F0F/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="OSharp代码格式"&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;CSArrangeThisQualifier&gt;True&lt;/CSArrangeThisQualifier&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;CAN_CHANGE_TO_EXPLICIT&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;ALWAYS_EXPLICIT&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_EXPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsFormatDocComments&gt;True&lt;/JsFormatDocComments&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;/Profile&gt;</s:String>

<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">OSharp代码格式</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">OSharp代码格式</s:String>
Expand Down
13 changes: 0 additions & 13 deletions samples/OSharp.Demo.Consoles/Program.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

using Autofac;

using Newtonsoft.Json;

using OSharp.App.Local.Initialize;
using OSharp.AutoMapper;
using OSharp.Core;
using OSharp.Core.Caching;
using OSharp.Core.Data;
using OSharp.Data.Entity;
using OSharp.Core.Dependency;
using OSharp.Core.Initialize;
using OSharp.Core.Reflection;
using OSharp.Core.Security;
using OSharp.Demo.Contracts;
using OSharp.Logging.Log4Net;
using OSharp.SiteBase.Initialize;
using OSharp.Utility.Data;
using OSharp.Utility.Extensions;
using OSharp.Utility.Secutiry;


namespace OSharp.Demo.Consoles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Web.Http;
using System.Web.Mvc;

using OSharp.Web.Mvc.Routing;


namespace OSharp.Demo.Web.Areas.Service
{
Expand All @@ -34,7 +36,7 @@ public override void RegisterArea(AreaRegistrationContext context)
new { area = "Service", id = RouteParameter.Optional }
);

context.MapRoute(
context.MapLowerCaseUrlRoute(
"Service_default",
"api/service/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
Expand Down
1 change: 0 additions & 1 deletion samples/OSharp.Demo.Web/Controllers/TestsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using OSharp.Core.Dependency;
using OSharp.Core.Extensions;
using OSharp.Core.Security;
using OSharp.Core.Security.Models;
using OSharp.Demo.Contracts;
using OSharp.Demo.Dtos.OAuth;
using OSharp.Demo.Identity;
Expand Down
31 changes: 31 additions & 0 deletions samples/OSharp.Demo.Web/Controllers/WebApi/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;


namespace OSharp.Demo.Web.Controllers
{
public class ValuesController : ApiController
{
private readonly IDictionary<int, string> _values = new Dictionary<int, string>() { { 1, "No.1 value" }, { 2, "No.2 value" } };

[HttpGet]
[Route("api/values/value")]
public IHttpActionResult Value()
{
return Ok("Hello My Api");
}

public IHttpActionResult Get(int id)
{
string value;
if (!_values.TryGetValue(id, out value))
{
return NotFound();
}
return Ok(value);
}
}
}
12 changes: 4 additions & 8 deletions samples/OSharp.Demo.Web/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@

using System;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

using OSharp.Autofac.Http;
using OSharp.Autofac.Mvc;
using OSharp.Autofac.SignalR;
using OSharp.Core;
using OSharp.Core.Caching;
using OSharp.Core.Dependency;
using OSharp.Demo.Dtos;
using OSharp.Logging.Log4Net;
using OSharp.Web.Http.Extensions;
using OSharp.Web.Mvc.Routing;


Expand All @@ -35,6 +29,8 @@ protected void Application_Start(object sender, EventArgs e)

private static void RoutesRegister()
{
GlobalConfiguration.Configuration.MapDefaultRoutes();

RouteCollection routes = RouteTable.Routes;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapLowerCaseUrlRoute(
Expand Down
1 change: 1 addition & 0 deletions samples/OSharp.Demo.Web/OSharp.Demo.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@
<Compile Include="Areas\Service\ServiceAreaRegistration.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\WebApi\ValuesController.cs" />
<Compile Include="Controllers\TestsController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
Expand Down
2 changes: 1 addition & 1 deletion samples/OSharp.Demo.Web/osharp.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<createInitializer type="OSharp.Demo.Data.CreateDatabaseIfNotExistsWithSeed,OSharp.Demo.Core"/>
</initializer>
</context>
<context name="logging" enabled="true" dataLoggingEnabled="false" connectionStringName="default" type="OSharp.Data.Entity.LoggingDbContext,OSharp.Data.Entity">
<context name="logging" enabled="true" dataLoggingEnabled="false" connectionStringName="default" type="OSharp.Data.Entity.Logging.LoggingDbContext,OSharp.Data.Entity">
<initializer type="OSharp.Data.Entity.Logging.LoggingDbContextInitializer, OSharp.Data.Entity" mapperFiles="OSharp.Data.Entity"/>
</context>
<!--<context name="mysql-default" enabled="true" dataLoggingEnabled="false" connectionStringName="mysql-default" type="OSharp.Data.Entity.DefaultDbContext,OSharp.Data.Entity">
Expand Down
6 changes: 6 additions & 0 deletions src/OSharp.Core/Configs/DbContextConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using System.Threading.Tasks;

using OSharp.Core.Configs.ConfigFile;
using OSharp.Core.Properties;
using OSharp.Utility;
using OSharp.Utility.Extensions;


namespace OSharp.Core.Configs
Expand Down Expand Up @@ -43,6 +45,10 @@ internal DbContextConfig(ContextElement element)
DataLoggingEnabled = element.DataLoggingEnabled;
ConnectionStringName = element.ConnectionStringName;
ContextType = Type.GetType(element.ContextTypeName);
if (ContextType == null)
{
throw new InvalidOperationException(Resources.ConfigFile_NameToTypeIsNull.FormatWith(element.ContextTypeName));
}
InitializerConfig = new DbContextInitializerConfig(element.DbContextInitializer);
}

Expand Down
6 changes: 5 additions & 1 deletion src/OSharp.Core/Configs/DbContextInitializerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ internal DbContextInitializerConfig(DbContextInitializerElement element)
.Select(fileName => Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, fileName)).ToArray();
EntityMapperAssemblies = mapperFiles.Select(Assembly.LoadFrom).ToList();

if (element.CreateDatabaseInitializer != null && element.CreateDatabaseInitializer.InitializerTypeName != null)
if (element.CreateDatabaseInitializer != null && !element.CreateDatabaseInitializer.InitializerTypeName.IsMissing())
{
CreateDatabaseInitializerType = Type.GetType(element.CreateDatabaseInitializer.InitializerTypeName);
if (CreateDatabaseInitializerType == null)
{
throw new InvalidOperationException(Resources.ConfigFile_NameToTypeIsNull.FormatWith(element.CreateDatabaseInitializer.InitializerTypeName));
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/OSharp.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/OSharp.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="ConfigFile_ItemKeyDefineRepeated" xml:space="preserve">
<value>标识为“{0}”的项重复定义</value>
</data>
<data name="ConfigFile_NameToTypeIsNull" xml:space="preserve">
<value>名称为“{0}”的类型不存在</value>
</data>
<data name="Context_BuildServicesFirst" xml:space="preserve">
<value>请先初始化依赖注入服务,再使用OSharpContext.IocRegisterServices属性</value>
</data>
Expand Down
11 changes: 11 additions & 0 deletions src/OSharp.Utility/Filter/FilterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public static class FilterHelper
return Expression.Call(left, typeof(string).GetMethod("Contains", new[] { typeof(string) }), right);
}
},
{
FilterOperate.NotContains,
(left, right) =>
{
if (left.Type != typeof(string))
{
throw new NotSupportedException("“NotContains”比较方式只支持字符串类型的数据");
}
return Expression.Not(Expression.Call(left, typeof(string).GetMethod("Contains", new[] { typeof(string) }), right));
}
}
//{
// FilterOperates.StdIn, (left, right) =>
// {
Expand Down
12 changes: 9 additions & 3 deletions src/OSharp.Utility/Filter/FilterOperate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,27 @@ public enum FilterOperate
EndsWith = 10,

/// <summary>
/// 包含(相似)
/// 字符串的包含(相似)
/// </summary>
[OperateCode("contains")]
Contains = 11,

/// <summary>
/// 字符串的不包含
/// </summary>
[OperateCode("notcontains")]
NotContains = 12,

///// <summary>
///// 包括在
///// </summary>
//[OperateCode("in")]
//In = 12,
//In = 13,

///// <summary>
///// 不包括在
///// </summary>
//[OperateCode("notin")]
//NotIn = 13
//NotIn = 14
}
}
32 changes: 32 additions & 0 deletions src/OSharp.Web.WebApi/Extensions/HttpConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// -----------------------------------------------------------------------
// <copyright file="HttpConfigurationExtensions.cs" company="OSharp开源团队">
// Copyright (c) 2014-2015 OSharp. All rights reserved.
// </copyright>
// <site>http://www.osharp.org</site>
// <last-editor>郭明锋</last-editor>
// <last-date>2015-11-18 15:00</last-date>
// -----------------------------------------------------------------------

using System.Web.Http;

using OSharp.Web.Http.Routing;


namespace OSharp.Web.Http.Extensions
{
/// <summary>
/// HttpConfiguration扩展
/// </summary>
public static class HttpConfigurationExtensions
{
/// <summary>
/// 注册WebApi默认路由
/// </summary>
public static void MapDefaultRoutes(this HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
//config.Routes.MapHttpRoute("ActionApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
}
}
}
8 changes: 1 addition & 7 deletions src/OSharp.Web.WebApi/Initialize/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
// </copyright>
// <site>http://www.osharp.org</site>
// <last-editor>郭明锋</last-editor>
// <last-date>2015-09-29 23:04</last-date>
// <last-date>2015-11-18 17:05</last-date>
// -----------------------------------------------------------------------

using System.Net.Http.Formatting;
using System.Web.Http;
using System.Web.Http.Dispatcher;

using Microsoft.Owin.Security.OAuth;

using OSharp.Core;
using OSharp.Core.Dependency;
using OSharp.Utility;
using OSharp.Web.Http.Filters;
using OSharp.Web.Http.Selectors;

using Owin;

Expand Down Expand Up @@ -49,10 +47,6 @@ public static IAppBuilder ConfigureWebApi(this IAppBuilder app)
{
HttpConfiguration config = GlobalConfiguration.Configuration;

config.Services.Replace(typeof(IHttpControllerSelector), new AreaHttpControllerSelector(config));
config.Routes.MapHttpRoute("ActionApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });

config.Filters.Add(new ExceptionHandlingAttribute());
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
Expand Down
1 change: 1 addition & 0 deletions src/OSharp.Web.WebApi/OSharp.Web.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<Compile Include="Content\CompressHandler.cs" />
<Compile Include="Extensions\ActionExtensions.cs" />
<Compile Include="Extensions\ContentNegotiationExtensions.cs" />
<Compile Include="Extensions\HttpConfigurationExtensions.cs" />
<Compile Include="Extensions\HttpMessageExtensions.cs" />
<Compile Include="Filters\EnableCorsAttribute.cs" />
<Compile Include="Filters\ExceptionHandlingAttribute.cs" />
Expand Down
9 changes: 9 additions & 0 deletions src/OSharp.Web.WebApi/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/OSharp.Web.WebApi/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="ActionMethodInfoFinder_TypeNotApiControllerType" xml:space="preserve">
<value>类型“{0}”不是API控制器类型</value>
</data>
<data name="ApiControllerNameIsNull" xml:space="preserve">
<value>获取的Api控制器名称为空</value>
</data>
<data name="FunctionHandler_DefindActionTypeIsNull" xml:space="preserve">
<value>声明功能“{0}”的类型为空</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions src/OSharp.Web.WebApi/Selectors/AreaHttpControllerSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Web.Http.Routing;

using OSharp.Utility.Extensions;
using OSharp.Web.Http.Properties;


namespace OSharp.Web.Http.Selectors
Expand Down Expand Up @@ -71,6 +72,10 @@ private HttpControllerDescriptor GetApiController(HttpRequestMessage request)
{
string areaName = GetAreaName(request);
string controllerName = GetControllerName(request);
if (controllerName == null)
{
throw new InvalidOperationException(Resources.ApiControllerNameIsNull);
}
Type type = GetControllerType(areaName, controllerName);
return new HttpControllerDescriptor(_configuration, controllerName, type);
}
Expand Down
4 changes: 2 additions & 2 deletions src/VersionAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
using System.Reflection;

[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.4.3.0")]
[assembly: AssemblyInformationalVersion("3.4.3")]
[assembly: AssemblyFileVersion("3.4.4.0")]
[assembly: AssemblyInformationalVersion("3.4.4")]

0 comments on commit d6eae77

Please sign in to comment.