Ejemplo n.º 1
0
        public void SetMetadata(Dictionary <PhysicalAddress, List <IPAddress> > metadata)
        {
            foreach (KeyValuePair <PhysicalAddress, List <IPAddress> > entry in metadata)
            {
                List <IPAddress> addresses   = entry.Value;
                PhysicalAddress  mac         = entry.Key;
                string           registryKey = mac.ToString();

                List <string>    registryKeys         = registryWriter.GetMultiStringValue(registryKey);
                List <IPAddress> registryForwardedIps = registryKeys.ConvertAll <IPAddress>(ConvertStringToIpAddress);
                List <IPAddress> addressesConfigured  = AddressSystemReader.GetAddresses();
                List <IPAddress> toAdd                = new List <IPAddress>(addresses.Except(addressesConfigured));
                List <IPAddress> toRemove             = new List <IPAddress>(registryForwardedIps.Except(addresses));
                List <string>    metadataStrings      = addresses.ConvertAll <string>(ip => ip.ToString());
                List <string>    toRemoveFromRegistry = new List <string>(registryKeys.Except(metadataStrings));
                List <string>    toAddToRegistry      = new List <string>(metadataStrings.Except(registryKeys));
                LogForwardedIpsChanges(mac, addressesConfigured, addresses, toAdd, toRemove);
                AddAddresses(toAdd, mac);
                RemoveAddresses(toRemove, mac);
                registryWriter.RemoveMultiStringValues(registryKey, toRemoveFromRegistry);
                foreach (string address in toAddToRegistry)
                {
                    registryWriter.AddMultiStringValue(mac.ToString(), address.ToString());
                }
            }
        }
        public void SetMetadata(List <IPAddress> metadata)
        {
            List <string>    registryKeys         = registryWriter.GetMultiStringValue(RegistryKey);
            List <IPAddress> registryForwardedIps = registryKeys.ConvertAll <IPAddress>(ConvertStringToIpAddress);
            List <IPAddress> addressesConfigured  = AddressSystemReader.GetAddresses();
            List <IPAddress> toAdd                = new List <IPAddress>(metadata.Except(addressesConfigured));
            List <IPAddress> toRemove             = new List <IPAddress>(registryForwardedIps.Except(metadata));
            List <string>    metadataStrings      = metadata.ConvertAll <string>(ip => ip.ToString());
            List <string>    toRemoveFromRegistry = new List <string>(registryKeys.Except(metadataStrings));

            LogForwardedIpsChanges(addressesConfigured, metadata, toAdd, toRemove);
            AddAddresses(toAdd);
            RemoveAddresses(toRemove);
            registryWriter.RemoveMultiStringValues(RegistryKey, toRemoveFromRegistry);
        }