//Click handler for Add button private void btnAdd_Click(object sender, EventArgs e) { string groupName = txtBoxAdd.Text; contactManager.GroupAdded += new EventHandler <GroupCollectionChangedEventArgs>(contactManager_GroupAdded); AsyncCallback callback = new AsyncCallback(BeginAddGroupComplete); contactManager.BeginAddGroup(groupName, BeginAddGroupComplete, null); }
//event handler adds a "Sample" group private void button1_Click(object sender, RoutedEventArgs e) { string groupName = "Sample"; contactManager.GroupAdded += new EventHandler <GroupCollectionChangedEventArgs>(contactManager_GroupAdded); AsyncCallback callback = new AsyncCallback(BeginAddGroupComplete); contactManager.BeginAddGroup(groupName, BeginAddGroupComplete, null); }
//button 1 click event handler //create a custom group called 'sample' private void button1_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Adding custom group.."); try { client = LyncClient.GetClient(); contactManager = client.ContactManager; listBox1.SelectionMode = SelectionMode.Multiple; string groupName = "Sample"; contactManager.GroupAdded += new EventHandler <GroupCollectionChangedEventArgs>(contactManager_GroupAdded); AsyncCallback callback = new AsyncCallback(BeginAddGroupComplete); contactManager.BeginAddGroup(groupName, BeginAddGroupComplete, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddCustomGroupButton_Click(object sender, RoutedEventArgs e) { string groupName = CustomGroupNameTextBox.Text.Trim(); if (!String.IsNullOrWhiteSpace(groupName)) { foreach (GroupInfo gi in Groups) { if (gi.GroupName.Equals(groupName, StringComparison.InvariantCultureIgnoreCase)) { MessageBox.Show( string.Format("Group \"{0}\" is already in the contact list. You cannot add it now.", groupName), "Failed adding custom group", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } ContactManager.BeginAddGroup(CustomGroupNameTextBox.Text.Trim(), AddGroup_Callback, null); } }
public static void ImportContacts(LyncClient _client) { ContactManager _contactManager = _client.ContactManager; XmlDocument doc = new XmlDocument(); if (!File.Exists("BuddyList.xml")) { Console.WriteLine("BuddyList.xml does not exist."); Environment.Exit(0); } doc.Load("BuddyList.xml"); XmlElement root = doc.DocumentElement; XmlNodeList groups = root.SelectNodes("ContactGroup"); GroupCollection current_groups = _contactManager.Groups; var current_group_colelction = new List <string>(); foreach (Group group in current_groups) { current_group_colelction.Add(group.Name); } foreach (XmlNode group in groups) { String group_name = group.ChildNodes.Item(0).FirstChild.Value; String group_type = group.Attributes.GetNamedItem("type").InnerText; if (group_type == "DistributionGroup") { _contactManager.BeginSearch( group_name, (ar) => { SearchResults searchResults = _contactManager.EndSearch(ar); if (searchResults.Groups.Count > 0) { Console.WriteLine(searchResults.Groups.Count.ToString() + " found"); foreach (Group dg in searchResults.Groups) { Console.WriteLine(System.Environment.NewLine + dg.Name); DistributionGroup dGroup = dg as DistributionGroup; if (!current_groups.Contains(dGroup)) { if (group_name == dGroup.Name) { _contactManager.BeginAddGroup(dGroup, null, null); } } } } else { Console.WriteLine("No groups found for search on " + group_name); } }, null); } else if (group_type == "FavoriteContacts" || group_type == "FrequentContacts") { //skip Favourites as it always exists continue; } else { //handle custom groups and favourites normally //check first if group exists or error if (!current_group_colelction.Contains(group_name)) { //continue to adding new group _contactManager.BeginAddGroup(group_name, null, null); Console.WriteLine(group_name + " created."); } else { //show message and do not try to create group Console.WriteLine(group_name + " already exists."); } } } //add the contacts to each group of typer Custom or Favourites System.Threading.Thread.Sleep(2000); Console.WriteLine("Importing contacts..."); foreach (XmlNode group in groups) { if (group.Attributes.GetNamedItem("type").InnerText != "DistributionGroup") { foreach (Group igroup in current_groups) { if (igroup.Name == group.ChildNodes.Item(0).FirstChild.Value) { Console.WriteLine(igroup.Name + " - " + igroup.Type.ToString()); //add contacts foreach (XmlNode contact in group.ChildNodes.Item(1).ChildNodes) { Console.WriteLine(contact.InnerText); Contact c = _contactManager.GetContactByUri(contact.InnerText); if (!igroup.Contains(c)) { igroup.BeginAddContact(c, null, null); } } } } } } Console.WriteLine("Finished import."); }