提交当前本机整理版本
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{060E4243-697C-40A3-BE89-F1853B62DF7A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Lskj.Redis</RootNamespace>
|
||||
<AssemblyName>Lskj.Redis</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StackExchange.Redis, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\StackExchange.Redis.1.2.1\lib\net40\StackExchange.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Runtime, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\Lskj.LserpAll\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Threading.Tasks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="RedisHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lskj.Business\Lskj.Business.csproj">
|
||||
<Project>{7eafccc2-a18f-49e9-85c6-a984966cfd01}</Project>
|
||||
<Name>Lskj.Business</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Lskj.Core\Lskj.Core.csproj">
|
||||
<Project>{2a1be6ac-1077-491b-a754-c5822fe8121e}</Project>
|
||||
<Name>Lskj.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Lskj.Model\Lskj.Model.csproj">
|
||||
<Project>{52bc40e0-c0c6-4f78-996b-cae028d209ca}</Project>
|
||||
<Name>Lskj.Model</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\Lskj.LserpAll\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\Lskj.LserpAll\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\Lskj.LserpAll\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\Lskj.LserpAll\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Lskj.Redius")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Lskj.Redius")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("060e4243-697c-40a3-be89-f1853b62df7a")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,273 @@
|
||||
using Lskj.Business.Impl;
|
||||
using Microsoft.Win32;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace Lskj.Redis
|
||||
{
|
||||
public static class RedisHelper
|
||||
{
|
||||
//private static readonly string ConnectionWriteString = "127.0.0.1:6379";
|
||||
private static readonly string ConnectionWriteString = "127.0.0.1:6379,abortConnect=false";
|
||||
private static readonly string RedisCmdStartPath = Environment.CurrentDirectory + "\\Redis";
|
||||
private static IConnectionMultiplexer ConnMultiplexer;
|
||||
private static IDatabase Database;
|
||||
private static int DbIndex = 0;
|
||||
/// <summary>
|
||||
/// 刷新数据键的集合
|
||||
/// </summary>
|
||||
private static readonly string RefRedisRefKeys = "defaultRedisRefKeys";
|
||||
public static bool InitRedis(int dbIndex)
|
||||
{
|
||||
bool rtn = false;
|
||||
Process process = new Process();
|
||||
try
|
||||
{
|
||||
process.StartInfo.FileName = "cmd.exe ";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardInput = true;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.WorkingDirectory = RedisCmdStartPath;
|
||||
process.Start();
|
||||
process.StandardInput.WriteLine("redis-server.exe --service-install redis.windows.conf --loglevel verbose");
|
||||
process.StandardInput.WriteLine("redis-server --service-start");
|
||||
process.StandardInput.Close();
|
||||
process.StandardOutput.ReadToEnd();
|
||||
if (ConnMultiplexer != null)
|
||||
{
|
||||
ConnMultiplexer.Dispose();
|
||||
ConnMultiplexer = null;
|
||||
}
|
||||
if (Database != null)
|
||||
{
|
||||
Database = null;
|
||||
}
|
||||
ConnMultiplexer = ConnectionMultiplexer.Connect(ConnectionWriteString);
|
||||
Database = ConnMultiplexer.GetDatabase(dbIndex);//参数为创建的数据库的位置
|
||||
rtn = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
rtn = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Close();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
public static void ClearRedis()
|
||||
{
|
||||
Process process = new Process();
|
||||
try
|
||||
{
|
||||
process.StartInfo.FileName = "cmd.exe ";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardInput = true;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.WorkingDirectory = RedisCmdStartPath;
|
||||
process.Start();
|
||||
process.StandardInput.WriteLine("redis-cli.exe -h 127.0.0.1 -p 6379");
|
||||
string selectOrder = string.Format("select {0}", DbIndex + "");
|
||||
process.StandardInput.WriteLine(selectOrder);
|
||||
process.StandardInput.WriteLine("flushdb");
|
||||
process.StandardInput.Close();
|
||||
process.StandardOutput.ReadToEnd();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Close();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置 key 并保存字符串(如果 key 已存在,则覆盖值)
|
||||
/// </summary>
|
||||
/// <param name="redisKey">名称</param>
|
||||
/// <param name="redisValue">值</param>
|
||||
/// <param name="expiry">时间</param>
|
||||
/// <returns></returns>
|
||||
public static bool StringSet(string redisKey, string redisValue, TimeSpan? expiry = null)
|
||||
{
|
||||
return Database.StringSet(redisKey, redisValue, expiry);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取字符串
|
||||
/// </summary>
|
||||
/// <param name="redisKey">名称</param>
|
||||
/// <param name="expiry">时间</param>
|
||||
/// <returns></returns>
|
||||
public static string StringGet(string redisKey, TimeSpan? expiry = null)
|
||||
{
|
||||
return Database.StringGet(redisKey);
|
||||
}
|
||||
/// <summary>
|
||||
/// 存储一个对象(该对象会被序列化保存)
|
||||
/// </summary>
|
||||
/// <param name="redisKey">名称</param>
|
||||
/// <param name="redisValue">值</param>
|
||||
/// <param name="expiry">时间</param>
|
||||
/// <returns></returns>
|
||||
public static bool SetValue<T>(string redisKey, T redisValue, TimeSpan? expiry = null)
|
||||
{
|
||||
bool rtn = false;
|
||||
try
|
||||
{
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream();//创建内存流对象
|
||||
IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
formatter.Serialize(ms, redisValue);//把Datatable对象序列化到内存流
|
||||
byte[] tabBuffer = ms.ToArray();//把内存流对象写入字节数组
|
||||
ms.Close();//关闭内存流对象
|
||||
ms.Dispose();//释放资源
|
||||
rtn = Database.StringSet(redisKey, tabBuffer, expiry);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
rtn = false;
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取一个对象(会进行反序列化)
|
||||
/// </summary>
|
||||
/// <param name="redisKey">名称</param>
|
||||
/// <param name="expiry">时间</param>
|
||||
/// <returns></returns>
|
||||
public static T GetValue<T>(string redisKey, TimeSpan? expiry = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] buffer = Database.StringGet(redisKey);
|
||||
if (buffer == null)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer))
|
||||
{
|
||||
stream.Position = 0;
|
||||
IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
object rtnObj = formatter.Deserialize(stream);
|
||||
T rtn = (T)Convert.ChangeType(rtnObj, typeof(T));
|
||||
return rtn;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断key是否存在
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public static bool ContainKey(string key)
|
||||
{
|
||||
bool rtn = false;
|
||||
try
|
||||
{
|
||||
rtn = Database.KeyExists(key);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
rtn = false;
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加键至刷新字典
|
||||
/// </summary>
|
||||
public static void SetRefKeyDic(string moudleid, string formkey)
|
||||
{
|
||||
string onlyOneKey = string.Format("{0}^{1}", moudleid, formkey);
|
||||
string mainModleId = Lskj.Model.ERPInfo.Instance.selectFormModleId;
|
||||
if (string.IsNullOrEmpty(mainModleId)) return;
|
||||
Dictionary<string, List<string>> keyValues = GetValue<Dictionary<string, List<string>>>(RefRedisRefKeys);
|
||||
if (keyValues == null)
|
||||
{
|
||||
keyValues = new Dictionary<string, List<string>>();
|
||||
}
|
||||
if (keyValues.ContainsKey(mainModleId))
|
||||
{
|
||||
List<string> moudleIds = keyValues[mainModleId];
|
||||
if (!moudleIds.Contains(onlyOneKey))
|
||||
{
|
||||
moudleIds.Add(onlyOneKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> moudleIds = new List<string>();
|
||||
moudleIds.Add(onlyOneKey);
|
||||
keyValues.Add(mainModleId, moudleIds);
|
||||
}
|
||||
SetValue<Dictionary<string, List<string>>>(RefRedisRefKeys, keyValues);
|
||||
}
|
||||
/// <summary>
|
||||
/// 刷新缓存数据源
|
||||
/// </summary>
|
||||
public static void RefRedisData(string mainModleid)
|
||||
{
|
||||
Dictionary<string, List<string>> keyValues = GetValue<Dictionary<string, List<string>>>(RefRedisRefKeys);
|
||||
if (keyValues == null)
|
||||
{
|
||||
keyValues = new Dictionary<string, List<string>>();
|
||||
}
|
||||
if (keyValues.ContainsKey(mainModleid))
|
||||
{
|
||||
System.Threading.Thread thread = new System.Threading.Thread(() =>
|
||||
{
|
||||
List<string> moudleIdsList = keyValues[mainModleid];
|
||||
foreach (string onlyOneKey in moudleIdsList)
|
||||
{
|
||||
if (!ContainKey(onlyOneKey)) continue;
|
||||
Dictionary<string, DataTable> sqlAndDataTable = RedisHelper.GetValue<Dictionary<string, DataTable>>(onlyOneKey);
|
||||
if (sqlAndDataTable != null && sqlAndDataTable.Count > 0)
|
||||
{
|
||||
string sourceSql = sqlAndDataTable.First().Key;
|
||||
if (!string.IsNullOrEmpty(sourceSql))
|
||||
{
|
||||
DataTable dataTable = BaseImpl.GetDataTableResult(sourceSql);
|
||||
sqlAndDataTable[sourceSql] = dataTable;
|
||||
RedisHelper.SetValue<Dictionary<string, DataTable>>(onlyOneKey, sqlAndDataTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据key删除redis数据
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public static void DeleteByKey(string key)
|
||||
{
|
||||
Database.KeyDelete(key);
|
||||
}
|
||||
/// <summary>
|
||||
/// 切换数据库
|
||||
/// </summary>
|
||||
/// <param name="dbIndex"></param>
|
||||
public static void ChangeRedisDataBase(int dbIndex)
|
||||
{
|
||||
Database = ConnMultiplexer.GetDatabase(dbIndex);//参数为创建的数据库的位置
|
||||
DbIndex = dbIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="NPOI" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.1.3.1" newVersion="2.1.3.1" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" />
|
||||
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" />
|
||||
<package id="StackExchange.Redis" version="1.2.1" targetFramework="net40" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user