示例#1
0
        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);
        }
示例#2
0
        public void SetContact(string ContactURIorDN)
        {
            FreeContact();

            if (_LyncClient != null)
            {
                string ContactURI = string.Empty;

                if (_RegExDistinguishedName.IsMatch(ContactURIorDN))
                {
                    ContactURI = _GetContactURIByDistinguishedName(ContactURIorDN);
                }
                else
                {
                    ContactURI = ContactURIorDN;
                }

                try
                {
                    _Contact = _LyncClient.ContactManager.GetContactByUri(ContactURI);
                    _Contact.SettingChanged            += _ContactSettingChanged;
                    _Contact.ContactInformationChanged += _ContactInformationChanged;
                    _Contact.UriChanged += _ContactUriChanged;
                    _ContactSubscription.AddContact(_Contact);
                    _ContactSubscription.Subscribe(ContactSubscriptionRefreshRate.High, _ContactInformationList);

                    _GetContactInfo();
                }
                catch (LyncClientException e)
                {
                    FreeContact();
                    _LyncClientInitialization();
                    ClientSignIn();
                    // Console.WriteLine(e);
                }
                catch (SystemException systemException)
                {
                    if (_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;
                    }
                    FreeContact();
                }
            }
        }
示例#3
0
 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
     {
     }
 }
示例#4
0
        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);
        }
示例#5
0
        public void GetContactInfo(string ContactURI)
        {
            FreeContact();

            if (_LyncClient != null)
            {
                try
                {
                    _Contact = _LyncClient.ContactManager.GetContactByUri(ContactURI);
                    _Contact.SettingChanged            += _Contact_SettingChanged;
                    _Contact.ContactInformationChanged += _Contact_ContactInformationChanged;
                    _Contact.UriChanged += _Contact_UriChanged;
                    _ContactSubscription.AddContact(_Contact);
                    _ContactSubscription.Subscribe(ContactSubscriptionRefreshRate.High, _ContactInformationList);

                    _ContactName         = (string)_Contact.GetContactInformation(ContactInformationType.DisplayName);
                    _ContactAvailability = (int)(ContactAvailability)_Contact.GetContactInformation(ContactInformationType.Availability);
                }
                catch (LyncClientException e)
                {
                    FreeContact();
                    LyncClientInitialization(true);
                    // Console.WriteLine(e);
                }
                catch (SystemException systemException)
                {
                    if (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;
                    }
                    FreeContact();
                }
            }
        }
示例#6
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);
        }