龙空技术网

ASP.NET原创框架五-应用基类函数介绍

散装码农 94

前言:

现在各位老铁们对“netaspx页面对象”都比较珍视,你们都想要了解一些“netaspx页面对象”的相关文章。那么小编在网络上网罗了一些对于“netaspx页面对象””的相关文章,希望你们能喜欢,兄弟们快快来了解一下吧!

ASP.NET原创框架五-应用基类函数介绍

接上集,对应用基类BaseJsonMode,开发应用时只需派生于BaseJsonMode

一、应用模块初始化函数

static public void SetJsonMode(string sPath, string sName)

对于应用需要初始化的动作都可在此函数内实现,如添加函数描述说明,绑定系统事件,如所有应用模块加载完成事件

BindP2PMessage("modeReady", onModeReady);//modeReady为事件名称 onModeReady事件处理函数

static private void onModeReady(string sFromServer, string message, Object m_MsgData)

{

...

}

绑定任务

protected static void BindP2PWork(string WorkType, Action<string, string, object> m_WorkCallBack);

WorkType:任务类型

m_WorkCallBack:任务处理函数

如:BindP2PWork("HelloMyWork", ReturnHelloMyWork);

static private void ReturnHelloMyWork(string sFromServer,string workName, Object m_WorkData)

{

WriteLog("收到任务:" + workName + ",数据:" + m_WorkData.ToString());

}

发消息给自己

protected static bool PostSelfP2PMessage(string MsgType, object m_MsgData);

发任务给自己

protected static bool AddSelfP2PWork(string WorkType, object m_WorkData);

给指定的服务发消息

bool PostP2PMessage(string ActionP2PServerName, string MsgType, object m_MsgData);

给指定的服务

protected static bool AddP2PWork(string ActionP2PServerName, string WorkType, object m_WorkData);

发送公共消息

protected static bool PostPublicMessage(string MsgType, object m_MsgData);

派发系统任务

protected static bool AddSYSWork(string WorkType, object m_WorkData);

二、添加函数说明

static protected void AddFunctionDescription(string ClassFullName,string FunctionName,string FunctionDescription,string InParameDescription,string OutParameDescription)

ClassFullName:应用模块类名

FunctionName:函数名称

FunctionDescription:函数说明

InParameDescription:输入参数描述

OutParameDescription:输出参数描述

如:

AddFunctionDescription("CoreSYS.SYS", "AddUser", "添加用户信息", "username:用户名称,realname:真实名称,sys_js_uuid:角色id,sys_companys_nodeuuid:企业id,sys_companyorgs_nodeuuid:部门id", "返回添加是否成功");

三、调用指定应用模块函数

protected static bool CallJsonModeFunction(HttpContext ctx, string ClassFullName, string FunctionName, object m_InParame, bool bClient, out object m_OutParame, out string sError);

ClassFullName:应用模块类名

FunctionName:函数名称

m_InParame:输入参数

m_OutParame:输出参数

sError:错误描述

四、调用指定服务商的应用模块函数

protected static bool CallP2PModeFunction(HttpContext ctx, string ServerName, string ClassFullName, string FunctionName, object m_InParame, out object m_OutParame, out string sError);

ServerName:服务名称

ClassFullName:应用模块类名

FunctionName:函数名称

m_InParame:输入参数

m_OutParame:输出参数

sError:错误描述

五、发送邮件

protected static void SendMail(string recieveMail, string subject, string mailbody);

recieveMail:接收邮件地址

subject:邮件主题

mailbody:邮件内容

六、调用应用模块共享函数

public static bool RunShareFunction(HttpContext ctx, string ClassFullName, string FunctionName, out object m_outParame, object m_Parame);

ClassFullName:应用模块类名

FunctionName:函数名称

m_InParame:输入参数

m_OutParame:输出参数

耗时函数使用例子

[ModeMethod("{CanNoLogin:true,CanEnable:true,PoolWait:false}")]

static public ReturnJson HelloThreadWait(HttpContext ctx, Object m_Parame)

{

//要另辟线程处理必须设置配置文件PoolWait=false;

ReturnJson m_ReturnJson = new ReturnJson();

m_ReturnJson.bOK = true;

try

{

//启用耗时操作

SetAsyncWait(ctx);

Hashtable m_HH = new Hashtable();

m_HH.Add("ctx", ctx);

Thread m_Thread = new Thread(WaitThread);

m_Thread.Start(m_HH);

}

catch(Exception e)

{

m_ReturnJson.bOK = false;

m_ReturnJson.sMsg = e.ToString();

}

return m_ReturnJson;

}

static private void WaitThread(Object O)

{

Hashtable m_XX = (Hashtable)O;

HttpContext ctx =(HttpContext) m_XX["ctx"];

Hashtable m_HH = new Hashtable();

DateTime t = DateTime.Now;

string sBDay = t.Year.ToString() + "-" + t.Month.ToString() + "-" + t.Day.ToString() + " " + t.Hour.ToString() + ":" + t.Minute.ToString() + ":" + t.Second.ToString();

m_HH.Add("开始时间", sBDay);

Thread.Sleep(20*60 * 1000);//等待一分钟

t = DateTime.Now;

string sEDay = t.Year.ToString() + "-" + t.Month.ToString() + "-" + t.Day.ToString() + " " + t.Hour.ToString() + ":" + t.Minute.ToString() + ":" + t.Second.ToString();

m_HH.Add("结束时间", sEDay);

//完成耗时操作

ReturnAsync(ctx, m_HH);

}

调用webservice例子

public static object InvokeWebService(string url, string classname, string methodname, params object[] args);

WebServiceHelper.InvokeWebService(";, "Service1", "HelloWorld",5,6).ToString();

调用V8Engine

#region 调用V8引擎例子

static private string AA(int A, int B, string str)

{

ReturnJson m_ReturnJson = new ReturnJson();

m_ReturnJson.bOK = false;

str = HttpUtility.UrlDecode(str);

m_ReturnJson.sMsg = "获得个人资料失败";

return "乘以:" + (A * B).ToString() + ",车牌号码:川A 88888,传入的str:" + str;

}

static private string HelloWorld(int A, int B, string str)

{

return AA(A, B, str);

}

[ModeMethod("{CanNoLogin:true,CanEnable:true}")]

static public ReturnJson HelloJS(HttpContext ctx, Object m_Parame)

{

ReturnJson m_ReturnJson = new ReturnJson();

m_ReturnJson.bOK = true;

object m_V8 = LoadJSCode("");

object result = "1";

result = RunJSCode(m_V8, "MyJS(5,6,'" + HttpUtility.UrlEncode("English&Chinese你好啊") + "')");

result = HttpUtility.UrlDecode(result.ToString()).Replace("\u0026", "&");

string allstr = "MyJS:" + result + "\r\n";

result = RunJSCode(m_V8, "RunFrameFunction(5,6,'" + HttpUtility.UrlEncode("English&Chinese你好啊") + "')");

result = HttpUtility.UrlDecode(result.ToString()).Replace("\u0026", "&");

allstr += "RunFrameFunction:" + result;

m_ReturnJson.m_ReturnOBJ = allstr;

return m_ReturnJson;

}

[ModeMethod("{CanNoLogin:true,CanEnable:true}")]

static public ReturnJson HelloCHNJS(HttpContext ctx, Object m_Parame)

{

ReturnJson m_ReturnJson = new ReturnJson();

m_ReturnJson.bOK = true;

object m_V8 = LoadJSCode("");

object result = "1";

result = CHNRunJSCode(m_V8, "MyJS", 5, 6, "English&Chinese你好啊");

string allstr = "MyJS:" + result.ToString() + "\r\n";

result = CHNRunJSCode(m_V8, "RunFrameFunction", 5, 6, "English&Chinese你好啊");

allstr += "RunFrameFunction:" + result.ToString();

m_ReturnJson.m_ReturnOBJ = allstr;

return m_ReturnJson;

}

[ModeMethod("{CanNoLogin:true,CanEnable:true}")]

static public ReturnJson HelloJson(HttpContext ctx, Object m_Parame)

{

ReturnJson m_ReturnJson = new ReturnJson();

m_ReturnJson.bOK = true;

object m_V8 = LoadJSFile(m_JsonModePath, "js\\hellojson.js");

object result = "1";

Hashtable m_HH = new Hashtable();

m_HH.Add("A", 1);

m_HH.Add("B", 2);

m_HH.Add("C", "中华");

string str = JsonHelper.OBJToJsonStr(m_HH);

result = CHNRunJSCode(m_V8, "hello", str);

m_ReturnJson.m_ReturnOBJ = result;

return m_ReturnJson;

}

[ModeMethod("{CanNoLogin:true,CanEnable:true}")]

// //特别注意由JS返回带中文的串一定要用函数encodeURI(),在C#中使用 HttpUtility.UrlDecode提取

static public ReturnJson RunApplicationJS(HttpContext ctx, Object m_Parame)

{

ReturnJson m_ReturnJson = new ReturnJson();

m_ReturnJson.bOK = false;

object m_V8 = LoadJSCode("");

object result = "1";

result = RunJSCode(m_V8, "getFlatternDistance(31.14,121.29,43.45,87.36)");

m_ReturnJson.sMsg += " 距离:" + result.ToString();

return m_ReturnJson;

}

#endregion

七、Cookie相关函数

保存Cookie

protected static bool SaveCookie(HttpContext ctx, HttpCookie cookie);

cookie:要保存的HttpCookie

protected static bool SaveCookie(HttpContext ctx, string name, string value);

name:保存的cookie名

value:保存的cookie值

protected static bool SaveCookie(HttpContext ctx, string name, string value, TimeSpan m_T);

name:保存的cookie名

value:保存的cookie值

m_T:Cookie超时

protected static bool SaveCookieValue(HttpContext ctx, string sKey, Hashtable m_HH);

sKey:保存的cookie的名

m_HH:保存cookie的Hashtable数据

读取cookie

protected static string ReadCookie(HttpContext ctx, string name);

name:cookie的key名称

读取指定cookie的Hashtable

static protected Hashtable GetCookieValue(HttpContext ctx, string sKey)

清除cookie

static protected void ClearCookie(HttpContext ctx, string sKey)

八、缓存使用

全局缓存保存

protected static bool SaveCache<T>(HttpContext ctx, string sKey, T m_T, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

bSlidTime:是否启用时间滑动

protected static bool SaveCache<T>(HttpContext ctx, string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

m_nOverTime:缓存保存时间

bSlidTime:是否启用时间滑动

读取全局缓存

protected static bool ReadCache<T>(HttpContext ctx, string sKey, out T m_T, int nDelayMinute = -1);

sKey:缓存的键值名称

m_T:缓存数据

清除缓存

static protected bool ClearCache(HttpContext ctx,string sKey)

用户缓存使用

保存用户缓存数据

protected static bool SaveOnceUserCache<T>(HttpContext ctx, string sKey, T m_T, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

bSlidTime:是否启用时间滑动

protected static bool SaveOnceUserCache<T>(HttpContext ctx, string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

m_nOverTime:缓存保存时间

bSlidTime:是否启用时间滑动

protected static bool SaveUserCache<T>(HttpContext ctx, string sKey, T m_T, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

bSlidTime:是否启用时间滑动

protected static bool SaveUserCache<T>(HttpContext ctx, string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

m_nOverTime:缓存保存时间

bSlidTime:是否启用时间滑动

清除用户缓存

static protected bool ClearUserCache<T>(HttpContext ctx, string sKey)

用户共享数据

protected static bool SaveUserShareCache<T>(HttpContext ctx, string sKey, T m_T, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

bSlidTime:是否启用时间滑动

protected static bool SaveUserShareCache<T>(HttpContext ctx, string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime = true);

sKey:缓存的键值名称

m_T:缓存数据

m_nOverTime:缓存保存时间

bSlidTime:是否启用时间滑动

读取缓存

protected static bool ReadOnceUserCache<T>(HttpContext ctx, string sKey, out T m_T, int nDelayMinute = -1);

sKey:缓存的键值名称

m_T:缓存数据

nDelayMinutee:延迟分钟数

protected static bool ReadUserCache<T>(HttpContext ctx, string sKey, out T m_T, int nDelayMinute = -1);

sKey:缓存的键值名称

m_T:缓存数据

nDelayMinutee:延迟分钟数

protected static bool ReadUserShareCache<T>(HttpContext ctx, string sKey, out T m_T, int nDelayMinute = -1);

sKey:缓存的键值名称

m_T:缓存数据

nDelayMinutee:延迟分钟数

网络锁

static protected bool DCSLock(string KeyString,TimeSpan tWaitTime)

KeyString:锁名称

tWaitTime:锁等待时长

static protected bool DCSLock(string KeyString,TimeSpan tWaitTime,TimeSpan tKeepLiveTime)

KeyString:锁名称

tWaitTime:锁等待时长

tKeepLiveTime:保存活跃时长

取消锁定

static protected void DCSUnLock(string KeyString)

KeyString:锁名称

另一网络同步锁函数

static protected bool LKRunFunction(LockFunctionPTR m_LockFunctionPTR, Object m_LKOBJ,TimeSpan m_TimeSpan, Hashtable m_inHH,out Hashtable m_outHH)

public delegate bool LockFunctionPTR(Hashtable m_inHH,out Hashtable m_outHH);

m_LockFunctionPTR:同步函数

m_LKOBJ:锁定对象一般为串

m_TimeSpan:锁等待时间

m_inHH:输入参数

m_outHH:输出参数

九、敏感词过滤

判断是否有敏感词

static protected bool haveFilterWord(string sSourceInput)

sSourceInput:输入串

处理带敏感词串

static protected string getDataByFilter(string sSourceInput, char replaceChar)

sSourceInput:输入串

replaceChar:取代敏感词的串

十、重启服务

static protected void Restart(HttpContext ctx)

十一、权限判断

当前用户的权限

static protected ReturnJson HavePower(HttpContext ctx, string sClassFullName, string sFunctionName, bool bClient)

sClassFullName:类名

sFunctionName:函数名

bClient:客户端调用

判断指定角色权限

static protected ReturnJson HavePower(HttpContext ctx, string sys_js_uuid,string username,string sClassFullName, string sFunctionName, bool bClient)

sys_js_uuid:角色id

username:用户id

sClassFullName:类名

sFunctionName:函数名

bClient:客户端调用

十二、页面渲染

static protected string RenderPageView(HttpContext m_ctx, string m_ModePath, string m_TamplateCTL, Object m_Model)

m_ModePath:视所在位置

m_TamplateCTL:视名

m_Model:模板数据

其渲染的模板可以是传统aspx页面,也可以shtml使用JNTemplate渲染

使用aspx作为页面模板时,派生于XNWebEngine.JsonBase.MyBasePageView

<%@ Page Language="C#" AutoEventWireup="true" Inherits="XNWebEngine.JsonBase.MyBasePageView" %>

页面获得页面模型数据

<script language="C# " runat="server">

public Object getModel()

{

return this.Model;

}

</script>

<%

Object m_OO = getModel();

%>

MyBasePageView常用函数和参数

获得文件上传参数

static public OneUpFileWEB GetUpFileURL(HttpContext ctx)

读取cookie

static protected string ReadCookie(HttpContext ctx, string name)

static protected HttpCookie GetCookie(HttpContext ctx, string sKey)

获得当前登录信息

protected SessionLink GetSessionLink()

判断当前用户权限

public bool HavePower(string ClassFullName, string FunctionName, bool bClient, out string sError)

判断指定角色权限

public bool HavePower(string sys_js_uuid, string username, string ClassFullName, string FunctionName, bool bClient, out string sError)

调用指定应用模块函数

public bool CallModeFunction(string classfullname, string functionname, object m_InParame, out object m_OutParame, out string sError)

执行指定模块的函数返回HTML

public string RenderModeHTML(string classfullname, string functionname, object m_InParame)

保存cookie

protected bool SaveCookie(string name, string value)

读取cookie

protected string ReadCookie( string name)

#region 读写Cache

protected bool SaveCache<T>(string sKey, T m_T,bool bSlidTime=true)

protected bool ReadCache<T>(string sKey, out T m_T, int nDelayMinute = -1)

protected bool SaveCache<T>(string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime=true)

protected bool ClearCache(string sKey)

#endregion

#region 清除cookie

protected void ClearCookie(string sKey)

#endregion

其他

protected bool SaveCookie( string name, string value, TimeSpan m_T)

protected bool SaveUserShareCache<T>(string sKey, T m_T, bool bSlidTime=true)

protected bool SaveUserShareCache<T>(string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime=true)

protected bool ReadUserShareCache<T>(string sKey, out T m_T, int nDelayMinute = -1)

protected bool ClearUserShareCache<T>( string sKey)

protected bool SaveUserCache<T>(string sKey, T m_T, bool bSlidTime=true)

protected bool SaveUserCache<T>(string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime=true)

protected bool ReadUserCache<T>(string sKey, out T m_T, int nDelayMinute = -1)

protected bool ClearUserCache<T>(string sKey)

读取key

static protected string GetConfigKeyString(string sKeyName)

获得资源url

static protected string GetResourceUrl(HttpContext ctx)

获得页面前缀

static protected string GetUrlBefore(HttpContext ctx)

protected static string GetUrlHead(HttpContext ctx)

判断是否是PC端

protected bool IsPCClient()

判断是否HTTPS

protected bool IsHTTPS()

下集继续介绍BaseJsonMode

标签: #netaspx页面对象