コード例 #1
0
 public static string GetDateTimeLongString(string prefix)
 {
     if (string.IsNullOrEmpty(prefix))
     {
         prefix = string.Empty;
     }
     return(prefix + TextUtility.GetDateTimeLongString());
 }
コード例 #2
0
 public static int DiffDateDays(string oneDateTime)
 {
     if (string.IsNullOrEmpty(oneDateTime))
     {
         return(0);
     }
     return(TextUtility.DiffDateDays(DateTime.Parse(oneDateTime)));
 }
コード例 #3
0
 public static string JavaScriptEncode(object obj)
 {
     if (obj == null)
     {
         return(string.Empty);
     }
     return(TextUtility.JavaScriptEncode(obj.ToString()));
 }
コード例 #4
0
 public static string CutStringProlongSymbol(string originalVal, int cutLength)
 {
     if (originalVal.Length <= cutLength)
     {
         return(originalVal);
     }
     return(TextUtility.CutLeft(originalVal, cutLength) + TextUtility.PROLONG_SYMBOL);
 }
コード例 #5
0
 public static string CutStringProlongSymbol(string originalVal, int cutLength, string prolongSymbol)
 {
     if (string.IsNullOrEmpty(prolongSymbol))
     {
         prolongSymbol = TextUtility.PROLONG_SYMBOL;
     }
     return(TextUtility.CutLeft(originalVal, cutLength) + prolongSymbol);
 }
コード例 #6
0
ファイル: Terminator.cs プロジェクト: archangelwin/QY
        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();
        }
コード例 #7
0
ファイル: IPQuery.cs プロジェクト: toowind/QY
 static IPQuery( )
 {
     filePath    = TextUtility.GetFullPath(Utility.GetIPDbFilePath);
     fileIsExsit = FileManager.Exists(filePath, FsoMethod.File);
     if (!fileIsExsit)
     {
         throw new FrameworkExcption("IPdataFileNotExists");
     }
     pcz.SetDbFilePath(filePath);
 }
コード例 #8
0
        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)));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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());
        }
コード例 #12
0
ファイル: CtrlHelper.cs プロジェクト: bylu/baiyiWeb
 public static string GetText(HtmlInputControl valueCtrl)
 {
     if (valueCtrl == null)
     {
         throw new ArgumentNullException("获取文本内容的控件不能为空!");
     }
     if (TextUtility.EmptyTrimOrNull(valueCtrl.Value))
     {
         return("");
     }
     return(TextFilter.FilterScript(valueCtrl.Value.Trim()));
 }
コード例 #13
0
        public static string EmailEncode(string originalStr)
        {
            string text = TextUtility.TextEncode(originalStr).Replace("@", "&#64;").Replace(".", "&#46;");

            return(TextUtility.JoinString("<a href='mailto:", new string[]
            {
                text,
                "'>",
                text,
                "</a>"
            }));
        }
コード例 #14
0
ファイル: CtrlHelper.cs プロジェクト: bylu/baiyiWeb
 public static string GetText(ITextControl textCtrl)
 {
     if (textCtrl == null)
     {
         throw new ArgumentNullException("获取文本内容的控件不能为空!");
     }
     if (TextUtility.EmptyTrimOrNull(textCtrl.Text))
     {
         return("");
     }
     return(TextFilter.FilterScript(textCtrl.Text.Trim()));
 }
コード例 #15
0
 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);
 }
コード例 #16
0
ファイル: CtrlHelper.cs プロジェクト: bylu/baiyiWeb
 public static string GetText(HiddenField hiddenCtrl)
 {
     if (hiddenCtrl == null)
     {
         throw new ArgumentNullException("获取文本内容的控件不能为空!");
     }
     if (TextUtility.EmptyTrimOrNull(hiddenCtrl.Value))
     {
         return("");
     }
     return(TextFilter.FilterScript(hiddenCtrl.Value.Trim()));
 }
コード例 #17
0
ファイル: IPQuery.cs プロジェクト: JackYang3567/vs-asp-agent
 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);
 }
コード例 #18
0
        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)));
        }
コード例 #19
0
        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), "\\"));
        }
コード例 #20
0
        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()));
        }
コード例 #21
0
        /// <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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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());
        }
コード例 #24
0
 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);
     }
 }
コード例 #25
0
 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);
     }
 }
コード例 #26
0
 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("");
     }
 }
コード例 #27
0
 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("");
     }
 }
コード例 #28
0
ファイル: AES.cs プロジェクト: JackYang3567/vs-asp-agent
 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);
 }
コード例 #29
0
        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);
        }
コード例 #30
0
ファイル: Utility.cs プロジェクト: bylu/baiyiWeb
        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"));
        }