public LyncClientWorker()
        {
            //Listen for events of changes in the state of the client
            try {
                _lyncClient = LyncClient.GetClient();
            }
            catch (ClientNotFoundException clientNotFoundException) {
                Console.WriteLine(clientNotFoundException);
                return;
            }
            catch (NotStartedByUserException notStartedByUserException) {
                Console.Out.WriteLine(notStartedByUserException);
                return;
            }
            catch (LyncClientException lyncClientException) {
                Console.Out.WriteLine(lyncClientException);
                return;
            }
            catch (SystemException systemException) {
                if (IsLyncException(systemException)) {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                    return;
                }
                else {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }

            // for watching out changesi
            _lyncClient.StateChanged +=
                new EventHandler<ClientStateChangedEventArgs>(LyncStateChanged);
        }
Example #2
0
        public void AddContact(string UserName)
        {
            if (lyncClient == null)
            {
                lyncClient = LyncClient.GetClient();
            }
            if (lyncClient.State == ClientState.SignedIn)
            {
                try
                {
                    Contact contact = lyncClient.ContactManager.GetContactByUri("sip:" + UserName);
                    contacts.Add(contact);
                    contact.ContactInformationChanged += new System.EventHandler<ContactInformationChangedEventArgs>(contact_ContactInformationChanged);
                    Microsoft.Lync.Model.ContactAvailability availability = (Microsoft.Lync.Model.ContactAvailability)contact.GetContactInformation(ContactInformationType.Availability);

                    string Name = (string)contact.GetContactInformation(ContactInformationType.DisplayName);
                    for (int rowIndex = 0; rowIndex < dataGridView.Rows.Count; rowIndex++)
                    {
                        if ((string)dataGridView.Rows[rowIndex].Cells["User"].Value == Name)
                        {
                            dataGridView.Rows[rowIndex].Cells["Status"].Value = availability.ToString();
                            break;
                        }
                    }
                }
                catch { }
            }
        }
        /// <summary>
        /// build up the asynchronous call to contact manager
        /// </summary>
        /// <param name="email"></param>
        public LyncManagerStatus(string email)
        {
            try
            {
                //Console.WriteLine("starting...");
                _uri = email;
                _client = Microsoft.Lync.Model.LyncClient.GetClient();

                _client.ContactManager.BeginSearch(_uri, BeginSearchCallback, new object[] { _client.ContactManager, _uri });

                //_client.ContactManager.BeginSearch(
                //    _uri,
                //    SearchProviders.GlobalAddressList,
                //    SearchFields.EmailAddresses,
                //    SearchOptions.IncludeContactsWithoutSipOrTelUri,
                //    2,
                //    BeginSearchCallback,
                //    new object[] { _client.ContactManager, _uri }
                //);
            }
            catch(Microsoft.Lync.Model.NotSignedInException)
            {
                Console.WriteLine(Resources.NotSignedIn);
                _done = true;
            }
            catch(Microsoft.Lync.Model.ClientNotFoundException)
            {
                Console.WriteLine(Resources.NotRunning);
                _done = true;
            }
        }
Example #4
0
        public void Setup()
        {
            while (lyncClient == null)
            {
                try
                {
                    lyncClient = LyncClient.GetClient();
                    lyncClient.StateChanged -= new EventHandler<ClientStateChangedEventArgs>(Client_StateChanged);
                    lyncClient.StateChanged += new EventHandler<ClientStateChangedEventArgs>(Client_StateChanged);

                }
                catch (ClientNotFoundException e)
                {
                    // Eat this for now.  It just means that the Lync client isn't running on the desktop.
                    // TODO figure out a better way to do this.
                    Thread.Sleep(1000);
                }
            }

            if (lyncClient.Self != null && lyncClient.Self.Contact != null)
            {
                lyncClient.Self.Contact.ContactInformationChanged -= new EventHandler<ContactInformationChangedEventArgs>(SelfContact_ContactInformationChanged);
                lyncClient.Self.Contact.ContactInformationChanged += new EventHandler<ContactInformationChangedEventArgs>(SelfContact_ContactInformationChanged);

                SetAvailability();
            }
        }
Example #5
0
        public Form1()
        {
            InitializeComponent();
            try
            {
                _LyncClient = LyncClient.GetClient();

                if (_LyncClient == null)
                {
                    throw new Exception("Unable to obtain client interface");
                }

                if (_LyncClient.InSuppressedMode == true)
                {
                    if (_LyncClient.State == ClientState.Uninitialized)
                    {
                        Object[] _asyncState = { _LyncClient };
                        _LyncClient.BeginInitialize(InitializeCallback, _asyncState);
                    }
                }
                _LyncClient.StateChanged += _LyncClient_ClientStateChanged;
                _LyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
            }
            catch (NotStartedByUserException)
            {
                throw new Exception("Lync is not running");
            }
        }
Example #6
0
        public LyncRunner()
        {
            lyncClient = LyncClient.GetClient(); // 1
            lyncClient.StateChanged += new EventHandler<ClientStateChangedEventArgs>(Client_StateChanged); // 2

            //Update the user interface
            UpdateUserInterface(lyncClient.State); //3
        }
Example #7
0
 public Form1()
 {
     InitializeComponent();
     if (lyncClient == null)
     {
         lyncClient = LyncClient.GetClient();
         lyncClient.StateChanged += new EventHandler<ClientStateChangedEventArgs>(lyncClient_StateChanged);
     }
     contacts = new List<Contact>();
     InitDataSet();
 }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         LyncClient       = LyncClient.GetClient();
         Automation       = LyncClient.GetAutomation();
         this.DataContext = this;
     }
     catch (Exception ex)
     {
     }
 }
Example #9
0
        private void Disconnect()
        {
            if (this.client != null)
            {
                this.client.ClientDisconnected -= this.ClientOnClientDisconnected;
                this.client.ConversationManager.ConversationAdded   -= this.ConversationAdded;
                this.client.ConversationManager.ConversationRemoved -= this.ConversationRemoved;
                this.logs.Keys.ToList().ForEach(this.RemoveConversation);
            }

            this.client = null;
        }
Example #10
0
        /// <summary>
        /// 启动会议
        /// </summary>
        public void StartConferenceOnlyc(LyncClient lyncClient, string selfUri, ConversationWindow conversationWindow, string selfName)
        {
            try
            {
                try
                {
                    Dictionary <AutomationModalitySettings, object> dic = new Dictionary <AutomationModalitySettings, object>();
                    dic.Add(AutomationModalitySettings.FirstInstantMessage, selfName + MainConversationAccrodingStr);
                    dic.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
                    ConversationCodeEnterEntity.lyncAutomation.BeginStartConversation(
                        AutomationModalities.InstantMessage,
                        null,
                        null,
                        (ar) =>
                    {
                        try
                        {
                            #region (会话窗体设置,参会人同步【呼叫】)

                            //获取主会话窗
                            ConversationWindow window = ConversationCodeEnterEntity.lyncAutomation.EndStartConversation(ar);
                            //设置会话窗体的事件
                            SettingConversationWindowEvent(window);

                            ///注册会话更改事件
                            window.StateChanged -= MainConversation_StateChanged;
                            ///注册会话更改事件
                            window.StateChanged += MainConversation_StateChanged;

                            //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            //{
                            //    ShareWhiteboard(window, selfName);
                            //}));

                            #endregion
                        }
                        catch (OperationException ex)
                        {
                            LogManage.WriteLog(typeof(LyncHelper), ex);
                        };
                    },
                        null);
                }
                catch (Exception ex)
                {
                    LogManage.WriteLog(typeof(LyncHelper), ex);
                }
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(typeof(LyncHelper), ex);
            }
        }
Example #11
0
 /// <summary>
 ///  联系人同步(研讨客户端与lync同步)
 /// </summary>
 protected static void ParticalsSynchronous(LyncClient lyncClient, ConversationWindow conversationWindow, List <string> participantList)
 {
     try
     {
         if (conversationWindow != null && conversationWindow.Conversation != null)
         {
             List <string> tempList = new List <string>();
             //重新填充主会话联系人列表(实际)
             foreach (var partical in conversationWindow.Conversation.Participants)
             {
                 tempList.Add(partical.Contact.Uri);
             }
             //遍历所有参会人
             foreach (var item in participantList)
             {
                 //获取参会人
                 Contact contact = ConversationCodeEnterEntity.contactManager.GetContactByUri(item);
                 //获取参会人状态
                 double s = Convert.ToDouble(contact.GetContactInformation(ContactInformationType.Availability));
                 //状态3500,对方不在线
                 if (s == 3500)
                 {
                     //呼叫在线参会人加入会话(添加参会人)
                     if (conversationWindow.Conversation.CanInvoke(ConversationAction.AddParticipant))
                     {
                         //添加除自己之外的参会人
                         if (!contact.Equals(lyncClient.Self.Contact))
                         {
                             //对应实际参会人列表
                             if (!tempList.Contains(contact.Uri))
                             {
                                 //主会议关闭状态停止进行呼叫并中断
                                 if (conversationWindow == null)
                                 {
                                     return;
                                 }
                                 //添加在线的参会人
                                 conversationWindow.Conversation.AddParticipant(contact);
                             }
                         }
                     }
                 }
             }
         }
         else
         {
         }
     }
     catch (Exception ex)
     {
         LogManage.WriteLog(typeof(LyncHelper), ex);
     }
 }
Example #12
0
 /// <summary>
 ///  When form loads, gets instance of LyncClient and ConversationManager
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void LockVideo_Load(object sender, EventArgs e)
 {
     try
     {
         client = LyncClient.GetClient();
         conversationManager = client.ConversationManager;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 public SendMessage()
 {
     _LyncClient = LyncClient.GetClient();
     if (_LyncClient.State == ClientState.SignedIn)
     {
         MessageBox.Show("Lync is signed in");
     }
     else
     {
         MessageBox.Show("Lync is not signed in");
     }
 }
Example #14
0
        private void _LyncClientInitialization()
        {
            _LyncClient = null;

            try
            {
                _LyncClient = LyncClient.GetClient();
                _LyncClient.ClientDisconnected += _ClientDisconnected;
                _LyncClient.StateChanged       += _ClientStateChanged;

                _ContactSubscription = _LyncClient.ContactManager.CreateSubscription();

                _ContactInformationList.Clear();
                //_ContactInformationList.Add(ContactInformationType.DisplayName);
                //_ContactInformationList.Add(ContactInformationType.Title);
                _ContactInformationList.Add(ContactInformationType.PersonalNote);
                _ContactInformationList.Add(ContactInformationType.Activity);
                //_ContactInformationList.Add(ContactInformationType.ActivityId);
                _ContactInformationList.Add(ContactInformationType.IdleStartTime);
                _ContactInformationList.Add(ContactInformationType.Availability);
                //_ContactInformationList.Add(ContactInformationType.Photo);
                //_ContactInformationList.Add(ContactInformationType.IconStream);
            }
            catch (ClientNotFoundException clientNotFoundException)
            {
                // Console.WriteLine(clientNotFoundException);
                return;
            }
            catch (NotStartedByUserException notStartedByUserException)
            {
                // Console.Out.WriteLine(notStartedByUserException);
                return;
            }
            catch (LyncClientException lyncClientException)
            {
                // Console.Out.WriteLine(lyncClientException);
                return;
            }
            catch (SystemException systemException)
            {
                if (_IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    // Console.WriteLine("Error: " + systemException);
                    return;
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
        }
Example #15
0
        public AgentContext()
        {
            ContextMenu myContext = new ContextMenu();

            myContext.MenuItems.Add("Configure", configure);
            MenuItem manual = new MenuItem("Manual");

            manual.MenuItems.Add("Online/Free", manualOnline);
            manual.MenuItems.Add("Away", manualAway);
            manual.MenuItems.Add("Busy", manualBusy);
            manual.MenuItems.Add("Do not disturb", manualDND);
            manual.MenuItems.Add("Offline", manualOffline);
            manual.MenuItems.Add("-");
            manual.MenuItems.Add("Rrrring!", manualRing);
            myContext.MenuItems.Add(manual);
            myContext.MenuItems.Add("-");
            myContext.MenuItems.Add("Exit", exit);

            //Initialize tray icon
            trayIcon = new NotifyIcon()
            {
                Icon        = Properties.Resources.trayicon,
                ContextMenu = myContext,
                Visible     = true,
                Text        = "Arduino Busylight Agent"
            };

            //Create connection
            createConnection();

            //Connect to Lync/SfB
            try
            {
                lyncClient = LyncClient.GetClient();
                if (lyncClient.Self.Contact != null)
                {
                    //Add event handler for changed availabilities
                    lyncClient.Self.Contact.ContactInformationChanged += Contact_ContactInformationChanged;
                    //Add event handler for incoming conversations
                    lyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                }
            }
            catch (ClientNotFoundException ex)
            {
                MessageBox.Show("No running Lync or Skype for Business client was found. Your state will not be changed automatically.", "Lync/SfB client not found!");
                Console.WriteLine("Lync/SfB client not found: '{0}'", ex.Message);
            }
            catch (System.Runtime.InteropServices.MarshalDirectiveException ex)
            {
                Console.WriteLine("Unable to read Lync/SfB state: '{0}'", ex.Message);
            }
        }
        //private ApplicationRegistration _myApplicationRegistration;

        public Window1()
        {
            InitializeComponent();
            _viewModel       = App.MainViewModel;
            this.DataContext = _viewModel;
            //scrollViewerMessageLog.DataContext = _viewModel;
            //listBoxHistory.DataContext = _viewModel.MessageHistory;

            try
            {
                // Get the instance of LyncClient and subscribe to outgoing/incoming conversation events
                _lyncClient = LyncClient.GetClient();
                _lyncClient.StateChanged += new EventHandler <ClientStateChangedEventArgs>(LyncClient_StateChanged);

                _lyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                _lyncClient.DelegatorClientAdded   += _lyncClient_DelegatorClientAdded;
                _lyncClient.DelegatorClientRemoved += _lyncClient_DelegatorClientRemoved;
                foreach (DelegatorClient dc in _lyncClient.DelegatorClients)
                {
                    dc.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;

                    foreach (Conversation c in dc.ConversationManager.Conversations)
                    {
                        // Subscribe to conversation events
                        c.InitialContextReceived += Conversation_InitialContextReceived;
                        c.ContextDataReceived    += Conversation_ContextDataReceived;
                        c.StateChanged           += Conversation_StateChanged;
                    }
                }
                if (_lyncClient.ConversationManager.Conversations.Count > 0)
                {
                    _conversation = (Conversation)_lyncClient.ConversationManager.Conversations[0];

                    foreach (Conversation c in _lyncClient.ConversationManager.Conversations)
                    {
                        // Subscribe to conversation events
                        c.InitialContextReceived += Conversation_InitialContextReceived;
                        c.ContextDataReceived    += Conversation_ContextDataReceived;
                        c.StateChanged           += Conversation_StateChanged;
                    }
                }
                else
                {
                    // throw new InvalidOperationException("There must be at least one active Lync Conversation instance running to record a meeting transcript");
                }

                Conversation conversation = _lyncClient.ConversationManager.AddConversation();
                conversation.AddParticipant(_lyncClient.Self.Contact);
            }
            catch (ClientNotFoundException) { Console.WriteLine("Lync client was not found on startup"); }
            catch (LyncClientException lce) { MessageBox.Show("Lyncclientexception: " + lce.Message); }
        }
Example #17
0
        /// <summary>
        /// Initiates the window for the specified conversation.
        /// </summary>
        public ConversationWindow(Conversation conversation, LyncClient client)
        {
            InitializeComponent();

            //saves the client reference
            this.client = client;

            //saves the conversation reference
            this.conversation = conversation;

            //saves the AVModality, AudioChannel and VideoChannel, just for the sake of readability
            avModality   = (AVModality)conversation.Modalities[ModalityTypes.AudioVideo];
            audioChannel = avModality.AudioChannel;
            videoChannel = avModality.VideoChannel;

            //show the current conversation and modality states in the UI
            toolStripStatusLabelConvesation.Text = conversation.State.ToString();
            toolStripStatusLabelModality.Text    = avModality.State.ToString();

            //enables and disables the checkbox associated with the ConversationProperty.AutoTerminateOnIdle property
            //based on whether the Lync client is running in InSuppressedMode
            //se more details in the checkBoxAutoTerminateOnIdle_CheckStateChanged() method
            checkBoxAutoTerminateOnIdle.Enabled = client.InSuppressedMode;

            //registers for conversation state updates
            conversation.StateChanged += conversation_StateChanged;

            //registers for participant events
            conversation.ParticipantAdded   += conversation_ParticipantAdded;
            conversation.ParticipantRemoved += conversation_ParticipantRemoved;

            //subscribes to the conversation action availability events (for the ability to add/remove participants)
            conversation.ActionAvailabilityChanged += conversation_ActionAvailabilityChanged;

            //subscribes to modality action availability events (all audio button except DTMF)
            avModality.ActionAvailabilityChanged += avModality_ActionAvailabilityChanged;

            //subscribes to the modality state changes so that the status bar gets updated with the new state
            avModality.ModalityStateChanged += avModality_ModalityStateChanged;

            //subscribes to the audio channel action availability events (DTMF only)
            audioChannel.ActionAvailabilityChanged += audioChannel_ActionAvailabilityChanged;

            //subscribes to the video channel state changes so that the status bar gets updated with the new state
            audioChannel.StateChanged += audioChannel_StateChanged;

            //subscribes to the video channel action availability events
            videoChannel.ActionAvailabilityChanged += videoChannel_ActionAvailabilityChanged;

            //subscribes to the video channel state changes so that the video feed can be presented
            videoChannel.StateChanged += videoChannel_StateChanged;
        }
Example #18
0
        /// <summary>
        /// If an instance of the Lync application exits this method will make a video call to the predefined User Id.
        /// </summary>
        public override void Perform()
        {
            try
            {
                lyncClient = LyncClient.GetClient();
            }
            catch (Exception ex)
            {
                ErrorLog.AddError(ErrorType.Failure, Strings.Lync_ApplicationNotFound);
                Logger.Write(ex);

                return;
            }

            try
            {
                self = lyncClient.Self;

                if (self == null)
                {
                    ErrorLog.AddError(ErrorType.Failure, Strings.Lync_NotLoggedIn);
                    return;
                }

                try
                {
                    Contact contact = self.Contact.ContactManager.GetContactByUri(userId);
                }
                catch (Exception ex)
                {
                    ErrorLog.AddError(ErrorType.Failure, Strings.Lync_NoUserId);
                    Logger.Write(ex);
                    return;
                }

                Automation automation = LyncClient.GetAutomation();

                var participants = new List <string>();
                participants.Add(userId);

                automation.BeginStartConversation(AutomationModalities.Video, participants, null, null, automation);
            }
            catch (Exception ex)
            {
                ErrorLog.AddError(ErrorType.Failure, Strings.Lync_ReactionCouldntPerform);
                Logger.Write(ex);
            }
            finally
            {
                lyncClient = null;
            }
        }
        //private ApplicationRegistration _myApplicationRegistration;

        public Window1()
        {
            InitializeComponent();
            _viewModel = App.MainViewModel;
            this.DataContext = _viewModel;
            //scrollViewerMessageLog.DataContext = _viewModel;
            //listBoxHistory.DataContext = _viewModel.MessageHistory;

            try
            {
                // Get the instance of LyncClient and subscribe to outgoing/incoming conversation events
                _lyncClient = LyncClient.GetClient();
                _lyncClient.StateChanged += new EventHandler<ClientStateChangedEventArgs>(LyncClient_StateChanged);

                _lyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                _lyncClient.DelegatorClientAdded += _lyncClient_DelegatorClientAdded;
                _lyncClient.DelegatorClientRemoved += _lyncClient_DelegatorClientRemoved;
                foreach (DelegatorClient dc in _lyncClient.DelegatorClients)
                {
                    dc.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;

                    foreach (Conversation c in dc.ConversationManager.Conversations)
                    {
                        // Subscribe to conversation events
                        c.InitialContextReceived += Conversation_InitialContextReceived;
                        c.ContextDataReceived += Conversation_ContextDataReceived;
                        c.StateChanged += Conversation_StateChanged;
                    }
                }
                if (_lyncClient.ConversationManager.Conversations.Count > 0)
                {
                    _conversation = (Conversation)_lyncClient.ConversationManager.Conversations[0];

                    foreach (Conversation c in _lyncClient.ConversationManager.Conversations)
                    {
                        // Subscribe to conversation events
                        c.InitialContextReceived += Conversation_InitialContextReceived;
                        c.ContextDataReceived += Conversation_ContextDataReceived;
                        c.StateChanged += Conversation_StateChanged;
                    }
                }
                else
                {
                    // throw new InvalidOperationException("There must be at least one active Lync Conversation instance running to record a meeting transcript");
                }

                Conversation conversation = _lyncClient.ConversationManager.AddConversation();
                conversation.AddParticipant(_lyncClient.Self.Contact);
            }
            catch (ClientNotFoundException) { Console.WriteLine("Lync client was not found on startup"); }
            catch (LyncClientException lce) { MessageBox.Show("Lyncclientexception: " + lce.Message); }
        }
Example #20
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         LyncClient     = LyncClient.GetClient();
         ContactManager = LyncClient.ContactManager;
         SearchStatisticsTextBox.Text = "Lync client State: " + LyncClient.State.ToString();
     }
     catch (Exception ex)
     {
         SearchStatisticsTextBox.Text = "Exception: " + ex.Message;
     }
 }
Example #21
0
 public SkypeManager()
 {
     try
     {
         lyncClient = LyncClient.GetClient();
         lyncClient.StateChanged += LyncClient_StateChanged;
     }
     catch (Microsoft.Lync.Model.ClientNotFoundException ex)
     {
         throw new SkypeLib.ClientNotFoundException(ex.Message);
     }
     InitializeConversationSignups();
 }
Example #22
0
 private static void BindNewInstance()
 {
     try
     {
         var client     = LyncClient.GetClient();
         var automation = LyncClient.GetAutomation();
         instance = new AppController(client, automation);
     }
     catch (ClientNotFoundException)
     {
         throw new InvalidStateException("No Skype / Lync app running");
     }
 }
Example #23
0
        protected override void OnDisabled(DisabledEventArgs e)
        {
            if (conversationManager != null)
            {
                conversationManager.ConversationAdded -= conversationAdded;
                conversationManager = null;
            }

            if (lyncClient != null)
            {
                lyncClient = null;
            }
        }
Example #24
0
 protected override bool CheckIsRunning()
 {
     try
     {
         _lyncClient = LyncClient.GetClient();
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
     return(true);
 }
Example #25
0
        public void Setup()
        {
            //Listen for events of changes in the state of the client
            try
            {
                lyncClient = LyncClient.GetClient();
            }
            catch (ClientNotFoundException clientNotFoundException)
            {
                Console.WriteLine(clientNotFoundException);
                return;
            }
            catch (NotStartedByUserException notStartedByUserException)
            {
                Console.Out.WriteLine(notStartedByUserException);
                return;
            }
            catch (LyncClientException lyncClientException)
            {
                Console.Out.WriteLine(lyncClientException);
                return;
            }
            catch (SystemException systemException)
            {
                if (IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                    return;
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
            lyncClient.ConversationManager.ConversationAdded += new EventHandler <Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs>(Conversation_Added);

            lyncClient.ConversationManager.ConversationRemoved += new EventHandler <Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs>(ConversationRemoved);
            lyncClient.StateChanged +=
                new EventHandler <ClientStateChangedEventArgs>(Client_StateChanged);

            lyncClient.Self.Contact.ContactInformationChanged +=
                new EventHandler <ContactInformationChangedEventArgs>(SelfContact_ContactInformationChanged);

            Id = rnd.Next(1, 17000);

            SetAvailability();
            updateCallStatuses();
            ExternalStatusChanged();
        }
Example #26
0
        /// <summary>
        /// 加载会话窗体
        /// </summary>
        /// <param name="window">指定窗体</param>
        public void DockConversationWindow(LyncClient lyncClient, ConversationWindow window)
        {
            try
            {
                Application.Current.MainWindow.Dispatcher.BeginInvoke(new Action(() =>
                {
                    try
                    {
                        if (!window.IsDocked)
                        {
                            if (this.DockConversationWindowCallBack != null)
                            {
                                this.DockConversationWindowCallBack(new Action <int, int>((width, height) =>
                                {
                                    //获取工作区域的宽度
                                    int borWidth = width;
                                    //获取工作区域的高度
                                    int borHeight = height;

                                    WindowsFormsHost host            = this.conversationHost.winHost;
                                    System.Windows.Forms.Panel panel = this.conversationHost.panel;
                                    host.Width  = panel.Width = borWidth - 110;
                                    host.Height = panel.Height = borHeight - 30;

                                    //panel.MinimumSize = new System.Drawing.Size() { Height = 696 };

                                    //if(borHeight<715)
                                    //{
                                    //    host.Height = panel.Height = borHeight - 20;
                                    //}
                                    //else
                                    //{
                                    //    host.Height = panel.Height = borHeight - 30;
                                    //}

                                    LyncHelper.DockToNewParentWindow(panel.Handle, this.DockInit);
                                }));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManage.WriteLog(this.GetType(), ex);
                    };
                }));
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(this.GetType(), ex);
            }
        }
        internal ConversationInfo(Conversation conversation, LyncClient client, IntPtr parentHandle, Rectangle bounds, AsyncCallback conversationEndedCallback, AsyncCallback videoCallStartedCallback)
        {
            this.conversation = conversation;
            this.client = client;
            this.parentHandle = parentHandle;
            this.bounds = bounds;
            this.conversationEndedCallback = conversationEndedCallback;
            this.videoCallStartedCallback = videoCallStartedCallback;

            this.videoChannel = ((AVModality)conversation.Modalities[ModalityTypes.AudioVideo]).VideoChannel;

            //subscribes to the video channel state changes so that the video feed can be presented
            videoChannel.StateChanged += videoChannel_StateChanged;
        }
Example #28
0
        public void Init()
        {
            _lyncClient = LyncClient.GetClient();

            //
            foreach (var conversation in _lyncClient.ConversationManager.Conversations)
            {
                _avModality = (AVModality)conversation.Modalities[ModalityTypes.AudioVideo];
                _avModality.ModalityStateChanged += AvModality_ModalityStateChanged;
            }

            _lyncClient.ConversationManager.ConversationAdded   += ConversationManager_ConversationAdded;
            _lyncClient.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
        }
Example #29
0
        internal ConversationInfo(Conversation conversation, LyncClient client, IntPtr parentHandle, Rectangle bounds, AsyncCallback conversationEndedCallback, AsyncCallback videoCallStartedCallback)
        {
            this.conversation = conversation;
            this.client       = client;
            this.parentHandle = parentHandle;
            this.bounds       = bounds;
            this.conversationEndedCallback = conversationEndedCallback;
            this.videoCallStartedCallback  = videoCallStartedCallback;

            this.videoChannel = ((AVModality)conversation.Modalities[ModalityTypes.AudioVideo]).VideoChannel;

            //subscribes to the video channel state changes so that the video feed can be presented
            videoChannel.StateChanged += videoChannel_StateChanged;
        }
        //constructor
        public ShutDown(SignIn signin)
        {
            _Client            = LyncClient.GetClient();
            _SignIn            = signin;
            _SignIn.SigningOut = true;      //set flag to indicate we're now signing out


            if (_Client.State == ClientState.SignedIn)
            {
                Object[] _asyncState = { _Client };
                _Client.BeginSignOut(SignOutCallback, _asyncState);
                MessageBox.Show("BeginSignOut method");
            }
        }
        public Client()
        {
            _signInAddress              = string.Empty;
            _username                   = string.Empty;
            _password                   = string.Empty;
            _retries                    = 0;
            _timeoutOccured             = false;
            _badSignInAddressIdentified = false;

            _signInProcedureEvent       = new AutoResetEvent(false);
            _signOutProcedureEvent      = new AutoResetEvent(false);
            _signShutdownProcedureEvent = new AutoResetEvent(false);

            try
            {
                _lock.WaitOne();
                GetValidLyncClient();

                if (IsClientValid)
                {
                    _lyncClient.StateChanged        += _LyncClient_StateChanged;
                    _lyncClient.SignInDelayed       += _LyncClient_SignInDelayed;
                    _lyncClient.CredentialRequested += _LyncClient_CredentialRequested;
                }
                else
                {
                    _lyncClient = null;
                    _lyncApInitializationFailed       = true;
                    _lyncApInitializationErrorMessage = "Client in invalid state";
                }
            }
            catch (ClientNotFoundException ex)
            {
                _lyncClient = null;
                _lyncApInitializationFailed       = true;
                _lyncApInitializationErrorMessage = $"Client not found: {ex.Message}";
            }
            catch (NotStartedByUserException ex)
            {
                _lyncClient = null;
                _lyncApInitializationFailed       = true;
                _lyncApInitializationErrorMessage = $"Client not started by user: {ex.Message}";
            }
            catch (Exception ex)
            {
                _lyncClient = null;
                _lyncApInitializationFailed       = true;
                _lyncApInitializationErrorMessage = $"Exception occured during lync sdk initialization: {ex.Message}";
            }
        }
        public ShowDashboard()
        {
            InitializeComponent();

            try
            {
                lyncClient = LyncClient.GetClient();
                contactMgr = lyncClient.ContactManager;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #33
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                LyncClient       = LyncClient.GetClient();
                ContactManager   = LyncClient.ContactManager;
                this.DataContext = this;

                //Load custom group combo box and associated contact list from
                //LyncClient.ContactManager.Groups property
                UpdateGroupList();
            }
            catch (Exception) {}
        }
Example #34
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         lyncClient = LyncClient.GetClient();
         Log("got client");
         UpdateUI();
         lyncClient.StateChanged += new EventHandler <ClientStateChangedEventArgs>(lyncClient_StateChanged);
     }
     catch (Exception ex)
     {
         Log("Error in getting Lync client object: " + ex.Message);
     }
 }
Example #35
0
        public AgentDashboardChannel(string guid)
        {
            Conversation = LyncClient.GetHostingConversation() as Conversation;

            ApplicationId     = guid;
            _requestProcessor = new RequestProcessor(null);

            Initialize();

            if (Conversation != null)
            {
                Conversation.ContextDataReceived += ConversationContextDataReceived;
            }
        }
Example #36
0
        static void Main(string[] args)
        {
            //Listen for events of changes in the state of the client
            try
            {
                lyncClient    = LyncClient.GetClient();
                arduinoSerial = new ArduinoSerial {
                    RunLoop = true
                };
                arduinoSerial.Setup();
            }
            catch (ClientNotFoundException clientNotFoundException)
            {
                Console.WriteLine(clientNotFoundException);
                return;
            }
            catch (NotStartedByUserException notStartedByUserException)
            {
                Console.Out.WriteLine(notStartedByUserException);
                return;
            }
            catch (LyncClientException lyncClientException)
            {
                Console.Out.WriteLine(lyncClientException);
                return;
            }
            catch (SystemException systemException)
            {
                if (IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                    return;
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }

            lyncClient.StateChanged +=
                new EventHandler <ClientStateChangedEventArgs>(Client_StateChanged);

            lyncClient.Self.Contact.ContactInformationChanged +=
                new EventHandler <ContactInformationChangedEventArgs>(SelfContact_ContactInformationChanged);

            SetAvailability();
            Console.ReadKey();
        }
Example #37
0
 private bool checkSkype()
 {
     if (lyncClient == null)
     {
         try
         {
             lyncClient      = LyncClient.GetClient();
             callbackEnabled = false;
         }
         catch (ClientNotFoundException clientNotFoundException)
         {
             Console.WriteLine(clientNotFoundException);
             return(false);
         }
         catch (NotStartedByUserException notStartedByUserException)
         {
             Console.Out.WriteLine(notStartedByUserException);
             return(false);
         }
         catch (LyncClientException lyncClientException)
         {
             Console.Out.WriteLine(lyncClientException);
             return(false);
         }
         catch (SystemException systemException)
         {
             if (IsLyncException(systemException))
             {
                 // Log the exception thrown by the Lync Model API.
                 Console.WriteLine("Error: " + systemException);
                 return(false);
             }
             else
             {
                 // Rethrow the SystemException which did not come from the Lync Model API.
                 throw;
             }
         }
     }
     if (!callbackEnabled)
     {
         if ((lyncClient.Self != null) && (lyncClient.Self.Contact != null))
         {
             lyncClient.Self.Contact.ContactInformationChanged += Contact_ContactInformationChanged;
             callbackEnabled = true;
         }
     }
     return(checkAvailability());
 }
Example #38
0
        /// <summary>
        /// Handler for the Loaded event of the Window.
        /// Used to initialize the values shown in the user interface (e.g. availability values), get the Lync client instance
        /// and start listening for events of changes in the client state.
        /// </summary>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Add the availability values to the ComboBox
            availabilityComboBox.Items.Add(ContactAvailability.Free);
            availabilityComboBox.Items.Add(ContactAvailability.Busy);
            availabilityComboBox.Items.Add(ContactAvailability.DoNotDisturb);
            availabilityComboBox.Items.Add(ContactAvailability.Away);

            //Listen for events of changes in the state of the client
            try
            {
                lyncClient = LyncClient.GetClient();
            }
            catch (ClientNotFoundException clientNotFoundException)
            {
                Console.WriteLine(clientNotFoundException);
                return;
            }
            catch (NotStartedByUserException notStartedByUserException)
            {
                Console.Out.WriteLine(notStartedByUserException);
                return;
            }
            catch (LyncClientException lyncClientException)
            {
                Console.Out.WriteLine(lyncClientException);
                return;
            }
            catch (SystemException systemException)
            {
                if (IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                    return;
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }

            lyncClient.StateChanged +=
                new EventHandler <ClientStateChangedEventArgs>(Client_StateChanged);

            //Update the user interface
            UpdateUserInterface(lyncClient.State);
        }
Example #39
0
 public void undoLyncSubscription()
 {
     try
     {
         _contactSubscription = LyncClient.GetClient().ContactManager.CreateSubscription();
         lync     = LyncClient.GetClient();
         _contact = lync.ContactManager.GetContactByUri(lync.Uri);
         _ContactInformationList.Add(ContactInformationType.Availability);
         _contactSubscription.AddContact(_contact);
         _contactSubscription.Unsubscribe();
     }
     catch
     {
     }
 }
        public ConversationWindow(Conversation conversation, LyncClient client, ContactInfo contact, ConversationType conversationType)
        {
            InitializeComponent();

            //this.ApplyThemes();

            this.client = client;
            this.conversation = conversation;
            this.Contact = contact;
            this.conversationType = conversationType;

            this.Title = contact.DisplayName;

            InitializeConversation();
        }
Example #41
0
        static void Main(string[] args)
        {
            //Listen for events of changes in the state of the client
            try
            {
                lyncClient = LyncClient.GetClient();
                arduinoSerial = new ArduinoSerial { RunLoop = true };
                arduinoSerial.Setup();
            }
            catch (ClientNotFoundException clientNotFoundException)
            {
                Console.WriteLine(clientNotFoundException);
                return;
            }
            catch (NotStartedByUserException notStartedByUserException)
            {
                Console.Out.WriteLine(notStartedByUserException);
                return;
            }
            catch (LyncClientException lyncClientException)
            {
                Console.Out.WriteLine(lyncClientException);
                return;
            }
            catch (SystemException systemException)
            {
                if (IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Console.WriteLine("Error: " + systemException);
                    return;
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }

            lyncClient.StateChanged +=
                new EventHandler<ClientStateChangedEventArgs>(Client_StateChanged);

            lyncClient.Self.Contact.ContactInformationChanged +=
                   new EventHandler<ContactInformationChangedEventArgs>(SelfContact_ContactInformationChanged);

            SetAvailability();
            Console.ReadKey();
        }
        public LyncAnimator(Func<bool> shouldCancel, Action<string> reportNewStatus)
        {
            _client = LyncClient.GetClient();
            _shouldCancel = shouldCancel;
            _reportNewStatus = reportNewStatus;

            _normalAnimations = new[]
            {
                Wave(),
                BoomBox(),
                Fish(),
                Singing(),
                PingPong(),
            };

            _happyFridayAnimation = ScrollTextRightToLeft("Happy Friday!", 25);
        }
Example #43
0
        public LyncBot()
        {
            this._client = LyncClient.GetClient();
            if (this._client == null)
                throw new ArgumentNullException("_client", "Unable to retrieve client");

            this._client.CredentialRequested += _client_CredentialRequested;
            this._client.StateChanged += _client_StateChanged;

            this._conversationService = new ConversationService(this._client.ConversationManager);

            if (this._client.InSuppressedMode)
            {
                if (this._client.State == ClientState.Uninitialized)
                    this.Initialize();
            }
        }
Example #44
0
        public bool StartObserving()
        {
            if (!Alive()) {
                _lyncClient = LyncClient.GetClient();

                if (!Alive())
                    return false;
            }

            if (!_isActive) {
                _lyncClient.ConversationManager.ConversationAdded += ConversationStarted;
                _lyncClient.ConversationManager.ConversationRemoved += ConversationEnded;
                _lyncClient.ClientDisconnected += ClientDisconnected;
                _isActive = true;
            }
            return true;
        }
Example #45
0
        public static void LyncChat(List<BotRule> rules)
        {
            client = LyncClient.GetClient();

            client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;

            client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;

            while (_conversation == null)
            {
                Thread.Sleep(1000);
            }

            ChatBot cb = new ChatBot(rules);
            cb.talkWith(_LyncConversation);
            Console.ReadKey();
        }
Example #46
0
 private void autoReply_Click(object sender, RoutedEventArgs e)
 {
     _LyncClient = LyncClient.GetClient();
     if (_LyncClient.State == ClientState.SignedIn)
     {
         string buttonContent=autoReply.Content.ToString();
         if (buttonContent.Equals("Start Auto Reply"))
         {
             StartAutoReply();
             autoReply.Content = "Stop Auto Reply";
         }
         else
         {
             StopAutoReply();
             autoReply.Content = "Start Auto Reply";
         }
     }
 }
Example #47
0
        public LyncManager(string email, string message)
        {
            _uri = email;
            _message = message;
            _client = Microsoft.Lync.Model.LyncClient.GetClient();

            _client.ContactManager.BeginSearch(_uri, BeginSearchCallback, new object[] { _client.ContactManager, _uri });

            //_client.ContactManager.BeginSearch(
            //    _uri,
            //    SearchProviders.GlobalAddressList,
            //    SearchFields.EmailAddresses,
            //    SearchOptions.ContactsOnly,
            //    2,
            //    BeginSearchCallback,
            //    new object[] { _client.ContactManager, _uri }
            //);
        }
        public async void Connect()
        {
            int connectRetriesRemaining = CONNECT_RETRY_MAX;
            bool insist = (connectRetriesRemaining < 0);
            bool wait = false;

            _client = null;

            while (_client == null &&
                   (insist || connectRetriesRemaining-- > 0))
            {
                if (wait)
                {
                    Log.Debug(String.Format("Waiting {0}ms before next connection attempt...",
                                            CONNECT_RETRY_WAIT_TIME_MS));
                    await Task.Delay(CONNECT_RETRY_WAIT_TIME_MS);
                }

                try
                {
                    Log.Info(String.Format("Establishing connection to Lync ({0} attempts remain)...",
                                           (insist ? "infinite" : connectRetriesRemaining.ToString())));
                    _client = LyncClient.GetClient();
                }
                catch (LyncClientException)
                {
                    Log.Error("Connection attempt failed...");
                }
                catch (Exception)
                {
                    Log.WriteLine(Severity.Calamity, ("error: Connection attempt failed catastrophically..."));
                }

                wait = true;
            }


            _client.ConversationManager.ConversationAdded += OnConversationAdded;
            _client.ConversationManager.ConversationRemoved += OnConversationRemoved;
            Log.Info("Intialization complete.");

            _keepAliveTimer.Enabled = true;
        }
        private CommunicationManager()
        {
            var unused = UiThreadControl.Handle;

            while (this._LyncClient == null)
            {
                try
                {
                    //obtains the lync client instance
                    this._LyncClient = LyncClient.GetClient();
                }
                //if the Lync process is not running and UISuppressionMode=false, this exception will be thrown
                catch (ClientNotFoundException)
                {
                    //explain to the user what happened
                    if (MessageBox.Show("Microsoft Lync does not appear to be running. Please start Skype For Business.", "Skype for Business not found", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
                    {
                        continue;
                    }
                    throw;
                }
                catch (NotStartedByUserException)
                {
                    //explain to the user what happened
                    if (MessageBox.Show("Microsoft Lync does not appear to be running. Please start Skype For Business.", "Skype for Business not found", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
                    {
                        continue;
                    }
                    throw;
                }

                if (this._LyncClient == null)
                {
                    Application.Exit();
                }

            }

            this.InitializeClient();
        }
        public MainPage()
        {
            InitializeComponent();
            _viewModel = App.MainViewModel;

            try
            {
                _translationService = new TranslationService();
                _conversationService = new ConversationService();

                // Get the instance of LyncClient and subscribe to outgoing/incoming conversation events
                _lyncClient = LyncClient.GetClient();
                _lyncClient.StateChanged += new EventHandler<ClientStateChangedEventArgs>(LyncClient_StateChanged);

                _conversation = (Conversation)Microsoft.Lync.Model.LyncClient.GetHostingConversation();

                // Perform run-time registration using the ApplicationRegistration class.
                _myApplicationRegistration = _lyncClient.CreateApplicationRegistration(App.AppId, App.AppName);
                this._myApplicationRegistration.AddRegistration();
            }
            catch (ClientNotFoundException) { Console.WriteLine("Lync client was not found on startup"); }
            catch (LyncClientException lce) { MessageBox.Show("Lyncclientexception: " + lce.Message); }
        }
 public UserSignIn(LyncClient lyncClient)
 {
     _LyncClient = lyncClient;
 }
Example #52
0
 private void ReleaseLyncClient()
 {
     _lyncClient = null;
       GC.Collect();
 }
Example #53
0
        private void HousekeepingTimer_Tick(object sender, EventArgs e)
        {
            _housekeepingTimer.Enabled = false;

              _buddies.RefreshList();

              if (_lyncClient != null && _lyncClient.State == ClientState.Invalid)
              {
            Trace.WriteLine("LyncFellow: _lyncClient != null && _lyncClient.State == ClientState.Invalid");
            ReleaseLyncClient();
              }
              if (_lyncClient == null)
              {
            try
            {
              _lyncClient = LyncClient.GetClient();
            }
            catch { }
            if (_lyncClient != null)
            {
              if (_lyncClient.State != ClientState.Invalid)
              {
            _lyncClient.StateChanged += new EventHandler<ClientStateChangedEventArgs>(LyncClient_StateChanged);
            _lyncClient.ConversationManager.ConversationAdded += new EventHandler<ConversationManagerEventArgs>(ConversationManager_ConversationAdded);
            HandleSelfContactEventConnection(_lyncClient.State);
              }
              else
              {
            ReleaseLyncClient();
              }
            }
              }
              if (_lyncClient != null && DateTime.Now.Subtract(_lyncEventsUpdated).TotalMinutes > 60)
              {
            Trace.WriteLine("LyncFellow: _lyncClient != null && DateTime.Now.Subtract(_lyncEventsUpdated).TotalMinutes > 60");
            HandleSelfContactEventConnection(_lyncClient.State);
              }

              UpdateBuddiesColor();

              bool deviceNotFunctioning = _buddies.LastWin32Error == 0x1f;    //ERROR_GEN_FAILURE
              bool lyncValid = IsLyncConnectionValid();
              if (_buddies.Count > 0 && !deviceNotFunctioning && lyncValid)
              {
            _notifyIcon.Text = Application.ProductName;
            _notifyIcon.Icon = Properties.Resources.LyncFellow;
              }
              else
              {
            _notifyIcon.Text = Application.ProductName;
            _notifyIcon.Icon = Properties.Resources.LyncFellowInfo;
            if (_buddies.Count == 0)
            {
              _notifyIcon.Text += "\r* No USB buddy found.";
            }
            else if (deviceNotFunctioning)
            {
              _notifyIcon.Text += "\r* Please reconnect USB buddy.";
            }
            if (!lyncValid)
            {
              _notifyIcon.Text += "\r* No Lync connection.";
            }
              }

              _housekeepingTimer.Enabled = true;
        }
        public void Initialize()
        {
            try
            {
                this.client = LyncClient.GetClient();

                client.StateChanged += this.Client_StateChanged;
                client.ClientDisconnected += this.Client_ClientDisconnected;

                //if this client is in UISuppressionMode and not yet initialized
                if (client.InSuppressedMode && client.State == ClientState.Uninitialized)
                {
                    // initialize the client
                    try
                    {
                        client.BeginInitialize(this.ClientInitialized, null);
                    }
                    catch (LyncClientException lyncClientException)
                    {
                        Console.WriteLine("LyncService: " + lyncClientException.Message);
                    }
                    catch (SystemException systemException)
                    {
                        if (LyncModelExceptionHelper.IsLyncException(systemException))
                        {
                            Console.WriteLine("LyncService: " + systemException.Message);
                        }
                        else
                        {
                            // Rethrow the SystemException which did not come from the Lync Model API.
                            throw;
                        }
                    }
                }
                else //not in UI Suppression, so the client was already initialized
                {
                    if (this.client.InSuppressedMode == true && this.client.State != ClientState.SignedIn)
                    {
                        this.SingIn();
                    }

                    //registers for conversation related events
                    //these events will occur when new conversations are created (incoming/outgoing) and removed
                    client.ConversationManager.ConversationAdded += this.ConversationManagerConversationAdded;
                    client.ConversationManager.ConversationRemoved += this.ConversationManagerConversationRemoved;
                }

            }
            catch (Exception ex)
            {
                //if the Lync process is not running and UISuppressionMode=false these exception will be thrown
                if (ex is ClientNotFoundException || ex is NotStartedByUserException)
                {
                    Console.WriteLine("LyncService: " + ex.Message);
                    MessageBox.Show("Microsoft Lync does not appear to be running. Please start Lync.");

                    return;
                }

                throw;
            }
        }
        public static void Initialize()
        {
            try
            {
                _client = LyncClient.GetClient();
                LyncContactManager = _client.ContactManager;
            }
            catch (ClientNotFoundException clne)
            {
                throw new Exception("Ensure Lync client is installed and is configured to run in Full UI suppression mode", clne);
            }

            if (!_client.InSuppressedMode)
                throw new ApplicationException("Ensure Lync client is configured to run in Full UI suppression mode");

            if (_client.State != ClientState.Uninitialized)
                throw new ApplicationException(string.Format("Client is in state '{0}', expected '{1}'", _client.State, ClientState.Uninitialized));

            _client.EndInitialize(_client.BeginInitialize(null, null));

            _client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
            _client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
        }
 public IncomingCallViewModel()
 {
     _lync = LyncClient.GetClient();
     _lync.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
 }
Example #57
0
 private void ClientDisconnected(object sender, EventArgs e)
 {
     _lyncClient = null;
     _isActive = false;
 }
        private void ConnectToLync()
        {
            try
            {
                lync = LyncClient.GetClient();
                lync.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                lync.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;

                if (LyncLightToggle.IsChecked.Value)
                {
                    ConnectToLight();
                }

                timer1.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
                timer1.Interval = 500;
                timer1.Enabled = true;
                timer1.Start();

                _connectedToLync = true;
                ErrorMessage.Text = "";
                LyncLightToggle.IsEnabled = true;
                ni.ShowBalloonTip(1000, "Lync Presence Indicator", "Connected To Lync", ToolTipIcon.Info);
                errorShown = false;
            }
            catch (Exception ex)
            {
                ErrorMessage.Text = ex.Message;
                _connectedToLync = false;
                timer1.Stop();
                if (!errorShown)
                {
                    ni.ShowBalloonTip(500, "Lync Presence Indicator", "Error - " + ex.Message, ToolTipIcon.Error);
                    errorShown = true;
                }
                DisconnectFromLight();
                LyncConnectRetryTimer.Start();
            }

        }
 /// <summary>
 /// 获取lync客户端
 /// </summary>
 void GetLyncClient()
 {
     while (_Client == null)
     {
         Thread.Sleep(iThreadSleepTime);
         try
         {
             _Client = LyncClient.GetClient();
             LyncContactManager = LyncClient.GetClient().ContactManager;
             LyncContactGroups = LyncClient.GetClient().ContactManager.Groups;                  
             _Client.StateChanged += new EventHandler<ClientStateChangedEventArgs>(LyncClientStateChanged);
             if (_Client.State == ClientState.SignedIn)//增加状态改变处理函数之前已经登录成功
             {
                 Thread.Sleep(iThreadSleepTime * 100);//等待1000毫秒,让lync状态改变时间触发
             }
         }
         catch
         {
             LogManager.SystemLog.Warn("LyncClient process is not running");
         }
     }
 }
Example #60
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lync = LyncClient.GetAutomation();
            client = LyncClient.GetClient();
            ConversationManager mgr = client.ConversationManager;
            mgr.ConversationAdded += (s, evt) =>
            {
                meetNowConvo = evt.Conversation;
                meetNowConvo.PropertyChanged += (s3, e3) =>
                {
                    Debug.Print("> Conversation.PropertyChanged : Property:{0}, Value:{1}", e3.Property, e3.Value);
                    if (e3.Property == ConversationProperty.NumberOfParticipantsRecording && e3.Value.Equals(0))
                    {
                        if(ConversationEnded != null)
                        {
                            ConversationEnded(s3, e3);
                        }
                    }
                };
                ConversationWindow win = lync.GetConversationWindow(meetNowConvo);

                Modality m = meetNowConvo.Modalities[ModalityTypes.AudioVideo];
                            
                AVModality avm = (AVModality)m;

                avm.ModalityStateChanged += (s2, e2) =>
                {
                    Debug.Print("> AVModality.ModalityStateChanged : {0}", e2.NewState);
                    if (e2.NewState == ModalityState.Connected)
                    {
                        Debug.Print("** AV Connected**");
                        ApplicationSharingModality m1 = (ApplicationSharingModality)meetNowConvo.Modalities[ModalityTypes.ApplicationSharing];
                        m1.ModalityStateChanged += (s5, e5) =>
                        {
                            Debug.Print("> ApplicationSharingModality.ModalityChanged : {0}", e5.NewState);

                            if (e5.NewState == ModalityState.Connected)
                            {
                                Debug.Print("** Sharing Ok **");                                

                                Windowing.SetForegroundWindow(win.Handle);
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait("{TAB}");
                                SendKeys.SendWait(" ");
                                SendKeys.SendWait("r");

                                Windowing.ShowWindow(win.Handle, (int)Windowing.ShowCommands.SW_SHOWMINNOACTIVE);
                            }
                        };
                        
                        m1.BeginShareDesktop(GetNullAsyncCallback("ApplicationSharingModality.BeginShareDesktop"), null);
                        
                    }
                };

                avm.BeginConnect(GetNullAsyncCallback("AVModality.BeginConnect"), null);

            };
            
        }