Ejemplo n.º 1
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     lyncClient.CredentialRequested += new EventHandler <CredentialRequestedEventArgs>(lyncClient_CredentialRequested);
     lyncClient.SignInDelayed       += new EventHandler <SignInDelayedEventArgs>(lyncClient_SignInDelayed);
     Log("Calling BeginInitialize()");
     lyncClient.BeginInitialize(InitializeCallback, null);
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        private void LoginInit()
        {
            //1) Register for the three Lync client events needed so that application is notified when:
            // * Lync client signs in or out
            _LyncClient.StateChanged        += new EventHandler <ClientStateChangedEventArgs>(_LyncClient_StateChanged);
            _LyncClient.SignInDelayed       += new EventHandler <SignInDelayedEventArgs>(_LyncClient_SignInDelayed);
            _LyncClient.CredentialRequested += new EventHandler <CredentialRequestedEventArgs>(_LyncClient_CredentialRequested);

            //2-4) Client state of uninitialized means that Lync is configured for UI suppression mode and
            //must be initialized before a user can sign in to Lync
            if (_LyncClient.State == ClientState.Uninitialized)
            {
                _LyncClient.BeginInitialize(
                    (ar) =>
                {
                    _LyncClient.EndInitialize(ar);
                    //_thisProcessInitializedLync = true;
                },
                    null);
            }

            //5) If the Lync client is signed out, sign into the Lync client
            else if (_LyncClient.State == ClientState.SignedOut)
            {
                SignUserIn();
            }
            //6) A sign in operation is pending
            else if (_LyncClient.State == ClientState.SigningIn)
            {
            }

            else if (_LyncClient.State == ClientState.SignedIn)
            {
            }
        }
Ejemplo n.º 4
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");
            }
        }
        public void SignIn(string signInAddress, string username, string password)
        {
            _signInAddress = signInAddress;
            _username      = username;
            _password      = password;

            if ((_lyncClient == null))
            {
                return;
            }

            try
            {
                //2-4) Client state of uninitialized means that Lync Is configured for UI suppression mode And
                //must be initialized before a user can sign in to Lync

                if (_lyncClient.State == ClientState.Uninitialized)
                {
                    Trace.WriteLine("SignIn: ClientState.Uninitialized");
                    _lyncClient.BeginInitialize(ar =>
                    {
                        _lyncClient.EndInitialize(ar);
                        _thisProcessInitializedLync = true;
                    }, null);

                    //If the Lync client Is signed out, sign into the Lync client
                }
                else if ((_lyncClient.State == ClientState.SignedOut))
                {
                    Trace.WriteLine("SignIn: ClientState.SignedOut");
                    SignUserIn();
                }
                else if ((_lyncClient.State == ClientState.SigningIn) || _lyncClient.State == ClientState.SignedIn)
                {
                    Trace.WriteLine($"SignIn: ClientState.SigningIn ({ClientState.SigningIn}) || ClientState.SignedIn ({ClientState.SignedIn})");
                    Trace.WriteLine($"SignIn: {_lyncClient.State}");
                    SignOut();
                    SignUserIn();
                }

                if ((!_signInProcedureEvent.WaitOne(75000)))
                {
                    //signIn timeout occured
                    TimeoutOccured = true;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Generic Exception during SignIn {ex.Message}");
            }
        }
Ejemplo n.º 6
0
 private void Window_Loaded_1(object sender, RoutedEventArgs e)
 {
     try
     {
         _client = LyncClient.GetClient();
         _client.StateChanged += client_StateChanged;
         StatusTextBlock.Text  = _client.State.ToString();
         if (_client.InSuppressedMode)
         {
             _client.BeginInitialize((ar) =>
             {
                 _client.EndInitialize(ar);
             }, null);
         }
         _client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
     }
     catch (Exception ex)
     {
         StatusTextBlock.Text = "Exception: " + ex.Message;
     }
 }
        /// <summary>
        /// Sign in to Lync Client if not signed in.
        /// </summary>
        public void SignInAndGetAvailability()
        {
            try
            {
                // Get Lync Client and Contact Manager.
                lyncClient = LyncClient.GetClient();

                // Register for the client state changed event
                lyncClient.StateChanged += lyncClient_StateChanged;

                //If lync client is Uninitialized then first initialize it.
                if (lyncClient.State == ClientState.Uninitialized)
                {
                    lyncClient.BeginInitialize((ar) =>
                    {
                        lyncClient.EndInitialize(ar);
                    },
                                               null);
                }
                // If lync client is signed out then let sign in user first.
                else if (lyncClient.State == ClientState.SignedOut)
                {
                    SignUserIntoLync();
                }
                // If user already signed in then get user list with their presence status.
                else if (lyncClient.State == ClientState.SignedIn)
                {
                    BindOnlineUsers();
                }
            }
            catch (ClientNotFoundException)
            {
                MessageBox.Show("Lync is not running on this computer");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public bool SigningOut;    //flag to identify whether the user is signing out.

        //Constructor
        //Called from a click event on Form1
        public SignIn(string passwrd, bool SigningOut)
        {
            password = passwrd;

            try
            {
                _LyncClient = LyncClient.GetClient();

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

                //Register event handlers right after getting the client object
                _LyncClient.SignInDelayed       += new EventHandler <SignInDelayedEventArgs>(_LyncClient_SignInDelayed);
                _LyncClient.StateChanged        += new EventHandler <ClientStateChangedEventArgs>(_LyncClient_StateChanged);
                _LyncClient.CredentialRequested += new EventHandler <CredentialRequestedEventArgs>(_LyncClient_CredentialRequested);


                if (_LyncClient.InSuppressedMode == true)
                {
                    if (_LyncClient.State == ClientState.Uninitialized)
                    {
                        MessageBox.Show("Lync is uninitialized");
                        Object[] _asyncState = { _LyncClient };
                        _LyncClient.BeginInitialize(InitializeCallback, _asyncState);
                    }
                }
            }
            catch (NotStartedByUserException h)
            {
                throw new Exception("Lync is not running: " + h.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("General Exception: " + ex.Message);
            }
        }
        private void InitializeClient()
        {
            UserSignIn signin = new UserSignIn(this._LyncClient);

            signin.StartUpLync(false);

            //***********************************************************************************
            // This application works with UISuppressionMode = true or false
            //
            // UISuppressionMode hides the Lync user interface.
            //
            // Registry key for enabling UISuppressionMode:
            //
            // 32bit OS:
            // [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\15.0\Lync]
            // "UISuppressionMode"=dword:00000001
            //
            // 64bit OS:
            // [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Communicator]
            // "UISuppressionMode"=dword:00000001
            //
            // When running with UISuppressionMode = 1 and this application is the only one
            // using the client, it's necessary to Initialize the client. The following check
            // verifies if the client has already been initialized. If it hasn't, the code will
            // call BeginInitialize() proving a callback method, on which this application's
            // main UI will be presented (either Sign-In or contact input, if already signed in).
            //***********************************************************************************

            //if this client is in UISuppressionMode...
            if (_LyncClient.InSuppressedMode && _LyncClient.State == ClientState.Uninitialized)
            {
                //...need to initialize it
                try
                {
                    _LyncClient.BeginInitialize(this.ClientInitialized, null);
                }
                catch (LyncClientException lyncClientException)
                {
                    Console.WriteLine(lyncClientException);
                }
                catch (SystemException systemException)
                {
                    if (Utilities.IsLyncException(systemException))
                    {
                        // Log the exception thrown by the Lync Model API.
                        Console.WriteLine("Error: " + systemException);
                    }
                    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
            {
                //registers for conversation related events
                //these events will occur when new conversations are created (incoming/outgoing) and removed
                _LyncClient.ConversationManager.ConversationAdded   += ConversationManager_ConversationAdded;
                _LyncClient.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;

                //show sign-in or contact selection
                //ShowMainContent();
            }
        }
Ejemplo n.º 10
0
        public void InitWithoutSignIn()
        {
            try
            {
                if (_lyncClient == null)
                {
                    //If sideBySide == false, a standard endpoint is created
                    //Otherwise, a side-by-side endpoint is created
                    _lyncClient = LyncClient.GetClient(false);

                    _log.Info("Connect  _lyncClientState:{0}", _lyncClient.State.ToString());
                }
                //Display the current state of the Lync client.
                if (ClientStateChanged != null)
                {
                    ClientStateChanged(_lyncClient.State.ToString());
                }

                //Register for the three Lync client events needed so that application is notified when:
                // * Lync client signs in or out
                _lyncClient.StateChanged += OnLyncClientStateChanged;



                //Client state of uninitialized means that Lync is configured for UI suppression mode and
                //must be initialized before a user can sign in to Lync
                if (_lyncClient.State == ClientState.Uninitialized)
                {
                    _lyncClient.BeginInitialize(
                        (ar) =>
                    {
                        _lyncClient.EndInitialize(ar);
                        _thisProcessInitializedLync = true;
                    },
                        null);
                }

                else if (_lyncClient.State == ClientState.SignedIn)
                {
                }
                //If the Lync client is signed out, sign into the Lync client
                else if (_lyncClient.State == ClientState.SignedOut)
                {
                }
                else if (_lyncClient.State == ClientState.SigningIn)
                {
                }
            }
            catch (NotInitializedException ni)
            {
                _log.ErrorException("Connect", ni);
            }
            catch (ClientNotFoundException cnf)
            {
                _log.ErrorException("Connect", cnf);
            }
            catch (Exception exc)
            {
                _log.ErrorException("Connect", exc);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the Lync client, initializes if in UI suppression, and
        /// starts the user sign in process. This method can raise exceptions
        /// which are thrown if the calling form has not registered a callback for
        /// exception specific events that are declared in this class.
        /// </summary>
        /// <param name="sideBySide">bool. Specifies endpoint mode</param>
        public void Connect(string userUrl, string password, bool sideBySide)
        {
            //Calling GetClient a second time in a running process will
            //return the previously cached client. For example, calling GetClient(bool sideBySideFlag)
            // the first time in a process returns a new endpoint.  Calling the method a second
            //time returns the original endpoint. If you call GetClient(false) to get a client
            //endpoint and then GetClient(true), the original client enpoint is returned even though
            // a true value argument is passed with the second call.

            try
            {
                _userUri      = userUrl;
                _userPassword = password;

                _log.Info("Connect  userUrl:{0}", userUrl);

                if (_lyncClient == null)
                {
                    //If sideBySide == false, a standard endpoint is created
                    //Otherwise, a side-by-side endpoint is created
                    _lyncClient = LyncClient.GetClient(sideBySide);

                    _log.Info("Connect  _lyncClientState:{0}", _lyncClient.State.ToString());
                }
                _inSideBySideMode = sideBySide;

                //Display the current state of the Lync client.
                if (ClientStateChanged != null)
                {
                    ClientStateChanged(_lyncClient.State.ToString());
                }

                //Register for the three Lync client events needed so that application is notified when:
                // * Lync client signs in or out
                _lyncClient.StateChanged        += OnLyncClientStateChanged;
                _lyncClient.SignInDelayed       += OnLyncClientSignInDelayed;
                _lyncClient.CredentialRequested += OnLyncClientCredentialRequested;



                //Client state of uninitialized means that Lync is configured for UI suppression mode and
                //must be initialized before a user can sign in to Lync
                if (_lyncClient.State == ClientState.Uninitialized)
                {
                    _lyncClient.BeginInitialize(
                        (ar) =>
                    {
                        _lyncClient.EndInitialize(ar);
                        _thisProcessInitializedLync = true;
                    },
                        null);
                }

                else if (_lyncClient.State == ClientState.SignedIn)
                {
                    if (UserIsSignedIn != null)
                    {
                        UserIsSignedIn(_lyncClient);
                    }
                }
                //If the Lync client is signed out, sign into the Lync client
                else if (_lyncClient.State == ClientState.SignedOut)
                {
                    SignUserIn();
                }
                else if (_lyncClient.State == ClientState.SigningIn)
                {
                }
            }
            catch (NotInitializedException ni)
            {
                _log.ErrorException("Connect", ni);
            }
            catch (ClientNotFoundException cnf)
            {
                _log.ErrorException("Connect", cnf);
            }
            catch (Exception exc)
            {
                _log.ErrorException("Connect", exc);
            }
        }
        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;
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Updates the initial UI state and registers for client events.
        /// </summary>
        private void MainWindow_Load(object sender, EventArgs e)
        {
            //shows the current client state
            toolStripStatusLabel.Text = client.State.ToString();

            // register for state updates. Whenever the client change its state, this
            // event will be fired. For example, during Sign-In it will likely move from:
            // SignedOut -> SigningIn -> SignedIn
            client.StateChanged += client_StateChanged;

            // register for the client exiting event
            // when/if the Lync process exits, it will fire this event
            client.ClientDisconnected += client_ClientDisconnected;

            //***********************************************************************************
            // This application works with UISuppressionMode = true or false
            //
            // UISuppressionMode hides the Lync user interface.
            //
            // Registry key for enabling UISuppressionMode:
            //
            // 32bit OS:
            // [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\15.0\Lync]
            // "UISuppressionMode"=dword:00000001
            //
            // 64bit OS:
            // [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Communicator]
            // "UISuppressionMode"=dword:00000001
            //
            // When running with UISuppressionMode = 1 and this application is the only one
            // using the client, it's necessary to Initialize the client. The following check
            // verifies if the client has already been initialized. If it hasn't, the code will
            // call BeginInitialize() proving a callback method, on which this application's
            // main UI will be presented (either Sign-In or contact input, if already signed in).
            //***********************************************************************************

            //if this client is in UISuppressionMode...
            if (client.InSuppressedMode && client.State == ClientState.Uninitialized)
            {
                //...need to initialize it
                try
                {
                    client.BeginInitialize(this.ClientInitialized, null);
                }
                catch (LyncClientException lyncClientException)
                {
                    Console.WriteLine(lyncClientException);
                }
                catch (SystemException systemException)
                {
                    if (LyncModelExceptionHelper.IsLyncException(systemException))
                    {
                        // Log the exception thrown by the Lync Model API.
                        Console.WriteLine("Error: " + systemException);
                    }
                    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
            {
                //registers for conversation related events
                //these events will occur when new conversations are created (incoming/outgoing) and removed
                client.ConversationManager.ConversationAdded   += ConversationManager_ConversationAdded;
                client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;

                //show sign-in or contact selection
                ShowMainContent();
            }
        }