Skip to content

Commit 9bde273

Browse files
committed
2 parents 658c18d + 7fbfb35 commit 9bde273

2 files changed

Lines changed: 100 additions & 4 deletions

File tree

Sources/EasyExtensions.AspNetCore.Sentry/Factories/UserFactory.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using EasyExtensions.AspNetCore.Extensions;
22
using Microsoft.AspNetCore.Http;
33
using Sentry;
4+
using System;
45
using System.Linq;
56
using System.Security.Claims;
67

@@ -21,13 +22,24 @@ public class UserFactory(IHttpContextAccessor httpContextAccessor) : ISentryUser
2122
{
2223
return null;
2324
}
25+
var context = httpContextAccessor.HttpContext;
26+
var claims = httpContextAccessor.HttpContext.User.Claims;
2427
int userId = httpContextAccessor.HttpContext.User.TryGetId();
28+
bool hasUserId = httpContextAccessor.HttpContext.User.TryGetUserId(out Guid guidUserId);
29+
string userIdStr = hasUserId ? guidUserId.ToString() : userId > 0 ? userId.ToString() : "Anonymous";
30+
string username = claims.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value
31+
?? claims.FirstOrDefault(x => x.Type == "preferred_username")?.Value
32+
?? "Anonymous";
33+
string email = claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value
34+
?? claims.FirstOrDefault(x => x.Type == "email")?.Value
35+
?? string.Empty;
36+
2537
return new SentryUser()
2638
{
27-
Id = userId.ToString(),
28-
IpAddress = httpContextAccessor.HttpContext.Request.GetRemoteAddress(),
29-
Username = httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value,
30-
Email = httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value,
39+
Id = userIdStr,
40+
IpAddress = context.Request.GetRemoteAddress(),
41+
Username = username,
42+
Email = email,
3143
};
3244
}
3345
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace EasyExtensions.Models.Enums
2+
{
3+
/// <summary>
4+
/// Specifies the available compression algorithms for encoding or decoding data streams.
5+
/// </summary>
6+
/// <remarks>Use this enumeration to select a compression algorithm based on your requirements for speed,
7+
/// compression ratio, compatibility, and platform support. Some algorithms are optimized for fast compression and
8+
/// decompression (such as LZ4 and Snappy), while others provide higher compression ratios at the cost of speed
9+
/// (such as XZ and LZMA). Not all algorithms may be supported on all platforms or by all libraries. Choose the
10+
/// algorithm that best matches your use case, such as archival storage, web asset delivery, or real-time
11+
/// processing.</remarks>
12+
public enum CompressionAlgorithm
13+
{
14+
/// <summary>
15+
/// No compression. Best for already-compressed data (JPEG/PNG/MP4/ZIP) to avoid wasted CPU.
16+
/// </summary>
17+
None = 0,
18+
19+
/// <summary>
20+
/// Raw DEFLATE stream (no container). Rare as a storage format; common inside ZIP/PNG and some protocols.
21+
/// </summary>
22+
Deflate = 1,
23+
24+
/// <summary>
25+
/// zlib wrapper around DEFLATE (RFC 1950). Common in libraries/protocols.
26+
/// </summary>
27+
Zlib = 2,
28+
29+
/// <summary>
30+
/// gzip container around DEFLATE (RFC 1952). Very compatible and widely supported; usually worse than Zstd for storage.
31+
/// </summary>
32+
Gzip = 3,
33+
34+
/// <summary>
35+
/// Brotli. Great for web assets (HTML/CSS/JS); often slower to compress for mixed-content storage.
36+
/// </summary>
37+
Brotli = 4,
38+
39+
/// <summary>
40+
/// Zstandard (Zstd). Excellent general-purpose default for storage: fast decompression + strong ratio.
41+
/// </summary>
42+
Zstd = 5,
43+
44+
/// <summary>
45+
/// LZ4. Extremely fast compression/decompression with low latency; weaker ratio than Zstd.
46+
/// </summary>
47+
Lz4 = 6,
48+
49+
/// <summary>
50+
/// Snappy. Very fast, common in some storage/log pipelines; typically weaker ratio than Zstd.
51+
/// </summary>
52+
Snappy = 7,
53+
54+
/// <summary>
55+
/// LZO. Older fast codec seen in some systems; usually less popular than LZ4/Zstd today.
56+
/// </summary>
57+
Lzo = 8,
58+
59+
/// <summary>
60+
/// bzip2. Better ratio than gzip in some cases, but slow; mostly legacy/archival.
61+
/// </summary>
62+
Bzip2 = 9,
63+
64+
/// <summary>
65+
/// XZ (LZMA2 in .xz container). Very high ratio, but slow and high-latency; archival, not “on-the-fly”.
66+
/// </summary>
67+
Xz = 10,
68+
69+
/// <summary>
70+
/// LZMA (classic). High ratio, very slow; mostly archival/legacy.
71+
/// </summary>
72+
Lzma = 11,
73+
74+
/// <summary>
75+
/// LZFSE. Apple codec (iOS/macOS). Fast-ish with decent ratio; mostly relevant on Apple ecosystems.
76+
/// </summary>
77+
Lzfse = 12,
78+
79+
/// <summary>
80+
/// Zopfli (deflate-optimizer). Extremely slow compression for slightly smaller gzip/deflate; offline packaging only.
81+
/// </summary>
82+
Zopfli = 13
83+
}
84+
}

0 commit comments

Comments
 (0)