提交 dc0a9da3 编写于 作者: JasonWcx's avatar JasonWcx

优化部分代码

上级 c1491ff2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mozi.HttpEmbedded.Page;
using Mozi.HttpEmbedded.Page;
namespace Mozi.HttpEmbedded.Test
{
......
......@@ -3,6 +3,9 @@ using System.Reflection;
namespace Mozi.HttpEmbedded.Docment
{
/// <summary>
/// 文档载入器
/// </summary>
public class DocLoader
{
public static string Load(string docName)
......
......@@ -7,60 +7,17 @@
<meta name="Authorization" content="Jason">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,maximum-scale=1,user-scalable=no">
<style type="text/css">
* {
font-size: 18px;
box-sizing: border-box;
-webkit-box-sizing: border-box;
color: #212121;
-moz-box-sizing: border-box;
-webkit-user-drag: none;
}
body {
padding: 0;
margin: 0;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
body {
padding: 0;
margin: 0;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
h1 {
font-size: 1.22rem;
}
h2 {
font-size: 1rem;
}
h3 {
font-size: 0.89rem;
}
h4 {
font-size: 0.78rem;
}
h5 {
font-size: 0.67rem;
}
p, p > *, pre {
font-size: 0.78rem;
}
* { font-size: 18px;box-sizing: border-box;-webkit-box-sizing: border-box;color: #212121;-moz-box-sizing: border-box;-webkit-user-drag: none;}
body { padding: 0; margin: 0;}
ul { list-style-type: none;padding: 0;margin: 0; }
body {padding: 0; margin: 0;}
ul { list-style-type: none;padding: 0;margin: 0; }
h1 { font-size: 1.22rem; }
h2 { font-size: 1rem;}
h3 { font-size: 0.89rem;}
h4 {font-size: 0.78rem;}
h5 { font-size: 0.67rem;}
p, p > * { font-size: 0.78rem; line-height: 1.22rem;}
</style>
</head>
<body style="padding:0 0.6rem;">
......
......@@ -10,41 +10,14 @@
* { font-size: 18px;box-sizing: border-box;-webkit-box-sizing: border-box;color: #212121;-moz-box-sizing: border-box;-webkit-user-drag: none;}
body { padding: 0; margin: 0;}
ul { list-style-type: none;padding: 0;margin: 0; }
body {
padding: 0;
margin: 0;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
h1 {
font-size: 1.22rem;
}
h2 {
font-size: 1rem;
}
h3 {
font-size: 0.89rem;
}
h4 {
font-size: 0.78rem;
}
h5 {
font-size: 0.67rem;
}
p, p > * {
font-size: 0.78rem;
line-height: 1.22rem;
}
body {padding: 0; margin: 0;}
ul { list-style-type: none;padding: 0;margin: 0; }
h1 { font-size: 1.22rem; }
h2 { font-size: 1rem; }
h3 { font-size: 0.89rem; }
h4 { font-size: 0.78rem; }
h5 { font-size: 0.67rem; }
p, p > * { font-size: 0.78rem; line-height: 1.22rem;}
</style>
</head>
<body style="width:640px;margin:0 auto;">
......
......@@ -4,7 +4,7 @@ using System.Reflection;
namespace Mozi.HttpEmbedded.Generic
{
/// <summary>
/// 仿枚举
/// 仿举 抽象类
/// </summary>
public abstract class AbsClassEnum
{
......
......@@ -60,11 +60,20 @@ namespace Mozi.HttpEmbedded
private string _serverName = "HttpEmbedded";
//默认首页为index.html,index.htm
private string _indexPageMatchPattern = "index.html,index.htm";
public string[] _indexPages = new string[] { "index.html","index.htm" };
//允许和公开的方法
private RequestMethod[] MethodAllow = new RequestMethod[] { RequestMethod.OPTIONS, RequestMethod.TRACE, RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.COPY, RequestMethod.PROPFIND, RequestMethod.LOCK, RequestMethod.UNLOCK };
/// <summary>
/// 默认首页
/// </summary>
public string IndexPages { get { return string.Join(",",_indexPages); } }
/// <summary>
/// 允许的方法
/// </summary>
private RequestMethod[] MethodAllow = new RequestMethod[] { RequestMethod.OPTIONS, RequestMethod.TRACE, RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.COPY, RequestMethod.PROPFIND, RequestMethod.LOCK, RequestMethod.UNLOCK };
/// <summary>
/// 公开的方法
/// </summary>
private RequestMethod[] MethodPublic = new RequestMethod[] { RequestMethod.OPTIONS, RequestMethod.GET, RequestMethod.HEAD, RequestMethod.PROPFIND, RequestMethod.PROPPATCH, RequestMethod.MKCOL, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.COPY, RequestMethod.MOVE, RequestMethod.LOCK, RequestMethod.UNLOCK };
//证书管理器
......@@ -358,33 +367,60 @@ namespace Mozi.HttpEmbedded
bool isStatic = st.IsStatic(fileext);
context.Response.SetContentType(contenttype);
if (path == "/")
var pathReal = path;
if (pathReal == "/")
{
var doc = DocLoader.Load("Home.html");
PageEngine pc = new PageEngine();
pc.LoadFromText(doc);
pc.Set("Info", new
{
VersionName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
});
pc.Prepare();
context.Response.Write(pc.GetBuffer());
context.Response.SetContentType(Mime.GetContentType("html"));
return StatusCode.Success;
//var existsIndex = false;
//foreach(var r in _indexPages)
//{
// if (st.Exists(path+r, ""))
// {
// string ifmodifiedsince = context.Request.Headers.GetValue(HeaderProperty.IfModifiedSince.PropertyName);
// if (st.CheckIfModified(path, ifmodifiedsince))
// {
// DateTime dtModified = st.GetLastModifiedTime(path).ToUniversalTime();
// context.Response.AddHeader(HeaderProperty.LastModified, dtModified.ToString("r"));
// context.Response.Write(st.Load(path, ""));
// //ETag 仅测试 不具备判断缓存的能力
// context.Response.AddHeader(HeaderProperty.ETag, String.Format("{0:x2}:{1:x2}", dtModified.ToUniversalTime().Ticks, context.Response.ContentLength));
// return StatusCode.Success;
// }
// }
//}
//if (!existsIndex)
//{
//优先加载
var doc = DocLoader.Load("Home.html");
PageEngine pc = new PageEngine();
pc.LoadFromText(doc);
pc.Set("Info", new
{
VersionName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
});
pc.Prepare();
context.Response.Write(pc.GetBuffer());
context.Response.SetContentType(Mime.GetContentType("html"));
return StatusCode.Success;
//}
}
//静态文件处理
else if (st.Enabled && isStatic)
{
//if (pathReal.EndsWith("/"))
//{
//}
//响应静态文件
if (st.Exists(path, ""))
if (st.Exists(pathReal, ""))
{
string ifmodifiedsince = context.Request.Headers.GetValue(HeaderProperty.IfModifiedSince.PropertyName);
if (st.CheckIfModified(path, ifmodifiedsince))
if (st.CheckIfModified(pathReal, ifmodifiedsince))
{
DateTime dtModified = st.GetLastModifiedTime(path).ToUniversalTime();
DateTime dtModified = st.GetLastModifiedTime(pathReal).ToUniversalTime();
context.Response.AddHeader(HeaderProperty.LastModified, dtModified.ToString("r"));
context.Response.Write(st.Load(path, ""));
context.Response.Write(st.Load(pathReal, ""));
//ETag 仅测试 不具备判断缓存的能力
context.Response.AddHeader(HeaderProperty.ETag, String.Format("{0:x2}:{1:x2}", dtModified.ToUniversalTime().Ticks, context.Response.ContentLength));
......@@ -688,7 +724,7 @@ namespace Mozi.HttpEmbedded
/// <param name="filePath"></param>
public void SetIndexPage(string pattern)
{
_indexPageMatchPattern = pattern;
_indexPages = pattern.Split(new char[] { ',' });
}
/// <summary>
/// 关闭服务器
......
......@@ -3,7 +3,7 @@
/// <summary>
/// 中间件 接入多层次逻辑处理
/// </summary>
public interface IMiddleware
internal interface IMiddleware
{
void Invoke();
}
......
......@@ -5,7 +5,9 @@
/// </summary>
public abstract class BaseApi
{
/// <summary>
/// 绑定的上下文对象
/// </summary>
public HttpContext Context { get; internal set; }
}
}
......@@ -5,15 +5,22 @@
/// </summary>
public abstract class BasePage
{
/// <summary>
/// 上下文对象
/// </summary>
protected HttpContext Context { get; set; }
/// <summary>
/// 重定向
/// </summary>
/// <param name="url"></param>
public abstract void RedirectTo(string url);
/// <summary>
/// GET方法
/// </summary>
public abstract void Get();
/// <summary>
/// POST方法
/// </summary>
public abstract void Post();
}
......
......@@ -10,7 +10,7 @@ namespace Mozi.HttpEmbedded.Page
{
//TODO 增加API下载的功能,允许客户端提取所有API,同时加入鉴权机制
/// <summary>
/// 全局路由
/// 全局路由 单例模式
/// </summary>
/// <remarks>
/// 实例化Router时会自动扫描此程序集内部的API
......@@ -321,14 +321,18 @@ namespace Mozi.HttpEmbedded.Page
return ap;
}
}
/// <summary>
/// 访问域
/// </summary>
public class AccessPoint
{
public string Domain { get; set; }
public string Controller { get; set; }
public string Action { get; set; }
}
/// <summary>
/// 访问对象
/// </summary>
public class AccessObject
{
public Type Target { get; set; }
......
......@@ -33,12 +33,12 @@ namespace Mozi.HttpEmbedded.Page
public RuntimeInfo Info()
{
RuntimeInfo info = new RuntimeInfo();
var exeAssembly = Assembly.GetExecutingAssembly();
info.Name = exeAssembly.GetName().Name;
info.VersionName = exeAssembly.GetName().Version.ToString();
info.PlatformName =exeAssembly.ImageRuntimeVersion;
var ass = Assembly.GetExecutingAssembly();
info.Name = ass.GetName().Name;
info.VersionName = ass.GetName().Version.ToString();
info.PlatformName =ass.ImageRuntimeVersion;
info.StartupTime = Context.Server.StartTime.ToUniversalTime().ToString("r");
Module[] modules = exeAssembly.GetLoadedModules();
Module[] modules = ass.GetLoadedModules();
foreach(var m in modules)
{
info.LoadedModules.Add(new LoadedModuleInfo()
......
......@@ -144,12 +144,33 @@ namespace Mozi.HttpEmbedded.Template
}
/// <summary>
/// $define表达式
/// <para>
/// $define 用于定义常量
/// </para>
/// </summary>
/// <returns></returns>
private PageEngine InflateStatementDefine()
{
throw new NotImplementedException();
}
/// <summary>
/// $undef 表达式
/// <para>
/// $undef 用于删除常量定义
/// </para>
/// </summary>
/// <returns></returns>
private PageEngine InflateStatementUndef()
{
throw new NotImplementedException();
}
/// <summary>
/// $set表达式
/// <para>
/// $set 用于定义变量
/// </para>
/// </summary>
/// <returns></returns>
private PageEngine InflateStatementSet()
{
throw new NotImplementedException();
......@@ -222,7 +243,7 @@ namespace Mozi.HttpEmbedded.Template
return this;
}
/// <summary>
/// == != <> && ||
/// == != <> > < >= <=, && || ,+ - * / %
/// </summary>
/// <returns></returns>
private PageEngine ParseOperator()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册