12345678910111213141516171819202122232425262728293031323334353637 |
- namespace KYFramework
- {
- public static class IdGenerater
- {
- private static long instanceIdGenerator;
- private static long appId;
- public static long AppId
- {
- set
- {
- appId = value;
- instanceIdGenerator = appId << 48;
- }
- }
- private static ushort value;
- public static long GenerateId()
- {
- long time = TimeHelper.ClientNow();
- return (appId << 48) + (time << 16) + ++value;
- }
- public static long GenerateInstanceId()
- {
- return ++instanceIdGenerator;
- }
- public static int GetAppId(long v)
- {
- return (int)(v >> 48);
- }
- }
- }
|