Skip to content

Commit

Permalink
Project First Submint.
Browse files Browse the repository at this point in the history
(项目首次提交)
  • Loading branch information
unknown committed Oct 7, 2016
0 parents commit f085155
Show file tree
Hide file tree
Showing 221 changed files with 48,162 additions and 0 deletions.
Binary file added .vs/Moon.Mvc/v14/.suo
Binary file not shown.
22 changes: 22 additions & 0 deletions Attributes/AreaAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Moon.Mvc
{
/// <summary>
/// 用于修饰控制器域名
/// </summary>
public class AreaAttribute : Attribute
{
public string AreaName
{
get; set;
}
public AreaAttribute(string areaName)
{
this.AreaName = areaName;
}
}
}
51 changes: 51 additions & 0 deletions Attributes/AspectAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Reflection;

namespace Moon.Mvc
{
/// <summary>
/// 告诉action不要验证请求是否安全(往往包括html标签)
/// </summary>
public class DontValidateRequestAttribute : Attribute
{

}
/// <summary>
/// Post请求
/// </summary>
public class PostAttribute : Attribute
{

}
/// <summary>
/// Get 请求
/// </summary>
public class GetAttribute : Attribute
{

}
/// <summary>
/// 方面注入的基类
/// </summary>
public abstract class AspectAttribute : Attribute
{
/// <summary>
/// 优先级,数值越大优先级越大,AspectAttributePriority枚举
/// </summary>
public int Priority{
get;
set;
}
public AspectAttribute(){
Priority=AspectAttributePriority.Common;
}
public virtual AspectResultType BeforeInvoke(MethodInfo methodInfo,System.Web.HttpContext context )
{
return AspectResultType.Continue;
}
public virtual AspectResultType AfterInvoke(MethodInfo methodInfo,System.Web.HttpContext context )
{
return AspectResultType.Continue;
}
}
}
69 changes: 69 additions & 0 deletions Attributes/Client304Expires.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 由SharpDevelop创建。
* 用户: qscq
* 日期: 2014/8/27
* 时间: 16:59
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using Moon.Orm.Util;
namespace Moon.Mvc
{
/// <summary>
/// 通过告诉客户端304状态进行缓存
/// </summary>
public class Client304Expires:AspectAttribute
{
/// <summary>
/// 缓存有效期
/// </summary>
protected int TimeOut{
get;
set;
}
/// <summary>
/// 构造
/// </summary>
/// <param name="howlong">客户端缓存有效期</param>
public Client304Expires(int howlong){
this.TimeOut=howlong;
this.Priority=AspectAttributePriority.High;
}
/// <summary>
/// action执行之前
/// </summary>
/// <param name="methodInfo"></param>
/// <param name="context"></param>
/// <returns></returns>
public override AspectResultType AfterInvoke(System.Reflection.MethodInfo methodInfo, System.Web.HttpContext context)
{
return AspectResultType.Continue;
}
/// <summary>
/// action执行之后
/// </summary>
/// <param name="methodInfo"></param>
/// <param name="context"></param>
/// <returns></returns>
public override AspectResultType BeforeInvoke(System.Reflection.MethodInfo methodInfo, System.Web.HttpContext context)
{

DateTime dt;
if (DateTime.TryParse(context.Request.Headers["If-Modified-Since"], out dt))
{
// 注意:如果是20秒内,我就以304的方式响应。
if ((DateTime.Now - dt).TotalSeconds < TimeOut)
{
context.Response.StatusCode = 304;
context.Response.End();
return AspectResultType.Stop;
}
}

string time = DateTime.Now.AddSeconds(TimeOut).ToUniversalTime().ToString("r");
context.Response.AddHeader("Last-Modified", time);
return AspectResultType.Continue;
}
}
}
51 changes: 51 additions & 0 deletions Attributes/ClientExpires.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 由SharpDevelop创建。
* 用户: qscq
* 日期: 2014/8/27
* 时间: 16:59
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using Moon.Orm.Util;
namespace Moon.Mvc
{
/// <summary>
/// 通过给客户端设置Expires头来决定过期时间.
/// </summary>
public class ClientExpires:AspectAttribute
{
/// <summary>
/// 客户端缓存时间
/// </summary>
protected int TimeOut{
get;
set;
}
/// <summary>
/// 构造
/// </summary>
/// <param name="howlong">过期时间(秒)</param>
public ClientExpires(int howlong){
this.TimeOut=howlong;
this.Priority=AspectAttributePriority.High;
}
/// <summary>
/// action执行前
/// </summary>
/// <param name="methodInfo">方法信息</param>
/// <param name="context">httpcontext</param>
/// <returns>该方法的反馈信息</returns>
public override AspectResultType AfterInvoke(System.Reflection.MethodInfo methodInfo, System.Web.HttpContext context)
{
return AspectResultType.Continue;
}
public override AspectResultType BeforeInvoke(System.Reflection.MethodInfo methodInfo, System.Web.HttpContext context)
{
string time=DateTime.Now.AddSeconds(TimeOut).ToUniversalTime().ToString("r");
context.Response.AddHeader("Expires",time);
return AspectResultType.Continue;
}
}

}
40 changes: 40 additions & 0 deletions Attributes/TimeLogAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 由SharpDevelop创建。
* 用户: qscq
* 日期: 2014/8/28
* 时间: 21:20
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using Moon.Orm;

namespace Moon.Mvc
{
/// <summary>
/// Description of TimeLogAttribute.
/// </summary>
public class TimeLogAttribute:AspectAttribute
{
public TimeLogAttribute(){
this.Priority=AspectAttributePriority.High;
}
protected long _start;
public override AspectResultType BeforeInvoke(System.Reflection.MethodInfo methodInfo, System.Web.HttpContext context)
{
_start=DateTime.Now.Ticks;
return AspectResultType.Continue;
}
public override AspectResultType AfterInvoke (System.Reflection.MethodInfo methodInfo, System.Web.HttpContext context)
{
var classFullName=methodInfo.DeclaringType.FullName;
var methodName=methodInfo.Name;
var result=DateTime.Now.Ticks-_start;
TimeSpan ts = new TimeSpan(result);
//var time=result/10000000;
string msg = classFullName + "." + methodName+" spent time(s):"+ts.TotalSeconds;
Moon.Orm.Util.LogUtil.Write("执行时间", msg);
return AspectResultType.Continue;
}
}
}
1 change: 1 addition & 0 deletions Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

33 changes: 33 additions & 0 deletions Common/AspectAttributePriority.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Reflection;

namespace Moon.Mvc
{
/// <summary>
/// 注入特性类优先级(如果默认则使用Common)
/// </summary>
public static class AspectAttributePriority
{
/// <summary>
/// 最高级别,10000
/// </summary>
public const int Highest = 10000;
/// <summary>
/// 高级,1000
/// </summary>
public const int High = 1000;
/// <summary>
/// 通常所用的级别,100
/// </summary>
public const int Common = 100;
/// <summary>
/// 低级,10
/// </summary>
public const int Low = 10;
/// <summary>
/// 最低级,0
/// </summary>
public const int Lowest = 0;
}

}
17 changes: 17 additions & 0 deletions Common/AspectResultType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Reflection;

namespace Moon.Mvc
{
public enum AspectResultType
{
/// <summary>
/// 继续后续操作
/// </summary>
Continue,
/// <summary>
/// 终止后续操作
/// </summary>
Stop,
}
}
17 changes: 17 additions & 0 deletions Common/Captcha/ICaptcha.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Moon.Mvc
{
public interface ICaptcha
{
string Value
{
get;
set;
}
byte[] GetImageByte();
}
}
Loading

0 comments on commit f085155

Please sign in to comment.