Ejemplo n.º 1
0
 private void OnClientAdding(int group)
 {
     if (GroupExists(group) == false)
     {
         GroupCreated?.Invoke(this, group);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="IGroup"/>.
        /// </summary>
        /// <param name="founder">The <see cref="IGroupable"/> that will be the founder of the group.</param>
        /// <returns>If the group was successfully created, returns the new <see cref="IGroup"/> with the
        /// <paramref name="founder"/> set as the group's founder. Otherwise, returns null.
        /// A group may not be created by someone who is already in a group.</returns>
        public IGroup TryCreateGroup(IGroupable founder)
        {
            // Make sure not already in a group
            if (founder.Group != null)
            {
                return(null);
            }

            // Create the group
            var newGroup = _tryCreateGroup(this, founder);

            if (newGroup == null)
            {
                return(null);
            }

            // Make sure the founder had their group property updated
            founder.Group = newGroup;

            // Add the new group to the list
            _groups.Add(newGroup);

            // Listen for when the group is disbanded so we can remove it
            newGroup.Disbanded += _groupDisbandHandler;

            // Raise events
            OnCreateGroup(newGroup);

            if (GroupCreated != null)
            {
                GroupCreated.Raise(this, EventArgsHelper.Create(newGroup));
            }

            return(newGroup);
        }
Ejemplo n.º 3
0
 private void Apply(GroupCreated e)
 {
     Id           = e.SourceId;
     Name         = e.Name;
     ManagementId = e.ManagementId;
     Deleted      = e.Deleted;
 }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
        private void Apply(GroupCreated groupCreated)
        {
            if (Version > 1)
            {
                throw new InvalidOperationException("Can't create the same group twice");
            }

            Id = groupCreated.Id;
        }
Ejemplo n.º 6
0
 private void When(GroupCreated e)
 {
     Id                 = e.Id;
     RegionId           = e.RegionId;
     _genreIds          = e.GenreIds.ToList();
     _buddyIds          = new List <string>();
     _buddyIdsBlackList = new List <string>();
     Status             = GroupStatus.Open;
 }
Ejemplo n.º 7
0
        public void Create(string groupId, string regionId, IList <string> genreIds)
        {
            if (Version > 0)
            {
                throw new InvalidOperationException("Can't create a group twice");
            }

            var e = new GroupCreated(groupId, regionId, genreIds);

            Publish(e);
        }
Ejemplo n.º 8
0
        public async Task Handle(GroupCreated message)
        {
            var group = new Group
            {
                Id           = Guid.Parse(message.SourceId),
                ManagementId = message.ManagementId,
                Name         = message.Name,
                Deleted      = message.Deleted
            };

            groupRepository.Save(group);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 private void HandleEvent(GroupCreated @event)
 {
     this.Name = @event.Name;
 }
Ejemplo n.º 11
0
 protected virtual void OnGroupCreated(EventArgs e)
 {
     GroupCreated?.Invoke(this, e);
 }
Ejemplo n.º 12
0
 public async Task HandleAsync(GroupCreated @event)
 => await CompleteForAuthenticatedUserAsync(@event);