using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.Security;using System.Web;using System.Web.UI;using CSharpLib.Entity;using System.IO;using System.Web.Script.Serialization;namespace CSharpLib.Common{ public class Utility { public static string Substring(string text, int index) { return text.Length > index ? text.Substring(0, index) + "..." : text; } public static WebSiteEntities OpenConnect() { return new WebSiteEntities(); } public static string Substring(string text, int index, string strEnding) { return text.Length > index ? text.Substring(0, index) + strEnding : text; } public static void MessageShow(Page pInstance, string msg) { ClientScriptManager csm = pInstance.ClientScript; csm.RegisterStartupScript(pInstance.GetType(), "message", ""); } public static void MessageShowUrl(Page pInstance, string strMessage, string strFileName) { ClientScriptManager csm = pInstance.ClientScript; string strContent = string.Format("", strMessage, strFileName); csm.RegisterStartupScript(pInstance.GetType(), "message", strContent); } public static string GetClientIP() { string result = String.Empty; result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (null == result || result == String.Empty) { result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (null == result || result == String.Empty) { result = HttpContext.Current.Request.UserHostAddress; } if (null == result || result == String.Empty) { return "0.0.0.0"; } return result; } public static string EncryptPassword(string strPassword) { return FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword, "sha1").Substring(0, 32).ToString(); } public static string JsonSerializer(object obj) { JavaScriptSerializer json = new JavaScriptSerializer(); return json.Serialize(obj); } public static void SendJson(string data) { HttpContext.Current.Response.Write(data); HttpContext.Current.Response.End(); } //public static ICacheManager GetCacheNode() //{ // return CacheFactory.GetCacheManager(); //} }}