IczpNet.Pusher.Application.Contracts 8.2.0.2

dotnet add package IczpNet.Pusher.Application.Contracts --version 8.2.0.2                
NuGet\Install-Package IczpNet.Pusher.Application.Contracts -Version 8.2.0.2                
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.Contracts" Version="8.2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IczpNet.Pusher.Application.Contracts --version 8.2.0.2                
#r "nuget: IczpNet.Pusher.Application.Contracts, 8.2.0.2"                
#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.
// Install IczpNet.Pusher.Application.Contracts as a Cake Addin
#addin nuget:?package=IczpNet.Pusher.Application.Contracts&version=8.2.0.2

// Install IczpNet.Pusher.Application.Contracts as a Cake Tool
#tool nuget:?package=IczpNet.Pusher.Application.Contracts&version=8.2.0.2                

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 Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

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

Package Downloads
IczpNet.Chat.Application.Contracts

IczpNet.Chat

IczpNet.Pusher.Application

Pusher for abpVNext8.2

IczpNet.Pusher.HttpApi.Client

Pusher for abpVNext8.2

IczpNet.Pusher.HttpApi

Pusher for abpVNext8.2

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.2.0.2 184 7/18/2024
8.2.0.1 165 7/17/2024

add logo