Skip to content

Commit c696154

Browse files
committed
Add ActiveSessionCount property and improve AOT support
Introduces a public ActiveSessionCount property to SmtpServer for session monitoring, replacing reflection-based access in health checks for better AOT compatibility. Updates Zetian.csproj with AOT-related properties for .NET 7.0+ and adjusts API documentation to reflect the new property and event order.
1 parent 3cde909 commit c696154

4 files changed

Lines changed: 111 additions & 101 deletions

File tree

.pages/app/api/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const apiCategories = [
3232
{
3333
name: 'SmtpServer',
3434
description: 'Main SMTP server class that handles connections and messages',
35-
properties: ['Configuration', 'StartTime', 'IsRunning', 'Endpoint'],
35+
properties: ['ActiveSessionCount', 'Configuration', 'StartTime', 'IsRunning', 'Endpoint'],
3636
methods: ['StartAsync()', 'StopAsync()', 'Dispose()'],
37-
events: ['MessageReceived', 'SessionCreated', 'SessionCompleted', 'ErrorOccurred']
37+
events: ['SessionCompleted', 'MessageReceived', 'SessionCreated', 'ErrorOccurred']
3838
},
3939
{
4040
name: 'SmtpServerBuilder',

src/Zetian.HealthCheck/Checks/SmtpServerHealthCheck.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
2-
using System.Collections.Concurrent;
32
using System.Collections.Generic;
43
using System.Diagnostics;
5-
using System.Reflection;
64
using System.Threading;
75
using System.Threading.Tasks;
86
using Zetian.Abstractions;
@@ -97,16 +95,8 @@ public Task<HealthCheckResult> CheckHealthAsync(CancellationToken cancellationTo
9795

9896
private int GetActiveSessionCount(SmtpServer server)
9997
{
100-
// Use reflection to access private field (for health monitoring purposes)
101-
FieldInfo? sessionsField = typeof(SmtpServer).GetField("_sessions",
102-
BindingFlags.NonPublic | BindingFlags.Instance);
103-
104-
if (sessionsField?.GetValue(server) is ConcurrentDictionary<string, object> sessions)
105-
{
106-
return sessions.Count;
107-
}
108-
109-
return 0;
98+
// Use the public ActiveSessionCount property (AOT-compatible)
99+
return server.ActiveSessionCount;
110100
}
111101

112102
private string GetUptime()

src/Zetian/Server/SmtpServer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public SmtpServer() : this(new SmtpServerConfiguration())
6565
/// </summary>
6666
public DateTime? StartTime { get; private set; }
6767

68+
/// <summary>
69+
/// Gets the number of active sessions
70+
/// </summary>
71+
public int ActiveSessionCount => _sessions?.Count ?? 0;
72+
6873
/// <inheritdoc />
6974
public event EventHandler<SessionEventArgs>? SessionCreated;
7075

src/Zetian/Zetian.csproj

Lines changed: 102 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,103 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
5-
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
6-
<ImplicitUsings>disable</ImplicitUsings>
7-
<DefaultLanguage>en-GB</DefaultLanguage>
8-
<RootNamespace>Zetian</RootNamespace>
9-
<Nullable>enable</Nullable>
10-
</PropertyGroup>
11-
12-
<PropertyGroup>
13-
<ApplicationIcon>Resources\Zetian.ico</ApplicationIcon>
14-
<Version>1.0.11</Version>
15-
<AssemblyVersion>$(Version)</AssemblyVersion>
16-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
17-
<Title>Zetian</Title>
18-
<PackageId>Zetian</PackageId>
19-
<Authors>Taiizor</Authors>
20-
<Product>Zetian SMTP Server</Product>
21-
<Copyright>Copyright © $([System.DateTime]::Today.ToString(yyyy)) $(Authors)</Copyright>
22-
<Summary>A professional, high-performance SMTP server library for .NET with minimal dependencies. Features include authentication, TLS/SSL support, rate limiting, and extensible architecture.</Summary>
23-
<Description>A professional, high-performance SMTP server library for .NET with minimal dependencies. Features include authentication, TLS/SSL support, rate limiting, and extensible architecture.</Description>
24-
<PackageReadmeFile>README.MD</PackageReadmeFile>
25-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
26-
<PackageLicenseExpression></PackageLicenseExpression>
27-
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
28-
<PackageReleaseNotes>All changes are detailed at https://zetian.soferity.com/changelog.</PackageReleaseNotes>
29-
<PackageTags>smtp;email;mail;server;smtp-server;mail-server;email-server;tcp;network;protocol;zetian</PackageTags>
30-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
31-
<!--<DocumentationFile>..\$(Title)\bin$(OutputPath)\$(Configuration)\$(TargetFramework)\$(Title).xml</DocumentationFile>-->
32-
<PackageProjectUrl>https://zetian.soferity.com</PackageProjectUrl>
33-
<RepositoryType>git</RepositoryType>
34-
<RepositoryUrl>git://github.com/Taiizor/Zetian</RepositoryUrl>
35-
<PackageDescription>$(Description)</PackageDescription>
36-
<PackageIcon>Zetian.png</PackageIcon>
37-
<Company>$(Authors)</Company>
38-
<Owners>$(Authors)</Owners>
39-
<AnalysisLevel>preview</AnalysisLevel>
40-
<LangVersion>preview</LangVersion>
41-
<NeutralLanguage>$(DefaultLanguage)</NeutralLanguage>
42-
<FileVersion>$(Version)</FileVersion>
43-
<PublishRepositoryUrl>true</PublishRepositoryUrl>
44-
<EmbedUntrackedSources>true</EmbedUntrackedSources>
45-
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
46-
<IncludeSymbols>true</IncludeSymbols>
47-
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
48-
<Configurations>Debug;Release</Configurations>
49-
<NoWarn>$(NoWarn);1591</NoWarn>
50-
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
51-
</PropertyGroup>
52-
53-
<ItemGroup>
54-
<PackageReference Include="Microsoft.SourceLink.GitHub">
55-
<Version>10.0.0-beta.25514.2</Version>
56-
<PrivateAssets>All</PrivateAssets>
57-
</PackageReference>
58-
</ItemGroup>
59-
60-
<ItemGroup>
61-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.10" />
62-
</ItemGroup>
63-
64-
<ItemGroup>
65-
<None Include="README.MD">
66-
<Pack>True</Pack>
67-
<PackagePath></PackagePath>
68-
</None>
69-
<None Include="..\..\LICENSE">
70-
<Pack>True</Pack>
71-
<PackagePath></PackagePath>
72-
</None>
73-
<None Include="Resources\Zetian.png">
74-
<Pack>True</Pack>
75-
<PackagePath></PackagePath>
76-
</None>
77-
</ItemGroup>
78-
79-
<ItemGroup>
80-
<Folder Include="Properties\" />
81-
</ItemGroup>
82-
83-
<ItemGroup>
84-
<InternalsVisibleTo Include="Zetian.Tests" />
85-
<InternalsVisibleTo Include="Zetian.Benchmarks" />
86-
</ItemGroup>
87-
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
5+
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
6+
<ImplicitUsings>disable</ImplicitUsings>
7+
<DefaultLanguage>en-GB</DefaultLanguage>
8+
<RootNamespace>Zetian</RootNamespace>
9+
<Nullable>enable</Nullable>
10+
</PropertyGroup>
11+
12+
<!-- AOT Support for .NET 7.0+ -->
13+
<PropertyGroup Condition="'$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net10.0'">
14+
<EnableAotAnalyzer Condition="'$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net10.0'">true</EnableAotAnalyzer>
15+
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
16+
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
17+
<PublishAot Condition="'$(RuntimeIdentifier)' != ''">true</PublishAot>
18+
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
19+
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
20+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
21+
<IsAotCompatible>true</IsAotCompatible>
22+
<IlcTrimMetadata>true</IlcTrimMetadata>
23+
<IsTrimmable>true</IsTrimmable>
24+
<TrimMode>link</TrimMode>
25+
</PropertyGroup>
26+
27+
<PropertyGroup>
28+
<ApplicationIcon>Resources\Zetian.ico</ApplicationIcon>
29+
<Version>1.0.11</Version>
30+
<AssemblyVersion>$(Version)</AssemblyVersion>
31+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
32+
<Title>Zetian</Title>
33+
<PackageId>Zetian</PackageId>
34+
<Authors>Taiizor</Authors>
35+
<Product>Zetian SMTP Server</Product>
36+
<Copyright>Copyright © $([System.DateTime]::Today.ToString(yyyy)) $(Authors)</Copyright>
37+
<Summary>A professional, high-performance SMTP server library for .NET with minimal dependencies. Features include authentication, TLS/SSL support, rate limiting, and extensible architecture.</Summary>
38+
<Description>A professional, high-performance SMTP server library for .NET with minimal dependencies. Features include authentication, TLS/SSL support, rate limiting, and extensible architecture.</Description>
39+
<PackageReadmeFile>README.MD</PackageReadmeFile>
40+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
41+
<PackageLicenseExpression></PackageLicenseExpression>
42+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
43+
<PackageReleaseNotes>All changes are detailed at https://zetian.soferity.com/changelog.</PackageReleaseNotes>
44+
<PackageTags>smtp;email;mail;server;smtp-server;mail-server;email-server;tcp;network;protocol;zetian</PackageTags>
45+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
46+
<!--<DocumentationFile>..\$(Title)\bin$(OutputPath)\$(Configuration)\$(TargetFramework)\$(Title).xml</DocumentationFile>-->
47+
<PackageProjectUrl>https://zetian.soferity.com</PackageProjectUrl>
48+
<RepositoryType>git</RepositoryType>
49+
<RepositoryUrl>git://github.com/Taiizor/Zetian</RepositoryUrl>
50+
<PackageDescription>$(Description)</PackageDescription>
51+
<PackageIcon>Zetian.png</PackageIcon>
52+
<Company>$(Authors)</Company>
53+
<Owners>$(Authors)</Owners>
54+
<AnalysisLevel>preview</AnalysisLevel>
55+
<LangVersion>preview</LangVersion>
56+
<NeutralLanguage>$(DefaultLanguage)</NeutralLanguage>
57+
<FileVersion>$(Version)</FileVersion>
58+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
59+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
60+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
61+
<IncludeSymbols>true</IncludeSymbols>
62+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
63+
<Configurations>Debug;Release</Configurations>
64+
<NoWarn>$(NoWarn);1591</NoWarn>
65+
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
66+
</PropertyGroup>
67+
68+
<ItemGroup>
69+
<PackageReference Include="Microsoft.SourceLink.GitHub">
70+
<Version>10.0.0-beta.25514.2</Version>
71+
<PrivateAssets>All</PrivateAssets>
72+
</PackageReference>
73+
</ItemGroup>
74+
75+
<ItemGroup>
76+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.10" />
77+
</ItemGroup>
78+
79+
<ItemGroup>
80+
<None Include="README.MD">
81+
<Pack>True</Pack>
82+
<PackagePath></PackagePath>
83+
</None>
84+
<None Include="..\..\LICENSE">
85+
<Pack>True</Pack>
86+
<PackagePath></PackagePath>
87+
</None>
88+
<None Include="Resources\Zetian.png">
89+
<Pack>True</Pack>
90+
<PackagePath></PackagePath>
91+
</None>
92+
</ItemGroup>
93+
94+
<ItemGroup>
95+
<Folder Include="Properties\" />
96+
</ItemGroup>
97+
98+
<ItemGroup>
99+
<InternalsVisibleTo Include="Zetian.Tests" />
100+
<InternalsVisibleTo Include="Zetian.Benchmarks" />
101+
</ItemGroup>
102+
88103
</Project>

0 commit comments

Comments
 (0)