private async Task PersistenceDomainEventsAsync() { var messages = TakeAwayDomainEvents() .Select(domainEvent => new UnpublishedMessage { Id = SequentialGuidHelper.GenerateComb(), EventType = domainEvent.GetType().ToString(), Content = _serializer.ToText(domainEvent), PersistenceUtcTime = DateTime.UtcNow }); await UnpublishedMessages.AddRangeAsync(messages); }
private MyDomainObject CreateDomainObject(SequentialGuidHelper.SequentialGuidType?guidType = null) { var m = new Random().Next(); return(new MyDomainObject { Id = guidType == null?Guid.NewGuid() : SequentialGuidHelper.GenerateComb(guidType.Value), Name = m % 3 == 0 ? "apple" : m % 2 == 0 ? "banana" : "pear", Gender = m % 2 == 0 ? Gender.Male : Gender.Female, Birthday = DateTime.Now, CreateTime = DateTime.UtcNow }); }
public bool CreateUser(CreateUserDto dto) { var user = new User { Id = SequentialGuidHelper.GenerateComb(), Name = dto.Name, Pwd = dto.Pwd, Nickname = dto.Nickname, CreatedUtcTime = DateTime.UtcNow }; return(_userDal.Add(user) > 0); }
public void SequentialGuidHelperTest() { for (var i = 0; i < 10000; ++i) { Console.WriteLine(SequentialGuidHelper.NewId()); } var t1Result = new List <string>(); var t1 = Task.Run(() => { var i = 0; while (i++ < 100000) { t1Result.Add(SequentialGuidHelper.NewId()); } }); var t2Result = new List <string>(); var t2 = Task.Run(() => { var i = 0; while (i++ < 100000) { t2Result.Add(SequentialGuidHelper.NewId()); } }); var t3Result = new List <string>(); var t3 = Task.Run(() => { var i = 0; while (i++ < 100000) { t3Result.Add(SequentialGuidHelper.NewId()); } }); Task.WaitAll(t1, t2, t3); Assert.IsTrue(!t1Result.Intersect(t2Result).Intersect(t3Result).Any()); }
private static MyPoco CreatePoco(SequentialGuidType?guidType = null) { var m = new Random().Next(); var id = guidType is null?Guid.NewGuid() : SequentialGuidHelper.GenerateComb(guidType.Value); return(new MyPoco { Id = id, Name = m % 3 is 0 ? "apple" : m % 2 is 0 ? "banana" : "pear", Gender = m % 2 is 0 ? Gender.Male : Gender.Female, Birthday = DateTime.Now, CreateTime = DateTime.UtcNow, // Kids = new List<MySubPoco> // { // new() // { // Id = guidType is null ? Guid.NewGuid() : SequentialGuidHelper.GenerateComb(guidType.Value), // MyPocoId = id, // Name = m % 3 is 0 ? "apple" : m % 2 is 0 ? "banana" : "pear", // Remark = "This is a sub poco." // } // } });