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); } }
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); }
/// <summary> /// Adds contacts found through a search to a ContactSubscription /// and raises the ContactAddedEvent. /// </summary> /// <param name="sContact">List[Contact]. The list of contacts found in a search.</param> public void SubscribeToSearchResults(List <Contact> sContactList) { try { if (searchResultSubscription == null) { // Create subscription for the contact manager // if the contact manager is not subscribed. searchResultSubscription = contactMgr.CreateSubscription(); } else { // Remove all existing search results. searchResultSubscription.Unsubscribe(); foreach (Contact c in searchResultSubscription.Contacts) { searchResultSubscription.RemoveContact(c); } } // Add the Contact to a ContactSubscription. searchResultSubscription.AddContacts(sContactList); // Specify the Contact Information Types to be // returned in ContactInformationChanged events. ContactInformationType[] ContactInformationTypes = { ContactInformationType.Availability, ContactInformationType.ActivityId }; // Activate the subscription. searchResultSubscription.Subscribe(ContactSubscriptionRefreshRate.High, ContactInformationTypes); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private void _LyncClientInitialization() { _LyncClient = null; try { _LyncClient = LyncClient.GetClient(); _LyncClient.ClientDisconnected += _ClientDisconnected; _LyncClient.StateChanged += _ClientStateChanged; _ContactSubscription = _LyncClient.ContactManager.CreateSubscription(); _ContactInformationList.Clear(); //_ContactInformationList.Add(ContactInformationType.DisplayName); //_ContactInformationList.Add(ContactInformationType.Title); _ContactInformationList.Add(ContactInformationType.PersonalNote); _ContactInformationList.Add(ContactInformationType.Activity); //_ContactInformationList.Add(ContactInformationType.ActivityId); _ContactInformationList.Add(ContactInformationType.IdleStartTime); _ContactInformationList.Add(ContactInformationType.Availability); //_ContactInformationList.Add(ContactInformationType.Photo); //_ContactInformationList.Add(ContactInformationType.IconStream); } catch (ClientNotFoundException clientNotFoundException) { // Console.WriteLine(clientNotFoundException); return; } catch (NotStartedByUserException notStartedByUserException) { // Console.Out.WriteLine(notStartedByUserException); return; } catch (LyncClientException lyncClientException) { // Console.Out.WriteLine(lyncClientException); return; } catch (SystemException systemException) { if (_IsLyncException(systemException)) { // Log the exception thrown by the Lync Model API. // Console.WriteLine("Error: " + systemException); return; } else { // Rethrow the SystemException which did not come from the Lync Model API. throw; } } }
public void undoLyncSubscription() { try { _contactSubscription = LyncClient.GetClient().ContactManager.CreateSubscription(); lync = LyncClient.GetClient(); _contact = lync.ContactManager.GetContactByUri(lync.Uri); _ContactInformationList.Add(ContactInformationType.Availability); _contactSubscription.AddContact(_contact); _contactSubscription.Unsubscribe(); } catch { } }
private void LyncClientInitialization(bool Signin) { try { _LyncClient = LyncClient.GetClient(); _ContactSubscription = _LyncClient.ContactManager.CreateSubscription(); _ContactInformationList.Clear(); _ContactInformationList.Add(ContactInformationType.DisplayName); _ContactInformationList.Add(ContactInformationType.Availability); } catch (ClientNotFoundException clientNotFoundException) { // Console.WriteLine(clientNotFoundException); return; } catch (NotStartedByUserException notStartedByUserException) { // Console.Out.WriteLine(notStartedByUserException); return; } catch (LyncClientException lyncClientException) { // Console.Out.WriteLine(lyncClientException); return; } catch (SystemException systemException) { if (IsLyncException(systemException)) { // Log the exception thrown by the Lync Model API. // Console.WriteLine("Error: " + systemException); return; } else { // Rethrow the SystemException which did not come from the Lync Model API. throw; } } if (Signin == true) { LyncClientSignin(); } }
public static void SearchForContacts(string searchKey) { List <ContactInformationType> ContactInformationList = new List <ContactInformationType>(); //ContactInformationList.Add(ContactInformationType.Activity); ContactInformationList.Add(ContactInformationType.Availability); // ContactInformationList.Add(ContactInformationType.CapabilityString); ContactSubscription contactSubscription = LyncClient.GetClient().ContactManager.CreateSubscription(); Console.WriteLine( "Searching for contacts on " + searchKey); name = searchKey; LyncClient.GetClient().ContactManager.BeginSearch( searchKey, (ar) => { SearchResults searchResults = LyncClient.GetClient().ContactManager.EndSearch(ar); if (searchResults.Contacts.Count > 0) { Console.WriteLine( searchResults.Contacts.Count.ToString() + " found"); foreach (Contact contact in searchResults.Contacts) { contactSubscription.AddContact(contact); contactSubscription.Subscribe(ContactSubscriptionRefreshRate.High, ContactInformationList); Console.WriteLine( contact.GetContactInformation(ContactInformationType.DisplayName).ToString() + " " + contact.GetContactInformation(ContactInformationType.Availability).ToString()); scode = (int)contact.GetContactInformation(ContactInformationType.Availability); // next update, make this int and pass int code rather than string .ToString() } } }, null); }
public Search() { InitializeComponent(); try { // Get instances of Lync Client and Contact Manager. lyncClient = LyncClient.GetClient(); automation = LyncClient.GetAutomation(); contactMgr = lyncClient.ContactManager; // Create a DataTable for search results. dt = new DataTable(); dt.Columns.Add("Contact Uri"); dt.Columns.Add("Contact Details"); // Create list to cache a list of SearchProviders instances // that are synchronized and can accept user search requests. activeSearchProviders = new List <SearchProviders>(); searchResultSubscription = contactMgr.CreateSubscription(); // Loads Expert search provider if it is configured and enables the checkbox. if (contactMgr.GetSearchProviderStatus(SearchProviders.Expert) == SearchProviderStatusType.SyncSucceeded || contactMgr.GetSearchProviderStatus(SearchProviders.Expert) == SearchProviderStatusType.SyncSucceededForExternalOnly || contactMgr.GetSearchProviderStatus(SearchProviders.Expert) == SearchProviderStatusType.SyncSucceededForInternalOnly) { activeSearchProviders.Add(SearchProviders.Expert); ExpertSearch.Enabled = true; } // Register for the SearchProviderStatusChanged event raised // by ContactManager. contactMgr.SearchProviderStateChanged += contactMgr_SearchProviderStateChanged; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
//adds custom group contacts to the listbox control private void GetGroupContacts(Group group) { ContactSubscription newSubscription = contactManager.CreateSubscription(); Dictionary <ContactInformationType, object> _ContactInformation = new Dictionary <ContactInformationType, object>(); group.ContactAdded += new EventHandler <GroupMemberChangedEventArgs>(group_ContactAdded); // Iterate on the contacts in the group. foreach (Contact _Contact in group) { // Test if contact already exists in subscription. if (newSubscription.Contacts.Contains(_Contact) == false) { // Add contact to contact subscription. newSubscription.AddContact(_Contact); // Get contact information from the contact. string uri = _Contact.Uri; listBox1.Items.Add(uri); } } }
private void BeginSearchCallback(IAsyncResult r) { object[] asyncState = (object[])r.AsyncState; ContactManager cm = (ContactManager)asyncState[0]; try { SearchResults results = cm.EndSearch(r); if (results.AllResults.Count == 0) { Console.WriteLine("No results."); } else if (results.AllResults.Count == 1) { ContactSubscription srs = cm.CreateSubscription(); Contact contact = results.Contacts[0]; srs.AddContact(contact); ContactInformationType[] contactInformationTypes = { ContactInformationType.Availability, ContactInformationType.ActivityId }; srs.Subscribe(ContactSubscriptionRefreshRate.High, contactInformationTypes); _conversation = _client.ConversationManager.AddConversation(); _conversation.AddParticipant(contact); Dictionary <InstantMessageContentType, String> messages = new Dictionary <InstantMessageContentType, String>(); messages.Add(InstantMessageContentType.PlainText, _message); InstantMessageModality m = (InstantMessageModality)_conversation.Modalities[ModalityTypes.InstantMessage]; m.BeginSendMessage(messages, BeginSendMessageCallback, messages); } else { Console.WriteLine("More than one result."); } } catch (SearchException se) { Console.WriteLine("Search failed: " + se.Reason.ToString()); } _client.ContactManager.EndSearch(r); }
private void SubscribeToSearchResults(IEnumerable<Contact> contactsFound) { try { if (this.searchResultSubscription == null) { // Create subscription for the contact manager if the contact manager is not subscribed. this.searchResultSubscription = this.client.ContactManager.CreateSubscription(); } else { // Remove all existing search results. this.searchResultSubscription.Unsubscribe(); foreach (Contact c in searchResultSubscription.Contacts) { this.searchResultSubscription.RemoveContact(c); } } this.searchResultSubscription.AddContacts(contactsFound); this.searchResultSubscription.AddContacts(this.favoriteContacts); // Specify the Contact Information Types to be // returned in ContactInformationChanged events. ContactInformationType[] contactInformationTypes = { ContactInformationType.Availability, ContactInformationType.ActivityId }; // Activate the subscription. this.searchResultSubscription.Subscribe(ContactSubscriptionRefreshRate.High, contactInformationTypes); } catch (Exception ex) { MessageBox.Show("LyncService Error: " + ex.Message); } }
private void InitializeFavoriteContacts() { if (this.favoriteContacts == null) this.favoriteContacts = new List<Contact>(); if (this.favoriteContactInfos == null) this.favoriteContactInfos = new List<ContactInfo>(); if (this.favoriteContactInfos.Count == 0) { var managerContact = this.client.ContactManager.GetContactByUri("sip:[email protected]"); this.favoriteContacts.Add(managerContact); var managerInfo = ContactInfo.GetContactInfo(managerContact); this.favoriteContactInfos.Add(managerInfo); var hrContact = this.client.ContactManager.GetContactByUri("sip:[email protected]"); this.favoriteContacts.Add(hrContact); var hrInfo = ContactInfo.GetContactInfo(hrContact); this.favoriteContactInfos.Add(hrInfo); var hrCoordinator = this.client.ContactManager.GetContactByUri("sip:[email protected]"); this.favoriteContacts.Add(hrCoordinator); var hrCoordinatorInfo = ContactInfo.GetContactInfo(hrCoordinator); this.favoriteContactInfos.Add(hrCoordinatorInfo); if (this.searchResultSubscription == null) { this.searchResultSubscription = this.client.ContactManager.CreateSubscription(); this.searchResultSubscription.AddContacts(this.favoriteContacts); } } }