Exemple #1
0
        private void ResendEvent(Session session, EventRequest request, byte[] data)
        {
            List <Session> sessionList;

            switch (request.RecipientType)
            {
            case EventRecipientType.All:
                sessionList = GetAllSessions();
                break;

            case EventRecipientType.Others:
                sessionList = GetAllSessionNotMe(session);
                break;

            case EventRecipientType.AllInGroup:
                sessionList = GetAllSessionsInGroup(request);
                break;

            case EventRecipientType.RandomInGroup:
                sessionList = GetRandomSessionInGroup(request);
                break;

            default:
                throw new NotImplementedException();
            }

            sessionList
            .ForEach(c => SendData(c, data, throwInvalidSessionException: false));
        }
Exemple #2
0
        private List <Session> GetAllSessionsInGroup(EventRequest request)
        {
            var resultList = new List <Session>();

            foreach (var session in SessionList.ToList())
            {
                var eventSession = (EventSession)session;

                lock (_SyncLock)
                {
                    if (!_SessionGroupNameDic.ContainsKey(eventSession.Id))
                    {
                        continue;
                    }
                    if (!_SessionGroupNameDic[eventSession.Id].Contains(request.GroupName))
                    {
                        continue;
                    }
                }

                resultList.Add(session);
            }

            return(resultList);
        }
        public void SendEventToOthers <T>(T args)
            where T : class
        {
            var data = new EventRequest()
            {
                Data          = SerializeManager.Current.Serialize(args),
                RecipientType = EventRecipientType.Others
            };

            var bytes = SerializeManager.Current.Serialize(data);

            SendData(bytes, throwInvalidSessionException: false);
        }
Exemple #4
0
        private List <Session> GetRandomSessionInGroup(EventRequest request)
        {
            var tempList = GetAllSessionsInGroup(request);

            if (!tempList.Any())
            {
                return(new List <Session>());
            }

            var index = _Random.Next(tempList.Count);

            return(new List <Session>()
            {
                tempList[index]
            });
        }
        public void SendEventToRandomInGroup <T>(T args, string groupName)
            where T : class
        {
            if (string.IsNullOrEmpty(groupName))
            {
                throw new ArgumentException($"{nameof(groupName)} is null or empty.", nameof(groupName));
            }

            var data = new EventRequest()
            {
                Data          = SerializeManager.Current.Serialize(args),
                RecipientType = EventRecipientType.RandomInGroup,
                GroupName     = groupName
            };

            var bytes = SerializeManager.Current.Serialize(data);

            SendData(bytes, throwInvalidSessionException: false);
        }