private void NotifierOnUserConnected(object sender, NotifierEventArgs <User> notifierEventArgs) { if (notifierEventArgs?.Payload != null) { var user = notifierEventArgs.Payload; Friends.Add(user); UserConnected?.Invoke(this, notifierEventArgs); } }
public void WhenUserDiconnectedThenUpdateSessionProjectionAndEnableDisconnectedFlag() { var userConnected = new UserConnected(SessionId.Generate(), new UserId("*****@*****.**"), DateTime.Now); _handler.Handle(userConnected); _handler.Handle(new UserDisconnected(userConnected.SessionId, userConnected.UserId)); Check.That(_repository.Projections) .ContainsExactly(new SessionProjection(userConnected.SessionId, userConnected.UserId, SessionState.Disabled)); }
private void SendMessage(object sender, RoutedEventArgs e) { String[] conversationToUserTextBox = this.conversationToUserTextBox.Text.ToLower().Split(' '); String RecipientFirstName = char.ToUpper(conversationToUserTextBox[0][0]) + conversationToUserTextBox[0].Substring(1); String RecipientLastName = char.ToUpper(conversationToUserTextBox[1][0]) + conversationToUserTextBox[1].Substring(1); User Recipient = dataUtils.GetListUsers().Find(x => (x.Nom == RecipientLastName.ToUpper() && x.Prenom == RecipientFirstName) || (x.Nom == RecipientFirstName && x.Prenom == RecipientLastName.ToUpper())); if (Recipient != null) { if (!String.IsNullOrWhiteSpace(this.MessageBody.Text)) { DateTime date = DateTime.Now; String DateSending = (date.Day < 10 ? "0" + date.Day.ToString() : date.Day.ToString()) + "/" + (date.Month < 10 ? "0" + date.Month.ToString() : date.Month.ToString()) + "/" + date.Year.ToString(); String HoraireSending = (date.Hour < 10 ? "0" + date.Hour.ToString() : date.Hour.ToString()) + ":" + (date.Minute < 10 ? "0" + date.Minute.ToString() : date.Minute.ToString()); Message newMessage = new Message( dataUtils.GetListMessages().Count + 1, Recipient.Id, UserConnected.GetUserConnected().Id, UserConnected.GetUserConnected().Nom, UserConnected.GetUserConnected().Prenom, this.MessageBody.Text, DateSending, HoraireSending, 0 ); dataUtils.AddMessage(newMessage); Conversation conversation = dataUtils.GetListConversations().Find(x => x.Users.Contains(UserConnected.GetUserConnected().Id) && x.Users.Contains(Recipient.Id)); if (conversation != null) { conversation.Messages.Add(newMessage.Id); } else { dataUtils.AddConversation(UserConnected.GetUserConnected().Id, Recipient.Id, newMessage.Id); } Conversation c = dataUtils.GetListConversations() .Find(x => x.Users.Contains(UserConnected.GetUserConnected().Id) && x.Users.Contains(Recipient.Id)); if (c != null) { ((Grid)this.Parent).Children.Add(new Chat(c)); ((Grid)this.Parent).Children.Remove(this); } } else { MessageBox.Show("Veuillez entrer un message !", "Epsi_Community"); } } else { MessageBox.Show("Aucun Utilisateur ne correpond à celui indiqué !", "Epsi_Community"); } }
public async Task <UserConnected> AddUser(string userId, string connectionId) { UserConnected newConnection = new UserConnected { Id = ObjectId.GenerateNewId().ToString(), UserId = userId, ConnectionId = connectionId }; await connectedUsers.InsertOneAsync(newConnection); return(newConnection); }
private void AddNewConversation(object sender, RoutedEventArgs e) { if (!UserConnected.VerifyHabilitation("100_4xCVN")) { MessageHabilitation.MessageNoHabilitatePersonnalized("créer une nouvelle conversation !"); } else { this.Body_Conversation.Children.Clear(); this.Body_Conversation.Children.Add(new AddChat()); } }
public bool AddOrUpdate(string name, string connectionId) { var userAlreadyExists = UsersConnected.ContainsKey(name); var userConnected = new UserConnected { ConnectionId = connectionId, UserName = name }; UsersConnected.AddOrUpdate(name, userConnected, (key, value) => userConnected); return(userAlreadyExists); }
private void ClickNewExtraitCode(object sender, MouseButtonEventArgs e) { if (!UserConnected.VerifyHabilitation("100_1xCD0")) { MessageHabilitation.MessageNoHabilitatePersonnalized("créer un nouvel extrait de code !"); } else { this.Body_Extrait.Children.Remove(NoExtraitText); this.Body_Extrait.Children.Add(new AddExtraitCode()); } }
private void SendComment(object sender, MouseButtonEventArgs e) { if (!UserConnected.VerifyHabilitation("100_1xCMT")) { MessageHabilitation.MessageNoHabilitatePersonnalized("ajouter un commentaire !"); } else { if (this.AddComment.Text.Equals("") || this.AddComment.Text.Equals("Écrire un commentaire...")) { MessageBox.Show("Veuillez écrire un commentaire !", "Espi Community", MessageBoxButton.OK, MessageBoxImage.Error); } else { DateTime fullDate = DateTime.Now; String date = (fullDate.Day < 10 ? "0" + fullDate.Day.ToString() : fullDate.Day.ToString()) + "/" + (fullDate.Month < 10 ? "0" + fullDate.Month.ToString() : fullDate.Month.ToString()) + "/" + fullDate.Year.ToString(); String hour = (fullDate.Hour < 10 ? "0" + fullDate.Hour.ToString() : fullDate.Hour.ToString()) + ":" + (fullDate.Minute < 10 ? "0" + fullDate.Minute.ToString() : fullDate.Minute.ToString()) + ":" + (fullDate.Second < 10 ? "0" + fullDate.Second.ToString() : fullDate.Second.ToString()); String dateComment = date + " " + hour; if ((this.TextBlock_ReponseName.Text != null || !this.TextBlock_ReponseName.Text.Equals("")) && this.TextBlock_Reponse.Visibility == Visibility.Collapsed && this.TextBlock_ReponseName.Visibility == Visibility.Collapsed) { dataUtils.AddComment( UserConnected.GetUserConnected().Id, UserConnected.GetUserConnected().Nom, UserConnected.GetUserConnected().Prenom, ec.Id, "ExtraitCode", this.AddComment.Text, dateComment ); } else { dataUtils.AddComment( UserConnected.GetUserConnected().Id, UserConnected.GetUserConnected().Nom, UserConnected.GetUserConnected().Prenom, IdCommentToResponse, "Comment", this.AddComment.Text, dateComment ); } this.AddComment.Text = "Écrire un commentaire..."; OrganizeListComment(); this.ListComments.ItemsSource = _listItemComment; } } }
public void UpdateServer() { NetIncomingMessage inc = null; while (server != null && (inc = server.ReadMessage()) != null) { switch (inc.MessageType) { case NetIncomingMessageType.StatusChanged: Console.WriteLine(inc.SenderEndPoint.ToString() + " Status: " + inc.SenderConnection.Status.ToString()); switch (inc.SenderConnection.Status) { case NetConnectionStatus.Connected: if ((connections.Count >= maxConnections && maxConnections > 0) || AcceptIncomingConnections == false) { inc.SenderConnection.Disconnect("Server full"); } else { connections.Add(inc.SenderConnection); UserConnected?.Invoke(this, new ProviderUserEventArgs() { UserKey = inc.SenderConnection, }); } break; case NetConnectionStatus.Disconnected: connections.Remove(inc.SenderConnection); UserDisconnected?.Invoke(this, new ProviderUserEventArgs() { UserKey = inc.SenderConnection, }); break; } break; case NetIncomingMessageType.Data: var bytes = inc.ReadBytes(inc.LengthBytes); DataReceived?.Invoke(this, new ProviderDataEventArgs(inc.SenderConnection, true, new DataBuffer(bytes), inc.LengthBytes)); break; case NetIncomingMessageType.Error: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.VerboseDebugMessage: Console.WriteLine(DateTime.Now.ToShortTimeString() + "Lidgren Server" + inc.ReadString()); break; } } }
/// <summary> /// Trace the event that a client connected. /// </summary> /// <param name="remoteAddress">The client that connected.</param> internal void TraceUserConnection(IPEndPoint remoteAddress) { Task.Run(() => { lock (ConnectedUsersSyncRoot) connectedUsers.Add(remoteAddress); try { UserConnected?.Invoke(remoteAddress); } catch { } }); }
private void ApprouveExtraitCode(object sender, MouseButtonEventArgs e) { if (!UserConnected.VerifyHabilitation("100_6xCD0")) { MessageHabilitation.MessageNoHabilitatePersonnalized("approuver l'extrait de code !"); } else { if (_listApprouvedUser.Contains(UserConnected.GetUserConnected())) { _listApprouvedUser.Remove(UserConnected.GetUserConnected()); } } }
public override async Task OnDisconnectedAsync(Exception ex) { var connectionId = GetConnectionId(); var userId = Context.GetHttpContext().Request.Query["userId"]; UserConnected newDisconnection = new UserConnected { Id = userId, ConnectionId = connectionId }; await userConnectedRepository.RemoveUserByUserId(userId); await Clients.All.SendAsync(KeyConstants.newDisconnectedUser, newDisconnection); await base.OnDisconnectedAsync(ex); }
private void StartAccept() { isAccepting = true; acceptThread = new Thread(() => { while (isAccepting) { var user = new GameUser(string.Empty, main.Accept()); pool.Add(user); UserConnected?.Invoke(this, new GameEventArgs(user, string.Empty)); } }); acceptThread.IsBackground = true; acceptThread.Start(); }
public ExtraitCodeHome() { InitializeComponent(); _codeViewModel = new CodeViewModel(); this.ListView_ExtraitsCode.Style = null; if (!UserConnected.VerifyHabilitation("100_1xCD0")) { BtnAddExtrait.Cursor = Cursors.No; } ICollectionView lesExtraitsCode = _codeViewModel.ExtraitsCode; this.ListView_ExtraitsCode.ItemsSource = lesExtraitsCode.Cast <ExtraitCode>().OrderBy(x => x.Date_Creation).ToList(); }
private void send_loginForm(object sender, RoutedEventArgs e) { User userToConnect = dataUtils.GetUserByMailAdress(MailAdressTextBox.Text); if (userToConnect != null && PasswordTextBox.Password == userToConnect.Password) { UserConnected.SetUserConnected(userToConnect); var mainWindow = new MainWindow(); mainWindow.Show(); this.Close(); } else { PasswordTextBox.Clear(); ErrorMessage.Visibility = Visibility.Visible; } }
public MessagerieHome() { InitializeComponent(); _messageViewModel = new MessageViewModel(); this.ListView_Messages.Style = null; if (!UserConnected.VerifyHabilitation("100_4xCVN")) { BtnAddConversation.Cursor = Cursors.No; } _lastsMessages = OrganiseLastMessageInContactList(_messageViewModel.Conversations); ICollectionView _lastMessageViewModel = CollectionViewSource.GetDefaultView(_lastsMessages); this.ListView_Messages.ItemsSource = _lastMessageViewModel; }
public void TryConnectClient(DirectClientProvider client) { if (AcceptIncomingConnections) { Clients.Add(client); UserConnected?.Invoke(this, new ProviderUserEventArgs() { UserKey = client, }); client.AcceptConnection(this); } else { client.RejectConnection(this); } }
private void OnConnect(IAsyncResult ar) { var conn = ar.AsyncState as Socket; conn.EndConnect(ar); if (conn.Connected) { UserConnected?.Invoke(this, new ProviderUserEventArgs() { UserKey = conn }); StateObject state = new StateObject(); state.socket = conn; conn.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, OnReceive, state); } }
public void ShowConversation(object sender, MouseButtonEventArgs e) { DependencyObject dep = (DependencyObject)e.OriginalSource; while ((dep != null) && !(dep is ListViewItem)) { dep = VisualTreeHelper.GetParent(dep); } Message item = (Message)ListView_Messages.ItemContainerGenerator.ItemFromContainer(dep); User correspondant = listUsers.Find(x => (x.Nom == item.Nom) && (x.Prenom == item.Prenom)); Conversation conversation = _messageViewModel.Conversations.Cast <Conversation>().ToList() .Find(x => x.Users.Contains(UserConnected.GetUserConnected().Id) && x.Users.Contains(correspondant.Id)); if (conversation != null) { Body_Conversation.Children.Remove(NoChatText); Body_Conversation.Children.Add(new Chat.Chat(conversation)); } }
public override Task OnConnectedAsync() { var httpContext = Context.GetHttpContext(); var userId = httpContext.Request.Query["userId"].ToString(); var userConnected = usersConnected.Where(u => u.UserId == userId); if (userConnected.Any()) { usersConnected.Remove(userConnected.FirstOrDefault()); } var connect = new UserConnected { ConnectionID = Context.ConnectionId, UserId = userId }; usersConnected.Add(connect); return(base.OnConnectedAsync()); }
public override async Task OnConnectedAsync() { var httpContext = Context.GetHttpContext(); var userId = httpContext.Request.Query["userId"].ToString(); var userConnected = usersConnected.Where(u => u.UserId == userId); if (userConnected.Any()) { usersConnected.Remove(userConnected.FirstOrDefault()); } var connect = new UserConnected { ConnectionID = Context.ConnectionId, UserId = userId }; usersConnected.Add(connect); var notificationCount = await _notificationService.GetNotificationCount(userId); await Clients.Caller.SendAsync("ReceiveNotificationCount", notificationCount); }
private void OnClientConnect(IAsyncResult asyncResult) { try { Socket socket = this.serverSocket.EndAccept(asyncResult); var conn = new TcpConnection(socket); conn.Disconnected += this.OnClientDisconnected; conn.StartListen(); connections.TryAdd(conn.Id, conn); UserConnected?.Invoke(conn); serverSocket.BeginAccept(this.OnClientConnect, null); } catch (ObjectDisposedException) { // This exception was preventing the console from closing when the // shutdown command was issued. } }
private void DeleteExtraitCode(object sender, RoutedEventArgs e) { if (!UserConnected.VerifyHabilitation("100_4xCD0")) { MessageHabilitation.MessageNoHabilitatePersonnalized("supprimer l'extrait de code !"); } else { dataUtils.RemoveExtraitCode(ec.Id); TextBlock NoExtraitText = new TextBlock { Text = "Aucun extrait à afficher...", Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#515151")), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Name = "NoExtraitText" }; ((ListView)((Grid)((Grid)((Grid)this.Parent).Parent).Children[0]).Children[3]).ItemsSource = dataUtils.GetListExtraitsCode().Cast <ExtraitCode>().OrderBy(x => x.Date_Creation).ToList(); ((Grid)this.Parent).Children.Add(NoExtraitText); ((Grid)this.Parent).Children.Remove(this); } }
public void Connect(INetContext context) { if (IsConnected) { Disconnect(); } message = new byte[1024 * 512]; client = new TcpClient { NoDelay = false }; client.SendBufferSize = client.ReceiveBufferSize = 1024 * 256; client.Connect(context.IPAddress, context.Port); if (client.Connected) { UserConnected?.Invoke(this, new ProviderUserEventArgs()); IsConnected = true; } }
public virtual void Add(IOnlineClient client) { lock (SyncObj) { var userWasAlreadyOnline = false; var context = client.ToClientContextOrNull(); if (context != null) { userWasAlreadyOnline = this.IsOnline(context); } Store.Add(client); ClientConnected?.Invoke(this, new OnlineClientEventArgs(client)); if (context != null && !userWasAlreadyOnline) { UserConnected?.Invoke(this, new OnlineUserEventArgs(context, client)); } } }
/// <summary> /// 添加Client /// </summary> /// <param name="client"></param> public void Add(IOnlineClient client) { lock (_syncObj) { var userWasAlreadyOnline = false; var user = client.ToUserIdentifierOrNull(); if (user != null) { userWasAlreadyOnline = IsUserOnline(user); } AddClientToRedisStore(client); ClientConnected.InvokeSafely(this, new OnlineClientEventArgs(client)); if (user != null && !userWasAlreadyOnline) { UserConnected.InvokeSafely(this, new OnlineUserEventArgs(user, client)); } } }
public void Add(IOnlineClient client) { lock (_syncObj) { var userWasAlreadyOnline = false; var user = client.ToUserIdentifier(); if (user != null) { userWasAlreadyOnline = this.IsOnline(user); } _clients[client.ConnectionId] = client; ClientConnected.InvokeSafely(this, new OnlineClientEventArgs(client)); if (user != null && !userWasAlreadyOnline) { UserConnected.InvokeSafely(this, new OnlineUserEventArgs(user, client)); } } }
public virtual void Add(IOnlineClient client) { lock (SyncObj) { var userWasAlreadyOnline = false; var user = client.ToUserIdentifierOrNull(); if (user != null) { userWasAlreadyOnline = this.IsOnline(user); } Clients[client.ConnectionId] = client; _cacheManager.GetCache <string, IOnlineClient>(nameof(IOnlineClient)) .Set(client.ConnectionId, client); ClientConnected.InvokeSafely(this, new OnlineClientEventArgs(client)); if (user != null && !userWasAlreadyOnline) { UserConnected.InvokeSafely(this, new OnlineUserEventArgs(user, client)); } } }
private void DeleteConversation(object sender, MouseButtonEventArgs e) { if (!UserConnected.VerifyHabilitation("100_4xCVN")) { MessageHabilitation.MessageNoHabilitatePersonnalized("supprimer la conversation !"); } else { dataUtils.DeleteMessages(dataUtils.GetMessagesOfConversation(conv.Id)); dataUtils.DeleteConversation(conv.Id); TextBlock NoChatText = new TextBlock { Text = "Aucun message à afficher...", Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#515151")), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Name = "NoChatText" }; ReOrganiseLastMessageInContactList(); ((Grid)this.Parent).Children.Add(NoChatText); ((Grid)this.Parent).Children.Remove(this); } }
public void Init() { if (_isInitialized) { return; } _isInitialized = true; _hubConnection = new HubConnection(Secrets.GoHubUrl); _goHub = _hubConnection.CreateHubProxy("GoHub"); _goHub.On(nameof(UserConnected), (UserPrefs user) => UserConnected?.Invoke(user)); _goHub.On(nameof(UserDisconnected), (string user) => UserDisconnected?.Invoke(user)); _goHub.On(nameof(LobbyPost), (Post post) => LobbyPost?.Invoke(post)); _goHub.On(nameof(GamePost), (Post post) => GamePost?.Invoke(post)); _goHub.On(nameof(GameRequested), (string name) => GameRequested?.Invoke(name)); _goHub.On(nameof(GameRequestDeclined), (string name) => GameRequestDeclined?.Invoke(name)); _goHub.On(nameof(GameRequestCancelled), (string name) => GameRequestCancelled?.Invoke(name)); _goHub.On(nameof(GameRequestAccepted), (string name) => GameRequestAccepted?.Invoke(name)); _goHub.On(nameof(GameAborted), (string name) => GameAborted?.Invoke(name)); }