8 Replies - 683 Views - Last Post: 26 August 2011 - 06:16 AM Rate Topic: -----

#1 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

How to compare list with master list and add or remove

Posted 25 August 2011 - 09:38 AM

Hey everyone. Can you point me in the right direction for comparing 2 lists? I've only found info on how to compare 2 lists and find the differences. I need to be able to compare a 2nd list to a Master list and either add or remove members to that 2nd list. So if the Master list has the member in it and it's not in the 2nd list, add it to the 2nd list. And if it's in the 2nd list but not in the Master list, remove it from the 2nd list.

Any ideas?

Thanks for any help!!!

Dave

Sorry, I should have mentioned, the lists contain numbers and will be sorted.

Dave

Is This A Good Question/Topic? 0
  • +

Replies To: How to compare list with master list and add or remove

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 09:39 AM

Could you provide a simple example of what your trying to do?
Was This Post Helpful? 0
  • +
  • -

#3 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 09:43 AM

Sure!!

MasterList
12
13
18
22
27
30

2nd List
12
13
14
22
27
30

The MasterList is the "Master List" and the 2nd list needs to match the Master List. I need to remove "14" and add "18" to the 2nd list.

Thanks for your help!!

Dave
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 10:08 AM

What version of .Net? There are a number of LINQ extension methods that will give you all of the items that are different between two lists, the same between two lists, items that are in one list but not in another. But these would only be available in .Net 3.5 and higher(possibly 3.0).
Was This Post Helpful? 0
  • +
  • -

#5 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 10:20 AM

I'm using 4.0...
Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 10:34 AM

You can use the Intersect method to determine items that are in both list.

You can use the Union method to create a new list of unique values of two lists.

You can use the Except method to create a new list of values that is in the first list but not in the second list.

There are a number of LINQ extension methods for Enumerable types. Here is a list of them.

http://msdn.microsof...le_methods.aspx

They may come in handy for what you are trying to do.
Was This Post Helpful? 1
  • +
  • -

#7 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 10:37 AM

With the above post you should be able to figure it out. If you need more help, post away. :)
Was This Post Helpful? 0
  • +
  • -

#8 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Re: How to compare list with master list and add or remove

Posted 25 August 2011 - 10:38 AM

Sweet!! Thanks for the help guys!!

Dave
Was This Post Helpful? 0
  • +
  • -

#9 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Re: How to compare list with master list and add or remove

Posted 26 August 2011 - 06:16 AM

Ok...just to be sure I'm heading in the right direction, I figured I'd post what I've figured out. But first, maybe some advice? This whole concept is that our Active Directory is the master list, and an LDAP file for our voice mail system is the "slave" list. There are a few voicemail groups that need to match the AD groups, and so far it's a manual process. The LDAP file is what needs to be edited. The easy way to do this, which I've figured out, is to use the "clear" command on the voicemail list. This clears out the entire list as opposed to removing each person from the list 1 at a time. This is pretty fast...maybe 2 seconds to clear out a list of 13 people. Then I just take everyone in the AD group and shove them into the voicemail list in the LDAP file. All done in 2 shakes of a lambs tail. For some reason, the clear command scares me. I'm having visions of my code runnig through the clear command, and then for whatever reason, fire earthquake or flood, my app crashes and I'm left with an empty voicemail list. Needless to say, that would not be looked favorably upon by my Management. So, what I thought I'd do is compare the 2 lists, only removing people who shouldn't be in it, and adding people who aren't already in it. From what I've found, I would have to do this in 2 parts. How I'm doint it is I get a list of people in AD, then I get a list of people in the voicemail list. I then loop through like so:

            lbADMembers.Items.Clear();
            string myADGroup = tbADGroup.Text;

            var rep = new ActiveDirectoryRepository<BankerData>();
            var users = rep.GetUsersInGroup(myADGroup);

            UCAdminServiceClient sc = new UCAdminServiceClient();

            EnhancedListsService.MMInfo st = sc.MMGetMMInfo("95000");
            string myEListGuid = st.Guid;
            //ff95993c9f5e11db89c6000423c71c19 = List 95000 "Test ELA 2"
            //a3645f22839f11de818d000e0ceaee19 = Dave

            List<string> myExtensions = new List<string>();

            foreach (var dude in users)
            {
                if (dude.Phone != null)
                {
                    string mainString = dude.Phone;
                    string newString = mainString.Substring(8, 6);
                    string finalString = newString.Replace("-", "");

                    EnhancedListsService.MMInfo st2 = sc.MMGetMMInfo(finalString);

                    myExtensions.Add(st2.Extension);
                }
            }

            string myBox = "95000";

            Members[] myMems = sc.MMGetAllEnhancedListMembers(myBox);

            foreach (var z in myMems)
            {
                string myChecker = z.ehExtension;
                string myVerifierGuid = z.ehGuid;
                int myVerifier = myExtensions.IndexOf(myChecker);
                if (myVerifier == -1)
                {
                    //add code to remove station from enhanced list here!!
                    EnhancedListsService.MMInfo ls = sc.MMRemoveUserFromEnhancedList(myVerifierGuid, myEListGuid);
                }
                else
                {

                }
            }
        }


It's a bit more complex than it needs to be because the AD groups have 5 digit extensions, and the LDAP file has a guid. I need to find the guid of each 5 digit extension before I can add it to the ldap group. Anyway, once I'm done looping through and removing those that don't belong, I'll need to loop through again and add those that aren't in it. The above loop takes about 15 seconds, and there's about 13 people in the group to check. This is a much much smaller group than I will eventually be checking. The groups can be up to 400 people. I'm worried that this can take waaaay too long to run.

Having said all that, is there any reason I should be afraid of using the clear command on an LDAP group? Any ideas how I could safeguard that?

Thanks for any input!!!

Dave
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1