public static string GetDateTimeLongString(string prefix) { if (string.IsNullOrEmpty(prefix)) { prefix = string.Empty; } return(prefix + TextUtility.GetDateTimeLongString()); }
public static int DiffDateDays(string oneDateTime) { if (string.IsNullOrEmpty(oneDateTime)) { return(0); } return(TextUtility.DiffDateDays(DateTime.Parse(oneDateTime))); }
public static string JavaScriptEncode(object obj) { if (obj == null) { return(string.Empty); } return(TextUtility.JavaScriptEncode(obj.ToString())); }
public static string CutStringProlongSymbol(string originalVal, int cutLength) { if (originalVal.Length <= cutLength) { return(originalVal); } return(TextUtility.CutLeft(originalVal, cutLength) + TextUtility.PROLONG_SYMBOL); }
public static string CutStringProlongSymbol(string originalVal, int cutLength, string prolongSymbol) { if (string.IsNullOrEmpty(prolongSymbol)) { prolongSymbol = TextUtility.PROLONG_SYMBOL; } return(TextUtility.CutLeft(originalVal, cutLength) + prolongSymbol); }
public virtual void Throw(string message, string title, string links, string autojump, bool showback) { HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.AddHeader("Content-Type", "text/html"); StringBuilder builder = new StringBuilder(this.template); builder.Replace("{$Charset}", Encoding.UTF8.BodyName); builder.Replace("{$Message}", TextUtility.TextEncode(message)); builder.Replace("{$Title}", ((title == null) || (title == "")) ? "发生了系统错误, 错误信息已经被记录, 请联系管理员" : title); if ((links != null) && (links != "")) { string[] strArray = links.Split(new char[] { '|' }); for (int i = 0; i < strArray.Length; i++) { string[] strArray2 = strArray[i].Split(new char[] { ',' }); if (strArray2.Length > 1) { if (strArray2[1].Trim() == "RefHref") { strArray2[1] = Utility.Referrer; } if ((strArray2[1] != string.Empty) && (strArray2[1] != null)) { string str = "<a href='" + strArray2[1] + "'"; if (strArray2.Length == 3) { str = str + " target='" + strArray2[2].Trim() + "'"; } if (strArray2[0].Trim() == "RefText") { strArray2[0] = TextUtility.TextEncode(Utility.Referrer); } str = str + ">" + strArray2[0].Trim() + "</a>\r\n\t\t\t\t"; builder.Replace("{$Links}", str + "{$Links}"); } } } } if ((autojump != null) && (autojump != string.Empty)) { builder.Replace("{$AutoJump}", "<meta http-equiv='refresh' content='3; url=" + ((autojump == "back") ? "javascript:history.back()" : autojump) + "' />"); } else { builder.Replace("{$AutoJump}", "<!-- no jump -->"); } if (showback) { builder.Replace("{$Links}", "<a href='javascript:history.back()'>返回前一页</a>"); } else { builder.Replace("{$Links}", "<!-- no back -->"); } this.Echo(builder.ToString()); this.End(); }
static IPQuery( ) { filePath = TextUtility.GetFullPath(Utility.GetIPDbFilePath); fileIsExsit = FileManager.Exists(filePath, FsoMethod.File); if (!fileIsExsit) { throw new FrameworkExcption("IPdataFileNotExists"); } pcz.SetDbFilePath(filePath); }
public static string Encrypt(string plainText, string cipherkey) { cipherkey = TextUtility.CutLeft(cipherkey, 0x20); cipherkey = cipherkey.PadRight(0x20, ' '); ICryptoTransform transform = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 0x20)), IV = Keys }.CreateEncryptor(); byte[] bytes = Encoding.UTF8.GetBytes(plainText); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
public static byte[] EncryptBuffer(byte[] plainText, string cipherkey) { cipherkey = TextUtility.CutLeft(cipherkey, 0x20); cipherkey = cipherkey.PadRight(0x20, ' '); RijndaelManaged managed = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 0x20)), IV = Keys }; return(managed.CreateEncryptor().TransformFinalBlock(plainText, 0, plainText.Length)); }
public static byte[] EncryptBuffer(byte[] plainText, string cipherkey) { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 32)); rijndaelManaged.IV = Keys; RijndaelManaged rijndaelManaged2 = rijndaelManaged; return(rijndaelManaged2.CreateEncryptor().TransformFinalBlock(plainText, 0, plainText.Length)); }
public static string CreateRandomNum2(int len) { StringBuilder stringBuilder = new StringBuilder(); Random random = new Random(TextUtility.GetNewSeed()); for (int i = 0; i < len; i++) { int num = random.Next(); stringBuilder.Append((char)(48 + (ushort)(num % 10))); } return(stringBuilder.ToString()); }
public static string GetText(HtmlInputControl valueCtrl) { if (valueCtrl == null) { throw new ArgumentNullException("获取文本内容的控件不能为空!"); } if (TextUtility.EmptyTrimOrNull(valueCtrl.Value)) { return(""); } return(TextFilter.FilterScript(valueCtrl.Value.Trim())); }
public static string EmailEncode(string originalStr) { string text = TextUtility.TextEncode(originalStr).Replace("@", "@").Replace(".", "."); return(TextUtility.JoinString("<a href='mailto:", new string[] { text, "'>", text, "</a>" })); }
public static string GetText(ITextControl textCtrl) { if (textCtrl == null) { throw new ArgumentNullException("获取文本内容的控件不能为空!"); } if (TextUtility.EmptyTrimOrNull(textCtrl.Text)) { return(""); } return(TextFilter.FilterScript(textCtrl.Text.Trim())); }
public static bool InArray(string matchStr, string originalStr, string separator) { string[] array = TextUtility.SplitStrArray(originalStr, separator); for (int i = 0; i < array.Length; i++) { if (matchStr == array[i]) { return(true); } } return(false); }
public static string GetText(HiddenField hiddenCtrl) { if (hiddenCtrl == null) { throw new ArgumentNullException("获取文本内容的控件不能为空!"); } if (TextUtility.EmptyTrimOrNull(hiddenCtrl.Value)) { return(""); } return(TextFilter.FilterScript(hiddenCtrl.Value.Trim())); }
static IPQuery() { IPQuery.fileIsExsit = true; IPQuery.filePath = ""; IPQuery.pcz = new IPQuery.PHCZIP(); IPQuery.filePath = TextUtility.GetFullPath(Utility.GetIPDbFilePath); IPQuery.fileIsExsit = FileManager.Exists(IPQuery.filePath, FsoMethod.File); if (!IPQuery.fileIsExsit) { throw new FrameworkExcption("IPdataFileNotExists"); } IPQuery.pcz.SetDbFilePath(IPQuery.filePath); }
public static string Encrypt(string plainText, string cipherkey) { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 32)); rijndaelManaged.IV = Keys; ICryptoTransform cryptoTransform = rijndaelManaged.CreateEncryptor(); byte[] bytes = Encoding.UTF8.GetBytes(plainText); return(Convert.ToBase64String(cryptoTransform.TransformFinalBlock(bytes, 0, bytes.Length))); }
public static string GetMapPath(string folderPath) { if (folderPath.IndexOf(":\\") > 0) { return(TextUtility.AddLast(folderPath, "\\")); } if (folderPath.StartsWith("~/")) { return(TextUtility.AddLast(HttpContext.Current.Server.MapPath(folderPath), "\\")); } string str = HttpContext.Current.Request.ApplicationPath + "/"; return(TextUtility.AddLast(HttpContext.Current.Server.MapPath(str + folderPath), "\\")); }
public static string Encrypt(string encryptString, string encryptKey) { encryptKey = TextUtility.CutLeft(encryptKey, 8); encryptKey = encryptKey.PadRight(8, ' '); byte[] bytes = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); byte[] keys = Keys; byte[] buffer = Encoding.UTF8.GetBytes(encryptString); DESCryptoServiceProvider provider = new DESCryptoServiceProvider(); MemoryStream stream = new MemoryStream(); CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(bytes, keys), CryptoStreamMode.Write); stream2.Write(buffer, 0, buffer.Length); stream2.FlushFinalBlock(); return(Convert.ToBase64String(stream.ToArray())); }
/// <summary> /// 写日志文件 /// </summary> /// <param name="logContent">日志内容</param> /// <param name="fileName">日志文件名</param> /// <returns>返回值true成功,false失败</returns> public static bool Write(string logContent, string fileName) { bool flag = true; if (string.IsNullOrEmpty(fileName)) { fileName = "AppError"; } try { string str = Path.Combine(APP_LOG_DIRECTORY, DateTime.Now.ToString("yyyyMMdd") + fileName + LOG_SUFFIX); FileInfo info = new FileInfo(str); if (info.Exists && (info.Length >= 0xc3500L)) { info.CopyTo(str.Replace(LOG_SUFFIX, TextUtility.CreateRandomNum(5) + LOG_SUFFIX)); File.Delete(str); } FileStream stream = new FileStream(str, FileMode.Append, FileAccess.Write, FileShare.Read); StreamWriter writer = new StreamWriter(stream, Encoding.UTF8); StringBuilder builder = new StringBuilder(); builder.AppendFormat("{0:yyyy'/'MM'/'dd' 'HH':'mm':'ss}", DateTime.Now); builder.Append("|"); if (WRITE_APP_LOG) { builder.Append(logContent.Replace("\r", "").Replace("\n", "<br />")); builder.Append("|"); builder.Append(GameRequest.GetUserIP()); builder.Append("|"); builder.Append(GameRequest.GetUrl()); } else { builder.Append(logContent); } builder.Append("\r\n"); writer.Write(builder.ToString()); writer.Flush(); writer.Close(); writer.Dispose(); stream.Close(); stream.Dispose(); } catch { flag = false; } return(flag); }
public static bool Write(string logContent, string fileName) { bool result = true; if (string.IsNullOrEmpty(fileName)) { fileName = "AppError"; } try { string text = Path.Combine(TextLogger.APP_LOG_DIRECTORY, DateTime.Now.ToString("yyyyMMdd") + fileName + TextLogger.LOG_SUFFIX); FileInfo fileInfo = new FileInfo(text); if (fileInfo.Exists && fileInfo.Length >= 800000L) { fileInfo.CopyTo(text.Replace(TextLogger.LOG_SUFFIX, TextUtility.CreateRandomNum(5) + TextLogger.LOG_SUFFIX)); File.Delete(text); } FileStream fileStream = new FileStream(text, FileMode.Append, FileAccess.Write, FileShare.Read); StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("{0:yyyy'/'MM'/'dd' 'HH':'mm':'ss}", DateTime.Now); stringBuilder.Append("|"); if (TextLogger.WRITE_APP_LOG) { stringBuilder.Append(logContent.Replace("\r", "").Replace("\n", "<br />")); stringBuilder.Append("|"); stringBuilder.Append(GameRequest.GetUserIP()); stringBuilder.Append("|"); stringBuilder.Append(GameRequest.GetUrl()); } else { stringBuilder.Append(logContent); } stringBuilder.Append("\r\n"); streamWriter.Write(stringBuilder.ToString()); streamWriter.Flush(); streamWriter.Close(); streamWriter.Dispose(); fileStream.Close(); fileStream.Dispose(); } catch { result = false; } return(result); }
public static string CreateAuthStr(int len, bool onlyNum) { if (!onlyNum) { return(TextUtility.CreateAuthStr(len)); } StringBuilder stringBuilder = new StringBuilder(); Random random = new Random(); for (int i = 0; i < len; i++) { int num = random.Next(); stringBuilder.Append((char)(48 + (ushort)(num % 10))); } return(stringBuilder.ToString()); }
public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey) { try { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey); rijndaelManaged.IV = Keys; RijndaelManaged rijndaelManaged2 = rijndaelManaged; return(rijndaelManaged2.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length)); } catch { return(null); } }
public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey) { try { cipherkey = TextUtility.CutLeft(cipherkey, 0x20); cipherkey = cipherkey.PadRight(0x20, ' '); RijndaelManaged managed = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey), IV = Keys }; return(managed.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length)); } catch { return(null); } }
public static string Decrypt(string cipherText, string cipherkey) { try { cipherkey = TextUtility.CutLeft(cipherkey, 0x20); cipherkey = cipherkey.PadRight(0x20, ' '); ICryptoTransform transform = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey), IV = Keys }.CreateDecryptor(); byte[] inputBuffer = Convert.FromBase64String(cipherText); byte[] bytes = transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length); return(Encoding.UTF8.GetString(bytes)); } catch { return(""); } }
public static string Decrypt(string cipherText, string cipherkey) { try { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey); rijndaelManaged.IV = Keys; ICryptoTransform cryptoTransform = rijndaelManaged.CreateDecryptor(); byte[] array = Convert.FromBase64String(cipherText); byte[] bytes = cryptoTransform.TransformFinalBlock(array, 0, array.Length); return(Encoding.UTF8.GetString(bytes)); } catch { return(""); } }
public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey) { byte[] result; try { cipherkey = TextUtility.CutLeft(cipherkey, 32); cipherkey = cipherkey.PadRight(32, ' '); RijndaelManaged rijndaelManaged = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(cipherkey), IV = AES.Keys }; result = rijndaelManaged.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length); } catch { result = null; } return(result); }
public static string GetFullPath(string strPath) { string text = TextUtility.AddLast(AppDomain.CurrentDomain.BaseDirectory, "\\"); if (strPath.IndexOf(":") < 0) { string text2 = strPath.Replace("..\\", ""); if (text2 != strPath) { int num = (strPath.Length - text2.Length) / "..\\".Length + 1; for (int i = 0; i < num; i++) { text = text.Substring(0, text.LastIndexOf("\\")); } text2 = "\\" + text2; } strPath = text + text2; } return(strPath); }
public static string[] SearchUTF8File(string directory) { StringBuilder builder = new StringBuilder(); FileInfo[] files = new DirectoryInfo(directory).GetFiles(); for (int i = 0; i < files.Length; i++) { if (files[i].Extension.ToLower().Equals(".htm")) { FileStream sbInputStream = new FileStream(files[i].FullName, FileMode.Open, FileAccess.Read); bool flag = IsUTF8(sbInputStream); sbInputStream.Close(); if (!flag) { builder.Append(files[i].FullName); builder.Append("\r\n"); } } } return(TextUtility.SplitStrArray(builder.ToString(), "\r\n")); }