Skip to content

Commit

Permalink
Merge pull request #3054 from JeffreySu/Developer
Browse files Browse the repository at this point in the history
发布新版本:Senparc.Weixin.Cache.Dapr v0.1.0-beta1
  • Loading branch information
JeffreySu authored Jul 31, 2024
2 parents 03a7fc8 + 46f2f5a commit 93a1dcf
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 2 deletions.
21 changes: 21 additions & 0 deletions Samples/All/net8-mvc/Senparc.Weixin.Sample.Net8.sln
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "公众号", "公众号", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senparc.Weixin.Sample.MP.Simple", "..\..\MP\Senparc.Weixin.Sample.MP.Simple\Senparc.Weixin.Sample.MP.Simple.csproj", "{C4370924-9D72-4859-93C0-AA619BFC583B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senparc.Weixin.Cache.Dapr.net8", "..\..\..\src\Senparc.Weixin.Cache\Senparc.Weixin.Cache.Dapr\Senparc.Weixin.Cache.Dapr.net8.csproj", "{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -691,6 +693,24 @@ Global
{C4370924-9D72-4859-93C0-AA619BFC583B}.Test|x64.Build.0 = Debug|Any CPU
{C4370924-9D72-4859-93C0-AA619BFC583B}.Test|x86.ActiveCfg = Debug|Any CPU
{C4370924-9D72-4859-93C0-AA619BFC583B}.Test|x86.Build.0 = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Debug|x64.ActiveCfg = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Debug|x64.Build.0 = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Debug|x86.ActiveCfg = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Debug|x86.Build.0 = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Release|Any CPU.Build.0 = Release|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Release|x64.ActiveCfg = Release|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Release|x64.Build.0 = Release|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Release|x86.ActiveCfg = Release|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Release|x86.Build.0 = Release|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Test|Any CPU.Build.0 = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Test|x64.ActiveCfg = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Test|x64.Build.0 = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Test|x86.ActiveCfg = Debug|Any CPU
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6}.Test|x86.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -739,6 +759,7 @@ Global
{F1AAA30B-2829-4410-8A96-F21B88B066B0} = {20CDE085-A7B1-447E-8875-981D8C3DF535}
{37E0EA13-96E7-423E-8C53-CE136C439B54} = {34CFB1D8-6025-4E93-A67F-D94DD3B9198F}
{C4370924-9D72-4859-93C0-AA619BFC583B} = {37E0EA13-96E7-423E-8C53-CE136C439B54}
{892FB0E9-9DFC-4E0D-B1DF-ADD775DD36A6} = {FDC9A3F1-A2EC-4E44-9093-BE0EE1C17093}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DC7AD3EC-AB37-497E-925B-DCD5129FE6D3}
Expand Down
3 changes: 2 additions & 1 deletion src/Senparc.Weixin.All/Senparc.Weixin.All.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2024.8.1</Version>
<Version>2024.8.1.1-beta1</Version>
<LangVersion>10.0</LangVersion>
<AssemblyName>Senparc.Weixin.All</AssemblyName>
<RootNamespace>Senparc.Weixin.All</RootNamespace>
Expand Down Expand Up @@ -65,6 +65,7 @@
<ProjectReference Include="..\Senparc.WebSocket\src\Senparc.WebSocket\Senparc.WebSocket\Senparc.WebSocket.net8.csproj" />
<ProjectReference Include="..\Senparc.Weixin.AspNet\Senparc.Weixin.AspNet.net8.csproj" />
<ProjectReference Include="..\Senparc.Weixin.Cache\Senparc.Weixin.Cache.CsRedis\Senparc.Weixin.Cache.CsRedis.net8.csproj" />
<ProjectReference Include="..\Senparc.Weixin.Cache\Senparc.Weixin.Cache.Dapr\Senparc.Weixin.Cache.Dapr.net8.csproj" />
<ProjectReference Include="..\Senparc.Weixin.Cache\Senparc.Weixin.Cache.Memcached\Senparc.Weixin.Cache.Memcached.net8.csproj" />
<ProjectReference Include="..\Senparc.Weixin.Cache\Senparc.Weixin.Cache.Redis\Senparc.Weixin.Cache.Redis.net8.csproj" />
<ProjectReference Include="..\Senparc.Weixin.MP.Middleware\Senparc.Weixin.MP.Middleware.net8.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2024 Senparc
文件名:DaprContainerCacheStrategy.cs
文件功能描述:Redis 容器缓存策略。
创建标识:Senparc - 20160308
修改标识:Senparc - 20160808
修改描述:v0.2.0 删除 ItemCollection 属性,直接使用ContainerBag加入到缓存
修改标识:Senparc - 20160812
修改描述:v0.2.1 解决Container无法注册的问题
修改标识:Senparc - 20170205
修改描述:v0.2.0 重构分布式锁
----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Senparc.CO2NET.Cache;
using Senparc.CO2NET.Cache.Dapr;
using Senparc.CO2NET.Cache.Dapr.ObjectCacheStrategy;
using Senparc.CO2NET.Helpers;
using Senparc.CO2NET.MessageQueue;
using Senparc.Weixin.Containers;
using Senparc.Weixin.Helpers;


namespace Senparc.Weixin.Cache.Dapr
{
/// <summary>
/// Redis容器缓存策略
/// </summary>
public sealed class DaprContainerCacheStrategy : BaseContainerCacheStrategy
{
#region IDomainExtensionCacheStrategy 成员
public override ICacheStrategyDomain CacheStrategyDomain { get { return ContainerCacheStrategyDomain.Instance; } }

#endregion

#region 单例

/// <summary>
/// Redis 缓存策略
/// </summary>
DaprContainerCacheStrategy() /*: base()*/
{
//base.ChildNamespace = "WeixinContainer";

//使用底层缓存策略
BaseCacheStrategy = () => DaprStateObjectCacheStrategy.Instance;

//向底层缓存注册当前缓存策略
base.RegisterCacheStrategyDomain(this);
}


//静态SearchCache
public static DaprContainerCacheStrategy Instance
{
get
{
return Nested.instance;//返回Nested类中的静态成员instance
}
}

class Nested
{
static Nested()
{
}
//将instance设为一个初始化的BaseCacheStrategy新实例
internal static readonly DaprContainerCacheStrategy instance = new DaprContainerCacheStrategy();
}

#endregion

static DaprContainerCacheStrategy()
{
}

/// <summary>
/// Redis 缓存策略析构函数,用于 _client 资源回收
/// </summary>
~DaprContainerCacheStrategy()
{
}

#region 实现 IContainerCacheStrategy 接口

/// <summary>
/// 获取所有 Bag 对象
/// </summary>
/// <typeparam name="TBag"></typeparam>
/// <returns></returns>
public override IDictionary<string, TBag> GetAll<TBag>()
{
#region 旧方法(没有使用Hash之前)

//var itemCacheKey = ContainerHelper.GetItemCacheKey(typeof(TBag), "*");
////var keyPattern = string.Format("*{0}", itemCacheKey);
//var keyPattern = GetFinalKey(itemCacheKey);

//var keys = GetServer().Keys(pattern: keyPattern);
//var dic = new Dictionary<string, TBag>();
//foreach (var redisKey in keys)
//{
// try
// {
// var bag = Get(redisKey, true);
// dic[redisKey] = (TBag)bag;
// }
// catch (Exception)
// {

// }

//}

#endregion


throw new NotImplementedException();

//var baseCacheStrategy = BaseCacheStrategy();
//var key = ContainerHelper.GetItemCacheKey(typeof(TBag), "");
//key = key.Substring(0, key.Length - 1);//去掉:号
//key = baseCacheStrategy.GetFinalKey(key);//获取带SenparcWeixin:DefaultCache:前缀的Key([DefaultCache]可配置)
//var list = (baseCacheStrategy as DaprStateObjectCacheStrategy).GetAllByPrefix<TBag>(key);

////var list = (baseCacheStrategy as RedisObjectCacheStrategy).GetAll(key);
//var dic = new Dictionary<string, TBag>();

//foreach (var item in list)
//{
// var fullKey = key + ":" + item.Key;//最完整的finalKey(可用于LocalCache),还原完整Key,格式:[命名空间]:[Key]
// //dic[fullKey] = StackExchangeRedisExtensions.Deserialize<TBag>(hashEntry.Value);
// dic[fullKey] = item;
//}

//return dic;
}


#region 异步方法

/// <summary>
/// 【异步方法】获取所有 Bag 对象
/// </summary>
/// <typeparam name="TBag"></typeparam>
/// <returns></returns>
public override async Task<IDictionary<string, TBag>> GetAllAsync<TBag>()
{
throw new NotImplementedException();
//var baseCacheStrategy = BaseCacheStrategy();
//var key = ContainerHelper.GetItemCacheKey(typeof(TBag), "");
//key = key.Substring(0, key.Length - 1);//去掉:号
//key = baseCacheStrategy.GetFinalKey(key);//获取带SenparcWeixin:DefaultCache:前缀的Key([DefaultCache]可配置)
//var list = await (baseCacheStrategy as DaprStateObjectCacheStrategy).GetAllByPrefixAsync<TBag>(key).ConfigureAwait(false);

////var list = (baseCacheStrategy as RedisObjectCacheStrategy).GetAll(key);
//var dic = new Dictionary<string, TBag>();

//foreach (var item in list)
//{
// var fullKey = key + ":" + item.Key;//最完整的finalKey(可用于LocalCache),还原完整Key,格式:[命名空间]:[Key]
// //dic[fullKey] = StackExchangeRedisExtensions.Deserialize<TBag>(hashEntry.Value);
// dic[fullKey] = item;
//}

//return dic;
}

#endregion

#endregion

}
}
49 changes: 49 additions & 0 deletions src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Dapr/Register.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*----------------------------------------------------------------
Copyright (C) 2024 Senparc
文件名:Register.cs
文件功能描述:Senparc.Weixin.Cache.Redis 注册类
创建标识:Senparc - 20180609
修改标识:Senparc - 20180802
修改描述:当前类所有方法支持 .net standard 2.0
修改标识:Senparc - 20191002
修改描述:v2.7.102 RegisterDomainCache() 方法重命名为 ActivityDomainCache()
修改标识:Senparc - 20191002
修改描述:v2.8.100 UseSenparcWeixinCacheRedis() 扩展方法 this 类型由 IApplicationBuilder 改为 IRegisterService
----------------------------------------------------------------*/

using Senparc.CO2NET.RegisterServices;

namespace Senparc.Weixin.Cache.Dapr
{
/// <summary>
/// Senparc.Weixin.Cache.Redis 注册类
/// </summary>
public static class Register
{
/// <summary>
/// 注册 Senparc.Weixin.Cache.Redis
/// </summary>
/// <param name="register"></param>
public static IRegisterService UseSenparcWeixinCacheDapr(this IRegisterService register)
{
ActivityDomainCache();
return register;
}

/// <summary>
/// 激活领域缓存
/// </summary>
public static void ActivityDomainCache()
{
//通过调用 ContainerCacheStrategy,激活领域模型注册过程
var cache = DaprContainerCacheStrategy.Instance;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Version>0.1.0-beta1</Version>
<AssemblyName>Senparc.Weixin.Cache.Dapr</AssemblyName>
<RootNamespace>Senparc.Weixin.Cache.Dapr</RootNamespace>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<Description>
微信 SDK - Redis 模块

Senparc.Weixin SDK 开源项目:
https://github.com/JeffreySu/WeiXinMPSDK
</Description>
<Copyright>Senparc Copyright © 2004~2024</Copyright>
<PackageTags>微信,weixin,公众号,WeChat,Senparc,盛派,SDK,C#,JSSDK,微信支付,分布式,小程序,Cache,Redis</PackageTags>
<Authors>Jeffrey Su</Authors>
<Owners>Senparc</Owners>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<ProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</ProjectUrl>
<Title>Senparc.Weixin.Cache.Dapr.dll</Title>
<Summary>微信 SDK for .NET / C#</Summary>
<PackageProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</PackageProjectUrl>
<PackageIcon>icon.jpg</PackageIcon>
<PackageReleaseNotes>
v0.1.0
创世
</PackageReleaseNotes>
<RepositoryUrl>https://github.com/JeffreySu/WeiXinMPSDK</RepositoryUrl>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\..\BuildOutPut</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\BuildOutPut</OutputPath>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
<DocumentationFile>..\..\BuildOutPut\Senparc.Weixin.Cache.Dapr.XML</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\net462\Senparc.Cache.Dapr.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\netstandard2.0\Senparc.Cache.Dapr.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'">
<OutputPath>..\..\BuildOutPut\</OutputPath>
<DocumentationFile>..\..\BuildOutPut\netstandard2.1\Senparc.Cache.Dapr.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Senparc.Weixin\icon.jpg" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Senparc.CO2NET.Cache.Dapr" Version="0.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Senparc.Weixin\Senparc.Weixin\Senparc.Weixin.net8.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Dapr/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading

0 comments on commit 93a1dcf

Please sign in to comment.