예제 #1
0
        public GroupObserver(GroupObserverOptions groupObserverOptions)
        {
            if (groupObserverOptions == null)
            {
                throw new ArgumentNullException(nameof(groupObserverOptions));
            }

            _cancellationToken = _cancellationTokenSource.Token;
            groupObserverOptions.Build();
            GroupOptions = groupObserverOptions.GroupOptions;
            GroupMembersProvider = groupObserverOptions.GroupMembersProvider;
            GroupMemberStore = groupObserverOptions.GroupMemberStore;
            ObserverSchedule = groupObserverOptions.ObserverSchedule;

            if (groupObserverOptions.Events != null)
            {
                Events = new GroupObserverEvents
                {
                    OnGroupMembersJoined = groupObserverOptions.Events.OnGroupMembersJoined,
                    OnGroupMembersLeft = groupObserverOptions.Events.OnGroupMembersLeft,
                    OnGroupObserverStatusChanged = groupObserverOptions.Events.OnGroupObserverStatusChanged,
                    OnErrorOccured = groupObserverOptions.Events.OnErrorOccured
                };
            }
        }
예제 #2
0
        public GroupObserverOptions SetEventHandlers(Func<IEnumerable<GroupMember>, Task> onGroupMembersJoinedHandler = null, 
            Func<IEnumerable<GroupMember>, Task> onGroupMembersLeftHandler = null,
            Func<GroupObserverStatus, Task> onGroupObserverStatusChangedHandler = null,
            Func<Exception, Task> onErrorOccuredHandler = null)
        {
            Events = new GroupObserverEvents();

            if (onGroupMembersJoinedHandler != null)
            {
                Events.OnGroupMembersJoined = onGroupMembersJoinedHandler;
            }
            if (onGroupMembersLeftHandler != null)
            {
                Events.OnGroupMembersLeft = onGroupMembersLeftHandler;
            }
            if (onGroupObserverStatusChangedHandler != null)
            {
                Events.OnGroupObserverStatusChanged = onGroupObserverStatusChangedHandler;
            }
            if (onErrorOccuredHandler != null)
            {
                Events.OnErrorOccured = onErrorOccuredHandler;
            }

            return this;
        }