/// <summary>
        /// Signs a user in to Lync as one of two possible users. User that is
        /// signed in depends on whether side-by-side client is chosen.
        /// </summary>
        internal void SignUserIn()
        {
            //Set the display cursor to indicate that user must wait for
            //sign in to complete
            if (SetWindowCursor != null)
            {
                SetWindowCursor(Cursors.WaitCursor);
            }

            //Set the sign in credentials of the user to the
            //appropriate credentials for the endpoint mode
            string userUri      = string.Empty;
            string userPassword = string.Empty;


            SignInCreds getCreds;

            getCreds = new SignInCreds("Sign in");
            if (getCreds.ShowDialog() == DialogResult.OK)
            {
                userUri      = getCreds.UserName;
                userPassword = getCreds.Password;
                getCreds.Close();
            }

            _UserUri = userUri;
            _LyncClient.BeginSignIn(
                userUri,
                userUri,
                userPassword,
                (ar) =>
            {
                try
                {
                    _LyncClient.EndSignIn(ar);
                }
                catch (Exception exc)
                {
                    throw exc;
                }
            },
                null);
        }
Exemple #2
0
        /// <summary>
        /// Signs a user in to Lync as one of two possible users. User that is
        /// signed in depends on whether side-by-side client is chosen.
        /// </summary>
        public void SignUserIn()
        {
            //Set the display cursor to indicate that user must wait for
            //sign in to complete
            if (SetWindowCursor != null)
            {
                SetWindowCursor(Cursors.WaitCursor);
            }

            //Set the sign in credentials of the user to the
            //appropriate credentials for the endpoint mode
            string userUri      = Constants.ID;
            string userName     = Constants.ID;
            string userPassword = Constants.PASSWORD;

            _UserUri = userUri;

            _LyncClient.BeginSignIn(
                userUri,
                userName,
                userPassword,
                (ar) =>
            {
                try
                {
                    _LyncClient.EndSignIn(ar);
                    if (UserIsSignedIn != null)
                    {
                        UserIsSignedIn();
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("exception on endsignin: " + exc.Message);
                }
            },
                null);
        }
        /// <summary>
        /// invoked when sample form is loaded. Initializes fields, gets API entry point,
        /// registers for events on Lync Client and ConversationManager.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShareResources_Form_Load(object sender, EventArgs e)
        {
            try
            {
                //Get the API entry point
                _LyncClient = LyncClient.GetClient();


                //Resource sharing is not supported in UI suppression mode. Sample closes
                //if Lync UI is suppressed
                if (_LyncClient.InSuppressedMode == true)
                {
                    MessageBox.Show("Lync Client is in UI Suppressed mode. Sharing is not supported.", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    this.Close();
                }

                //Display the current state of the Lync client.
                ClientStateString_Label.Text = _LyncClient.State.ToString();

                //If the Lync client is signed out, sign into the Lync client
                if (_LyncClient.State == ClientState.SignedOut)
                {
                    _LyncClient.EndSignIn(_LyncClient.BeginSignIn(
                                              "*****@*****.**",
                                              "*****@*****.**",
                                              "MyPassword",
                                              null,
                                              null));
                }

                //Display the current state of the Lync client.
                ClientStateString_Label.Text = _LyncClient.State.ToString();

                //Register for the three Lync client events needed so that application is notified when:
                // * Lync client signs in or out
                // * A new conversation is added (remotely via invite or locally by user)
                // * A conversation is removed (conversation ends)
                _LyncClient.StateChanged += _LyncClient_StateChanged;
                _LyncClient.ConversationManager.ConversationAdded   += ConversationManager_ConversationAdded;
                _LyncClient.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;

                //Enable the start conversation button on the UI
                Start_Button.Enabled = true;

                //ShareDesktop.LoadAllContacts loads the contact list on the UI with  all contacts that are in the user's Lync client contact list.
                LoadAllContacts();
            }
            catch (NotInitializedException)
            {
                MessageBox.Show("Client is not initialized.  Closing form", "Lync Client Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.Close();
            }
            catch (ClientNotFoundException)
            {
                MessageBox.Show("Client is not running.  Closing form", "Lync Client Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.Close();
            }
            catch (Exception exc)
            {
                MessageBox.Show("General exception: " + exc.Message, "Lync Client Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.Close();
            }
        }