VOOZH about

URL: https://www.nuget.org/packages/IczpNet.Pusher.Application/

⇱ NuGet Gallery | IczpNet.Pusher.Application 9.0.0.1




👁 Image
IczpNet.Pusher.Application 9.0.0.1

dotnet add package IczpNet.Pusher.Application --version 9.0.0.1
 
 
NuGet\Install-Package IczpNet.Pusher.Application -Version 9.0.0.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IczpNet.Pusher.Application" Version="9.0.0.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IczpNet.Pusher.Application" Version="9.0.0.1" />
 
Directory.Packages.props
<PackageReference Include="IczpNet.Pusher.Application" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IczpNet.Pusher.Application --version 9.0.0.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IczpNet.Pusher.Application, 9.0.0.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IczpNet.Pusher.Application@9.0.0.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IczpNet.Pusher.Application&version=9.0.0.1
 
Install as a Cake Addin
#tool nuget:?package=IczpNet.Pusher.Application&version=9.0.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Iczp.Pusher

abpvnext push module

IczpNet.Pusher.Domain.Shared

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);
 }
}

Usage

IczpNet.Pusher.HttpApi.Host

PusherHttpApiHostModule.cs

[DependsOn(typeof(IczpNetPusherXXXXXXModule))]

[DependsOn(typeof(IczpNetPusherModule))]
public class IMServerModule : AbpModule
{
	//...
}

ConfigureServices

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on IczpNet.Pusher.Application:

Package Downloads
IczpNet.Chat.Application

Chat module for abp

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.0.1 274 1/9/2025
8.2.0.2 253 7/18/2024
8.2.0.1 220 7/17/2024

add logo