Exemple #1
0
 private void OnClientAdding(int group)
 {
     if (GroupExists(group) == false)
     {
         GroupCreated?.Invoke(this, group);
     }
 }
Exemple #2
0
        internal void OnMessage(Guid clientId, MessageContainer container)
        {
            if (!_connections.TryGetValue(clientId, out WsConnection connection))
            {
                return;
            }

            switch (container.Identifier)
            {
            case nameof(ConnectionRequest):
                var connectionRequest  = ((JObject)container.Payload).ToObject(typeof(ConnectionRequest)) as ConnectionRequest;
                var connectionResponse = new ConnectionResponse
                {
                    Result    = ResultCode.Ok,
                    IsSuccess = true,
                };
                if (_connections.Values.Any(c => c.Username == connectionRequest.Username))
                {
                    string reason = $"User '{connectionRequest.Username}' is already logged in.";
                    connectionResponse.Result    = ResultCode.Failure;
                    connectionResponse.IsSuccess = false;
                    connectionResponse.Reason    = reason;
                    connection.Send(connectionResponse.GetContainer());
                    ErrorReceived?.Invoke(this, new ErrorReceivedEventArgs(reason, DateTime.Now));
                }
                else
                {
                    connection.Username            = connectionRequest.Username;
                    connectionResponse.ActiveUsers = _connections.Where(c => c.Value.Username != null).Select(u => u.Value.Username).ToList();
                    connection.Send(connectionResponse.GetContainer());
                    ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(connection.Username, true, DateTime.Now));
                    ConnectionReceived?.Invoke(this, new ConnectionReceivedEventArgs(connection.Username, true, DateTime.Now));
                }
                break;

            case nameof(MessageRequest):
                var messageRequest = ((JObject)container.Payload).ToObject(typeof(MessageRequest)) as MessageRequest;
                MessageReceived?.Invoke(this, new MessageReceivedEventArgs(connection.Username, messageRequest.Target, messageRequest.Message, messageRequest.Groupname, DateTime.Now));
                break;

            case nameof(FiltrationRequest):
                var filtrationRequest = ((JObject)container.Payload).ToObject(typeof(FiltrationRequest)) as FiltrationRequest;
                FiltrationReceived?.Invoke(this, new FiltrationReceivedEventArgs(connection.Username, filtrationRequest.FirstDate, filtrationRequest.SecondDate, filtrationRequest.EventType));
                break;

            case nameof(CreateGroupRequest):
                var createGroupRequest = ((JObject)container.Payload).ToObject(typeof(CreateGroupRequest)) as CreateGroupRequest;
                createGroupRequest.UserList.Add(connection.Username);
                GroupCreated?.Invoke(this, new GroupCreatedEventArgs(createGroupRequest.Groupname, createGroupRequest.UserList));
                break;

            case nameof(LeaveGroupRequest):
                var leaveGroupRequest = ((JObject)container.Payload).ToObject(typeof(LeaveGroupRequest)) as LeaveGroupRequest;
                GroupLeaved?.Invoke(this, new GroupLeavedEventArgs(connection.Username, leaveGroupRequest.Groupname));
                break;
            }
        }
Exemple #3
0
        private async void btnCreateGroup_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            GroupDTO group = null;

            //Create group
            try
            {
                group = await groupsApi.CreateGroupAsync(new CreateGroupDTO()
                {
                    AllowEmployeeAcknowledgeable = ucGroupSettings.IsAcknowledgeableSelected(),
                    AllowEmployeeBookmark        = ucGroupSettings.IsBookmarkSelected(),
                    AllowEmployeeSticky          = ucGroupSettings.IsStickySelected(),
                    GroupName = ucGroupSettings.GetGroupName()
                });
            }
            catch (HttpOperationException er)
            {
                new ErrorDialog(er.Response.ReasonPhrase, er.Response.Content).ShowDialog();
                return;
            }

            //Add users, roles, and channels
            List <string> channelNames = ucGroupSettings.GetChannels().Select(c => c.Name).ToList();

            try
            {
                await groupsApi.AddUsersToGroupAsync(group.Id, ucGroupSettings.GetSelectedUsers());

                await groupsApi.AddRolesToGroupAsync(group.Id, ucGroupSettings.GetSelectedRoles());

                foreach (string channelName in channelNames)
                {
                    await channelsApi.CreateChannelAsync(group.Id, channelName);
                }
            }
            catch (HttpOperationException er)
            {
                new ErrorDialog(er.Response.ReasonPhrase, er.Response.Content).ShowDialog();
                return;
            }

            MessageBox.Show("The group has now been created!");
            GroupCreated?.Invoke(group);
        }
Exemple #4
0
 protected virtual void OnGroupCreated(EventArgs e)
 {
     GroupCreated?.Invoke(this, e);
 }