82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Web;
|
|||
|
|
using System.Threading;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace CYQ.Data.Tool
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
internal static class StaticTool
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>GUIDת<44><D7AA>16<31>ֽ<EFBFBD><D6BD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
internal static string ToGuidByteString(string guid)
|
|||
|
|
{
|
|||
|
|
return BitConverter.ToString(new Guid(guid).ToByteArray()).Replace("-", "");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ڷֲ<DAB7>ʽ<EFBFBD><CABD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sourceString"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
internal static string GetHashKey(string sourceString)
|
|||
|
|
{
|
|||
|
|
return HashCreator.CreateKey(sourceString);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ڱ<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>Ψһ<CEA8><D2BB>ʶ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string GetMasterSlaveKey()
|
|||
|
|
{
|
|||
|
|
return "MasterSlave_" + GetMasterSlaveID();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ڱ<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD><CEBB><EFBFBD><EFBFBD> ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ψһ<CEA8><D2BB>ʶ
|
|||
|
|
/// </summary>
|
|||
|
|
public static string GetTransationKey(string conn)
|
|||
|
|
{
|
|||
|
|
//<2F><>Task Э<><D0AD> <20>첽<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>ܻ<EFBFBD><DCBB>в<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>߳<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٿ<EFBFBD><D9BF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string hash = ConnBean.GetHashKey(conn);
|
|||
|
|
return "Transation_" + Thread.CurrentThread.ManagedThreadId + hash;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static string GetMasterSlaveID()
|
|||
|
|
{
|
|||
|
|
string id = string.Empty;
|
|||
|
|
//<2F>ܿ<EFBFBD><DCBF>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ã<EFBFBD>Global.asax.cs<63><73>Application_Start <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
HttpContext context = HttpContext.Current;
|
|||
|
|
if (context != null && context.Handler != null)
|
|||
|
|
{
|
|||
|
|
HttpRequest request = context.Request;
|
|||
|
|
if (request["token"] != null)
|
|||
|
|
{
|
|||
|
|
id = request["token"];
|
|||
|
|
}
|
|||
|
|
else if (request.Headers["token"] != null)
|
|||
|
|
{
|
|||
|
|
id = request.Headers["token"];
|
|||
|
|
}
|
|||
|
|
else if (context.Session != null)
|
|||
|
|
{
|
|||
|
|
id = context.Session.SessionID;
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(id))
|
|||
|
|
{
|
|||
|
|
id = request.UserHostAddress;//<2F><>ȡIP<49><50>ַ<EFBFBD><D6B7>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(id))
|
|||
|
|
{
|
|||
|
|
id = LocalEnvironment.ProcessID.ToString();//winform
|
|||
|
|
}
|
|||
|
|
return id;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|