internal override bool ProcessAndDispatchEventsToChild(EventContext eventcontext) { ParticipantChangeEventArgs participantChangeEventArgs = null; //No child to dispatch any more, need to dispatch to child , process locally for message type if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantResource)))) { if (eventcontext.EventEntity.In != null) { //TODO: currently we do not handle in link return(true); } string normalizedUri = UriHelper.NormalizeUri(eventcontext.EventEntity.Link.Href, this.BaseUri); ParticipantResource participantResource = this.ConvertToPlatformServiceResource <ParticipantResource>(eventcontext); switch (eventcontext.EventEntity.Relationship) { case EventOperation.Added: { Participant tempParticipant = null; if (!m_participantsCache.TryGetValue(normalizedUri, out tempParticipant)) { tempParticipant = new Participant(this.RestfulClient, participantResource, this.BaseUri, UriHelper.CreateAbsoluteUri(this.BaseUri, eventcontext.EventEntity.Link.Href), this.Parent as Conversation); m_participantsCache.TryAdd(normalizedUri, tempParticipant); participantChangeEventArgs = new ParticipantChangeEventArgs(); participantChangeEventArgs.AddedParticipants = new List <IParticipant> { tempParticipant }; } else { //Should get some participant added In event , ignore currently } break; } case EventOperation.Updated: { Participant tempParticipant = null; if (!m_participantsCache.TryGetValue(normalizedUri, out tempParticipant)) { Logger.Instance.Warning("Get a participant updated event for a participant not in cache, any error happened ?"); tempParticipant = new Participant(this.RestfulClient, participantResource, this.BaseUri, UriHelper.CreateAbsoluteUri(this.BaseUri, eventcontext.EventEntity.Link.Href), this.Parent as Conversation); m_participantsCache.TryAdd(normalizedUri, tempParticipant); } tempParticipant.HandleResourceEvent(eventcontext); participantChangeEventArgs = new ParticipantChangeEventArgs(); participantChangeEventArgs.UpdatedParticipants = new List <IParticipant> { tempParticipant }; break; } case EventOperation.Deleted: { Participant tempParticipant = null; if (m_participantsCache.TryRemove(normalizedUri, out tempParticipant)) { tempParticipant.HandleResourceEvent(eventcontext); participantChangeEventArgs = new ParticipantChangeEventArgs(); participantChangeEventArgs.RemovedParticipants = new List <IParticipant> { tempParticipant }; } break; } } if (participantChangeEventArgs != null) { var conv = this.Parent as Conversation; conv.OnParticipantChange(participantChangeEventArgs); } return(true); } else if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantMessagingResource))) || string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantAudioResource))) || string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantApplicationSharingResource)))) { if (eventcontext.EventEntity.In != null) { string normalizedParticipantUri = UriHelper.NormalizeUri(eventcontext.EventEntity.In.Href, this.BaseUri); Participant tempParticipant = null; if (m_participantsCache.TryGetValue(normalizedParticipantUri, out tempParticipant)) { tempParticipant.ProcessAndDispatchEventsToChild(eventcontext); } } return(true); //We do not rely on the response of tempParticipant.ProcessAndDispatchEventsToChild since we already know this is participant modality event } else { return(false); } }
/// <summary> /// On participant changed /// </summary> /// <param name="participantChangeEventArgs"></param> internal void OnParticipantChange(ParticipantChangeEventArgs participantChangeEventArgs) { m_handleParticipantChange?.Invoke(this, participantChangeEventArgs); }