private void Conference_Executed(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) { try { if (!CanConference) { return; } var interactionsForConference = SelectedInteractions.ToArray(); //var interactionsForConference = Interactions.Where(i => !i.IsDisconnected).Select(i=>i.Interaction).ToArray(); MainViewModel.Instance.LogMessage("Making a conference with interactions: " + interactionsForConference.Select(i => i.InteractionId.Id.ToString()) .Aggregate((current, next) => current + ", " + next)); InteractionsManager.GetInstance(_session).MakeNewConference(interactionsForConference); } catch (Exception ex) { MainViewModel.Instance.LogMessage(ex); } }
private void QueueOnQueueContentsChanged(object sender, QueueContentsChangedEventArgs e) { try { //MainViewModel.Instance.LogMessage("Queue contents changed"); // Add interactions foreach (var interaction in e.ItemsAdded) { MainViewModel.Instance.LogMessage(string.Format("[{0}] Interaction Added", interaction.Interaction.InteractionId.Id)); Context.Send(s => { try { Interactions.Add(new InteractionViewModel(interaction.Interaction)); // Select the interaction if there is only one non-disconnected one var candidates = Interactions.Where(i => !i.IsDisconnected).ToList(); if (candidates.Count() == 1) { SelectedInteraction = candidates[0]; } } catch (Exception ex) { MainViewModel.Instance.LogMessage(ex); } }, null); } // Update interactions foreach (var interaction in e.ItemsChanged) { var existingInteraction = FindInteractionById(interaction.Interaction.InteractionId.Id); if (existingInteraction != null) { // Update properties MainViewModel.Instance.LogMessage( string.Format("[{0}] Interaction Changed with attributes: {1}", interaction.Interaction.InteractionId.Id, interaction.InteractionAttributeNames.Aggregate((current, next) => current + ", " + next))); foreach (var property in interaction.InteractionAttributeNames) { existingInteraction.RaisePropertyChanged(property); } } else { // Add because it's missing (this shouldn't happen) MainViewModel.Instance.LogMessage( string.Format("[{0}] Interaction Changed (adding to list) with attributes: {1}", interaction.Interaction.InteractionId.Id, interaction.InteractionAttributeNames.Aggregate((current, next) => current + ", " + next))); Context.Send(s => Interactions.Add(new InteractionViewModel(interaction.Interaction)), null); } // Update this because something might have changed (like state or capabilities), but only if we have this interaction selected if (SelectedInteractions.Any(i => interaction.Interaction.InteractionId.Id == i.InteractionId.Id)) { RaisePermissionProperties(); } } // Remove interactions foreach (var interaction in e.ItemsRemoved) { var existingInteraction = FindInteractionById(interaction.Interaction.InteractionId.Id); if (existingInteraction != null) { MainViewModel.Instance.LogMessage(string.Format("[{0}] Interaction Removed", interaction.Interaction.InteractionId.Id)); Context.Send(s => Interactions.Remove(existingInteraction), null); } else { MainViewModel.Instance.LogMessage(string.Format("[{0}] Interaction Removed (was not in list)", interaction.Interaction.InteractionId.Id)); } } /* Conference member description: * * ConferenceId - The ID of the conference object * ConferenceItem - The interaction ID of the call in the conference to which the event is referring * Interaction - The interaction ID of "you" in the conference */ // Add Conference Parties foreach (var conference in e.ConferenceItemsAdded) { MainViewModel.Instance.LogMessage( string.Format("Conference item added:{0}ConferenceId={1}{2}ConferenceItem={3}{4}Interaction={5}", Environment.NewLine, conference.ConferenceId, Environment.NewLine, conference.ConferenceItem.InteractionId.Id, Environment.NewLine, conference.Interaction.InteractionId.Id)); var existingInteraction = FindInteractionById(conference.Interaction.InteractionId.Id); if (existingInteraction != null) { // Add conference party Context.Send( s => { try { existingInteraction.ConferenceParties.Add( new InteractionViewModel(conference.ConferenceItem)); } catch (Exception ex) { MainViewModel.Instance.LogMessage(ex); } }, null); } else { Context.Send(s => { try { // Create interaction VM var newInteraction = new InteractionViewModel(conference.Interaction); // Add conference party to interaction newInteraction.ConferenceParties.Add(new InteractionViewModel(conference.ConferenceItem)); // Add interaction to list Interactions.Add(newInteraction); } catch (Exception ex) { MainViewModel.Instance.LogMessage(ex); } }, null); } } // Update Conference Parties foreach (var conference in e.ConferenceItemsChanged) { MainViewModel.Instance.LogMessage( string.Format("Conference item changed:{0}ConferenceId={1}{2}ConferenceItem={3}{4}Interaction={5}{6}Attributes={7}", Environment.NewLine, conference.ConferenceId, Environment.NewLine, conference.ConferenceItem.InteractionId.Id, Environment.NewLine, conference.Interaction.InteractionId.Id, Environment.NewLine, conference.InteractionAttributeNames.Aggregate((current, next) => current + ", " + next))); // Find conference host interaction var existingInteraction = FindInteractionById(conference.Interaction.InteractionId.Id); if (existingInteraction != null) { // Find party in conference members var conferenceParty = FindInteractionById(conference.ConferenceItem.InteractionId.Id, existingInteraction.ConferenceParties); if (conferenceParty == null) { // Couldn't find main conference party in list. This should never happen. MainViewModel.Instance.LogMessage( new Exception("Unable to find conference interaction " + conference.ConferenceItem.InteractionId.Id + "in cache.")); } else { // Raise property changed event for each property foreach (var property in conference.InteractionAttributeNames) { conferenceParty.RaisePropertyChanged(property); } } } else { // Couldn't find main interaction in list. This should never happen. MainViewModel.Instance.LogMessage( new Exception("Unable to find interaction " + conference.Interaction.InteractionId.Id + "in cache.")); } } // Remove Conference Parties foreach (var conference in e.ConferenceItemsRemoved) { MainViewModel.Instance.LogMessage( string.Format("Conference item removed:{0}ConferenceId={1}{2}ConferenceItem={3}{4}Interaction={5}", Environment.NewLine, conference.ConferenceId, Environment.NewLine, conference.ConferenceItem.InteractionId.Id, Environment.NewLine, conference.Interaction.InteractionId.Id)); // Find conference host interaction var existingInteraction = FindInteractionById(conference.Interaction.InteractionId.Id); if (existingInteraction != null) { // Find party in conference members var conferenceParty = FindInteractionById(conference.ConferenceItem.InteractionId.Id, existingInteraction.ConferenceParties); if (conferenceParty == null) { // Couldn't find main interaction in list. This should never happen. MainViewModel.Instance.LogMessage("Unable to find conference party " + conference.ConferenceItem.InteractionId.Id); } else { Context.Send(s => { try { existingInteraction.ConferenceParties.Remove(conferenceParty); } catch (Exception ex) { MainViewModel.Instance.LogMessage(ex); } }, null); } } } } catch (Exception ex) { MainViewModel.Instance.LogMessage(ex); } }