![]() |
VOOZH | about |
dotnet add package IczpNet.Pusher.Domain --version 9.0.1.903
NuGet\Install-Package IczpNet.Pusher.Domain -Version 9.0.1.903
<PackageReference Include="IczpNet.Pusher.Domain" Version="9.0.1.903" />
<PackageVersion Include="IczpNet.Pusher.Domain" Version="9.0.1.903" />Directory.Packages.props
<PackageReference Include="IczpNet.Pusher.Domain" />Project file
paket add IczpNet.Pusher.Domain --version 9.0.1.903
#r "nuget: IczpNet.Pusher.Domain, 9.0.1.903"
#:package IczpNet.Pusher.Domain@9.0.1.903
#addin nuget:?package=IczpNet.Pusher.Domain&version=9.0.1.903Install as a Cake Addin
#tool nuget:?package=IczpNet.Pusher.Domain&version=9.0.1.903Install as a Cake Tool
abpvnext push module
CommandAttribute.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace IczpNet.Pusher.Commands;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class CommandAttribute : Attribute
{
public string Command { get; }
public CommandAttribute(string command)
{
Command = command;
}
public static string GetValue<T>()
{
return GetValue(typeof(T));
}
public static List<string> GetValues<T>()
{
return GetValues(typeof(T));
}
public static List<string> GetValues(Type type)
{
var nameAttributes = type.GetCustomAttributes<CommandAttribute>();
if (!nameAttributes.Any())
{
return [type.FullName];
}
return nameAttributes.Select(x => x.Command).ToList();
}
public static string GetValue(Type type)
{
var nameAttribute = type.GetCustomAttribute<CommandAttribute>();
if (nameAttribute == null)
{
return type.FullName;
}
return nameAttribute.Command;
}
}
TicketInfo.cs
using System;
namespace IczpNet.Pusher.Tickets;
public class TicketInfo
{
public string Id { get; set; }
public string ConnectionId { get; set; }
public Guid AppUserId { get; set; }
public string DeviceId { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long ExpireSeconds { get; set; }
public override string ToString()
{
return $"Id={Id},ConnectionId={ConnectionId},AppUserId={AppUserId},DeviceId={DeviceId},CreationTime={CreationTime},ExpireSeconds={ExpireSeconds}";
}
}
DeviceIdAuditLogContributor.cs 加入审计日志
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Users;
namespace IczpNet.Pusher.DeviceIds;
public class DeviceIdAuditLogContributor : AuditLogContributor//, ITransientDependency
{
//protected IDeviceIdResolver DeviceIdResolver { get; }
//protected IOptions<PusherOptions> Options { get; }
//public DeviceIdAuditLogContributor(IDeviceIdResolver deviceIdResolver,
// IOptions<PusherOptions> options)
//{
// DeviceIdResolver = deviceIdResolver;
// Options = options;
//}
public override void PreContribute(AuditLogContributionContext context)
{
//deviceId for user
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
if (currentUser != null)
{
var userDeviceId = currentUser.FindClaimValue(DeviceIdExtensions.DeviceIdClaim);
context.AuditInfo.SetProperty(DeviceIdExtensions.DeviceIdClaim, userDeviceId);
}
var htpContextAccessor = context.ServiceProvider.GetRequiredService<IHttpContextAccessor>();
htpContextAccessor.HttpContext.Request.Headers
.Where(x => x.Key != "User-Agent")
.Where(x => x.Key != "Authorization")
.Where(x => !string.IsNullOrEmpty(x.Value))
.ToList()
.ForEach(x =>
{
context.AuditInfo.SetProperty(x.Key, x.Value);
});
////deviceId for request header
//var deviceIdResolver = context.ServiceProvider.GetRequiredService<IDeviceIdResolver>();
//void setProperty(string key)
//{
// var value = deviceIdResolver.GetHeader(key);
// if (!string.IsNullOrEmpty(value))
// {
// context.AuditInfo.SetProperty(key, value);
// }
//}
//new List<string>() { "app-platform", "app-id", "app-version", deviceIdResolver.GetDeviceIdKey() }.ForEach(setProperty);
}
public override void PostContribute(AuditLogContributionContext context)
{
//context.AuditInfo.Comments.Add("Some comment deviceId...");
}
}
DeviceIdClaimsPrincipalContributor.cs 加入用户 Claims
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
namespace IczpNet.Pusher.DeviceIds;
public class DeviceIdClaimsPrincipalContributor : IAbpClaimsPrincipalContributor, ITransientDependency
{
//public const string DeviceIdClaim = "device_id";
protected IDeviceIdResolver DeviceIdResolver { get; }
public DeviceIdClaimsPrincipalContributor(IDeviceIdResolver deviceIdResolver)
{
DeviceIdResolver = deviceIdResolver;
}
public async Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
{
var identity = context.ClaimsPrincipal.Identities.FirstOrDefault();
//var userId = identity?.FindUserId();
//if (!userId.HasValue)
//{
// return;
//}
var deviceId = await DeviceIdResolver.GetDeviceIdAsync();
if (!string.IsNullOrWhiteSpace(deviceId))
{
identity.AddIfNotContains(new Claim(DeviceIdExtensions.DeviceIdClaim, deviceId, ClaimValueTypes.Integer));
}
}
}
DeviceIdExtensions.cs
using Volo.Abp.Users;
namespace IczpNet.Pusher.DeviceIds;
public static class DeviceIdExtensions
{
public const string DeviceIdClaim = "device_id";
/// <summary>
/// Get DeviceId by ICurrentUser
/// </summary>
/// <param name="currentUser"></param>
/// <returns></returns>
public static string GetDeviceId(this ICurrentUser currentUser)
{
return currentUser.FindClaimValue(DeviceIdClaim);
}
}
PusherHttpApiHostModule.cs
[DependsOn(typeof(IczpNetPusherXXXXXXModule))][DependsOn(typeof(IczpNetPusherModule))]
public class IMServerModule : AbpModule
{
//...
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
//...
Configure<PusherOptions>(options =>
{
options.Redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
});
//...
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
//...
app.UsePusherSubscriber(); //add this line
}
appsettings.json{
"Redis": {
"Configuration": "127.0.0.1"
},
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on IczpNet.Pusher.Domain:
| Package | Downloads |
|---|---|
|
IczpNet.Chat.Domain
Chat module for abp |
|
|
IczpNet.Pusher.Application
Pusher for abpVNext |
This package is not used by any popular GitHub repositories.
add logo