/// <summary> /// Create the image by the valid code. /// </summary> /// <param name="validCode">the valid code.</param> /// <returns>the image of the valid code.</returns> public static Bitmap CreateImage(string validCode) { ThrowExceptionUtil.ArgumentNotNullOrEmpty(validCode, "validCode"); int iwidth = (int)(validCode.Length * 15); System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 25); using (Graphics g = Graphics.FromImage(image)) { g.Clear(Color.White); Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.SteelBlue, Color.Black, Color.Purple }; string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" }; Random rand = new Random(); for (int i = 0; i < 25; i++) { int x1 = rand.Next(image.Width); int x2 = rand.Next(image.Width); int y1 = rand.Next(image.Height); int y2 = rand.Next(image.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } for (int i = 0; i < validCode.Length; i++) { int cindex = rand.Next(7); int findex = rand.Next(5); Font f = new System.Drawing.Font(font[findex], 14, System.Drawing.FontStyle.Bold); Brush b = new System.Drawing.SolidBrush(c[cindex]); int ii = 2; if ((i + 1) % 2 == 0) { ii = 0; } g.DrawString(validCode.Substring(i, 1), f, b, (i * 13), ii); } for (int i = 0; i < 100; i++) { int x = rand.Next(image.Width); int y = rand.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(rand.Next())); } g.DrawRectangle(new Pen(Color.Black, 0), 0, 0, image.Width - 1, image.Height - 1); } return(image); }
internal static CheckMethodResult GetEntityMethodName(Type type, string methodName, BeeDataAdapter dataAdapter) { ThrowExceptionUtil.ArgumentNotNull(type, "type"); ThrowExceptionUtil.ArgumentNotNullOrEmpty(methodName, "methodName"); if (dataAdapter == null) { dataAdapter = new BeeDataAdapter(); } CheckMethodResult result = new CheckMethodResult(); MethodSchema methodSchema = null; List <MethodSchema> list = null; //lock (lockobject) { // 保证参数长的先被匹配 // 该方法本身就排过序了 list = EntityProxyManager.Instance.GetEntityMethods(type); foreach (MethodSchema item in list) { // Check the name of the method. if (string.Compare(item.Name, methodName, true) == 0) { if (CheckMethod(item, methodName, dataAdapter, out result.DataAdapter)) { methodSchema = item; break; } } } } if (methodSchema != null) { result.MethodName = methodSchema.MemberInfo.ToString(); } else { CoreException exception = new CoreException("Can not match a method for {0}.{1}\r\n".FormatWith(type.Name, methodName)); exception.ErrorCode = ErrorCode.MVCNoAction; throw exception; } return(result); }
/// <summary> /// Combine the path using the base directory of current AppDomain. /// </summary> /// <param name="relativePath">the relative path.</param> /// <returns>the combined path.</returns> public static string CombinePath(string relativePath) { ThrowExceptionUtil.ArgumentNotNullOrEmpty(relativePath, "relativePath"); return(Path.Combine(baseDirectory, relativePath)); }