public void NewGuidTest1() { List <Guid> ids = new List <Guid>(); for (int i = 0; i < 100; i++) { ids.Add(SequentialGuid.Create(SequentialGuidType.SequentialAtEnd)); } ids.Distinct().Count().ShouldBe(100); ids.Clear(); for (int i = 0; i < 100; i++) { ids.Add(SequentialGuid.Create(SequentialGuidType.SequentialAsString)); } ids.Distinct().Count().ShouldBe(100); ids.Clear(); for (int i = 0; i < 100; i++) { ids.Add(SequentialGuid.Create(SequentialGuidType.SequentialAsBinary)); } ids.Distinct().Count().ShouldBe(100); ids.Clear(); }
public void Like(string statusId) { this.Init(); var like = new Like { TimeLiked = DateTime.Now, StatusId = statusId, UserId = this._curUserChat.UserId }; this._likeRepository.Like(like); var newFeedId = SequentialGuid.Create(); NewFeeds newfeed = new NewFeeds { UserId = this._curUserChat.UserId, NewFeedId = newFeedId, TypeActionId = TypeAction.LIKE, StatusId_Or_UserId = statusId }; this._newFeedRepository.AddNewFeed(newfeed); var ownerStatus = this._statusRepository.GetShortStatusByStatusId(statusId); Clients.Clients(this._allUserRelate_ConnectionId).like(this._curUserChat.Displayname, statusId); Clients.Clients(this._friendListConnectionId_Online).likeNewFeeds(this._curUserChat, statusId, ownerStatus.UserOwner.Displayname); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { var user = _readWriteContext.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email); if (user == null) // user doesn't exist { var toAdd = _mapper.Map <User>(request); toAdd.Id = SequentialGuid.Create(); _readWriteContext.Users.Add(toAdd); AddUserAccount(request); } else { if (!(user.FirstName.ToLower() == request.FirstName.ToLower() && user.LastName.ToLower() == request.LastName.ToLower())) { return(new Result("Email address is in use")); } var userAccount = _readWriteContext.UserAccounts.SingleOrDefault(x => x.AccountId == request.AccountId && x.UserId == user.Id); if (userAccount == null) { AddUserAccount(request); } else { return(new Result("User already exists for this account")); } } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result() : new Result(HttpStatusCode.BadRequest)); }
private void AddUserAccount(Request request) { var toAdd = _mapper.Map <UserAccount>(request); toAdd.Id = SequentialGuid.Create(); _readWriteContext.UserAccounts.Add(toAdd); }
public List <TournamentTeamGroup> AddTeamsToAllGroup(Guid accountId, Guid tournamentId, List <Guid> teamIds, List <Guid> groupIds, int teamPerGroup, int noOfGroupsNeeded) { var teamGroups = new List <TournamentTeamGroup>(); Random groupRand = new Random(DateTime.Now.ToString().GetHashCode()); Random teamRand = new Random(DateTime.Now.ToString().GetHashCode()); //this will add all teams to a group before moving to the next group for (int i = 0; i < noOfGroupsNeeded; i++) { var groupIndex = groupRand.Next(0, groupIds.Count); var groupId = groupIds[groupIndex]; for (int j = 0; j < teamPerGroup; j++) { var teamIndex = teamRand.Next(0, teamIds.Count); var teamId = teamIds[teamIndex]; teamGroups.Add(new TournamentTeamGroup { AccountId = accountId, Id = SequentialGuid.Create(), TournamentId = tournamentId, TournamentGroupId = groupId, TournamentTeamId = teamId }); teamIds.RemoveAt(teamIndex); } groupIds.RemoveAt(groupIndex); } return(teamGroups); }
public void Comment(string statusId, string cmtMessage) { this.Init(); var commentId = SequentialGuid.Create(); var comment = new DemoSignalRChat.Models.Comment { CommentId = commentId, Content = cmtMessage, StatusId = statusId, UserId = this._curUserChat.UserId, TimeComment = DateTime.Now }; this._commentRepository.AddComment(comment); var newFeedId = SequentialGuid.Create(); NewFeeds newfeed = new NewFeeds { UserId = this._curUserChat.UserId, NewFeedId = newFeedId, TypeActionId = TypeAction.COMMENT, StatusId_Or_UserId = commentId }; this._newFeedRepository.AddNewFeed(newfeed); string commentDisplay = ProcessComment.ProcessNewComment(this._curUserChat, cmtMessage); Clients.Clients(this._allUserRelate_ConnectionId).comment(this._curUserChat.Displayname, statusId, commentDisplay); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { if (_readWriteContext.Players.Any(x => x.AccountId == request.AccountId && x.PlayerNo.ToLower() == request.PlayerNo.ToLower())) { return(new Result("Player with this number already exists")); } var toAdd = _mapper.Map <Player>(request); toAdd.Id = SequentialGuid.Create(); _readWriteContext.Players.Add(toAdd); if (request.TeamId.HasValue) { var teamPlayer = _mapper.Map <TeamPlayer>(request); teamPlayer.Id = SequentialGuid.Create(); teamPlayer.TeamId = request.TeamId.Value; teamPlayer.PlayerId = toAdd.Id; _readWriteContext.TeamPlayers.Add(teamPlayer); } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result(toAdd.Id) : new Result(HttpStatusCode.BadRequest)); }
public void Share(string statusId) { this.Init(); var share = new Share { TimeShared = DateTime.Now, StatusId = statusId, UserId = this._curUserChat.UserId }; this._shareRepository.AddShare(share); var message = this._statusMessageRepository.GetMessageByStatusId(statusId); var messageProcessed = ProcessMessage.ProcessMessageStatus(statusId, this._curUserChat, message, null); var newFeedId = SequentialGuid.Create(); NewFeeds newfeed = new NewFeeds { UserId = this._curUserChat.UserId, NewFeedId = newFeedId, TypeActionId = TypeAction.SHARE, StatusId_Or_UserId = statusId }; this._newFeedRepository.AddNewFeed(newfeed); var ownerStatus = this._statusRepository.GetShortStatusByStatusId(statusId); Clients.Clients(this._allUserRelate_ConnectionId).share(this._curUserChat.Displayname, messageProcessed); Clients.Clients(this._friendListConnectionId_Online).likeNewFeeds(this._curUserChat, statusId, ownerStatus.UserOwner.Displayname); }
//todo: incomplete implementation public List <TournamentTeamGroup> AddTeamsToGroups(Guid accountId, Guid tournamentId, List <Guid> teamIds, List <Guid> groupIds, int teamPerGroup, int noOfGroupsNeeded) { var teamGroups = new List <TournamentTeamGroup>(); Random groupRand = new Random(DateTime.Now.ToString().GetHashCode()); Random teamRand = new Random(DateTime.Now.ToString().GetHashCode()); for (int i = 0; i < noOfGroupsNeeded; i++) { var groupIndex = groupRand.Next(0, groupIds.Count); var groupId = groupIds[groupIndex]; var teamIndex = teamRand.Next(0, teamIds.Count); var teamId = teamIds[teamIndex]; teamGroups.Add(new TournamentTeamGroup { AccountId = accountId, Id = SequentialGuid.Create(), TournamentId = tournamentId, TournamentGroupId = groupId, TournamentTeamId = teamId }); teamIds.RemoveAt(teamIndex); //todo: find out how to remove the group if no of teams is reached // groupIds.RemoveAt(groupIndex); } return(teamGroups); }
private void SetEmptyGuidKey(TEntity entity) { Type keyType = typeof(TKey); //自增int if (keyType == typeof(int)) { IKeyGenerator <int> generator = _serviceProvider.GetService <IKeyGenerator <int> >(); entity.Id = generator.Create().CastTo <TKey>(); return; } //雪花long if (keyType == typeof(long)) { IKeyGenerator <long> generator = _serviceProvider.GetService <IKeyGenerator <long> >(); entity.Id = generator.Create().CastTo <TKey>(); } //顺序guid if (keyType == typeof(Guid) && entity.Id.Equals(Guid.Empty)) { DatabaseType databaseType = _dbContext.GetDatabaseType(); ISequentialGuidGenerator generator = _serviceProvider.GetServices <ISequentialGuidGenerator>().FirstOrDefault(m => m.DatabaseType == databaseType); entity.Id = generator == null?SequentialGuid.Create(databaseType).CastTo <TKey>() : generator.Create().CastTo <TKey>(); } }
public override object Perform(object obj, EntityState state, object originalValue, object parentEntity, string propertyName) { //not null check because you cant have a nullable primary key var shouldAct = (state == EntityState.Added || state == EntityState.Modified) && obj != null && (Guid)obj == default(Guid); return(shouldAct ? SequentialGuid.Create() : obj); }
public EventDescriptor(IEvent data) { this.Id = SequentialGuid.Create(); this.Data = data; this.AggregateRootId = data.Id; this.Timestamp = data.Timestamp; this.Version = data.Version; this.OperatorId = data.OperatorId; this.EventType = data.GetType().FullName; }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { if (_readWriteContext.Tournaments.Any(x => x.AccountId == request.AccountId && x.Id == request.TournamentId && !x.IsDeleted)) { return(new Result("Tournament cannot be found")); } if (_readWriteContext.TournamentPrizes.Any(x => x.AccountId == request.AccountId && x.TournamentId == request.TournamentId && !x.IsDeleted)) { return(new Result("Tournament prize already saved. Update or remove individual prizes instead")); } var maxRank = request.Prizes.Max(x => x.Rank); // var minRank = request.Prizes.Min(x => x.Rank); if (request.Prizes.Select(x => x.Rank).Distinct().Count() != maxRank) { return(new Result("Prize rank cannot contain duplicates")); } if (request.Prizes.Count != maxRank) //since ranks start from 1, count should be equal to maxRank { return(new Result("Prize rank must be consecutive positive numbers")); } if (request.IsPercentage && (request.Prizes.Sum(x => x.Amount) > 80)) { return(new Result("Sum of all percentages cannot be more than 80%")); } request.Prizes = request.Prizes.OrderBy(x => x.Rank).ToList(); foreach (var prize in request.Prizes) { _readWriteContext.TournamentPrizes.Add(new TournamentPrize { Id = SequentialGuid.Create(), AccountId = request.AccountId, TournamentId = request.TournamentId, IsPercentage = request.IsPercentage, Rank = prize.Rank, Name = prize.Name, Amount = prize.Amount }); } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result(request.TournamentId) : new Result(HttpStatusCode.BadRequest)); }
public void CreateTest2() { var id1 = SequentialGuid.Create(SequentialGuidType.SequentialAsBinary).ToString(); var id2 = SequentialGuid.Create(SequentialGuidType.SequentialAsBinary).ToString(); var id3 = SequentialGuid.Create(SequentialGuidType.SequentialAsBinary).ToString(); var id4 = SequentialGuid.Create(SequentialGuidType.SequentialAsBinary).ToString(); var a = id1.Substring(0, 8); var b = id2.Substring(0, 8); var c = id3.Substring(0, 8); var d = id4.Substring(0, 8); a.Should().Be(b).And.Be(c).And.Be(d); }
public void CreateTest3() { var id1 = SequentialGuid.Create(SequentialGuidType.SequentialAtEnd).ToString(); var id2 = SequentialGuid.Create(SequentialGuidType.SequentialAtEnd).ToString(); var id3 = SequentialGuid.Create(SequentialGuidType.SequentialAtEnd).ToString(); var id4 = SequentialGuid.Create(SequentialGuidType.SequentialAtEnd).ToString(); var a = id1.Substring(id1.Length - 9, 8); var b = id2.Substring(id2.Length - 9, 8); var c = id3.Substring(id3.Length - 9, 8); var d = id4.Substring(id4.Length - 9, 8); a.Should().Be(b).And.Be(c).And.Be(d); }
public virtual async Task <IActionResult> CreateAsync([FromBody] JObject model) { var command = this.GetCreateCommand(model); command.OperatorId = this.GetAuthUserId(); if (command.Id == Guid.Empty) { command.Id = SequentialGuid.Create(); } await this.commandSender.SendAsync(command); return(Created(Url.Action("Get", new { id = command.Id }), new ResponseValue <Guid>(command.Id))); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { if (_readWriteContext.Accounts.Any(x => x.Name.ToLower() == request.Name.ToLower())) { return(new Result("Account name already exists")); } var toAdd = _mapper.Map <Account>(request); toAdd.Id = SequentialGuid.Create(); _readWriteContext.Accounts.Add(toAdd); return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result(toAdd.Id) : new Result(HttpStatusCode.BadRequest)); }
/// <summary> /// Generates the GUIDs and displays them in the form. /// </summary> /// <param name="sender">The Generate button.</param> /// <param name="e">Additional information related to the event.</param> private void GenerateButton_Click(object sender, EventArgs e) { int count = 100; SequentialGuidType method = (SequentialGuidType)this.methodComboBox.SelectedItem; // Initialize the RTF text to enable color highlighting StringBuilder text = new StringBuilder(); text.Append("{\\rtf1\\ansi\\deff0\n{\\colortbl;\\red0\\green0\\blue0;\\red128\\green0\\blue0;}\n"); for (int i = 0; i < count; i++) { Guid guid = SequentialGuid.Create(method); string output = string.Empty; switch (method) { case SequentialGuidType.SequentialAsBinary: byte[] bytes = guid.ToByteArray(); foreach (byte b in bytes) { output += string.Format("{0:x2}", b); } output = "\\cf2\n" + output.Substring(0, 12) + "\n\\cf1\n" + output.Substring(12) + "\n\\line\n"; break; case SequentialGuidType.SequentialAsString: output = guid.ToString(); output = "\\cf2\n" + output.Substring(0, 13) + "\n\\cf1\n" + output.Substring(13) + "\n\\line\n"; break; case SequentialGuidType.SequentialAtEnd: output = guid.ToString(); output = "\\cf1\n" + output.Substring(0, 24) + "\n\\cf2\n" + output.Substring(24) + "\n\\line\n"; break; default: output = guid.ToString(); break; } text.Append(output); System.Threading.Thread.Sleep(1); } this.resultsTextBox.Rtf = text.ToString(); }
private void SetEmptyGuidKey(TEntity entity) { if (typeof(TKey) != typeof(Guid)) { return; } if (!entity.Id.Equals(Guid.Empty)) { return; } DatabaseType databaseType = _dbContext.GetDatabaseType(); entity.Id = SequentialGuid.Create(databaseType).CastTo <TKey>(); }
public void ExtractDateTimeTicksTest1() { var now = DateTime.UtcNow; long timestampSrc = DateTime.UtcNow.Ticks / 10000L; var ticksBytes = BitConverter.GetBytes(timestampSrc); ticksBytes[0] = 0; ticksBytes[1] = 0; long timestampNew = BitConverter.ToInt64(ticksBytes); var id = SequentialGuid.Create(); var ticks = SequentialGuid.ExtractDateTimeTicks(id); ticks.Should().Be(timestampNew); var dt = new DateTime(ticks); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { foreach (var playerId in request.PlayerIds) { if (_readWriteContext.TeamPlayers.Any(x => x.AccountId == request.AccountId && x.TeamId == request.TeamId && x.PlayerId == playerId)) { continue; } var toAdd = _mapper.Map <TeamPlayer>(request); toAdd.Id = SequentialGuid.Create(); toAdd.TeamId = request.TeamId; toAdd.PlayerId = playerId; _readWriteContext.TeamPlayers.Add(toAdd); } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result() : new Result(HttpStatusCode.BadRequest)); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { foreach (var groupId in request.GroupIds) { if (_readWriteContext.TournamentGroups.Any(x => x.AccountId == request.AccountId && x.TournamentId == request.TournamentId && x.GroupId == groupId)) { continue; } _readWriteContext.TournamentGroups.Add(new TournamentGroup { AccountId = request.AccountId, GroupId = groupId, Id = SequentialGuid.Create(), TournamentId = request.TournamentId }); } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result() : new Result(HttpStatusCode.BadRequest)); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { foreach (var userId in request.UserIds) { if (_readWriteContext.UserAccounts.Any(x => x.AccountId == request.AccountId && x.UserId == userId)) { continue; } _readWriteContext.UserAccounts.Add(new UserAccount { AccountId = request.AccountId, Id = SequentialGuid.Create(), UserId = userId, IsPending = true, CreatedOn = DateTime.Now }); } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result() : new Result(HttpStatusCode.BadRequest)); }
public void PostStatus(string message, string location) { this.Init(); var statusId = SequentialGuid.Create(); Status status = new Status { StatusId = statusId, UserId = this._curUserChat.UserId }; this._statusRepository.AddStatus(status); this._statusMessageRepository.AddMessage(new StatusMessage { StatusId = statusId, Message = message }); if (!string.IsNullOrEmpty(location)) { this._statusLocationRepository.AddLocation(statusId, location); } var newFeedId = SequentialGuid.Create(); NewFeeds newfeed = new NewFeeds { UserId = this._curUserChat.UserId, NewFeedId = newFeedId, TypeActionId = TypeAction.POST_STATUS, StatusId_Or_UserId = statusId }; this._newFeedRepository.AddNewFeed(newfeed); message = ProcessMessage.ProcessMessageStatus(statusId, this._curUserChat, message, null); Clients.Clients(this._allUserRelate_ConnectionId).postCastStatus(this._curUserChat.Displayname, message); Clients.Clients(this._friendListConnectionId_Online).statusNewFeeds(this._curUserChat); }
public void PostImage(string message, string[] imageNames) { this.Init(); var statusId = SequentialGuid.Create(); Status status = new Status { StatusId = statusId, UserId = this._curUserChat.UserId }; this._statusRepository.AddStatus(status); this._statusMessageRepository.AddMessage(new StatusMessage { StatusId = statusId, Message = message }); message = ProcessMessage.ProcessMessageStatus(statusId, this._curUserChat, message, imageNames); this._statusImageRepository.AddRangeImage(statusId, imageNames); Clients.Clients(this._allUserRelate_ConnectionId).postImage(this._curUserChat.Displayname, message); }
protected Entity() { Id = SequentialGuid.Create(SequentialGuidType.SequentialAtEnd); }
public MovieInfo() { Id = SequentialGuid.Create(SequentialGuidType.SequentialAsString); }
/// <summary> /// 获取一个<see cref="Guid"/>类型的主键数据 /// </summary> /// <returns></returns> public Guid Create() { return(SequentialGuid.Create(SequentialGuidType.SequentialAsString)); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { var tournament = _readWriteContext.Tournaments.SingleOrDefault(x => x.AccountId == request.AccountId && x.Id == request.TournamentId && !x.IsDeleted); if (tournament == null) { return(new Result("Tournament cannot be found")); } if (_readWriteContext.TournamentGroups.Any(x => x.AccountId == request.AccountId && x.TournamentId == request.TournamentId)) { return(new Result("Tournament rounds already saved. Update or remove individual rounds instead")); } var maxRank = request.Rounds.Max(x => x.RoundRank); // var minRank = request.Rounds.Min(x => x.RoundRank); if (request.Rounds.Select(x => x.RoundRank).Distinct().Count() != maxRank) { return(new Result("Round rank cannot contain duplicates")); } if (request.Rounds.Count != maxRank) //since ranks start from 1, count should be equal to maxRank { return(new Result("Round rank must be consecutive positive numbers starting from 1")); } var teamsInRound1 = Math.Pow(2, request.Rounds.Count); var teamCount = _readWriteContext.TournamentTeams.Count(x => x.AccountId == request.AccountId && x.TournamentId == request.TournamentId && !x.IsDeleted); if (teamCount > teamsInRound1 && !tournament.HasGroupStage) { return(new Result("Teams are greater than the number required in first round")); } if (teamCount < teamsInRound1 && tournament.HasGroupStage) { return(new Result("Too few teams. Add more before you can continue")); } var maxComputerTeam = teamsInRound1 > 8 ? 3 : 0; // for round 1 greater than 8 teams, there can be a maximum of 3 computer teams if (!tournament.HasGroupStage && teamCount < teamsInRound1 - maxComputerTeam) { return(new Result("Too few teams. Add more before you can continue")); } request.Rounds = request.Rounds.OrderBy(x => x.RoundRank).ToList(); int teamsInRound = (int)teamsInRound1; foreach (var round in request.Rounds) { _readWriteContext.TournamentRounds.Add(new TournamentRound { Id = SequentialGuid.Create(), AccountId = request.AccountId, TournamentId = request.TournamentId, RoundRank = round.RoundRank, Round = round.Round, TeamsInRound = teamsInRound }); teamsInRound /= 2; } return(await _readWriteContext.SaveChangesAsync() > 0 ? new Result() : new Result(HttpStatusCode.BadRequest)); }
public CodeProject() { Id = SequentialGuid.Create(DatabaseType.Sqlite); }