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 #2
0
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            if ((String.IsNullOrEmpty(ConfigurationManager.AppSettings["PrimaryLabUserId"]))
                || (String.IsNullOrEmpty(ConfigurationManager.AppSettings["SecondaryLabUserId"]))
                || (String.IsNullOrEmpty(ConfigurationManager.AppSettings["ApplicationGuid"]))
                || (String.IsNullOrEmpty(ConfigurationManager.AppSettings["ApplicationName"])))
            {
                MessageBox.Show("Please provide values for all keys in app.config",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            }

            _primaryLabUserId = ConfigurationManager.AppSettings["PrimaryLabUserId"];
            _secondaryLabUserId = ConfigurationManager.AppSettings["SecondaryLabUserId"];
            _applicationGuid = ConfigurationManager.AppSettings["ApplicationGuid"];
            _applicationName = ConfigurationManager.AppSettings["ApplicationName"];

            _accounts = new Accounts();
            accountsList.ItemsSource = _accounts;

            try
            {
                _lyncClient = Microsoft.Lync.Model.LyncClient.GetClient();

                if (App.CommandLineArgs.Count > 0 && App.CommandLineArgs["AccountId"] != null)
                {
                    LoadSelectedAccount(Convert.ToInt32(App.CommandLineArgs["AccountId"]));
                }
                InitializeClient();
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
 static void Main(string[] args)
 {
     client       = Microsoft.Lync.Model.LyncClient.GetClient();
     conversation = new LyncConversationManager(client);
     conversation.StartListening();
     //conversation.SendLyncMessage("*****@*****.**", "Test");
     Console.ReadKey();
 }
Example #4
0
 public void Run()
 {
     try
     {
         /* attach to skype */
         this.lyncClient = mslm.LyncClient.GetClient();
         this.lyncClient.ConversationManager.ConversationAdded += this.IncomingConversationAdded;
     }
     catch (Exception x)
     {
         AppLogger.Save(x);
     }
 }
Example #5
0
        public SeriousBusinessCat(MainWindow main)
        {
            this._main = main;

            this.whisperCat = new WhisperCat(this);

            try
            {
#if DEBUG
                debug = new DebugWindow();
                debug.info("Test");
                debug.Show();

                /*
                 * var _testWhisper = new WhisperWindow(null, null, null, "Your key: 12345\r\nTheir key: 6789A");
                 *
                 * _testWhisper.AddWhisper(new Whisper(true, "testing a really really long message, at least it seems pretty long, but i guess it is really not that long to begin with", "cipher1"));
                 * _testWhisper.AddWhisper(new Whisper(false, "okay, looks good", "cipher2"));
                 * _testWhisper.AddWhisper(new Whisper(true, "glad you think so, you jerk", "cipher3"));
                 * _testWhisper.Show();
                 */
#endif


                //Start the conversation
                automation = LyncClient.GetAutomation();
                client     = LyncClient.GetClient();

                ConversationManager conversationManager = client.ConversationManager;
                conversationManager.ConversationAdded   += ConversationManager_ConversationAdded;
                conversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
                //conversationManager.ConversationAdded += new EventHandler<ConversationManagerEventArgs>(conversationManager_ConversationAdded);

                _main.lbConversations.ItemsSource = _conversations;

                RefreshConversations(true);

                try
                {
                    _selfUserName = client.Self.Contact.GetContactInformation(ContactInformationType.PrimaryEmailAddress).ToString();
                    if (_selfUserName.Contains("@"))
                    {
                        _selfUserName = _selfUserName.Split('@')[0];
                    }
                    _selfUserNameLast = _selfUserName;
                    if (_selfUserNameLast.Contains('.'))
                    {
                        _selfUserNameLast = _selfUserNameLast.Split('.')[1];
                    }
                }
                catch (Exception)
                {
                    // ignore
                }
            }
            catch (LyncClientException lyncClientException)
            {
                MessageBox.Show("Failed to connect to Lync: " + lyncClientException.ToString());
                Console.Out.WriteLine(lyncClientException);
            }
            catch (SystemException systemException)
            {
                if (Util.IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    MessageBox.Show("Failed to connect to Lync with system error: " + systemException.ToString());
                    Console.WriteLine("Error: " + systemException);
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }

            CreateFileWatcher();
        }
        /// <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">boolean. Specifies endpoint mode</param>
        internal void StartUpLync(Boolean sideBySide)
        {
            //Calling GetClient a second time in a running process will
            //return the previously cached client. For example, calling GetClient(boolean 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
            {
                if (_LyncClient == null)
                {
                    //If sideBySide == false, a standard endpoint is created
                    //Otherwise, a side-by-side endpoint is created
                    _LyncClient = LyncClient.GetClient(sideBySide);
                }
                _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        += _LyncClient_StateChanged;
                _LyncClient.SignInDelayed       += _LyncClient_SignInDelayed;
                _LyncClient.CredentialRequested += _LyncClient_CredentialRequested;



                //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)
                {
                    if (MessageBox.Show(
                            "Lync is signing in. Do you want to continue waiting?",
                            "Sign in delay",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    {
                        if (CloseAppConditionHit != null)
                        {
                            CloseAppConditionHit();
                        }
                    }
                }
            }
            catch (NotInitializedException ni)
            {
                MessageBox.Show(
                    "Client is not initialized.  Closing form",
                    "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);

                //If calling form has registered a handler for this delegate,
                //call the delegate
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }
                //otherwise, throw the exception.
                else
                {
                    throw ni;
                }
            }
            catch (ClientNotFoundException cnf)
            {
                MessageBox.Show(
                    "Client is not running.  Closing form",
                    "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //If calling form has registered a handler for this delegate,
                //call the delegate
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }
                //otherwise, throw the exception.
                else
                {
                    throw cnf;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(
                    "General exception: " +
                    exc.Message, "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //If calling form has registered a handler for this delegate,
                //call the delegate
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }
                //otherwise, throw the exception.
                else
                {
                    throw exc;
                }
            }
        }
        /// <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();
            }
        }
 public UserSignIn(LyncClient lyncClient)
 {
     _LyncClient = lyncClient;
 }
        /// <summary>
        /// Gets the Lync client, initializes if in UI suppression, and 
        /// starts the user sign in process
        /// </summary>
        /// <param name="sideBySide">boolean. Specifies endpoint mode</param> 
        internal void StartUpLync(Boolean sideBySide)
        {
            //Calling GetClient a second time in a running process will
            //return the previously cached client. For example, calling GetClient(boolean 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
            {
                if (_LyncClient == null)
                {
                    //If sideBySide == false, a standard endpoint is created
                    //Otherwise, a side-by-side endpoint is created
                    _LyncClient = LyncClient.GetClient(sideBySide);
                }

                //if (_LyncClient.Self.Contact == null)
                //{
                //    foreach (var process in System.Diagnostics.Process.GetProcessesByName(Constants.PROCESSNAME))
                //    {
                //        process.Kill();
                //    }

                //    var unused = _LyncClient.State;
                //    _LyncClient = LyncClient.GetClient();
                //}
                if (_LyncClient.State == ClientState.Invalid)
                    _LyncClient = LyncClient.GetClient(false);

                _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 += _LyncClient_StateChanged;
                _LyncClient.SignInDelayed += _LyncClient_SignInDelayed;
                _LyncClient.CredentialRequested += _LyncClient_CredentialRequested;

                //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);
                }

                //If the Lync client is signed out, sign into the Lync client

                if (_LyncClient.State == ClientState.SignedOut)
                {
                    SignUserIn();
                }

                // don't wait more than 5 seconds.
                int waitCounter = 0;
                while (_LyncClient.State == ClientState.SigningIn && waitCounter < 50)
                {
                    //if (MessageBox.Show(
                    //    "Lync is signing in. Do you want to continue waiting?",
                    //    "Sign in delay",
                    //    MessageBoxButtons.YesNo,
                    //    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    //{
                    //    if (CloseAppConditionHit != null)
                    //    {
                    //        CloseAppConditionHit();
                    //    }

                    //}
                    System.Threading.Thread.Sleep(100);
                    waitCounter++;
                }
            }
            catch (NotInitializedException)
            {
                MessageBox.Show(
                    "Client is not initialized.  Closing form",
                    "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }

            }
            catch (ClientNotFoundException)
            {
                MessageBox.Show(
                    "Client is not running.  Closing form",
                    "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }

            }
            catch (Exception exc)
            {
                MessageBox.Show(
                    "General exception: " +
                    exc.Message, "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }

            }
        }
Example #10
0
        public SeriousBusinessCat(MainWindow main)
        {
            this._main = main;

            this.whisperCat = new WhisperCat(this);

            try
            {
#if DEBUG
                var _testWhisper = new WhisperWindow(null, null, null, "Your key: 12345\r\nTheir key: 6789A");
     
                _testWhisper.AddWhisper(new Whisper(true, "testing a really really long message, at least it seems pretty long, but i guess it is really not that long to begin with", "cipher1"));
                _testWhisper.AddWhisper(new Whisper(false, "okay, looks good", "cipher2"));
                _testWhisper.AddWhisper(new Whisper(true, "glad you think so, you jerk", "cipher3"));
                _testWhisper.Show();
#endif


                //Start the conversation
                automation = LyncClient.GetAutomation();
                client = LyncClient.GetClient();

                ConversationManager conversationManager = client.ConversationManager;
                conversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                conversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
                //conversationManager.ConversationAdded += new EventHandler<ConversationManagerEventArgs>(conversationManager_ConversationAdded);

                _main.lbConversations.ItemsSource = _conversations;

                RefreshConversations(true);

                try
                {
                    _selfUserName = client.Self.Contact.GetContactInformation(ContactInformationType.PrimaryEmailAddress).ToString();
                    if (_selfUserName.Contains("@"))
                    {
                        _selfUserName = _selfUserName.Split('@')[0];
                    }
                    _selfUserNameLast = _selfUserName;
                    if (_selfUserNameLast.Contains('.'))
                    {
                        _selfUserNameLast = _selfUserNameLast.Split('.')[1];
                    }
                }
                catch (Exception)
                {
                    // ignore
                }
            }
            catch (LyncClientException lyncClientException)
            {
                MessageBox.Show("Failed to connect to Lync: " + lyncClientException.ToString());
                Console.Out.WriteLine(lyncClientException);
            }
            catch (SystemException systemException)
            {
                if (Util.IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    MessageBox.Show("Failed to connect to Lync with system error: " + systemException.ToString());
                    Console.WriteLine("Error: " + systemException);
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
        }
Example #11
0
        /// <summary>
        /// Gets the Lync client, initializes if in UI suppression, and
        /// starts the user sign in process
        /// </summary>
        /// <param name="sideBySide">boolean. Specifies endpoint mode</param>
        internal void StartUpLync(Boolean sideBySide)
        {
            //Calling GetClient a second time in a running process will
            //return the previously cached client. For example, calling GetClient(boolean 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
            {
                if (_LyncClient == null)
                {
                    //If sideBySide == false, a standard endpoint is created
                    //Otherwise, a side-by-side endpoint is created
                    _LyncClient = LyncClient.GetClient(sideBySide);
                }

                //if (_LyncClient.Self.Contact == null)
                //{
                //    foreach (var process in System.Diagnostics.Process.GetProcessesByName(Constants.PROCESSNAME))
                //    {
                //        process.Kill();
                //    }

                //    var unused = _LyncClient.State;
                //    _LyncClient = LyncClient.GetClient();
                //}
                if (_LyncClient.State == ClientState.Invalid)
                {
                    _LyncClient = LyncClient.GetClient(false);
                }

                _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        += _LyncClient_StateChanged;
                _LyncClient.SignInDelayed       += _LyncClient_SignInDelayed;
                _LyncClient.CredentialRequested += _LyncClient_CredentialRequested;



                //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);
                }

                //If the Lync client is signed out, sign into the Lync client

                if (_LyncClient.State == ClientState.SignedOut)
                {
                    SignUserIn();
                }

                // don't wait more than 5 seconds.
                int waitCounter = 0;
                while (_LyncClient.State == ClientState.SigningIn && waitCounter < 50)
                {
                    //if (MessageBox.Show(
                    //    "Lync is signing in. Do you want to continue waiting?",
                    //    "Sign in delay",
                    //    MessageBoxButtons.YesNo,
                    //    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    //{
                    //    if (CloseAppConditionHit != null)
                    //    {
                    //        CloseAppConditionHit();
                    //    }

                    //}
                    System.Threading.Thread.Sleep(100);
                    waitCounter++;
                }
            }
            catch (NotInitializedException)
            {
                MessageBox.Show(
                    "Client is not initialized.  Closing form",
                    "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }
            }
            catch (ClientNotFoundException)
            {
                MessageBox.Show(
                    "Client is not running.  Closing form",
                    "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(
                    "General exception: " +
                    exc.Message, "Lync Client Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                if (CloseAppConditionHit != null)
                {
                    CloseAppConditionHit();
                }
            }
        }
Example #12
0
 public UserSignIn(LyncClient lyncClient)
 {
     _LyncClient = lyncClient;
 }