diff --git a/Lazy.Captcha.Core/CaptchaBuilder.cs b/Lazy.Captcha.AspNetCore/AspNetCore/CaptchaBuilder.cs similarity index 92% rename from Lazy.Captcha.Core/CaptchaBuilder.cs rename to Lazy.Captcha.AspNetCore/AspNetCore/CaptchaBuilder.cs index 8459ddc8c8785fa3f252716ab6169296d2c3afab..03c9b0ae30ad7dc62b06e3f51abfceeb7b68f5ef 100644 --- a/Lazy.Captcha.Core/CaptchaBuilder.cs +++ b/Lazy.Captcha.AspNetCore/AspNetCore/CaptchaBuilder.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Lazy.Captcha.Core +namespace Lazy.Captcha.AspNetCore { internal class CaptchaBuilder : ICaptchaBuilder { diff --git a/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs b/Lazy.Captcha.AspNetCore/AspNetCore/CaptchaServiceCollectionExtensions.cs similarity index 92% rename from Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs rename to Lazy.Captcha.AspNetCore/AspNetCore/CaptchaServiceCollectionExtensions.cs index b164e63d4c9f37f33dfe9fe871c371a2eaa22d46..5226f09957402ac0e231d5bc823bb3ba78272ab6 100644 --- a/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs +++ b/Lazy.Captcha.AspNetCore/AspNetCore/CaptchaServiceCollectionExtensions.cs @@ -1,29 +1,27 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.IO; using System.Linq; using Lazy.Captcha.Core; -using Lazy.Captcha.Core.Storage; -using Lazy.Captcha.Core.Storeage; +using Lazy.Captcha.Storage; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using SkiaSharp; -namespace Microsoft.Extensions.DependencyInjection +namespace Lazy.Captcha.AspNetCore { public static class CaptchaServiceCollectionExtensions { public static IServiceCollection AddCaptcha(this IServiceCollection services) { - return AddCaptcha(services, null); + return services.AddCaptcha(null); } public static IServiceCollection AddCaptcha(this IServiceCollection services, Action optionsAction) { var factory = services.FirstOrDefault(p => p.ServiceType == typeof(IConfiguration)); IConfiguration configuration = (IConfiguration)factory.ImplementationFactory(null); - return AddCaptcha(services, configuration, optionsAction); + return services.AddCaptcha(configuration, optionsAction); } public static IServiceCollection AddCaptcha(this IServiceCollection services, IConfiguration configuration, Action optionsAction = null) diff --git a/Lazy.Captcha.Core/DefaultCaptcha.cs b/Lazy.Captcha.AspNetCore/AspNetCore/DefaultCaptcha.cs similarity index 91% rename from Lazy.Captcha.Core/DefaultCaptcha.cs rename to Lazy.Captcha.AspNetCore/AspNetCore/DefaultCaptcha.cs index 4dd6b6b18444a7815d0758c2a798deae7406f07d..e23fb0200e79904f472f952424fd9ef0d6c67af8 100644 --- a/Lazy.Captcha.Core/DefaultCaptcha.cs +++ b/Lazy.Captcha.AspNetCore/AspNetCore/DefaultCaptcha.cs @@ -1,14 +1,11 @@ +using System; +using Lazy.Captcha.Core; using Lazy.Captcha.Core.Generator.Code; using Lazy.Captcha.Core.Generator.Image; -using Lazy.Captcha.Core.Storage; +using Lazy.Captcha.Storage; using Microsoft.Extensions.Options; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Lazy.Captcha.Core +namespace Lazy.Captcha.AspNetCore { public class DefaultCaptcha : ICaptcha { @@ -66,7 +63,7 @@ namespace Lazy.Captcha.Core !string.IsNullOrWhiteSpace(val) && string.Equals(val, code, comparisonType); - if ((!success && removeIfFail) || (success && removeIfSuccess)) + if(!success && removeIfFail || success && removeIfSuccess) { _storage.Remove(captchaId); } diff --git a/Lazy.Captcha.Core/ICaptchaBuilder.cs b/Lazy.Captcha.AspNetCore/AspNetCore/ICaptchaBuilder.cs similarity index 88% rename from Lazy.Captcha.Core/ICaptchaBuilder.cs rename to Lazy.Captcha.AspNetCore/AspNetCore/ICaptchaBuilder.cs index eb1850abfd2a202e001ed8091fff6073f77bfcb6..b0e63f73ca18aada08a4d97f1d0d7e11c3765bdd 100644 --- a/Lazy.Captcha.Core/ICaptchaBuilder.cs +++ b/Lazy.Captcha.AspNetCore/AspNetCore/ICaptchaBuilder.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Lazy.Captcha.Core +namespace Lazy.Captcha.AspNetCore { public interface ICaptchaBuilder { diff --git a/Lazy.Captcha.AspNetCore/Lazy.Captcha.AspNetCore.csproj b/Lazy.Captcha.AspNetCore/Lazy.Captcha.AspNetCore.csproj new file mode 100644 index 0000000000000000000000000000000000000000..ae0b5d086c9bf89ea4d3d34b61ed6f16a9ec3d93 --- /dev/null +++ b/Lazy.Captcha.AspNetCore/Lazy.Captcha.AspNetCore.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.0 + Lazy.Captcha + + + + + + + + + + + + + + diff --git a/Lazy.Captcha.Core/Storage/DefaultStorage.cs b/Lazy.Captcha.AspNetCore/Storage/DefaultStorage.cs similarity index 87% rename from Lazy.Captcha.Core/Storage/DefaultStorage.cs rename to Lazy.Captcha.AspNetCore/Storage/DefaultStorage.cs index f93d0f7bddee62bbe2b69410c2dd0a637e5362eb..3ce02c187319def3bfaf5d1e6170487e153accbe 100644 --- a/Lazy.Captcha.Core/Storage/DefaultStorage.cs +++ b/Lazy.Captcha.AspNetCore/Storage/DefaultStorage.cs @@ -1,9 +1,9 @@ using System; -using Lazy.Captcha.Core.Storage; +using Lazy.Captcha.Core; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; -namespace Lazy.Captcha.Core.Storeage +namespace Lazy.Captcha.Storage { public class DefaultStorage : IStorage { @@ -18,7 +18,7 @@ namespace Lazy.Captcha.Core.Storeage private string WrapKey(string key) { - return $"{this._options.CurrentValue.StoreageKeyPrefix}{key}"; + return $"{_options.CurrentValue.StoreageKeyPrefix}{key}"; } public string Get(string key) diff --git a/Lazy.Captcha.Core/CaptchaData.cs b/Lazy.Captcha.Core/Core/CaptchaData.cs similarity index 81% rename from Lazy.Captcha.Core/CaptchaData.cs rename to Lazy.Captcha.Core/Core/CaptchaData.cs index 31664ffef547dbe3be46d5cd232c58adc554eb19..583f32c6ee051db4e84319a1f21d8a1591ede2e3 100644 --- a/Lazy.Captcha.Core/CaptchaData.cs +++ b/Lazy.Captcha.Core/Core/CaptchaData.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Lazy.Captcha.Core { diff --git a/Lazy.Captcha.Core/CaptchaHelper.cs b/Lazy.Captcha.Core/Core/CaptchaHelper.cs similarity index 87% rename from Lazy.Captcha.Core/CaptchaHelper.cs rename to Lazy.Captcha.Core/Core/CaptchaHelper.cs index 32641b9152ca7188b8be52da182cefd785816bef..d5b0d3798b228f7e0c73814829c7e981ff5dde54 100644 --- a/Lazy.Captcha.Core/CaptchaHelper.cs +++ b/Lazy.Captcha.Core/Core/CaptchaHelper.cs @@ -1,10 +1,4 @@ -using Lazy.Captcha.Core.Generator.Code; -using Lazy.Captcha.Core.Generator.Image; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Lazy.Captcha.Core +namespace Lazy.Captcha.Core { /// /// 验证码帮助类 diff --git a/Lazy.Captcha.Core/CaptchaOptions.cs b/Lazy.Captcha.Core/Core/CaptchaOptions.cs similarity index 97% rename from Lazy.Captcha.Core/CaptchaOptions.cs rename to Lazy.Captcha.Core/Core/CaptchaOptions.cs index fd93a852671819558af8f673eeb118aad20035d7..553f61cd49dd5de81943f60956a0c9d61fb83dc9 100644 --- a/Lazy.Captcha.Core/CaptchaOptions.cs +++ b/Lazy.Captcha.Core/Core/CaptchaOptions.cs @@ -1,4 +1,4 @@ -using Lazy.Captcha.Core.Generator; +using Lazy.Captcha.Core.Generator.Extensions; using Lazy.Captcha.Core.Generator.Image.Option; namespace Lazy.Captcha.Core diff --git a/Lazy.Captcha.Core/CaptchaService.cs b/Lazy.Captcha.Core/Core/CaptchaService.cs similarity index 98% rename from Lazy.Captcha.Core/CaptchaService.cs rename to Lazy.Captcha.Core/Core/CaptchaService.cs index 607d73d50395a56d5dc5ee0d09cab5bf742defa7..98fa4e9784a47fb63a3f5d8b7016f59addce7003 100644 --- a/Lazy.Captcha.Core/CaptchaService.cs +++ b/Lazy.Captcha.Core/Core/CaptchaService.cs @@ -1,7 +1,7 @@ using System; using Lazy.Captcha.Core.Generator.Code; using Lazy.Captcha.Core.Generator.Image; -using Lazy.Captcha.Core.Storage; +using Lazy.Captcha.Storage; namespace Lazy.Captcha.Core { diff --git a/Lazy.Captcha.Core/CaptchaServiceBuilder.cs b/Lazy.Captcha.Core/Core/CaptchaServiceBuilder.cs similarity index 98% rename from Lazy.Captcha.Core/CaptchaServiceBuilder.cs rename to Lazy.Captcha.Core/Core/CaptchaServiceBuilder.cs index 82b610a2dc17484e4a76582ae9a8161987d96190..216fe9778590b355d98ff937e3f8b5be9ba7b4c4 100644 --- a/Lazy.Captcha.Core/CaptchaServiceBuilder.cs +++ b/Lazy.Captcha.Core/Core/CaptchaServiceBuilder.cs @@ -1,9 +1,6 @@ -using Lazy.Captcha.Core.Generator; -using Lazy.Captcha.Core.Storage; +using System.Collections.Generic; +using Lazy.Captcha.Storage; using SkiaSharp; -using System; -using System.Collections.Generic; -using System.Text; namespace Lazy.Captcha.Core { diff --git a/Lazy.Captcha.Core/CaptchaType.cs b/Lazy.Captcha.Core/Core/CaptchaType.cs similarity index 69% rename from Lazy.Captcha.Core/CaptchaType.cs rename to Lazy.Captcha.Core/Core/CaptchaType.cs index 9228795fccee38ced2e187f24fa0821950c94f26..af83d9de237fbce9e519ec4572af3281df20ec5e 100644 --- a/Lazy.Captcha.Core/CaptchaType.cs +++ b/Lazy.Captcha.Core/Core/CaptchaType.cs @@ -1,71 +1,65 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Lazy.Captcha.Core.Generator +namespace Lazy.Captcha.Core { public enum CaptchaType { /// /// 默认(英文字符大小写,数字混合) /// - DEFAULT=0, + DEFAULT = 0, /// /// 中文 /// - CHINESE=1, + CHINESE = 1, /// /// 数字 /// - NUMBER=2, + NUMBER = 2, /// /// 中文数字小写 /// - NUMBER_ZH_CN=3, + NUMBER_ZH_CN = 3, /// /// 中文数字大写 /// - NUMBER_ZH_HK=4, + NUMBER_ZH_HK = 4, /// /// 英文字符大小写混合 /// - WORD=5, + WORD = 5, /// /// 英文字符小写 /// - WORD_LOWER=6, + WORD_LOWER = 6, /// /// 英文字符大写 /// - WORD_UPPER=7, + WORD_UPPER = 7, /// /// 英文小写,数字混合 /// - WORD_NUMBER_LOWER=8, + WORD_NUMBER_LOWER = 8, /// /// 英文大写,数字混合 /// - WORD_NUMBER_UPPER=9, + WORD_NUMBER_UPPER = 9, /// /// 数字计算 /// - ARITHMETIC=10, + ARITHMETIC = 10, /// /// 数字计算,中文 /// - ARITHMETIC_ZH=11 + ARITHMETIC_ZH = 11 } } \ No newline at end of file diff --git a/Lazy.Captcha.Core/DefaultColors.cs b/Lazy.Captcha.Core/Core/DefaultColors.cs similarity index 83% rename from Lazy.Captcha.Core/DefaultColors.cs rename to Lazy.Captcha.Core/Core/DefaultColors.cs index 0a0d8aa35ffced3c7656ce504b97dda28c2370df..9953ee842432d82b6a01124f5bd1dbb12aae54ca 100644 --- a/Lazy.Captcha.Core/DefaultColors.cs +++ b/Lazy.Captcha.Core/Core/DefaultColors.cs @@ -1,9 +1,5 @@ -using SkiaSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; +using SkiaSharp; namespace Lazy.Captcha.Core { diff --git a/Lazy.Captcha.Core/DefaultFontFamilys.cs b/Lazy.Captcha.Core/Core/DefaultFontFamilys.cs similarity index 100% rename from Lazy.Captcha.Core/DefaultFontFamilys.cs rename to Lazy.Captcha.Core/Core/DefaultFontFamilys.cs diff --git a/Lazy.Captcha.Core/Generator/Code/Characters.cs b/Lazy.Captcha.Core/Core/Generator/Code/Characters.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Code/Characters.cs rename to Lazy.Captcha.Core/Core/Generator/Code/Characters.cs diff --git a/Lazy.Captcha.Core/Generator/Code/DefaultCaptchaCodeGenerator.cs b/Lazy.Captcha.Core/Core/Generator/Code/DefaultCaptchaCodeGenerator.cs similarity index 91% rename from Lazy.Captcha.Core/Generator/Code/DefaultCaptchaCodeGenerator.cs rename to Lazy.Captcha.Core/Core/Generator/Code/DefaultCaptchaCodeGenerator.cs index b6939fdb87faa1634ee4ee351f687cd6c2dbd836..6c740ba915597b671e5887d7f4c59d9bac9c0201 100644 --- a/Lazy.Captcha.Core/Generator/Code/DefaultCaptchaCodeGenerator.cs +++ b/Lazy.Captcha.Core/Core/Generator/Code/DefaultCaptchaCodeGenerator.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Threading; +using Lazy.Captcha.Core; namespace Lazy.Captcha.Core.Generator.Code { @@ -58,19 +59,19 @@ namespace Lazy.Captcha.Core.Generator.Code /// (渲染文本,code) public (string renderText, string code) Generate(int length) { - if (_captchaType == CaptchaType.ARITHMETIC) + if(_captchaType == CaptchaType.ARITHMETIC) { return GenerateaArithmetic(length); } - else if (_captchaType == CaptchaType.ARITHMETIC_ZH) + else if(_captchaType == CaptchaType.ARITHMETIC_ZH) { return GenerateaArithmeticZh(length); } - else if (_captchaType == CaptchaType.NUMBER_ZH_CN) + else if(_captchaType == CaptchaType.NUMBER_ZH_CN) { return GenerateaNumberZH(length, false); } - else if (_captchaType == CaptchaType.NUMBER_ZH_HK) + else if(_captchaType == CaptchaType.NUMBER_ZH_HK) { return GenerateaNumberZH(length, true); } @@ -88,7 +89,7 @@ namespace Lazy.Captcha.Core.Generator.Code var sb2 = new StringBuilder(); var characters = isHk ? Characters.NUMBER_ZH_HK : Characters.NUMBER_ZH_CN; - for (var i = 0; i < length; i++) + for(var i = 0; i < length; i++) { var num = random.Next(characters.Count); sb1.Append(characters[num]); @@ -122,7 +123,7 @@ namespace Lazy.Captcha.Core.Generator.Code var result = random.Next(max); var number1 = random.Next(max); - if (number1 > result) + if(number1 > result) return (number1, '-', number1 - result, result); else return (number1, '+', result - number1, result); @@ -154,11 +155,11 @@ namespace Lazy.Captcha.Core.Generator.Code { var (renderText, code) = GenerateaArithmetic(length); var sb = new StringBuilder(renderText.Length); - foreach (var item in renderText) + foreach(var item in renderText) { - if (item is >= '0' and <= '9') + if(item is >= '0' and <= '9') sb.Append(Characters.NUMBER_ZH_CN[item - '0']); - else if (item is '+' or '-') + else if(item is '+' or '-') sb.Append(OPERATOR_MAP[item]); else sb.Append(item); @@ -177,7 +178,7 @@ namespace Lazy.Captcha.Core.Generator.Code { var result = new StringBuilder(); - for (var i = 0; i < count; i++) + for(var i = 0; i < count; i++) { result.Append(characters[random.Next(characters.Count)]); } diff --git a/Lazy.Captcha.Core/Generator/Code/ExpressionEvaluator.cs b/Lazy.Captcha.Core/Core/Generator/Code/ExpressionEvaluator.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Code/ExpressionEvaluator.cs rename to Lazy.Captcha.Core/Core/Generator/Code/ExpressionEvaluator.cs diff --git a/Lazy.Captcha.Core/Generator/Code/ICaptchaCodeGenerator.cs b/Lazy.Captcha.Core/Core/Generator/Code/ICaptchaCodeGenerator.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Code/ICaptchaCodeGenerator.cs rename to Lazy.Captcha.Core/Core/Generator/Code/ICaptchaCodeGenerator.cs diff --git a/Lazy.Captcha.Core/Generator/Extensions/ByteExtensions.cs b/Lazy.Captcha.Core/Core/Generator/Extensions/ByteExtensions.cs similarity index 87% rename from Lazy.Captcha.Core/Generator/Extensions/ByteExtensions.cs rename to Lazy.Captcha.Core/Core/Generator/Extensions/ByteExtensions.cs index 93804063a801de5e4ed9427c689a7f5aafcb9f67..6327d4767f9eba99d40792266a9dd5f8089b496f 100644 --- a/Lazy.Captcha.Core/Generator/Extensions/ByteExtensions.cs +++ b/Lazy.Captcha.Core/Core/Generator/Extensions/ByteExtensions.cs @@ -5,12 +5,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Lazy.Captcha.Core +namespace Lazy.Captcha.Core.Generator.Extensions { public static class ByteExtensions { public static Stream ToStream(this byte[] bytes) - { + { return new MemoryStream(bytes); } diff --git a/Lazy.Captcha.Core/Generator/Extensions/CaptchaTypeExtensions.cs b/Lazy.Captcha.Core/Core/Generator/Extensions/CaptchaTypeExtensions.cs similarity index 85% rename from Lazy.Captcha.Core/Generator/Extensions/CaptchaTypeExtensions.cs rename to Lazy.Captcha.Core/Core/Generator/Extensions/CaptchaTypeExtensions.cs index bd58954066fb083563518400e6f7929b96429be9..3ae900f46e493477ffd6551c05da10920f234dcb 100644 --- a/Lazy.Captcha.Core/Generator/Extensions/CaptchaTypeExtensions.cs +++ b/Lazy.Captcha.Core/Core/Generator/Extensions/CaptchaTypeExtensions.cs @@ -1,11 +1,12 @@ -using Lazy.Captcha.Core.Generator.Code; +using Lazy.Captcha.Core; +using Lazy.Captcha.Core.Generator.Code; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Lazy.Captcha.Core.Generator +namespace Lazy.Captcha.Core.Generator.Extensions { public static class CaptchaTypeExtensions { diff --git a/Lazy.Captcha.Core/Generator/Image/DefaultCaptchaImageGenerator.cs b/Lazy.Captcha.Core/Core/Generator/Image/DefaultCaptchaImageGenerator.cs similarity index 90% rename from Lazy.Captcha.Core/Generator/Image/DefaultCaptchaImageGenerator.cs rename to Lazy.Captcha.Core/Core/Generator/Image/DefaultCaptchaImageGenerator.cs index 29c4d8293e43b9962a8bd06962b51e37b0baf9ce..eae9c0f02a957d162cb29eb4202c59ff81ec4c49 100644 --- a/Lazy.Captcha.Core/Generator/Image/DefaultCaptchaImageGenerator.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/DefaultCaptchaImageGenerator.cs @@ -38,10 +38,10 @@ namespace Lazy.Captcha.Core.Generator.Image { var result = new List(); - if (colors.Count() < count) + if(colors.Count() < count) { // 可重复选择 - for (var i = 0; i < count; i++) + for(var i = 0; i < count; i++) { result.Add(RandomColor(colors)); } @@ -50,7 +50,7 @@ namespace Lazy.Captcha.Core.Generator.Image { // 不重复选择 var pickIndexs = Enumerable.Range(0, colors.Count()).ToList(); - for (var i = 0; i < count; i++) + for(var i = 0; i < count; i++) { var selectedIndex = Random.Next(pickIndexs.Count()); result.Add(colors.ElementAt(pickIndexs[selectedIndex])); @@ -75,7 +75,7 @@ namespace Lazy.Captcha.Core.Generator.Image { var result = new List(); - for (var i = 0; i < count; i++) + for(var i = 0; i < count; i++) { var radius = Random.Next(minRadius, maxRadius + 1); var cx = Random.Next(width - 25) + radius; @@ -102,7 +102,7 @@ namespace Lazy.Captcha.Core.Generator.Image { graphicDescriptions.ForEach(gd => { - using (var paint = new SKPaint()) + using(var paint = new SKPaint()) { paint.IsAntialias = true; paint.StrokeWidth = gd.Thickness; @@ -135,7 +135,7 @@ namespace Lazy.Captcha.Core.Generator.Image { var result = new List(); - for (var i = 0; i < count; i++) + for(var i = 0; i < count; i++) { var leftInBottom = Random.Next(2) == 0; int x1 = 5, y1 = leftInBottom ? Random.Next(height / 2, height - 5) : Random.Next(5, height / 2); @@ -165,14 +165,14 @@ namespace Lazy.Captcha.Core.Generator.Image { graphicDescriptions.ForEach(gd => { - using (var paint = new SKPaint()) + using(var paint = new SKPaint()) { paint.IsAntialias = true; paint.StrokeWidth = 1; paint.Style = SKPaintStyle.Stroke; paint.Color = gd.Color.WithAlpha((byte)(255 * gd.BlendPercentage)); - using (var path = new SKPath()) + using(var path = new SKPath()) { path.MoveTo(gd.Start); path.CubicTo(gd.Ctrl1, gd.Ctrl2, gd.End); @@ -209,7 +209,7 @@ namespace Lazy.Captcha.Core.Generator.Image var textPositions = MeasureTextPositions(width, height, text, font, fontSize); var colors = RandomColor(foregroundColors, text.Count()); - for (var i = 0; i < text.Count(); i++) + for(var i = 0; i < text.Count(); i++) { result.Add(new TextGraphicDescription { @@ -234,7 +234,7 @@ namespace Lazy.Captcha.Core.Generator.Image { graphicDescriptions.ForEach(gd => { - using (var paint = new SKPaint()) + using(var paint = new SKPaint()) { paint.StrokeWidth = 1; paint.TextSize = gd.FontSize; @@ -269,7 +269,7 @@ namespace Lazy.Captcha.Core.Generator.Image /// 返回每个字符的位置 public virtual List MeasureTextPositions(int width, int height, string text, SKTypeface font, float fontSize) { - using (var paint = new SKPaint()) + using(var paint = new SKPaint()) { paint.StrokeWidth = 1; paint.TextSize = fontSize; @@ -277,11 +277,11 @@ namespace Lazy.Captcha.Core.Generator.Image paint.Typeface = font; var result = new List(); - if (string.IsNullOrWhiteSpace(text)) return result; + if(string.IsNullOrWhiteSpace(text)) return result; // 计算每个字符宽度 var charWidths = new List(); - foreach (var s in text) + foreach(var s in text) { var charWidth = paint.MeasureText(s.ToString()); charWidths.Add(charWidth); @@ -297,7 +297,7 @@ namespace Lazy.Captcha.Core.Generator.Image paint.MeasureText(text, ref textBounds); var fontHeight = (int)textBounds.Height; - for (var i = 0; i < text.Count(); i++) + for(var i = 0; i < text.Count(); i++) { // 根据文字宽度比例,计算文字包含框宽度 var wrapperWidth = charWidths[i] * 1.0f / charTotalWidth * width; @@ -321,7 +321,7 @@ namespace Lazy.Captcha.Core.Generator.Image /// public virtual byte[] Generate(string text, CaptchaImageGeneratorOption option) { - if (option.Animation) + if(option.Animation) { return GenerateAnimation(text, option); } @@ -333,9 +333,9 @@ namespace Lazy.Captcha.Core.Generator.Image private byte[] GenerateNormal(string text, CaptchaImageGeneratorOption option) { - using (var bitmap = new SKBitmap(option.Width, option.Height, false)) + using(var bitmap = new SKBitmap(option.Width, option.Height, false)) { - using (var canvas = new SKCanvas(bitmap)) + using(var canvas = new SKCanvas(bitmap)) { // 绘制背景色 canvas.DrawColor(option.BackgroundColor); @@ -346,7 +346,7 @@ namespace Lazy.Captcha.Core.Generator.Image // 绘制文字 DrawTexts(canvas, text, option); - using (var p = bitmap.Encode(SKEncodedImageFormat.Jpeg, option.Quality)) + using(var p = bitmap.Encode(SKEncodedImageFormat.Jpeg, option.Quality)) { return p.ToArray(); } @@ -366,7 +366,7 @@ namespace Lazy.Captcha.Core.Generator.Image var num = frameIndex + textIndex; var r = (float)1 / (len - 1); var s = len * r; - return num >= len ? (num * r - s) : num * r; + return num >= len ? num * r - s : num * r; } /// @@ -393,25 +393,25 @@ namespace Lazy.Captcha.Core.Generator.Image //-1:no repeat,0:always repeat gifEncoder.SetRepeat(0); - for (var i = 0; i < text.Length; i++) + for(var i = 0; i < text.Length; i++) { // 调整透明度 - for (var j = 0; j < texGraphicDescriptions.Count; j++) + for(var j = 0; j < texGraphicDescriptions.Count; j++) { texGraphicDescriptions[j].BlendPercentage = GenerateBlendPercentage(i, j, text.Length); } - for (var j = 0; j < interferenceLineGraphicDescriptions.Count; j++) + for(var j = 0; j < interferenceLineGraphicDescriptions.Count; j++) { interferenceLineGraphicDescriptions[j].BlendPercentage = 0.7f; } - for (var j = 0; j < bubbleGraphicDescriptions.Count; j++) + for(var j = 0; j < bubbleGraphicDescriptions.Count; j++) { bubbleGraphicDescriptions[j].BlendPercentage = Random.Next(10) * 0.1f; } - using (var bitmap = new SKBitmap(option.Width, option.Height, false)) + using(var bitmap = new SKBitmap(option.Width, option.Height, false)) { - using (var canvas = new SKCanvas(bitmap)) + using(var canvas = new SKCanvas(bitmap)) { // 绘制背景色 canvas.DrawColor(option.BackgroundColor); @@ -422,9 +422,9 @@ namespace Lazy.Captcha.Core.Generator.Image // 绘制文字 DrawTexts(canvas, texGraphicDescriptions); - using (var skData = bitmap.Encode(SKEncodedImageFormat.Jpeg, option.Quality)) + using(var skData = bitmap.Encode(SKEncodedImageFormat.Jpeg, option.Quality)) { - using (var image = SKImage.FromEncodedData(skData)) + using(var image = SKImage.FromEncodedData(skData)) { gifEncoder.AddFrame(image); } diff --git a/Lazy.Captcha.Core/Generator/Image/Gif/AnimatedGifEncoder.cs b/Lazy.Captcha.Core/Core/Generator/Image/Gif/AnimatedGifEncoder.cs similarity index 91% rename from Lazy.Captcha.Core/Generator/Image/Gif/AnimatedGifEncoder.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Gif/AnimatedGifEncoder.cs index 41acf059effca12c764f0036ebc21364d19f2bd5..bb351fa8f2961dd3591e24bda99e6ccf4edb1d45 100644 --- a/Lazy.Captcha.Core/Generator/Image/Gif/AnimatedGifEncoder.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/Gif/AnimatedGifEncoder.cs @@ -105,7 +105,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public void SetDispose(int code) { - if (code >= 0) + if(code >= 0) { dispose = code; } @@ -122,7 +122,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public void SetRepeat(int iter) { - if (iter >= 0) + if(iter >= 0) { repeat = iter; } @@ -156,14 +156,14 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public bool AddFrame(SKImage im) { - if ((im == null) || !started) + if(im == null || !started) { return false; } bool ok = true; try { - if (!sizeSet) + if(!sizeSet) { // use first frame's size SetSize(im.Width, im.Height); @@ -171,11 +171,11 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif image = im; GetImagePixels(); // convert to correct format if necessary AnalyzePixels(); // build color table & map pixels - if (firstFrame) + if(firstFrame) { WriteLSD(); // logical screen descriptior WritePalette(); // global color table - if (repeat >= 0) + if(repeat >= 0) { // use NS app extension to indicate reps WriteNetscapeExt(); @@ -183,14 +183,14 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif } WriteGraphicCtrlExt(); // write graphic control extension WriteImageDesc(); // image descriptor - if (!firstFrame) + if(!firstFrame) { WritePalette(); // local color table } WritePixels(); // encode and write pixel data firstFrame = false; } - catch (IOException) + catch(IOException) { ok = false; } @@ -205,19 +205,19 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public bool Finish() { - if (!started) return false; + if(!started) return false; bool ok = true; started = false; try { ms.WriteByte(0x3b); // gif trailer ms.Flush(); - if (closeStream) + if(closeStream) { // ms.Close(); } } - catch (IOException) + catch(IOException) { ok = false; } @@ -243,7 +243,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public void SetFrameRate(float fps) { - if (fps != 0f) + if(fps != 0f) { delay = (int)Math.Round(100f / fps); } @@ -262,7 +262,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public void SetQuality(int quality) { - if (quality < 1) quality = 1; + if(quality < 1) quality = 1; sample = quality; } @@ -276,11 +276,11 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ public void SetSize(int w, int h) { - if (started && !firstFrame) return; + if(started && !firstFrame) return; width = w; height = h; - if (width < 1) width = 320; - if (height < 1) height = 240; + if(width < 1) width = 320; + if(height < 1) height = 240; sizeSet = true; } @@ -294,7 +294,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif public bool Start(MemoryStream os) { - if (os == null) return false; + if(os == null) return false; bool ok = true; closeStream = false; ms = os; @@ -302,7 +302,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif { WriteString("GIF89a"); // header } - catch (IOException) + catch(IOException) { ok = false; } @@ -322,7 +322,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif ok = Start(new MemoryStream(10 * 1024)); closeStream = true; } - catch (IOException) + catch(IOException) { ok = false; } @@ -342,7 +342,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif fs.Write(ms.ToArray(), 0, (int)ms.Length); fs.Close(); } - catch (IOException) + catch(IOException) { return false; } @@ -375,7 +375,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif // } // map image pixels to new palette int k = 0; - for (int i = 0; i < nPix; i++) + for(int i = 0; i < nPix; i++) { int index = nq.Map(pixels[k++] & 0xff, @@ -388,7 +388,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif colorDepth = 8; palSize = 7; // get closest match to transparent color if specified - if (transparent != SKColor.Empty) + if(transparent != SKColor.Empty) { //transIndex = FindClosest(transparent); transIndex = nq.Map(transparent.Blue, transparent.Green, transparent.Red); @@ -401,21 +401,21 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif */ protected int FindClosest(SKColor c) { - if (colorTab == null) return -1; + if(colorTab == null) return -1; int r = c.Red; int g = c.Green; int b = c.Blue; int minpos = 0; int dmin = 256 * 256 * 256; int len = colorTab.Length; - for (int i = 0; i < len;) + for(int i = 0; i < len;) { int dr = r - (colorTab[i++] & 0xff); int dg = g - (colorTab[i++] & 0xff); int db = b - (colorTab[i] & 0xff); int d = dr * dr + dg * dg + db * db; int index = i / 3; - if (usedEntry[index] && (d < dmin)) + if(usedEntry[index] && d < dmin) { dmin = d; minpos = index; @@ -433,12 +433,12 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif int w = image.Width; int h = image.Height; // int type = image.GetType().; - if ((w != width) || (h != height)) + if(w != width || h != height) { // create new image with right size/format - using (var temp = new SKBitmap(width, height)) + using(var temp = new SKBitmap(width, height)) { - using (var canvas = new SKCanvas(temp)) + using(var canvas = new SKCanvas(temp)) { canvas.DrawBitmap(SKBitmap.FromImage(image), 0, 0); image = SKImage.FromBitmap(temp); @@ -449,12 +449,12 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif ToDo: improve performance: use unsafe code */ - pixels = new Byte[3 * image.Width * image.Height]; + pixels = new byte[3 * image.Width * image.Height]; int count = 0; SKBitmap tempBitmap = SKBitmap.FromImage(image); - for (int th = 0; th < image.Height; th++) + for(int th = 0; th < image.Height; th++) { - for (int tw = 0; tw < image.Width; tw++) + for(int tw = 0; tw < image.Width; tw++) { SKColor color = tempBitmap.GetPixel(tw, th); pixels[count] = color.Red; @@ -478,7 +478,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif ms.WriteByte(0xf9); // GCE label ms.WriteByte(4); // data block size int transp, disp; - if (transparent == SKColor.Empty) + if(transparent == SKColor.Empty) { transp = 0; disp = 0; // dispose = no action @@ -488,7 +488,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif transp = 1; disp = 2; // force clear if using transparent color } - if (dispose >= 0) + if(dispose >= 0) { disp = dispose & 7; // user override } @@ -516,7 +516,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif WriteShort(width); // image size WriteShort(height); // packed fields - if (firstFrame) + if(firstFrame) { // no LCT - GCT is used for first (or only) frame ms.WriteByte(0); @@ -572,8 +572,8 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif protected void WritePalette() { ms.Write(colorTab, 0, colorTab.Length); - int n = (3 * 256) - colorTab.Length; - for (int i = 0; i < n; i++) + int n = 3 * 256 - colorTab.Length; + for(int i = 0; i < n; i++) { ms.WriteByte(0); } @@ -595,16 +595,16 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif protected void WriteShort(int value) { ms.WriteByte(Convert.ToByte(value & 0xff)); - ms.WriteByte(Convert.ToByte((value >> 8) & 0xff)); + ms.WriteByte(Convert.ToByte(value >> 8 & 0xff)); } /** * Writes string to output stream */ - protected void WriteString(String s) + protected void WriteString(string s) { char[] chars = s.ToCharArray(); - for (int i = 0; i < chars.Length; i++) + for(int i = 0; i < chars.Length; i++) { ms.WriteByte((byte)chars[i]); } diff --git a/Lazy.Captcha.Core/Generator/Image/Gif/LZWEncoder.cs b/Lazy.Captcha.Core/Core/Generator/Image/Gif/LZWEncoder.cs similarity index 90% rename from Lazy.Captcha.Core/Generator/Image/Gif/LZWEncoder.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Gif/LZWEncoder.cs index 1251fb7e40a8b4042b79d190cccd21edf6196285..3b60f242cab7289b0475651aafd258a9aa685edf 100644 --- a/Lazy.Captcha.Core/Generator/Image/Gif/LZWEncoder.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/Gif/LZWEncoder.cs @@ -133,7 +133,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif void Add(byte c, Stream outs) { accum[a_count++] = c; - if (a_count >= 254) + if(a_count >= 254) Flush(outs); } @@ -152,7 +152,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif // reset code table void ResetCodeTable(int hsize) { - for (int i = 0; i < hsize; ++i) + for(int i = 0; i < hsize; ++i) htab[i] = -1; } @@ -174,7 +174,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif n_bits = g_init_bits; maxcode = MaxCode(n_bits); - ClearCode = 1 << (init_bits - 1); + ClearCode = 1 << init_bits - 1; EOFCode = ClearCode + 1; free_ent = ClearCode + 2; @@ -183,7 +183,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif ent = NextPixel(); hshift = 0; - for (fcode = hsize; fcode < 65536; fcode *= 2) + for(fcode = hsize; fcode < 65536; fcode *= 2) ++hshift; hshift = 8 - hshift; // set hash code range bound @@ -192,36 +192,36 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif Output(ClearCode, outs); - outer_loop: while ((c = NextPixel()) != EOF) + outer_loop: while((c = NextPixel()) != EOF) { fcode = (c << maxbits) + ent; - i = (c << hshift) ^ ent; // xor hashing + i = c << hshift ^ ent; // xor hashing - if (htab[i] == fcode) + if(htab[i] == fcode) { ent = codetab[i]; continue; } - else if (htab[i] >= 0) // non-empty slot + else if(htab[i] >= 0) // non-empty slot { disp = hsize_reg - i; // secondary hash (after G. Knott) - if (i == 0) + if(i == 0) disp = 1; do { - if ((i -= disp) < 0) + if((i -= disp) < 0) i += hsize_reg; - if (htab[i] == fcode) + if(htab[i] == fcode) { ent = codetab[i]; goto outer_loop; } - } while (htab[i] >= 0); + } while(htab[i] >= 0); } Output(ent, outs); ent = c; - if (free_ent < maxmaxcode) + if(free_ent < maxmaxcode) { codetab[i] = free_ent++; // code -> hashtable htab[i] = fcode; @@ -250,7 +250,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif // Flush the packet to disk, and reset the accumulator void Flush(Stream outs) { - if (a_count > 0) + if(a_count > 0) { outs.WriteByte(Convert.ToByte(a_count)); outs.Write(accum, 0, a_count); @@ -270,21 +270,21 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif { int upperBound = pixAry.GetUpperBound(0); - return (curPixel <= upperBound) ? (pixAry[curPixel++] & 0xff) : EOF; + return curPixel <= upperBound ? pixAry[curPixel++] & 0xff : EOF; } void Output(int code, Stream outs) { cur_accum &= masks[cur_bits]; - if (cur_bits > 0) - cur_accum |= (code << cur_bits); + if(cur_bits > 0) + cur_accum |= code << cur_bits; else cur_accum = code; cur_bits += n_bits; - while (cur_bits >= 8) + while(cur_bits >= 8) { Add((byte)(cur_accum & 0xff), outs); cur_accum >>= 8; @@ -293,9 +293,9 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif // If the next entry is going to be too big for the code size, // then increase it, if possible. - if (free_ent > maxcode || clear_flg) + if(free_ent > maxcode || clear_flg) { - if (clear_flg) + if(clear_flg) { maxcode = MaxCode(n_bits = g_init_bits); clear_flg = false; @@ -303,17 +303,17 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif else { ++n_bits; - if (n_bits == maxbits) + if(n_bits == maxbits) maxcode = maxmaxcode; else maxcode = MaxCode(n_bits); } } - if (code == EOFCode) + if(code == EOFCode) { // At EOF, write the rest of the buffer. - while (cur_bits > 0) + while(cur_bits > 0) { Add((byte)(cur_accum & 0xff), outs); cur_accum >>= 8; diff --git a/Lazy.Captcha.Core/Generator/Image/Gif/NeuQuant.cs b/Lazy.Captcha.Core/Core/Generator/Image/Gif/NeuQuant.cs similarity index 73% rename from Lazy.Captcha.Core/Generator/Image/Gif/NeuQuant.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Gif/NeuQuant.cs index a104096727503882b6078a5ab2cdcbe6183710a8..6769fadfc13049098af1c78fa3260c614efdf997 100644 --- a/Lazy.Captcha.Core/Generator/Image/Gif/NeuQuant.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/Gif/NeuQuant.cs @@ -17,7 +17,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif protected static readonly int prime2 = 491; protected static readonly int prime3 = 487; protected static readonly int prime4 = 503; - protected static readonly int minpicturebytes = (3 * prime4); + protected static readonly int minpicturebytes = 3 * prime4; /* minimum size for input image */ /* Program Skeleton ---------------- @@ -33,38 +33,38 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif /* Network Definitions ------------------- */ - protected static readonly int maxnetpos = (netsize - 1); + protected static readonly int maxnetpos = netsize - 1; protected static readonly int netbiasshift = 4; /* bias for colour values */ protected static readonly int ncycles = 100; /* no. of learning cycles */ /* defs for freq and bias */ protected static readonly int intbiasshift = 16; /* bias for fractions */ - protected static readonly int intbias = (((int)1) << intbiasshift); + protected static readonly int intbias = 1 << intbiasshift; protected static readonly int gammashift = 10; /* gamma = 1024 */ - protected static readonly int gamma = (((int)1) << gammashift); + protected static readonly int gamma = 1 << gammashift; protected static readonly int betashift = 10; - protected static readonly int beta = (intbias >> betashift); /* beta = 1/1024 */ + protected static readonly int beta = intbias >> betashift; /* beta = 1/1024 */ protected static readonly int betagamma = - (intbias << (gammashift - betashift)); + intbias << gammashift - betashift; /* defs for decreasing radius factor */ - protected static readonly int initrad = (netsize >> 3); /* for 256 cols, radius starts */ + protected static readonly int initrad = netsize >> 3; /* for 256 cols, radius starts */ protected static readonly int radiusbiasshift = 6; /* at 32.0 biased by 6 bits */ - protected static readonly int radiusbias = (((int)1) << radiusbiasshift); - protected static readonly int initradius = (initrad * radiusbias); /* and decreases by a */ + protected static readonly int radiusbias = 1 << radiusbiasshift; + protected static readonly int initradius = initrad * radiusbias; /* and decreases by a */ protected static readonly int radiusdec = 30; /* factor of 1/30 each cycle */ /* defs for decreasing alpha factor */ protected static readonly int alphabiasshift = 10; /* alpha starts at 1.0 */ - protected static readonly int initalpha = (((int)1) << alphabiasshift); + protected static readonly int initalpha = 1 << alphabiasshift; protected int alphadec; /* biased by 10 bits */ /* radbias and alpharadbias used for radpower calculation */ protected static readonly int radbiasshift = 8; - protected static readonly int radbias = (((int)1) << radbiasshift); - protected static readonly int alpharadbshift = (alphabiasshift + radbiasshift); - protected static readonly int alpharadbias = (((int)1) << alpharadbshift); + protected static readonly int radbias = 1 << radbiasshift; + protected static readonly int alpharadbshift = alphabiasshift + radbiasshift; + protected static readonly int alpharadbias = 1 << alpharadbshift; /* Types and Global Variables -------------------------- */ @@ -99,11 +99,11 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif samplefac = sample; network = new int[netsize][]; - for (i = 0; i < netsize; i++) + for(i = 0; i < netsize; i++) { network[i] = new int[4]; p = network[i]; - p[0] = p[1] = p[2] = (i << (netbiasshift + 8)) / netsize; + p[0] = p[1] = p[2] = (i << netbiasshift + 8) / netsize; freq[i] = intbias / netsize; /* 1/netsize */ bias[i] = 0; } @@ -113,15 +113,15 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif { byte[] map = new byte[3 * netsize]; int[] index = new int[netsize]; - for (int i = 0; i < netsize; i++) + for(int i = 0; i < netsize; i++) index[network[i][3]] = i; int k = 0; - for (int i = 0; i < netsize; i++) + for(int i = 0; i < netsize; i++) { int j = index[i]; - map[k++] = (byte)(network[j][0]); - map[k++] = (byte)(network[j][1]); - map[k++] = (byte)(network[j][2]); + map[k++] = (byte)network[j][0]; + map[k++] = (byte)network[j][1]; + map[k++] = (byte)network[j][2]; } return map; } @@ -138,16 +138,16 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif previouscol = 0; startpos = 0; - for (i = 0; i < netsize; i++) + for(i = 0; i < netsize; i++) { p = network[i]; smallpos = i; smallval = p[1]; /* index on g */ /* find smallest in i..netsize-1 */ - for (j = i + 1; j < netsize; j++) + for(j = i + 1; j < netsize; j++) { q = network[j]; - if (q[1] < smallval) + if(q[1] < smallval) { /* index on g */ smallpos = j; smallval = q[1]; /* index on g */ @@ -155,7 +155,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif } q = network[smallpos]; /* swap p (i) and q (smallpos) entries */ - if (i != smallpos) + if(i != smallpos) { j = q[0]; q[0] = p[0]; @@ -171,17 +171,17 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif p[3] = j; } /* smallval entry is now in position i */ - if (smallval != previouscol) + if(smallval != previouscol) { - netindex[previouscol] = (startpos + i) >> 1; - for (j = previouscol + 1; j < smallval; j++) + netindex[previouscol] = startpos + i >> 1; + for(j = previouscol + 1; j < smallval; j++) netindex[j] = i; previouscol = smallval; startpos = i; } } - netindex[previouscol] = (startpos + maxnetpos) >> 1; - for (j = previouscol + 1; j < 256; j++) + netindex[previouscol] = startpos + maxnetpos >> 1; + for(j = previouscol + 1; j < 256; j++) netindex[j] = maxnetpos; /* really 256 */ } @@ -195,9 +195,9 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif byte[] p; int pix, lim; - if (lengthcount < minpicturebytes) + if(lengthcount < minpicturebytes) samplefac = 1; - alphadec = 30 + ((samplefac - 1) / 3); + alphadec = 30 + (samplefac - 1) / 3; p = thepicture; pix = 0; lim = lengthcount; @@ -207,25 +207,25 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif radius = initradius; rad = radius >> radiusbiasshift; - if (rad <= 1) + if(rad <= 1) rad = 0; - for (i = 0; i < rad; i++) + for(i = 0; i < rad; i++) radpower[i] = - alpha * (((rad * rad - i * i) * radbias) / (rad * rad)); + alpha * ((rad * rad - i * i) * radbias / (rad * rad)); //fprintf(stderr,"beginning 1D learning: initial radius=%d\n", rad); - if (lengthcount < minpicturebytes) + if(lengthcount < minpicturebytes) step = 3; - else if ((lengthcount % prime1) != 0) + else if(lengthcount % prime1 != 0) step = 3 * prime1; else { - if ((lengthcount % prime2) != 0) + if(lengthcount % prime2 != 0) step = 3 * prime2; else { - if ((lengthcount % prime3) != 0) + if(lengthcount % prime3 != 0) step = 3 * prime3; else step = 3 * prime4; @@ -233,7 +233,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif } i = 0; - while (i < samplepixels) + while(i < samplepixels) { b = (p[pix + 0] & 0xff) << netbiasshift; g = (p[pix + 1] & 0xff) << netbiasshift; @@ -241,26 +241,26 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif j = Contest(b, g, r); Altersingle(alpha, j, b, g, r); - if (rad != 0) + if(rad != 0) Alterneigh(rad, j, b, g, r); /* alter neighbours */ pix += step; - if (pix >= lim) + if(pix >= lim) pix -= lengthcount; i++; - if (delta == 0) + if(delta == 0) delta = 1; - if (i % delta == 0) + if(i % delta == 0) { alpha -= alpha / alphadec; radius -= radius / radiusdec; rad = radius >> radiusbiasshift; - if (rad <= 1) + if(rad <= 1) rad = 0; - for (j = 0; j < rad; j++) + for(j = 0; j < rad; j++) radpower[j] = - alpha * (((rad * rad - j * j) * radbias) / (rad * rad)); + alpha * ((rad * rad - j * j) * radbias / (rad * rad)); } } //fprintf(stderr,"finished 1D learning: readonly alpha=%f !\n",((float)alpha)/initalpha); @@ -280,30 +280,30 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif i = netindex[g]; /* index on g */ j = i - 1; /* start at netindex[g] and work outwards */ - while ((i < netsize) || (j >= 0)) + while(i < netsize || j >= 0) { - if (i < netsize) + if(i < netsize) { p = network[i]; dist = p[1] - g; /* inx key */ - if (dist >= bestd) + if(dist >= bestd) i = netsize; /* stop iter */ else { i++; - if (dist < 0) + if(dist < 0) dist = -dist; a = p[0] - b; - if (a < 0) + if(a < 0) a = -a; dist += a; - if (dist < bestd) + if(dist < bestd) { a = p[2] - r; - if (a < 0) + if(a < 0) a = -a; dist += a; - if (dist < bestd) + if(dist < bestd) { bestd = dist; best = p[3]; @@ -311,28 +311,28 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif } } } - if (j >= 0) + if(j >= 0) { p = network[j]; dist = g - p[1]; /* inx key - reverse dif */ - if (dist >= bestd) + if(dist >= bestd) j = -1; /* stop iter */ else { j--; - if (dist < 0) + if(dist < 0) dist = -dist; a = p[0] - b; - if (a < 0) + if(a < 0) a = -a; dist += a; - if (dist < bestd) + if(dist < bestd) { a = p[2] - r; - if (a < 0) + if(a < 0) a = -a; dist += a; - if (dist < bestd) + if(dist < bestd) { bestd = dist; best = p[3]; @@ -341,7 +341,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif } } } - return (best); + return best; } public byte[] Process() { @@ -358,7 +358,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif int i; - for (i = 0; i < netsize; i++) + for(i = 0; i < netsize; i++) { network[i][0] >>= netbiasshift; network[i][1] >>= netbiasshift; @@ -376,41 +376,41 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif int[] p; lo = i - rad; - if (lo < -1) + if(lo < -1) lo = -1; hi = i + rad; - if (hi > netsize) + if(hi > netsize) hi = netsize; j = i + 1; k = i - 1; m = 1; - while ((j < hi) || (k > lo)) + while(j < hi || k > lo) { a = radpower[m++]; - if (j < hi) + if(j < hi) { p = network[j++]; try { - p[0] -= (a * (p[0] - b)) / alpharadbias; - p[1] -= (a * (p[1] - g)) / alpharadbias; - p[2] -= (a * (p[2] - r)) / alpharadbias; + p[0] -= a * (p[0] - b) / alpharadbias; + p[1] -= a * (p[1] - g) / alpharadbias; + p[2] -= a * (p[2] - r) / alpharadbias; } - catch (Exception) + catch(Exception) { } // prevents 1.3 miscompilation } - if (k > lo) + if(k > lo) { p = network[k--]; try { - p[0] -= (a * (p[0] - b)) / alpharadbias; - p[1] -= (a * (p[1] - g)) / alpharadbias; - p[2] -= (a * (p[2] - r)) / alpharadbias; + p[0] -= a * (p[0] - b) / alpharadbias; + p[1] -= a * (p[1] - g) / alpharadbias; + p[2] -= a * (p[2] - r) / alpharadbias; } - catch (Exception) + catch(Exception) { } } @@ -424,9 +424,9 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif /* alter hit neuron */ int[] n = network[i]; - n[0] -= (alpha * (n[0] - b)) / initalpha; - n[1] -= (alpha * (n[1] - g)) / initalpha; - n[2] -= (alpha * (n[2] - r)) / initalpha; + n[0] -= alpha * (n[0] - b) / initalpha; + n[1] -= alpha * (n[1] - g) / initalpha; + n[2] -= alpha * (n[2] - r) / initalpha; } /* Search for biased BGR values @@ -443,43 +443,43 @@ namespace Lazy.Captcha.Core.Generator.Image.Gif int bestpos, bestbiaspos, bestd, bestbiasd; int[] n; - bestd = ~(((int)1) << 31); + bestd = ~(1 << 31); bestbiasd = bestd; bestpos = -1; bestbiaspos = bestpos; - for (i = 0; i < netsize; i++) + for(i = 0; i < netsize; i++) { n = network[i]; dist = n[0] - b; - if (dist < 0) + if(dist < 0) dist = -dist; a = n[1] - g; - if (a < 0) + if(a < 0) a = -a; dist += a; a = n[2] - r; - if (a < 0) + if(a < 0) a = -a; dist += a; - if (dist < bestd) + if(dist < bestd) { bestd = dist; bestpos = i; } - biasdist = dist - ((bias[i]) >> (intbiasshift - netbiasshift)); - if (biasdist < bestbiasd) + biasdist = dist - (bias[i] >> intbiasshift - netbiasshift); + if(biasdist < bestbiasd) { bestbiasd = biasdist; bestbiaspos = i; } - betafreq = (freq[i] >> betashift); + betafreq = freq[i] >> betashift; freq[i] -= betafreq; - bias[i] += (betafreq << gammashift); + bias[i] += betafreq << gammashift; } freq[bestpos] += beta; bias[bestpos] -= betagamma; - return (bestbiaspos); + return bestbiaspos; } } } diff --git a/Lazy.Captcha.Core/Generator/Image/ICaptchaImageGenerator.cs b/Lazy.Captcha.Core/Core/Generator/Image/ICaptchaImageGenerator.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Image/ICaptchaImageGenerator.cs rename to Lazy.Captcha.Core/Core/Generator/Image/ICaptchaImageGenerator.cs diff --git a/Lazy.Captcha.Core/Generator/Image/ICaptchaImageGeneratorBuilder.cs b/Lazy.Captcha.Core/Core/Generator/Image/ICaptchaImageGeneratorBuilder.cs similarity index 75% rename from Lazy.Captcha.Core/Generator/Image/ICaptchaImageGeneratorBuilder.cs rename to Lazy.Captcha.Core/Core/Generator/Image/ICaptchaImageGeneratorBuilder.cs index 2500499d9f56a7dd5720ef9289f88b61aac25d61..27f3bbf2b96e333fc3cc6f4f474685dafa49f5ff 100644 --- a/Lazy.Captcha.Core/Generator/Image/ICaptchaImageGeneratorBuilder.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/ICaptchaImageGeneratorBuilder.cs @@ -1,5 +1,4 @@ -using Lazy.Captcha.Core.Generator; -using Lazy.Captcha.Core.Generator.Image.Option; +using Lazy.Captcha.Core.Generator.Image.Option; using System; using System.Collections.Generic; using System.Linq; diff --git a/Lazy.Captcha.Core/Generator/Image/Models/BubbleGraphicDescription.cs b/Lazy.Captcha.Core/Core/Generator/Image/Models/BubbleGraphicDescription.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Image/Models/BubbleGraphicDescription.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Models/BubbleGraphicDescription.cs diff --git a/Lazy.Captcha.Core/Generator/Image/Models/InterferenceLineGraphicDescription.cs b/Lazy.Captcha.Core/Core/Generator/Image/Models/InterferenceLineGraphicDescription.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Image/Models/InterferenceLineGraphicDescription.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Models/InterferenceLineGraphicDescription.cs diff --git a/Lazy.Captcha.Core/Generator/Image/Models/TextGraphicDescription.cs b/Lazy.Captcha.Core/Core/Generator/Image/Models/TextGraphicDescription.cs similarity index 100% rename from Lazy.Captcha.Core/Generator/Image/Models/TextGraphicDescription.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Models/TextGraphicDescription.cs diff --git a/Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs b/Lazy.Captcha.Core/Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs similarity index 94% rename from Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs index 2b5c4ead2e63931c6b6166419ea04e19f0da75e3..a0f91ec243edeb9aea81ba7198734ae1b2810eae 100644 --- a/Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs @@ -1,4 +1,5 @@ -using SkiaSharp; +using Lazy.Captcha.Core; +using SkiaSharp; using System; using System.Collections.Generic; using System.Linq; @@ -24,7 +25,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// /// FontFamily /// - public SKTypeface FontFamily { get; set;}= DefaultFontFamilys.Instance.Kaiti; + public SKTypeface FontFamily { get; set; } = DefaultFontFamilys.Instance.Kaiti; /// /// 字体大小 /// diff --git a/Lazy.Captcha.Core/Generator/Image/Option/DefaultCaptchaImageOptionBuilder.cs b/Lazy.Captcha.Core/Core/Generator/Image/Option/DefaultCaptchaImageOptionBuilder.cs similarity index 82% rename from Lazy.Captcha.Core/Generator/Image/Option/DefaultCaptchaImageOptionBuilder.cs rename to Lazy.Captcha.Core/Core/Generator/Image/Option/DefaultCaptchaImageOptionBuilder.cs index bd4397d5576f64f36911a92fc1bb09c126dca91d..c78e7ccd57dd6ab35fc03a875ad0fd3dced70160 100644 --- a/Lazy.Captcha.Core/Generator/Image/Option/DefaultCaptchaImageOptionBuilder.cs +++ b/Lazy.Captcha.Core/Core/Generator/Image/Option/DefaultCaptchaImageOptionBuilder.cs @@ -1,5 +1,5 @@ -using Lazy.Captcha.Core.Generator; -using Lazy.Captcha.Core.Generator.Code; +using Lazy.Captcha.Core.Generator.Code; +using Lazy.Captcha.Core.Generator.Image; using SkiaSharp; using System; using System.Collections.Generic; @@ -14,7 +14,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option private CaptchaImageGeneratorOption _option = new CaptchaImageGeneratorOption(); public static DefaultCaptchaImageOptionBuilder Create() - { + { return new DefaultCaptchaImageOptionBuilder(); } @@ -25,7 +25,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder CaptchaType(SKColor backgroundColor) { - this._option.BackgroundColor = backgroundColor; + _option.BackgroundColor = backgroundColor; return this; } @@ -36,7 +36,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder FontFamily(SKTypeface fontFamily) { - this._option.FontFamily = fontFamily; + _option.FontFamily = fontFamily; return this; } @@ -47,7 +47,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder FontFamily(float fontSize) { - this._option.FontSize = fontSize; + _option.FontSize = fontSize; return this; } @@ -59,8 +59,8 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder Size(int width, int height) { - this._option.Width = width; - this._option.Height = height; + _option.Width = width; + _option.Height = height; return this; } @@ -71,7 +71,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder BubbleCount(int bubbleCount) { - this._option.BubbleCount = bubbleCount; + _option.BubbleCount = bubbleCount; return this; } @@ -82,7 +82,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder BubbleCount(float bubbleThickness) { - this._option.BubbleThickness = bubbleThickness; + _option.BubbleThickness = bubbleThickness; return this; } @@ -93,14 +93,14 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// public DefaultCaptchaImageOptionBuilder InterferenceLineCount(int interferenceLineCount) { - this._option.InterferenceLineCount = interferenceLineCount; + _option.InterferenceLineCount = interferenceLineCount; return this; } public CaptchaImageGeneratorOption Build() { - return this._option; + return _option; } } } diff --git a/Lazy.Captcha.Core/ICaptcha.cs b/Lazy.Captcha.Core/Core/ICaptcha.cs similarity index 100% rename from Lazy.Captcha.Core/ICaptcha.cs rename to Lazy.Captcha.Core/Core/ICaptcha.cs diff --git a/Lazy.Captcha.Core/fonts/actionj.ttf b/Lazy.Captcha.Core/Core/fonts/actionj.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/actionj.ttf rename to Lazy.Captcha.Core/Core/fonts/actionj.ttf diff --git a/Lazy.Captcha.Core/fonts/epilog.ttf b/Lazy.Captcha.Core/Core/fonts/epilog.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/epilog.ttf rename to Lazy.Captcha.Core/Core/fonts/epilog.ttf diff --git a/Lazy.Captcha.Core/fonts/fresnel.ttf b/Lazy.Captcha.Core/Core/fonts/fresnel.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/fresnel.ttf rename to Lazy.Captcha.Core/Core/fonts/fresnel.ttf diff --git a/Lazy.Captcha.Core/fonts/headache.ttf b/Lazy.Captcha.Core/Core/fonts/headache.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/headache.ttf rename to Lazy.Captcha.Core/Core/fonts/headache.ttf diff --git a/Lazy.Captcha.Core/fonts/kaiti.ttf b/Lazy.Captcha.Core/Core/fonts/kaiti.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/kaiti.ttf rename to Lazy.Captcha.Core/Core/fonts/kaiti.ttf diff --git a/Lazy.Captcha.Core/fonts/lexo.ttf b/Lazy.Captcha.Core/Core/fonts/lexo.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/lexo.ttf rename to Lazy.Captcha.Core/Core/fonts/lexo.ttf diff --git a/Lazy.Captcha.Core/fonts/prefix.ttf b/Lazy.Captcha.Core/Core/fonts/prefix.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/prefix.ttf rename to Lazy.Captcha.Core/Core/fonts/prefix.ttf diff --git a/Lazy.Captcha.Core/fonts/progbot.ttf b/Lazy.Captcha.Core/Core/fonts/progbot.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/progbot.ttf rename to Lazy.Captcha.Core/Core/fonts/progbot.ttf diff --git a/Lazy.Captcha.Core/fonts/ransom.ttf b/Lazy.Captcha.Core/Core/fonts/ransom.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/ransom.ttf rename to Lazy.Captcha.Core/Core/fonts/ransom.ttf diff --git a/Lazy.Captcha.Core/fonts/robot.ttf b/Lazy.Captcha.Core/Core/fonts/robot.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/robot.ttf rename to Lazy.Captcha.Core/Core/fonts/robot.ttf diff --git a/Lazy.Captcha.Core/fonts/scandal.ttf b/Lazy.Captcha.Core/Core/fonts/scandal.ttf similarity index 100% rename from Lazy.Captcha.Core/fonts/scandal.ttf rename to Lazy.Captcha.Core/Core/fonts/scandal.ttf diff --git a/Lazy.Captcha.Core/Lazy.Captcha.Core.csproj b/Lazy.Captcha.Core/Lazy.Captcha.Core.csproj index b7650d5e3ae30aa6ab5ee5f5c1e8a23a44aec33b..f9c278db50bb55529e95b7c119df3394216a7b55 100644 --- a/Lazy.Captcha.Core/Lazy.Captcha.Core.csproj +++ b/Lazy.Captcha.Core/Lazy.Captcha.Core.csproj @@ -1,77 +1,73 @@  - - netstandard2.0 - latest - 仿EasyCaptcha和SimpleCaptcha,基于.Net Standard 2.0的图形验证码模块。版本2.0.0起绘图由ImageSharp调整为SkiaSharp。文档地址: https://gitee.com/pojianbing/lazy-captcha - https://gitee.com/pojianbing/lazy-captcha - https://gitee.com/pojianbing/lazy-captcha - git - true - snupkg - 2.0.6 - 2.0.6 - captcha 验证码 - + + netstandard2.0 + latest + 仿EasyCaptcha和SimpleCaptcha,基于.Net Standard 2.0的图形验证码模块。版本2.0.0起绘图由ImageSharp调整为SkiaSharp。文档地址: https://gitee.com/pojianbing/lazy-captcha + https://gitee.com/pojianbing/lazy-captcha + https://gitee.com/pojianbing/lazy-captcha + git + true + snupkg + 2.0.6 + 2.0.6 + captcha 验证码 + Lazy.Captcha + - - - - - + + + + + - - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - + + + - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Lazy.Captcha.Core/Storage/Caches/CacheEntity.cs b/Lazy.Captcha.Core/Storage/Caches/CacheEntity.cs index 3f986ff2fbc10feb503520e56a0e782cff10bebd..19456f4f08f01ae5252cb5ea30ea0580f7648674 100644 --- a/Lazy.Captcha.Core/Storage/Caches/CacheEntity.cs +++ b/Lazy.Captcha.Core/Storage/Caches/CacheEntity.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Lazy.Captcha.Core.Storage.Caches +namespace Lazy.Captcha.Storage.Caches { /// /// 缓存实体 @@ -41,8 +41,8 @@ namespace Lazy.Captcha.Core.Storage.Caches /// 值 public CacheEntity(string key, string value) { - this.Key = key; - this.Value = value; + Key = key; + Value = value; } } } diff --git a/Lazy.Captcha.Core/Storage/Caches/MemoryCache.cs b/Lazy.Captcha.Core/Storage/Caches/MemoryCache.cs index 87b94cf707f04794ba0ecb246c5c4de7796a020d..ce1eafab378391574a148847aacca2bbd9212bc0 100644 --- a/Lazy.Captcha.Core/Storage/Caches/MemoryCache.cs +++ b/Lazy.Captcha.Core/Storage/Caches/MemoryCache.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Timers; -namespace Lazy.Captcha.Core.Storage.Caches +namespace Lazy.Captcha.Storage.Caches { public class MemoryCache { @@ -24,9 +21,9 @@ namespace Lazy.Captcha.Core.Storage.Caches public string Get(string key) { - if (Cache.TryGetValue(key, out var data)) + if(Cache.TryGetValue(key, out var data)) { - if (data.IsExpired) + if(data.IsExpired) { Cache.TryRemove(key, out var _); return null; @@ -62,18 +59,18 @@ namespace Lazy.Captcha.Core.Storage.Caches { try { - foreach (string cacheKey in Cache.Keys) + foreach(string cacheKey in Cache.Keys) { - if (Cache.TryGetValue(cacheKey, out var data)) + if(Cache.TryGetValue(cacheKey, out var data)) { - if (data.IsExpired) + if(data.IsExpired) { Cache.TryRemove(cacheKey, out var _); } } } } - catch (Exception ex) + catch(Exception ex) { Console.WriteLine(ex.ToString()); } diff --git a/Lazy.Captcha.Core/Storage/IStorage.cs b/Lazy.Captcha.Core/Storage/IStorage.cs index 27522852a4cea8d50bc1b4b1c6b256410f1801db..0835a4710010edc8f79639c4e69ccf9ae9b41e0d 100644 --- a/Lazy.Captcha.Core/Storage/IStorage.cs +++ b/Lazy.Captcha.Core/Storage/IStorage.cs @@ -1,13 +1,12 @@ using System; -namespace Lazy.Captcha.Core.Storage +namespace Lazy.Captcha.Storage; + +public interface IStorage { - public interface IStorage - { - void Set(string key, string value, DateTimeOffset absoluteExpiration); + void Set(string key, string value, DateTimeOffset absoluteExpiration); - string Get(string key); + string Get(string key); - void Remove(string key); - } + void Remove(string key); } \ No newline at end of file diff --git a/Lazy.Captcha.Core/Storage/MemeoryStorage.cs b/Lazy.Captcha.Core/Storage/MemeoryStorage.cs index 6c84cb704d0e04078bae05ca2e8545a8122c63ca..46324ee8f94bf99e76d9e2c287002526b6b03be8 100644 --- a/Lazy.Captcha.Core/Storage/MemeoryStorage.cs +++ b/Lazy.Captcha.Core/Storage/MemeoryStorage.cs @@ -1,9 +1,7 @@ -using Lazy.Captcha.Core.Storage.Caches; +using Lazy.Captcha.Storage.Caches; using System; -using System.Collections.Generic; -using System.Text; -namespace Lazy.Captcha.Core.Storage +namespace Lazy.Captcha.Storage { public class MemeoryStorage : IStorage { diff --git a/Lazy.Captcha.xUnit/Demo.cs b/Lazy.Captcha.xUnit/Demo.cs index d65e5a6f66ec3b02a968f519d59dcff061f60686..5cc3a53f71712b512a5154a9236b297acb0b607b 100644 --- a/Lazy.Captcha.xUnit/Demo.cs +++ b/Lazy.Captcha.xUnit/Demo.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.IO; using Xunit.Abstractions; namespace Lazy.Captcha.xUnit diff --git a/LazyCaptcha.sln b/LazyCaptcha.sln index b27f72db656de79146c9c01f87541dfcc9e4d294..98c37de9c8b571cb1be82a77374568ff85731a23 100644 --- a/LazyCaptcha.sln +++ b/LazyCaptcha.sln @@ -15,6 +15,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.NetCore", "Sample.Ne EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.MvcFramework", "Sample.MvcFramework\Sample.MvcFramework.csproj", "{F172A3CE-0295-40FC-B739-694EFE9A41C8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lazy.Captcha.AspNetCore", "Lazy.Captcha.AspNetCore\Lazy.Captcha.AspNetCore.csproj", "{A0280047-2AE0-4DC7-89FE-0FAA892D31CE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{D97FE79C-0516-4A80-A60F-292692C5AB5A}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + LICENSE = LICENSE + README.md = README.md + README_V1.md = README_V1.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +51,10 @@ Global {F172A3CE-0295-40FC-B739-694EFE9A41C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {F172A3CE-0295-40FC-B739-694EFE9A41C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {F172A3CE-0295-40FC-B739-694EFE9A41C8}.Release|Any CPU.Build.0 = Release|Any CPU + {A0280047-2AE0-4DC7-89FE-0FAA892D31CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0280047-2AE0-4DC7-89FE-0FAA892D31CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0280047-2AE0-4DC7-89FE-0FAA892D31CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0280047-2AE0-4DC7-89FE-0FAA892D31CE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sample.NetCore/Controllers/CaptchaController.cs b/Sample.NetCore/Controllers/CaptchaController.cs index b98784eb04bf3adec6eabb282352123e3119ef28..5e5c02541e3885988015cd30f23df1235c665013 100644 --- a/Sample.NetCore/Controllers/CaptchaController.cs +++ b/Sample.NetCore/Controllers/CaptchaController.cs @@ -1,5 +1,4 @@ using Lazy.Captcha.Core; -using Lazy.Captcha.Core.Generator; using Lazy.Captcha.Core.Generator.Image; using Lazy.Captcha.Core.Generator.Image.Option; using Microsoft.AspNetCore.Mvc; diff --git a/Sample.NetCore/Program.cs b/Sample.NetCore/Program.cs index c39af57599a5012de53fda599d83bf291241befa..7816f47d357c79905ee69ef88fa13ae6c8c9b0dc 100644 --- a/Sample.NetCore/Program.cs +++ b/Sample.NetCore/Program.cs @@ -1,7 +1,6 @@ -using Lazy.Captcha.Core; -using Lazy.Captcha.Core.Generator; -using Sample.NetCore; -using SkiaSharp; +using Lazy.Captcha.AspNetCore; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; var builder = WebApplication.CreateBuilder(args); diff --git a/Sample.NetCore/RandomCaptcha.cs b/Sample.NetCore/RandomCaptcha.cs index c6800d95dcb4c386a8229d60cf60df731acf9618..9379f695d8c2ea9f6e786a44808482948f83f03b 100644 --- a/Sample.NetCore/RandomCaptcha.cs +++ b/Sample.NetCore/RandomCaptcha.cs @@ -1,7 +1,9 @@ -using Lazy.Captcha.Core.Generator; -using Lazy.Captcha.Core.Storage; -using Lazy.Captcha.Core; +using Lazy.Captcha.Core; using Microsoft.Extensions.Options; +using Lazy.Captcha.Core.Generator.Extensions; +using System; +using Lazy.Captcha.AspNetCore; +using Lazy.Captcha.Storage; namespace Sample.NetCore { diff --git a/Sample.NetCore/Sample.NetCore.csproj b/Sample.NetCore/Sample.NetCore.csproj index e52ded0d75fe0ff911f69591db6bc1a4cebeac31..fb822b1cc503a26acd44fec36bc6ba2fbfea58dd 100644 --- a/Sample.NetCore/Sample.NetCore.csproj +++ b/Sample.NetCore/Sample.NetCore.csproj @@ -26,6 +26,7 @@ +