Exemplo n.º 1
0
 public static SnowflakeId Default(long datacenterId = 0)
 {
     lock (s_lock)
     {
         return(_snowflakeId ?? (_snowflakeId = new SnowflakeId(AppDomain.CurrentDomain.Id, datacenterId)));
     }
 }
Exemplo n.º 2
0
        public static SnowflakeId Default()
        {
            lock (SLock)
            {
                if (_snowflakeId != null)
                {
                    return(_snowflakeId);
                }

                var random       = new Random();
                var workerId     = random.Next((int)MaxWorkerId);
                var datacenterId = random.Next((int)MaxDatacenterId);
                return(_snowflakeId = new SnowflakeId(workerId, datacenterId));
            }
        }
Exemplo n.º 3
0
        public static SnowflakeId Default()
        {
            lock (SLock)
            {
                if (_snowflakeId != null)
                {
                    return(_snowflakeId);
                }

                var random = new Random();

                if (!int.TryParse(Environment.GetEnvironmentVariable("CAP_WORKERID", EnvironmentVariableTarget.Machine), out var workerId))
                {
                    workerId = random.Next((int)MaxWorkerId);
                }

                if (!int.TryParse(Environment.GetEnvironmentVariable("CAP_DATACENTERID", EnvironmentVariableTarget.Machine), out var datacenterId))
                {
                    datacenterId = random.Next((int)MaxDatacenterId);
                }

                return(_snowflakeId = new SnowflakeId(workerId, datacenterId));
            }
        }