/// <summary>
        /// Try connect to the current lync instance
        /// </summary>
        private void ConnectToLync()
        {
            // Connect to Lync
            try
            {
                _lyncClient = LyncClient.GetClient();

                if (this.IsSignedIn)
                {
                    ConnnectedAction?.Invoke();
                    LastKnownStatus = ConnectionStatus.Connected;
                }

                // And when we ever disconnect, try to establish again
                _lyncClient.StateChanged -= ClientStateChangedEvent;
                _lyncClient.StateChanged += ClientStateChangedEvent;

                // Default binds
                // When a new convo starts
                _lyncClient.ConversationManager.ConversationAdded -= ConversationAddedHandler;
                _lyncClient.ConversationManager.ConversationAdded += ConversationAddedHandler;
            }
            catch (ClientNotFoundException ex)
            {
                if (LastKnownStatus == ConnectionStatus.Connected)
                {
                    DisconnectedAction?.Invoke();
                }
                else
                {
                    LastKnownStatus = ConnectionStatus.Disconnected;
                }
            }
        }
Example #2
0
	    static void Main(string[] args)
        {
                // Let's hide the console window first ...
                IntPtr hwnd;
                hwnd = GetConsoleWindow();
                ShowWindow(hwnd, SW_HIDE);
                // I recommend you start a separate thread from here, I removed it for the sake of simplicity
                Boolean clientConnected = false;
                while (!clientConnected)
                {
	               try
	               {
 	                  LyncClient lyncClient = LyncClient.GetClient();
 	                  clientConnected = true;
			// Do your stuff here...
	               }
	               catch (ClientNotFoundException ex)
            	   {
                	  // Client not found : the client is probably not running...
                	  // There is nothing to do besides wait and expect to have the user starting his client...
                	  clientConnected = false; // not needed, just to highlight the fact that we are not connected yet
            	   }
            	// Don't forget to make your application sleep/do nothing on regular intervals to avoid taking 100% CPU time while you are polling
		       }
	}
Example #3
0
        public Configuracion()
        {
            InitializeComponent();

            try
            {
                //Obtener instancias de Lync Client y Contact Manager.
                lyncClient = LyncClient.GetClient();
                automation = LyncClient.GetAutomation();
                contactMgr = lyncClient.ContactManager;

                activeSearchProviders    = new List <SearchProviders>();
                searchResultSubscription = contactMgr.CreateSubscription();

                // Carga Proveedor de búsqueda experto si está configurado y habilita la casilla de verificación.
                if (contactMgr.GetSearchProviderStatus(SearchProviders.Expert)
                    == SearchProviderStatusType.SyncSucceeded || contactMgr.GetSearchProviderStatus(SearchProviders.Expert)
                    == SearchProviderStatusType.SyncSucceededForExternalOnly || contactMgr.GetSearchProviderStatus(SearchProviders.Expert)
                    == SearchProviderStatusType.SyncSucceededForInternalOnly)
                {
                    activeSearchProviders.Add(SearchProviders.Expert);
                }

                // Registrarse para el evento SearchProviderStatusChanged
                // by ContactManager.
                //contactMgr.SearchProviderStateChanged += contactMgr_SearchProviderStateChanged;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:    " + ex.Message);
            }
        }
Example #4
0
        /// <summary>
        /// Prevents a default instance of the <see cref="CallHandler"/> class from being created.
        /// </summary>
        private CallHandler()
        {
            this.lyncClient = LyncClient.GetClient();

            // FOR CWE WINDOW,use current hosting conversation
            this.conversation = (Conversation)Microsoft.Lync.Model.LyncClient.GetHostingConversation();
            if (this.conversation == null)
            {
                this.conversation = this.lyncClient.ConversationManager.Conversations[this.lyncClient.ConversationManager.Conversations.Count - 1];
            }

            this.audioVideoModality = (AVModality)this.conversation.Modalities[ModalityTypes.AudioVideo];
            this.audioChannel       = this.audioVideoModality.AudioChannel;

            this.conversation.StateChanged += this.Conversation_StateChangedEvent;
            this.conversation.BeginSendContextData("{553C1CE2-0C73-51B6-81C7-75F2D071FCD2}", @"plain/text", "hi", SendContextDataCallBack, null);

            this.audioVideoModality.ModalityStateChanged += new EventHandler <ModalityStateChangedEventArgs>(this.AudioVideoModality_ModalityStateChanged);

            this.instantMessageModality = (InstantMessageModality)this.conversation.Modalities[ModalityTypes.InstantMessage];

            this.remoteModality = this.conversation.Participants[1].Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;

            this.remoteModality.InstantMessageReceived += new EventHandler <MessageSentEventArgs>(this.RemoteModality_InstantMessageReceived);

            this.instantMessageModality.InstantMessageReceived += new EventHandler <MessageSentEventArgs>(this.ImModality_InstantMessageReceived);

            this.CurrentMenuLevel = 0;
        }
Example #5
0
        public void SendIM()
        {
            Console.WriteLine("exiting");

            //Get a Lync client automation object.
            LyncClient client     = LyncClient.GetClient();
            Automation automation = LyncClient.GetAutomation();

            //Add two URIs to the list of IM addresses.
            System.Collections.Generic.List <string> inviteeList = new System.Collections.Generic.List <string>();
            inviteeList.Add(ConfigurationManager.AppSettings["UserURI"]);
            //inviteeList.Add(ConfigurationManager.AppSettings["CallingUserURI"]);
            inviteeList.Add(ConfigurationManager.AppSettings["UserURI2"]);

            //Specify IM settings.
            System.Collections.Generic.Dictionary <AutomationModalitySettings, object> mSettings = new System.Collections.Generic.Dictionary <AutomationModalitySettings, object>();
            string messageText = ImMessageText();

            mSettings.Add(AutomationModalitySettings.FirstInstantMessage, messageText);
            mSettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);

            //Broadcast the IM messages.
            IAsyncResult ar = automation.BeginStartConversation(AutomationModalities.InstantMessage, inviteeList, mSettings, null, null);

            cWindow = automation.EndStartConversation(ar);
            AutoResetEvent completedEvent = new AutoResetEvent(false);

            completedEvent.WaitOne();
        }
Example #6
0
        public static LyncClient GetLyncClient()
        {
            // start Lync client if not already running
            if (GetLyncProcess() == null)
            {
                Process.Start("Lync");
            }

            DebugLog.Write("Connecting to Lync client...");

            LyncClient client      = null;
            bool       isConnected = false;

            // wait for lync client to initialize and sign in
            while (!isConnected)
            {
                try
                {
                    client = LyncClient.GetClient();
                }
                catch (ClientNotFoundException) { }

                if (client == null || client.State != ClientState.SignedIn)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    isConnected = true;
                }
            }

            return(client);
        }
 public UserControl1()
 {
     InitializeComponent();
     client                 = LyncClient.GetClient();
     contactManager         = client.ContactManager;
     listBox1.SelectionMode = SelectionMode.Multiple;
 }
Example #8
0
 static void CheckLyncClient()
 {
     try
     {
         Logger.Log("LyncClientThread Started.");
         do
         {
             lock (__lyncClientLock)
             {
                 if (_lyncClient == null)
                 {
                     try
                     {
                         _lyncClient = LyncClient.GetClient();
                         _lyncClient.StateChanged += new EventHandler <ClientStateChangedEventArgs>(SkypeClientStateChenged);
                         _lyncClient.Self.Contact.ContactInformationChanged += new EventHandler <ContactInformationChangedEventArgs>(SkypeSelfStateChenged);
                         UpdateSkypeAvilability();
                     }
                     catch { _lyncClient = null; }
                 }
             }
             Thread.Sleep(3000);
         } while (!_finish);
     }
     catch (Exception Ex)
     {
         Logger.Log(Ex.Message, Logger.LEVEL.ERROR);
     }
 }
 internal IncomingCallMonitor()
 {
     // Get a reference to the running Lync client, register for the ConversationAdded event.
     // Note: This assumes that the Lync client is running
     _lyncClient = LyncClient.GetClient();
     _lyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
 }
Example #10
0
 /// <summary>
 /// Loads the user's followed chat rooms into a UI listbox.
 /// </summary>
 private void LoadRoomList()
 {
     foreach (Room room in LyncClient.GetClient().RoomManager.FollowedRooms)
     {
         RoomList_ListBox.Items.Add(new RoomWrapper(room));
     }
 }
Example #11
0
        public void StatusSetup()
        {
            while (_lyncClient == null)
            {
                try
                {
                    _lyncClient = LyncClient.GetClient();
                }
                catch (Exception)
                {
                    MessageBox.Show("Cannot find a Lync client - Quitting", "Lync Client Process Not found", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //Quit - We cant do anything.
                    Environment.Exit(1);
                }

                if (_lyncClient != null && _lyncClient.State == ClientState.SignedIn)
                {
                    //Subscribe to Conversation Added events for Incoming call alerts:
                    _lyncClient.ConversationManager.ConversationAdded += ConversationAdded;

                    //Subscribe to Contact Information Changed events for client status changes.
                    _lyncClient.Self.Contact.ContactInformationChanged += ContactChangeStatusUpdate;
                }
            }
        }
Example #12
0
        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;
        }
Example #13
0
        /// <summary>
        /// Main form load event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetParticipants_Load(object sender, EventArgs e)
        {
            try
            {
                //Get the lync client platform, the entry point for all group chat room related code.
                _client = LyncClient.GetClient();

                if (_client.RoomManager.State == RoomManagerState.Disabled)
                {
                    MessageBox.Show("Persistent Chat Server is not reachable. Quitting");
                }

                //Register for sign in/sign out events on the client
                _client.StateChanged += new EventHandler <ClientStateChangedEventArgs>(client_StateChanged);

                //If the client is signed in then load the followed room list
                if (_client.State == ClientState.SignedIn)
                {
                    //Set the numeric updown control maximum property to the number of
                    //followed rooms in the followed room collection on the room manager.
                    FollowedRoom_Numeric.Maximum = _client.RoomManager.FollowedRooms.Count;
                    FollowedRoom_Numeric.Minimum = 1;
                }

                //Set the lync client state label to show the current state of the client
                RefreshClientStateLabel();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #14
0
        void OnTimer(object sender, EventArgs e)
        {
            if (_client == null)
            {
                try
                {
                    _client = LyncClient.GetClient();
                    _client.ClientDisconnected += OnClientDisconnected;
                    _client.StateChanged       += OnClientStateChanged;

                    if (_client.State == ClientState.SignedIn)
                    {
                        SubscribeToLyncEvents();
                    }
                }
                catch (Exception)
                {
                    // we could not subscribe to the lync client and will retry later
                    ShowText("Waiting for Lync");
                }
            }
            else if (_client.State == ClientState.Invalid)
            {
                Cleanup();
                ShowText("Lync exited");
            }
        }
Example #15
0
 public void Initialize()
 {
     try
     {
         _lyncClient = LyncClient.GetClient();
         _lyncClient.StateChanged += StateChanged;
         if (_lyncClient.State == ClientState.SignedOut)
         {
             _lyncClient.BeginSignIn(
                 null,
                 null,
                 null,
                 (ar) =>
             {
                 _lyncClient.EndSignIn(ar);
             }
                 ,
                 null);
         }
         else if (_lyncClient.State == ClientState.SignedIn)
         {
             _conversationManager = _lyncClient.ConversationManager;
             _conversationManager.ConversationAdded += ConversationAdded;
         }
     }
     catch (NotStartedByUserException)
     {
         throw new Exception("Lync is not running");
     }
 }
Example #16
0
        /// <summary>
        /// Handles the event raised when a user signs in to or out of the Lync client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _LyncClient_StateChanged(object sender, ClientStateChangedEventArgs e)
        {
            try
            {
                lync = LyncClient.GetClient();
            }
            catch {
                Thread.Sleep(sleepInterval);
                notifyIcon.Visible = false;
                notifyIcon.Icon    = null;

                Application.Restart();
            }
            //Wait for Lync to sign in
            while (lync.State != ClientState.SignedIn)
            {
                setLED(ERROR);
                Thread.Sleep(sleepInterval);
                try
                {
                    lync = LyncClient.GetClient();
                }
                catch {
                }
            }

            initLyncSubscription();
            ShowMessage(null, null);
        }
 internal AvailabilityMonitor()
 {
     // Get a reference to the running Lync client, register for the ConversationAdded event.
     // Note: This assumes that the Lync client is running
     _lyncClient = LyncClient.GetClient();
     _lyncClient.Self.Contact.ContactInformationChanged += Contact_ContactInformationChanged;
 }
Example #18
0
        /// <summary>
        /// Form constructor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RoomQuery_Load(object sender, EventArgs e)
        {
            try
            {
                //Get the API entry point
                _client = LyncClient.GetClient();

                //Register for the state changed event on the lync client platform.
                _client.StateChanged       += new EventHandler <ClientStateChangedEventArgs>(client_StateChanged);
                _client.ClientDisconnected += new EventHandler(client_ClientDisconnected);

                //Set the enable state of the query start button based on the state of the RoomManager.
                EnableDisableStartQueryButton();

                //Register for room manager state event. If room manager is disabled, disable the "Go" button on the UI so that
                //a user does not attempt to query the room manager for a room.
                if (_client.RoomManager.State == RoomManagerState.Disabled)
                {
                    MessageBox.Show("Persistent Chat Server is not reachable. Quitting");
                }
                _client.RoomManager.RoomManagerStateChanged += roomManager_RoomManagerStateChanged;

                //Display the current sign in state of the Lync client.
                RefreshClientStateLabel();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #19
0
        public const int C = 0x43;                       //A Control key code

        public VM()
        {
            //get a handler to the Lync Client, then subscribe to state changes.
            _client = LyncClient.GetClient();
            _client.StateChanged += _client_StateChanged;
            SubscribetoPresenceIfSignedIn(_client.State);
        }
Example #20
0
        static void SubscribeToEvents()
        {
            try
            {
                var client = LyncClient.GetClient();

                Console.WriteLine("Attaching client events");

                client.ConversationManager.ConversationAdded +=
                    PrintEvent <ConversationManagerEventArgs>("Conversation added");

                client.ConversationManager.ConversationRemoved +=
                    PrintEvent <ConversationManagerEventArgs>("Conversation removed");

                client.ConversationManager.ConversationAdded += (o, e) =>
                {
                    var av = (AVModality)e.Conversation.Modalities[ModalityTypes.AudioVideo];

                    av.ModalityStateChanged += (sender, args) =>
                    {
                        Console.WriteLine("AV modality " + args.OldState + " --> " + args.NewState);
                    };
                };

                client.StateChanged += (o, e) =>
                {
                    Console.WriteLine("Client state " + e.OldState + " --> " + e.NewState);
                };
            }
            catch (ClientNotFoundException)
            {
                Console.WriteLine("Could not connect to Lync - waiting process start.");
            }
        }
 public MainWindow()
 {
     InitializeComponent();
     try
     {
         //Start the conversation
         automation = LyncClient.GetAutomation();
         client     = LyncClient.GetClient();
     }
     catch (LyncClientException lyncClientException)
     {
         MessageBox.Show("Failed to connect to Lync.");
         Console.Out.WriteLine(lyncClientException);
     }
     catch (SystemException systemException)
     {
         if (IsLyncException(systemException))
         {
             // Log the exception thrown by the Lync Model API.
             MessageBox.Show("Failed to connect to Lync.");
             Console.WriteLine("Error: " + systemException);
         }
         else
         {
             // Rethrow the SystemException which did not come from the Lync Model API.
             throw;
         }
     }
 }
Example #22
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)
                {
                    // 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(5000);
                }
            }

            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 #23
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // get Lync client
            try
            {
                lyncClient = LyncClient.GetClient();
            }
            catch (ClientNotFoundException ex)
            {
                // Lync is not started.
                Log(ex.ToString());
                return;
            }
            catch (NotSignedInException ex)
            {
                // Lync app is running but no signed in.
                Log(ex.ToString());
                return;
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
                return;
            }

            // get the device manager class.
            deviceManager = lyncClient.DeviceManager;
            RefreshUI();
        }
Example #24
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // get the Lync client.
            try
            {
                _lyncClient = LyncClient.GetClient();
            }
            catch (ClientNotFoundException exception)
            {
                // Lync application should be running.
                Log(exception.ToString());
                return;
            }
            catch (NotSignedInException exception)
            {
                // This sample require user to be signed into Lync application
                // Sign in can be initiated through Lync APIs as well. See SignIn
                // sample for that code.
                Log(exception.ToString());
                return;
            }
            catch (Exception exception)
            {
                Log(exception.ToString());
                return;
            }

            // Subscribe to ConversationAdded event to know when someone tries to call you to share content.
            _lyncClient.ConversationManager.ConversationAdded   += new EventHandler <ConversationManagerEventArgs>(ConversationManager_ConversationAdded);
            _lyncClient.ConversationManager.ConversationRemoved += new EventHandler <ConversationManagerEventArgs>(ConversationManager_ConversationRemoved);
        }
        public LyncConversationHandler(ITelegramBotClient bot)
        {
            _bot = bot;
            _initClient();


            string[]     targetContactUris = { "sip:[email protected]" };
            LyncClient   client            = LyncClient.GetClient();
            Conversation conv = client.ConversationManager.AddConversation();

            foreach (string target in targetContactUris)
            {
                conv.AddParticipant(client.ContactManager.GetContactByUri(target));
            }
            InstantMessageModality m = conv.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;

            m.BeginSendMessage("Test Message", null, null);


            Microsoft.Win32.SystemEvents.SessionSwitch += (s, e) =>
            {
                if (e.Reason == SessionSwitchReason.SessionLock)
                {
                    _isSessionLock = true;
                }
                else if (e.Reason == SessionSwitchReason.SessionUnlock)
                {
                    _isSessionLock = false;
                }
            };
        }
Example #26
0
        /// <summary>
        /// Connect to the lync client, if possible
        /// </summary>
        private void ConnectLyncClient()
        {
            Console.WriteLine("Connecting Lync...");

            try
            {
                lyncClient = LyncClient.GetClient();
                lyncClient.StateChanged += CallbackStateChanged;

                if (lyncClient.State == ClientState.SignedIn)
                {
                    lyncClient.Self.Contact.ContactInformationChanged += CallbackContactInformationChanged;
                }
            }
            catch (ClientNotFoundException)
            {
                Console.WriteLine("Lync not running");
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception connection lync: " + e.ToString());
                return;
            }

            // Source: https://stackoverflow.com/questions/9207549/detecting-an-incoming-call-in-lync

            foreach (var conv in lyncClient.ConversationManager.Conversations)
            {
                conv.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += new EventHandler <ModalityStateChangedEventArgs>(AVModalityStateChanged);
            }

            lyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
        }
Example #27
0
        public bool initLyncSubscription()
        {
            try
            {
                serialPortInit();

                _contactSubscription = LyncClient.GetClient().ContactManager.CreateSubscription();
                lync = LyncClient.GetClient();
                //Wait for Lync to sign in
                while (lync.State != ClientState.SignedIn)
                {
                    setLED(ERROR);
                    Thread.Sleep(sleepInterval);
                    lync = LyncClient.GetClient();
                }



                _contact  = lync.ContactManager.GetContactByUri(lync.Uri);
                firstName = lync.Uri.Split(':')[1].Split('.')[0].ToUpper();

                if (string.IsNullOrEmpty(TaskTrayApplication.Properties.Settings.Default.reponsePrefix))
                {
                    TaskTrayApplication.Properties.Settings.Default.reponsePrefix = firstName;
                }

                _ContactInformationList.Add(ContactInformationType.Availability);
                _contactSubscription.AddContact(_contact);
                _contactSubscription.Subscribe(ContactSubscriptionRefreshRate.High, _ContactInformationList);
                //Register for event raised when selected user contact information
                //is re-published.
                _contact.ContactInformationChanged += ShowMessage;

                //register for new message

                lync.StateChanged += _LyncClient_StateChanged;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("running"))
                {
                    //   MessageBox.Show("Error: Skype not running.  Try again after starting skype");
                    //   Environment.Exit(10);
                    return(false);
                }
                try
                {
                    if (!TaskTrayApplication.Properties.Settings.Default.disableLyncLED)
                    {
                        _serialPort.Open();
                        _serialPort.Write("4");
                        _serialPort.Close();
                    }
                }
                catch {
                    return(false);
                }
            }
            return(true);
        }
        private void GetLyncClient()
        {
            try
            {
                // try to get the running lync client and register for change events, if Client is not running then ClientNoFound Exception is thrown by lync api
                lyncClient = LyncClient.GetClient();
                lyncClient.StateChanged += lyncClient_StateChanged;

                if (lyncClient.State == ClientState.SignedIn)
                {
                    lyncClient.Self.Contact.ContactInformationChanged += Contact_ContactInformationChanged;
                }

                SetCurrentContactState();
            }
            catch (ClientNotFoundException)
            {
                Debug.WriteLine("Lync Client not started.");

                SetLyncIntegrationMode(false);

                trayIcon.ShowBalloonTip(1000, "Error", "Lync Client not started. Running in manual mode now. Please use the context menu to change your blink color.", ToolTipIcon.Warning);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());

                trayIcon.ShowBalloonTip(1000, "Error", "Something went wrong by getting your Lync status. Running in manual mode now. Please use the context menu to change your blink color.", ToolTipIcon.Warning);
                Debug.WriteLine(e.Message);
            }
        }
Example #29
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // get the Lync client.
            try
            {
                _lyncClient = LyncClient.GetClient();
            }
            catch (ClientNotFoundException exception)
            {
                // Lync application should be running.
                Log(exception.ToString());
                return;
            }
            catch (NotSignedInException exception)
            {
                // User should be signed into Lync application
                Log(exception.ToString());
                return;
            }
            catch (Exception exception)
            {
                Log(exception.ToString());
                return;
            }

            // Subscribe to ConversationAdded event to know when someone tries to call you to share content.
            _lyncClient.ConversationManager.ConversationAdded   += new EventHandler <ConversationManagerEventArgs>(ConversationManager_ConversationAdded);
            _lyncClient.ConversationManager.ConversationRemoved += new EventHandler <ConversationManagerEventArgs>(ConversationManager_ConversationRemoved);
        }
Example #30
0
        private void SetCurrentLyncStatus()
        {
            try
            {
                _lyncClient = LyncClient.GetClient();

                if (_lyncClient != null && _lyncClient.State == ClientState.SignedIn)
                {
                    var status = _lyncClient.Self.Contact.GetContactInformation(ContactInformationType.ActivityId).ToString();

                    switch (status)
                    {
                    case "Free":
                        _serialSender.SendSerialData(ColourStates.Green);
                        break;

                    case "in-a-meeting":
                    case "Busy":
                        _serialSender.SendSerialData(ColourStates.Red);
                        break;

                    case "DoNotDisturb":
                    case "out-of-office":
                    case "urgent-interruptions-only":
                    case "presenting":
                        _serialSender.SendSerialData(ColourStates.Purple);
                        break;

                    case "Away":
                    case "BeRightBack":
                    case "off-work":
                    case "Inactive":
                        _serialSender.SendSerialData(ColourStates.Yellow);
                        break;

                    case "on-the-phone":
                    case "in-a-conference":
                        _serialSender.SendSerialData(ColourStates.RedFadeInACall);
                        break;

                    default:
                        _serialSender.SendSerialData(ColourStates.Off);
                        break;
                    }
                }
                else
                {
                    _serialSender.SendSerialData(ColourStates.Off);
                }
            }
            catch (ClientNotFoundException ex)
            {
                _serialSender.SendSerialData(ColourStates.Off);
            }
            catch (FileNotFoundException ex)
            {
                _serialSender.SendSerialData(ColourStates.Off);
            }
        }