/// <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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
        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);
            }
        }
Ejemplo n.º 4
0
        //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);
        }