예제 #1
0
        public void Load()
        {
            _interfaces = InterfaceManagement.GetValidInterface();

            using (var profile = File.OpenRead(Profile.PATH))
            {
                _profiles = new DataContractJsonSerializer(typeof(List <Profile>)).ReadObject(profile) as List <Profile>;
                foreach (var item in _profiles)
                {
                    if (string.IsNullOrWhiteSpace(item.Mask))
                    {
                        item.Mask = "255.255.255.0";
                    }
                    if (!item.StaticAddress)
                    {
                        item.Address = "DHCP";
                        item.Gateway = "DHCP";
                        item.Mask    = "";
                    }
                    if (!item.StaticDns)
                    {
                        item.DnsServer = "DHCP";
                    }
                }
            }
        }
예제 #2
0
        private string apply()
        {
            string message = "Succeed!", output = "\r\n";

            var currentProfile = profileList.SelectedItem as Data.Profile;
            var currentInterface = interfaceList.SelectedItem as NetworkInterface;

            if (currentProfile.StaticDns)
            {
                output = InterfaceManagement.SetStaticDns(currentInterface, currentProfile.DnsServer);
                if (output != "\r\n")
                {
                    message = output;
                    return message;
                }
            }
            else
            {
                output = InterfaceManagement.SetDhcpDns(currentInterface);
                if (output != "\r\n")
                {
                    message = output;
                    return message;
                }
            }

            if (currentProfile.StaticAddress)
            {
                output = InterfaceManagement.SetStaticAddress(currentInterface, currentProfile.Address, currentProfile.Gateway, currentProfile.Mask);
                if (output != "\r\n")
                {
                    message = output;
                    return message;
                }
            }
            else
            {
                output = InterfaceManagement.SetDhcpAddress(currentInterface);
                if (output != "\r\n")
                {
                    message = output;
                    return message;
                }
            }

            return message;
        }