Skip to content

Commit

Permalink
upgrade to net8.0 (#17)
Browse files Browse the repository at this point in the history
* init

* tweaks
  • Loading branch information
qiuhaotc authored Jan 31, 2024
1 parent bbacecf commit e79de9b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup .NET 7
- name: Setup .NET 8
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Install dependencies
run: |
cd src
Expand Down
4 changes: 2 additions & 2 deletions src/CodeIndex.Common/CodeIndex.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog" Version="4.7.14" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

Expand Down
12 changes: 6 additions & 6 deletions src/CodeIndex.ConsoleApp/CodeIndex.ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CodeIndex.Files/CodeIndex.Files.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/CodeIndex.IndexBuilder/CodeIndex.IndexBuilder.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -10,7 +10,7 @@
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00016" />
<PackageReference Include="Lucene.Net.ICU" Version="4.8.0-beta00016" />
<PackageReference Include="Lucene.Net.QueryParser" Version="4.8.0-beta00016" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CodeIndex.MaintainIndex/CodeIndex.MaintainIndex.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/CodeIndex.Search/CodeIndex.Search.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
16 changes: 9 additions & 7 deletions src/CodeIndex.Server/CodeIndex.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<UserSecretsId>869cc96a-d1b8-4328-9b99-bc356c26a33a</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
Expand All @@ -15,12 +15,14 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.2" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
<PackageReference Include="NSwag.AspNetCore" Version="13.15.10" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.1" />
<PackageReference Include="System.Drawing.Common" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
98 changes: 50 additions & 48 deletions src/CodeIndex.Server/Data/CaptchaImageUtils.cs
Original file line number Diff line number Diff line change
@@ -1,97 +1,99 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

namespace CodeIndex.Server
{
public class CaptchaImageUtils
{
public static byte[] GenerateCaptchaImage(int width, int height, string captchaCode, Random random)
{
using var baseMap = new Bitmap(width, height);
using var graphics = Graphics.FromImage(baseMap);
graphics.Clear(GetRandomLightColor(random));
DrawCaptchaCode(width, height, captchaCode, random, graphics);
DrawDisorderLine(random, width, height, graphics);
AdjustRippleEffect(baseMap);
var fontSize = GetFontSize(width, captchaCode.Length);
var fondFamily = SystemFonts.Collection.Families.FirstOrDefault(u => u.Name == "Consolas");
fondFamily = fondFamily == default ? SystemFonts.Collection.Families.Last() : fondFamily;
var font = SystemFonts.CreateFont(fondFamily.Name, fontSize);

using var ms = new MemoryStream();
baseMap.Save(ms, ImageFormat.Png);
using var image = new Image<Rgba32>(width, height, GetRandomLightColor(random));
DrawCaptchaCode(height, captchaCode, fontSize, font, random, image);
DrawDisorderLine(width, height, image, random);

using var ms = new MemoryStream();
image.SaveAsPng(ms);
return ms.ToArray();
}

static int GetFontSize(int imageWidth, int captchCodeCount)
static void DrawCaptchaCode(int height, string captchaCode, int fontSize, Font font, Random random, Image<Rgba32> image)
{
var averageSize = imageWidth / captchCodeCount;
for (int i = 0; i < captchaCode.Length; i++)
{
var shiftPx = fontSize / 6;
var x = random.Next(-shiftPx, shiftPx) + random.Next(-shiftPx, shiftPx);
if (x < 0 && i == 0)
{
x = 0;
}

return Convert.ToInt32(averageSize);
x += i * fontSize;

var maxY = height - fontSize;
if (maxY < 0)
{
maxY = 0;
}

var y = random.Next(0, maxY);

image.Mutate(operation => operation.DrawText(captchaCode[i].ToString(), font, GetRandomDeepColor(random), new PointF(x, y)));
}
}

static Color GetRandomDeepColor(Random random)
{
var redlow = 160;
var greenLow = 100;
var blueLow = 160;
return Color.FromArgb(random.Next(redlow), random.Next(greenLow), random.Next(blueLow));
return Color.FromRgb((byte)random.Next(redlow), (byte)random.Next(greenLow), (byte)random.Next(blueLow));
}

static Color GetRandomLightColor(Random random)
{
var low = 200;
var high = 255;
const int low = 200;
const int high = 255;

var nRend = random.Next(high) % (high - low) + low;
var nGreen = random.Next(high) % (high - low) + low;
var nBlue = random.Next(high) % (high - low) + low;

return Color.FromArgb(nRend, nGreen, nBlue);
return Color.FromRgb((byte)nRend, (byte)nGreen, (byte)nBlue);
}

static void DrawCaptchaCode(int width, int height, string captchaCode, Random random, Graphics graphics)
static int GetFontSize(int imageWidth, int captchCodeCount)
{
SolidBrush fontBrush = new SolidBrush(Color.Black);
var fontSize = GetFontSize(width, captchaCode.Length);
var font = new Font(FontFamily.GenericSerif, fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
for (int i = 0; i < captchaCode.Length; i++)
{
fontBrush.Color = GetRandomDeepColor(random);

int shiftPx = fontSize / 6;

var x = i * fontSize + random.Next(-shiftPx, shiftPx) + random.Next(-shiftPx, shiftPx);
var maxY = height - fontSize;
if (maxY < 0)
{
maxY = 0;
}

var y = random.Next(0, maxY);
var averageSize = imageWidth / captchCodeCount;

graphics.DrawString(captchaCode[i].ToString(), font, fontBrush, x, y);
}
return Convert.ToInt32(averageSize);
}

static void DrawDisorderLine(Random random, int width, int height, Graphics graphics)
static void DrawDisorderLine(int width, int height, Image graphics, Random random)
{
var linePen = new Pen(new SolidBrush(Color.Black), 3);
for (int i = 0; i < random.Next(3, 5); i++)
{
linePen.Color = GetRandomLightColor(random);

var linePen = new SolidPen(new SolidBrush(GetRandomLightColor(random)), 3);
var startPoint = new Point(random.Next(0, width), random.Next(0, height));
var endPoint = new Point(random.Next(0, width), random.Next(0, height));
graphics.DrawLine(linePen, startPoint, endPoint);
graphics.Mutate(operation => operation.DrawLine(linePen, startPoint, endPoint));

//var bezierPoint1 = new Point(random.Next(0, width), random.Next(0, height));
//var bezierPoint2 = new Point(random.Next(0, width), random.Next(0, height));
//graphics.DrawBezier(linePen, startPoint, bezierPoint1, bezierPoint2, endPoint);
//var bezierPoint3 = new Point(random.Next(0, width), random.Next(0, height));
//var bezierPoint4 = new Point(random.Next(0, width), random.Next(0, height));
//graphics.Mutate(operation => operation.DrawBeziers(linePen, bezierPoint1, bezierPoint2, bezierPoint3, bezierPoint4));
}
}

static void AdjustRippleEffect(Bitmap baseMap)
{
}
}
}
}
7 changes: 3 additions & 4 deletions src/CodeIndex.Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
RUN apt-get update && apt-get install -y libgdiplus
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT Production
ENV CodeIndex__LuceneIndex /luceneindex
Expand All @@ -11,7 +10,7 @@ ENV CodeIndex__LocalUrl http://localhost:80/
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["CodeIndex.Server/CodeIndex.Server.csproj", "CodeIndex.Server/"]
COPY ["CodeIndex.Common/CodeIndex.Common.csproj", "CodeIndex.Common/"]
Expand Down
2 changes: 1 addition & 1 deletion src/CodeIndex.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApp

// Register the Swagger generator and the Swagger UI middlewares
app.UseOpenApi();
app.UseSwaggerUi3();
app.UseSwaggerUi();

app.UseAuthentication();
app.UseAuthorization();
Expand Down
8 changes: 4 additions & 4 deletions src/CodeIndex.Test/CodeIndex.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PackageReference Include="nunit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit e79de9b

Please sign in to comment.