/// <summary> /// If a user unexpectedly disconnects whilst sending a message, clients will be unaware and continue seeing the user as /// typing a message. /// This procedure will go through conversations a client is in and forcefully tell other clients that the user has stopped /// typing. /// </summary> /// <remarks> /// This could have be done in the Client when a client senses that a user's <see cref="ConnectionStatus" /> has been /// modified. /// But I'd rather have it as a rule here where a client can use their same /// <see cref="EntityNotification{UserNotification}" /> logic. /// </remarks> /// <param name="userId">The user that disconnected.</param> /// <param name="clientManager">Holds the connected clients.</param> /// <param name="repositoryManager">Holds the repositories in the system.</param> private static void SendUserTypingNotification(int userId, IClientManager clientManager, RepositoryManager repositoryManager) { var participationRepository = (ParticipationRepository)repositoryManager.GetRepository <Participation>(); var userRepository = (UserRepository)repositoryManager.GetRepository <User>(); IEnumerable <int> conversationIdsUserIsIn = participationRepository.GetAllConversationIdsByUserId(userId); foreach (int conversationId in conversationIdsUserIsIn) { Participation participation = participationRepository.GetParticipationByUserIdandConversationId(userId, conversationId); var userTyping = new UserTyping(false, participation.Id); var userTypingNotification = new EntityNotification <UserTyping>(userTyping, NotificationType.Create); List <Participation> participationsForConversation = participationRepository.GetParticipationsByConversationId(conversationId); List <int> userIdsInConversation = participationsForConversation.Select(x => x.UserId).ToList(); foreach (int userIdInConversation in userIdsInConversation) { User user = userRepository.FindEntityById(userIdInConversation); if (user.ConnectionStatus.UserConnectionStatus != ConnectionStatus.Status.Disconnected) { clientManager.SendMessageToClient(userTypingNotification, userIdInConversation); } } } }
private void RequestEntity(EntityNotification entityNotification) { if (!IsServerSide) { return; } var entity = entities.FirstOrDefault(e => e.Id == entityNotification.EntityId); if (entity == null) { return; } var remoteEntity = new RemoteEntity(entity); remoteEntity.Components.AddComponent(new PositionComponent { Position = new Coordinate(0, new Index3(0, 0, 78), new Vector3(0, 0, 0)) }); remoteEntity.Components.AddComponent(new RenderComponent { Name = "Wauzi", ModelName = "dog", TextureName = "texdog", BaseZRotation = -90 }, true); remoteEntity.Components.AddComponent(new BodyComponent() { Mass = 50f, Height = 2f, Radius = 1.5f }); ResourceManager.UpdateHub.Push(new EntityNotification() { Entity = remoteEntity, Type = EntityNotification.ActionType.Add }, DefaultChannels.Network); }
private void OnConversationAdded(object sender, EntityChangedEventArgs <Conversation> e) { var conversationNotification = new EntityNotification <Conversation>(e.Entity, NotificationType.Create); IEnumerable <int> userIds = participationRepository.GetParticipationsByConversationId(e.Entity.Id).Select(participation => participation.UserId); ClientManager.SendMessageToClients(conversationNotification, userIds); }
/// <summary> /// Deserialises a <see cref="EntityNotification{T}" /> from the <see cref="NetworkStream" />. /// </summary> /// <param name="networkStream"> /// The <see cref="NetworkStream" /> containing the serialised /// <see cref="EntityNotification{T}" />. /// </param> /// <returns>The deserialised <see cref="EntityNotification{T}" />.</returns> public override IMessage Deserialise(NetworkStream networkStream) { NotificationType notificationType = notificationTypeSerialiser.Deserialise(networkStream); var entityNotification = new EntityNotification <T>(bandSerialiser.Deserialise(networkStream), notificationType); Log.InfoFormat("{0} message deserialised", entityNotification.MessageIdentifier); return(entityNotification); }
private void OnUserTypingChanged(Participation participation) { List <Participation> participationsForConversation = participationRepository.GetParticipationsByConversationId(participation.ConversationId); List <int> usersInConversation = participationsForConversation.Select(x => x.UserId).ToList(); var userTypingNotification = new EntityNotification <UserTyping>(participation.UserTyping, NotificationType.Update); ClientManager.SendMessageToClients(userTypingNotification, usersInConversation); }
protected override void HandleMessage(EntityNotification <User> message) { var userRepository = (IEntityRepository <User>)ServiceRegistry.GetService <RepositoryManager>().GetRepository <User>(); switch (message.NotificationType) { case NotificationType.Create: userRepository.AddEntity(message.Entity); break; } }
protected override void HandleMessage(EntityNotification <UserTyping> message) { var participationRepository = (IEntityRepository <Participation>)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Participation>(); Participation participation = participationRepository.FindEntityById(message.Entity.ParticipationId); Participation clonedParticipation = Participation.DeepClone(participation); clonedParticipation.UserTyping = message.Entity; participationRepository.UpdateEntity(clonedParticipation); }
private void OnContributionAdded(IContribution contribution) { var contributionNotification = new EntityNotification <IContribution>(contribution, NotificationType.Create); List <Participation> participationsByConversationId = participationRepository.GetParticipationsByConversationId(contribution.ConversationId); IEnumerable <User> participantUsers = participationsByConversationId.Select(participant => userRepository.FindEntityById(participant.UserId)); IEnumerable <int> connectedUserIds = participantUsers.Where(user => user.ConnectionStatus.UserConnectionStatus == ConnectionStatus.Status.Connected).Select(user => user.Id); ClientManager.SendMessageToClients(contributionNotification, connectedUserIds); }
=> base.Deserialize(reader, definitionManager); // Entity public override void OnUpdate(SerializableNotification notification) { base.OnUpdate(notification); var entityNotification = new EntityNotification { Entity = this, Type = EntityNotification.ActionType.Update, Notification = notification as PropertyChangedNotification }; Simulation?.OnUpdate(entityNotification); }
protected override void HandleMessage(EntityNotification <Conversation> message) { var conversationRepository = (ConversationRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Conversation>(); switch (message.NotificationType) { case NotificationType.Create: conversationRepository.AddEntity(message.Entity); break; case NotificationType.Update: conversationRepository.UpdateEntity(message.Entity); break; } }
private void EntityUpdate(EntityNotification notification) { var entity = entities.FirstOrDefault(e => e.Id == notification.EntityId); if (entity == null) { ResourceManager.UpdateHub.Push(new EntityNotification(notification.EntityId) { Type = EntityNotification.ActionType.Request }, DefaultChannels.Network); } else { entity.Update(notification.Notification); } }
private void EntityUpdate(EntityNotification notification) { var entity = entities.FirstOrDefault(e => e.Id == notification.EntityId); if (entity == null) { var entityNotification = entityNotificationPool.Get(); entityNotification.EntityId = notification.EntityId; entityNotification.Type = EntityNotification.ActionType.Request; ResourceManager.UpdateHub.Push(entityNotification, DefaultChannels.Network); entityNotification.Release(); } else { entity.Update(notification.Notification); } }
public ModelViewNotification Update(ModelViewNotification model) { EntityNotification data = new EntityNotification() { MessageID = model.MessageID, Message = model.Message, MessageRead = model.MessageRead, Title = model.Title, Url = model.Url, UserID = model.UserID, Status = model.Status, CreateDate = model.CreateDate, ModifyDate = DateTime.UtcNow }; data = new RepositoryNotification().Update(data); return(model); }
public ModelViewNotification Insert(ModelViewNotification model) { EntityNotification data = new EntityNotification() { MessageID = model.MessageID, Message = model.Message, MessageRead = model.MessageRead, Title = model.Title, Url = model.Url, UserID = model.UserID, Status = true, CreateDate = DateTime.UtcNow, ModifyDate = DateTime.UtcNow }; data = new RepositoryNotification().Insert(data); model.MessageID = data.MessageID; return(model); }
private void OnParticipationAdded(object sender, EntityChangedEventArgs <Participation> e) { Participation participation = e.Entity; List <Participation> conversationParticipants = participationRepository.GetParticipationsByConversationId(participation.ConversationId); var participationNotification = new EntityNotification <Participation>(participation, NotificationType.Create); IEnumerable <int> conversationParticipantUserIds = conversationParticipants.Select(conversationParticipation => conversationParticipation.UserId); ClientManager.SendMessageToClients(participationNotification, conversationParticipantUserIds); List <Participation> otherParticipants = conversationParticipants.Where(conversationParticipant => !conversationParticipant.Equals(participation)).ToList(); otherParticipants.ForEach( otherParticipant => ClientManager.SendMessageToClient(new EntityNotification <Participation>(otherParticipant, NotificationType.Create), participation.UserId)); Conversation conversation = conversationRepository.FindEntityById(participation.ConversationId); SendConversationNotificationToParticipants(conversation, participation.UserId, otherParticipants); }
public DataResponse <EntityNotification> GetNotificationById(int NotificationId) { DataResponse <EntityNotification> response = new DataResponse <EntityNotification>(); try { base.DBInit(); var query = base.DBEntity.Notifications.Where(a => a.Id == NotificationId).FirstOrDefault(); var entity = new EntityNotification { NotificationId = query.Id, Message = query.Message, TargetId = query.TargetId, TargetTypeId = query.TargetType, UserId = query.NotificationUsers.FirstOrDefault().UserId }; if (query != null) { response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { //response.ThrowError(ex); ex.Log(); } finally { base.DBClose(); } return(response); }
protected override void HandleMessage(EntityNotification <Participation> message) { var participationRepository = (IEntityRepository <Participation>)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Participation>(); participationRepository.AddEntity(message.Entity); }
private void OnUserAdded(object sender, EntityChangedEventArgs <User> e) { var userNotification = new EntityNotification <User>(e.Entity, NotificationType.Create); ClientManager.SendMessageToClients(userNotification); }
private void OnUserConnectionUpdated(User user) { var userNotification = new EntityNotification <ConnectionStatus>(user.ConnectionStatus, NotificationType.Update); ClientManager.SendMessageToClients(userNotification); }
private void OnUserAvatarUpdated(User user) { var avatarNotification = new EntityNotification <Avatar>(user.Avatar, NotificationType.Update); ClientManager.SendMessageToClients(avatarNotification); }
protected override void HandleMessage(EntityNotification <Avatar> message) { var userRepository = (UserRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <User>(); userRepository.UpdateUserAvatar(message.Entity); }
protected override void HandleMessage(EntityNotification <IContribution> message) { var conversationRepository = (ConversationRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Conversation>(); conversationRepository.AddContributionToConversation(message.Entity); }
/// <summary> /// Serialise a <see cref="EntityNotification{T}" /> down the wire. /// </summary> /// <param name="networkStream">The networkStream that connects the Client and Server.</param> /// <param name="message">The <see cref="EntityNotification{T}" /> to serialise.</param> protected override void Serialise(NetworkStream networkStream, EntityNotification <T> message) { notificationTypeSerialiser.Serialise(networkStream, message.NotificationType); bandSerialiser.Serialise(networkStream, message.Entity); }