private void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            var callId = e.Conversation.Properties[ConversationProperty.Id].ToString();
            var fromId = e.Conversation.SelfParticipant.Properties[ParticipantProperty.Name].ToString();
            var toId   = "";

            foreach (var participant in e.Conversation.Participants)
            {
                if (!participant.IsSelf)
                {
                    toId = participant.Properties[ParticipantProperty.Name].ToString();
                    break;
                }
            }

            OnCallChanged(
                new SkypeCall()
            {
                CallId = callId, From = new SkypeUser()
                {
                    SkypeId = fromId, DisplayName = fromId
                },
                To = new SkypeUser()
                {
                    SkypeId = toId, DisplayName = toId
                }, Started = DateTime.Now
            }, SkypeCallState.Started);
        }
Exemplo n.º 2
0
        void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            ConversationContainer newcontainer = new ConversationContainer()
            {
                Conversation        = e.Conversation,
                ConversationCreated = DateTime.Now,
                m_convId            = nextConvId++
            };

            ActiveConversations.Add(e.Conversation, newcontainer);
            try
            {
                using (StreamWriter outfile = new StreamWriter(appDataPath + programFolder + @"\nextConvId.txt", false))
                {
                    outfile.WriteLine(nextConvId);
                    outfile.Close();
                }
            }
            catch (Exception _ex)
            {
                //ignore
            }
            e.Conversation.ParticipantAdded   += Conversation_ParticipantAdded;
            e.Conversation.ParticipantRemoved += Conversation_ParticipantRemoved;
            String s = String.Format("Conversation #{0} started.", newcontainer.m_convId);

            consoleWriteLine(s);
            if (WindowState == FormWindowState.Minimized)
            {
                this.notifyIcon.BalloonTipText = s;
                this.notifyIcon.ShowBalloonTip(BALOON_POPUP_TIMEOUT);
            }
        }
 /// <summary>
 /// 会话卸载
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public static void ConversationManager_ConversationRemoved(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
 {
     try
     {
     }
     catch (Exception ex)
     {
         LogManage.WriteLog(typeof(LyncHelper), ex);
     }
 }
Exemplo n.º 4
0
 private void ConversationEnded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
 {
     if (!ModalityIsNotified(e.Conversation, ModalityTypes.AudioVideo))
     {
         return;
     }
     if (ReactOnEvent != null)
     {
         ReactOnEvent(JukeboxCommand.PlayAfterPaused);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// New conversation is added because the user added it or was invited to a conversation by another user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            if (_conversation == null)
            {
                _conversation = e.Conversation;
            }

            e.Conversation.InitialContextReceived += Conversation_InitialContextReceived;
            e.Conversation.ContextDataReceived    += Conversation_ContextDataReceived;
            e.Conversation.StateChanged           += Conversation_StateChanged;
        }
Exemplo n.º 6
0
        private void ConversationStarted(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            if (!IsValidCall(e.Conversation))
            {
                return;
            }

            if (ReactOnEvent != null)
            {
                ReactOnEvent(JukeboxCommand.Pause);
            }
        }
Exemplo n.º 7
0
        static void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            var conversation = e.Conversation;



            // Note - only handles 1 conversation at time
            if (_conversation != null)
            {
                conversation.End();
            }


            Console.WriteLine(conversation.Modalities[ModalityTypes.AudioVideo].State);

            // TODO - Check state
            //if (!_conversation.Modalities.ContainsKey(ModalityTypes.AudioVideo) || _conversation.Modalities[ModalityTypes.AudioVideo].State != ModalityState.Notified) ;

            // TODO - Locking?
            _conversation = conversation;

            var avModality = (AVModality)_conversation.Modalities[ModalityTypes.AudioVideo];

            if (avModality.State == ModalityState.Notified)
            {
                //incoming call

                avModality.ModalityStateChanged += avModality_ModalityStateChanged;
                avModality.Accept();

                OnCallAccepted();
            }
            else
            {
                //outgoing call

                conversation.ParticipantAdded += conversation_ParticipantAdded;
                conversation.StateChanged     += conversation_StateChanged;

                if (conversation.CanInvoke(ConversationAction.AddParticipant))
                {
                    var contact = _client.ContactManager.GetContactByUri(_outgoingSipUri);
                    conversation.AddParticipant(contact);
                }
            }
        }
        private static void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            var conversation = e.Conversation;

            // Note - only handles 1 conversation at time
            if (_conversation != null)
            {
                conversation.End();
            }

            // TODO - Locking?
            _conversation = conversation;

            var avModality = (AVModality)_conversation.Modalities[ModalityTypes.AudioVideo];

            System.Diagnostics.Debug.WriteLine(String.Format("avMod state is {0}", avModality.State));

            if (avModality.State == ModalityState.Notified)
            {
                //incoming call

                avModality.ModalityStateChanged += avModality_ModalityStateChanged;
                avModality.Accept();

                OnCallAccepted();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(String.Format("else avMod state is {0}", avModality.State));
                //outgoing call

                conversation.ParticipantAdded += conversation_ParticipantAdded;
                conversation.StateChanged     += conversation_StateChanged;

                if (conversation.CanInvoke(ConversationAction.AddParticipant))
                {
                    var contact = _client.ContactManager.GetContactByUri(_outgoingSipUri);
                    conversation.AddParticipant(contact);
                }
            }
        }
Exemplo n.º 9
0
        void ConversationManager_ConversationRemoved(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            string ConversationID = e.Conversation.Properties[ConversationProperty.Id].ToString();

            e.Conversation.ParticipantAdded   -= Conversation_ParticipantAdded;
            e.Conversation.ParticipantRemoved -= Conversation_ParticipantRemoved;
            if (ActiveConversations.ContainsKey(e.Conversation))
            {
                ConversationContainer container = ActiveConversations[e.Conversation];
                TimeSpan conversationLength     = DateTime.Now.Subtract(container.ConversationCreated);
                consoleWriteLine(String.Format("Conversation #{0} ended. It lasted {1} seconds", container.m_convId, conversationLength.ToString(@"hh\:mm\:ss")));
                ActiveConversations.Remove(e.Conversation);

                String s = String.Format("Conversation #{0} ended.", container.m_convId);
                if (WindowState == FormWindowState.Minimized)
                {
                    this.notifyIcon.BalloonTipText = s;
                    this.notifyIcon.ShowBalloonTip(BALOON_POPUP_TIMEOUT);
                }
            }
        }
        void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            var conversation = e.Conversation;

            // Test conversation state. If inactive, then the new conversation window was opened by the user, not a remote participant
            if (conversation.State == ConversationState.Inactive)
            {
                return;
            }

            // Get the URI of the "Inviter" contact
            var remoteParticipant = ((Contact)conversation.Properties[ConversationProperty.Inviter]).Uri;

            // Determine which modalities are available in the conversation
            bool hasSharingOnly = true;

            bool hasInstantMessaging = false;

            if (ModalityIsNotified(conversation, ModalityTypes.InstantMessage))
            {
                hasInstantMessaging = true;
                hasSharingOnly      = false;
            }

            bool hasAudioVideo = false;

            if (ModalityIsNotified(conversation, ModalityTypes.AudioVideo))
            {
                hasAudioVideo  = true;
                hasSharingOnly = false;
            }

            // Get whether this is a conference
            bool isConference = conversation.Properties[ConversationProperty.ConferencingUri] != null;

            // Raise the NewCall event
            OnNewCall(remoteParticipant, hasSharingOnly, hasInstantMessaging, hasAudioVideo, isConference);
        }
Exemplo n.º 11
0
 /// <summary>
 /// New Conversation added
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
 {
     e.Conversation.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += AVModalityStateChanged;
 }
        /// <summary>
        /// Handles the event raised when a new conversation is added. This sample only hosts one conversation
        /// at a time. Once this event is handled, the sample un-registers for this event. The event is registered again when
        /// this conversation is removed from the ContactManager.Conversations collection upon termination of this conversation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            Boolean addedByThisProcess = true;

            try
            {
                //Suspend hosting new conversations until this conversation is ended
                _LyncClient.ConversationManager.ConversationAdded -= ConversationManager_ConversationAdded;
            }

            catch (Exception ex) { MessageBox.Show("Exception on de-register for ConversationAdded: " + ex.Message); }

            //If this class field is null then the new conversation was not started by this running process. It was
            //Started by the Lync client or by a remote user.
            if (_conversation == null)
            {
                addedByThisProcess = false;
                _conversation      = e.Conversation;
            }



            //Register for conversation state changes such as Active->Terminated.
            _conversation.StateChanged += _conversation_StateChanged;

            //Register for the application sharing modality event on the conversation itself
            _sharingModality = (ApplicationSharingModality)_conversation.Modalities[ModalityTypes.ApplicationSharing];

            //Register for state changes like connecting->connected
            _sharingModality.ModalityStateChanged += _sharingModality_ModalityStateChanged;

            //Register to catch requests from other participants for control of the locally owned sharing resource.
            _sharingModality.ControlRequestReceived += _sharingModality_ControlRequestReceived;
            _sharingModality.ControllerChanged      += _sharingModality_ControllerChanged;

            //Register to catch changes in the list of local sharable resources such as a process that starts up or terminates.
            _sharingModality.LocalSharedResourcesChanged += _sharingModality_LocalSharedResourcesChanged;

            //Register for changes in the availbility of resource controlling actions such as grant and revoke.
            _sharingModality.ActionAvailabilityChanged += _sharingModality_ActionAvailabilityChanged;

            //Register for changes in the local participant's mode of sharing participation
            // such as Viewing->Sharing, Requesting Control->Controlling.
            _sharingModality.ParticipationStateChanged += _sharingModality_ParticipationStateChanged;

            //Register for participant added events on the new conversation
            //The next important action in the chain of conversation intiating action happens in the ParticipantAdded event handler.
            _conversation.ParticipantAdded   += _conversation_ParticipantAdded;
            _conversation.ParticipantRemoved += _conversation_ParticipantRemoved;


            if (addedByThisProcess == true)
            {
                //Clear out the contact list on the UI to be replaced with only the contacts selected for the current conversation.
                this.Invoke(new ClearAllContactsDelegate(ClearAllContacts));

                //Iterate on the contact dictionary that is filled from the contact Sip addresses selected from the
                //contact list UI control. Add each selected contact to the conversation, causing an invitation to be
                //sent to each contact.
                foreach (Contact selectedContact in _selectedContacts.Values)
                {
                    Participant newParticipant = _conversation.AddParticipant(selectedContact);

                    //Register for events on the conversation participant's application sharing modality
                    ((ApplicationSharingModality)newParticipant.Modalities[ModalityTypes.ApplicationSharing]).ActionAvailabilityChanged += _sharingModality_ActionAvailabilityChanged;
                }
            }

            //Update the list of local sharable resources on the UI
            this.Invoke(new UpdateSharedResourcesListboxDelegate(UpdateSharedResourcesListbox));

            //Set the enabled state of the resource sharing button, end conversation button, and start conversation button.

            EnableDisableButtonDelegate buttonDelegate = new EnableDisableButtonDelegate(EnableDisableButton);

            this.Invoke(buttonDelegate, new object[] { StartSharingResource_Button, true });
            this.Invoke(buttonDelegate, new object[] { EndConversation_Button, true });
            this.Invoke(buttonDelegate, new object[] { Start_Button, false });
        }
Exemplo n.º 13
0
        /// <summary>
        /// 会话加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
        {
            //查看是否已进入一个会议【倘若未进入会议,则直接进行拒绝,该逻辑有待斟酌】
            bool canOpenTheConversation = true;

            if (HasConferenceCallBack != null)
            {
                HasConferenceCallBack(new Action <bool>((hasConference) =>
                {
                    //if (hasConference)
                    //{
                    //    canOpenTheConversation = false;
                    //}
                }));
            }


            //子线程不可直接调用主线程的UI(需要通过异步委托的机制去执行)
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                try
                {
                    #region 响应会话

                    //获取发起人的会话模式
                    IDictionary <ModalityTypes, Modality> modalities = e.Conversation.Modalities;

                    //通知模式
                    //NotifyType notifyType = NotifyType.InstantMessage;

                    AVModality avModality = (AVModality)modalities[ModalityTypes.AudioVideo];

                    //视频通道
                    VideoChannel videoChannel = ((AVModality)modalities[ModalityTypes.AudioVideo]).VideoChannel;

                    //音频通道
                    AudioChannel audioChannel = ((AVModality)modalities[ModalityTypes.AudioVideo]).AudioChannel;
                    //IM类型
                    var instantMessage = modalities[ModalityTypes.InstantMessage];
                    //查看当前视频会话具体应用
                    if (videoChannel.State == ChannelState.Notified)
                    {
                        if (canOpenTheConversation)
                        {
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Accept();
                            //notifyType = NotifyType.Video;

                            TimerJob.StartRun(new Action(() =>
                            {
                                //判断是否可以执行该操作
                                if (videoChannel.CanInvoke(ChannelAction.Start))
                                {
                                    ////接受请求,开启摄像头
                                    videoChannel.BeginStart(null, null);
                                    //停止计时器
                                    timerAcept.Stop();
                                }
                            }), 500, out timerAcept);
                        }
                        else
                        {
                            //拒绝音频会话
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Reject(ModalityDisconnectReason.NotAcceptableHere);
                            return;
                        }
                    }
                    //查看当前音频会话具体应用
                    else if (audioChannel.State == ChannelState.Notified)
                    {
                        if (canOpenTheConversation)
                        {
                            //接受音频会话
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Accept();
                            //notifyType = NotifyType.Autio;
                        }
                        else
                        {
                            //拒绝音频会话
                            ((AVModality)modalities[ModalityTypes.AudioVideo]).Reject(ModalityDisconnectReason.NotAcceptableHere);
                        }
                    }
                    //IMM文本会话,查看是否为通知状态(避免与语音、视频通话相互之间发生冲突)
                    if (instantMessage.State == ModalityState.Notified || instantMessage.State == ModalityState.Connected)
                    {
                        if (canOpenTheConversation)
                        {
                            ((InstantMessageModality)modalities[ModalityTypes.InstantMessage]).Accept();

                            #region old solution

                            //if (e.Conversation.Participants.Count <= 2)
                            //{
                            //    //模仿鼠标点击
                            //    Win32API.SetCursorPos(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - 100, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - 160);
                            //    Win32API.mouse_event(Win32API.MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
                            //    Win32API.mouse_event(Win32API.MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
                            //}

                            #endregion
                        }
                        else
                        {
                            ((InstantMessageModality)modalities[ModalityTypes.InstantMessage]).Reject(ModalityDisconnectReason.NotAcceptableHere);
                        }
                    }

                    #endregion

                    #region 设置窗体位置和尺寸

                    //获取会话窗体
                    ConversationWindow window = null;

                    //获取会话窗体
                    window = ConversationCodeEnterEntity.lyncAutomation.GetConversationWindow(e.Conversation);
                    window.NeedsSizeChange -= window_NeedsSizeChange;
                    window.NeedsSizeChange += window_NeedsSizeChange;
                    if (MainConversationOutCallBack != null)
                    {
                        MainConversationOutCallBack(window);
                    }

                    //设置会话窗体的事件
                    SettingConversationWindowEvent(window);

                    #endregion

                    #region 共享设置

                    window.StateChanged -= MainConversation_StateChanged;
                    //状态更改
                    window.StateChanged += MainConversation_StateChanged;

                    //为共享做准备
                    TimerJob.StartRun(new Action(() =>
                    {
                        //连接共享
                        var modaly = ((ContentSharingModality)e.Conversation.SelfParticipant.Conversation.Modalities[ModalityTypes.ContentSharing]);

                        if (modaly.CanInvoke(ModalityAction.Accept))
                        {
                            modaly.Accept();
                        }

                        if (modaly.CanInvoke(ModalityAction.Connect))
                        {
                            modaly.BeginConnect(null, null);
                        }
                    }));

                    #endregion

                    #region 会话加载完成事件激活

                    if (ConversationAddCompleateCallBack != null)
                    {
                        ConversationAddCompleateCallBack();
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                    LogManage.WriteLog(typeof(LyncHelper), ex);
                }
            }));
        }
Exemplo n.º 14
0
 void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
 {
     _conversation = e.Conversation;
 }