Esempio n. 1
0
        static void TestSnowflake()
        {
            Console.WriteLine(SnowflakeHelper.Instance().NextId());

            //HashSet<long> set = new HashSet<long>();
            //SnowflakeHelper idWorker1 = new SnowflakeHelper(0, 0);
            //SnowflakeHelper idWorker2 = new SnowflakeHelper(1, 0);
            //762884413578018816
            //762884520121729024
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            //for (int i = 0; i < 1; i++)
            //{
            //long id = idWorker1.nextId();
            //    set.Add(id);
            //    if (!set.Add(id))
            //    {
            //Console.WriteLine("duplicate:" + id);
            //}
            //    }
            //sw.Stop();
            //foreach (var item in set)
            //{
            //    Console.WriteLine("结果:" + item);
            //}
            //Console.WriteLine("时间:" + sw.ElapsedTicks);
        }
Esempio n. 2
0
        public bool Register(string userName, string password)
        {
            var usserBaseInfo = this.UserBaseInfoDal.Get(userName);

            if (usserBaseInfo != null)
            {
                return(false);
            }
            string encryptPassword = EncryptionHelper.GetMD5Hash(password);
            string id = SnowflakeHelper.Instance().GetString();

            usserBaseInfo = new Model.UserBaseInfo()
            {
                ID             = id,
                CreateDatetime = DateTime.Now,
                Password       = encryptPassword,
                UserName       = userName
            };
            return(this.UserBaseInfoDal.Insert(usserBaseInfo));
        }
 public void NextIdTest()
 {
     Assert.IsTrue(SnowflakeHelper.Instance().NextId() > 0);
 }