Exemple #1
2
        public void NewRasEntry()
        {
            ReadOnlyCollection<RasDevice> devices = RasDevice.GetDevices();

            foreach (RasDevice modem in devices)
            {
                if (modem.Name.ToLower().Contains("(pptp)"))
                {
                    this.rDevice = modem;
                }
            }

            newRas = RasEntry.CreateVpnEntry(entryName, entryAddress, RasVpnStrategy.PptpOnly, rDevice, false);

            newRas.Options.RemoteDefaultGateway = false;
            newRas.Options.IPv6RemoteDefaultGateway = false;
            newRas.NetworkProtocols.IPv6 = false;
            newRas.IdleDisconnectSeconds = 10;
            newRas.Options.RequireMSChap2 = true;

            newRas.Options.Internet = false;

            newRas.Options.UseLogOnCredentials = true;

            NetworkCredential cred = new NetworkCredential();
            cred.UserName = this.entryUsername;
            cred.Password = this.entrySecret;

            Data.Pbk.Entries.Add(newRas);
            Data.Pbk.Entries[Data.Pbk.Entries.Last().Name].UpdateCredentials(cred);
        }
Exemple #2
0
        public void RasEntryConstructorTest()
        {
            string name = "Test Entry";

            RasEntry target = new RasEntry(name);

            Assert.AreEqual(name, target.Name);
        }
Exemple #3
0
        public static void Dial(Contact contact)
        {
            RasPhoneBook phoneBook = new RasPhoneBook();

            phoneBook.Open();

            if (!phoneBook.Entries.Contains(networkConnectionName))
            {
                DotRas.RasEntry entry = RasEntry.CreateDialUpEntry(networkConnectionName, contact.number, RasDevice.GetDeviceByName("Modem", RasDeviceType.Modem, false));
                phoneBook.Entries.Add(entry);
            }

            RasDialer dialer = new RasDialer();

            phoneBook.Entries[networkConnectionName].PhoneNumber = contact.number;
            phoneBook.Entries[networkConnectionName].Update();
            dialer.EntryName      = networkConnectionName;
            dialer.DialCompleted += new EventHandler <DialCompletedEventArgs>(Dialer.dialer_DialCompleted);
            dialer.StateChanged  += new EventHandler <StateChangedEventArgs>(Dialer.dialer_StateChanged);
            TargetDotRas.dialer   = dialer;

            dialer.DialAsync(new System.Net.NetworkCredential(networkCredentialUsername, networkCredentialPassword));
        }
Exemple #4
0
        public void ChannelsTest()
        {
            string name = "Test Entry";
            int expected = int.MaxValue;

            RasEntry target = new RasEntry(name);
            target.Channels = expected;

            int actual = target.Channels;

            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void IdleDisconnectSecondsTest()
        {
            string name = "Test Entry";
            int expected = RasIdleDisconnectTimeout.Disabled;

            RasEntry target = new RasEntry(name);
            target.IdleDisconnectSeconds = expected;

            int actual = target.IdleDisconnectSeconds;

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        /// <summary>
        /// Creates a new virtual private network (VPN) entry.
        /// </summary>
        /// <param name="name">The name of the entry.</param>
        /// <param name="serverAddress">The server address to connect to.</param>
        /// <param name="strategy">The virtual private network (VPN) strategy of the connection.</param>
        /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
        /// <param name="useRemoteDefaultGateway"><b>true</b> if the connection should use the remote default gateway, otherwise <b>false</b>.</param>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        /// <remarks>The device for this connection is typically a WAN Miniport (L2TP) or WAN Miniport (PPTP).</remarks>
        /// <exception cref="System.ArgumentException"><paramref name="name"/> or <paramref name="serverAddress"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasEntry CreateVpnEntry(string name, string serverAddress, RasVpnStrategy strategy, RasDevice device, bool useRemoteDefaultGateway)
        {
            if (string.IsNullOrEmpty(name))
            {
                ThrowHelper.ThrowArgumentException("name", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (string.IsNullOrEmpty(serverAddress))
            {
                ThrowHelper.ThrowArgumentException("serverAddress", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (device == null)
            {
                ThrowHelper.ThrowArgumentNullException("device");
            }

            RasEntry entry = new RasEntry(name);

            entry.Device = device;
            entry.EncryptionType = RasEncryptionType.Require;
            entry.EntryType = RasEntryType.Vpn;
            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.NetworkProtocols.IP = true;
            entry.Options.ModemLights = true;

#if (WIN7 || WIN8)
            if (strategy == RasVpnStrategy.IkeV2First || strategy == RasVpnStrategy.IkeV2Only)
            {
                entry.Options.RequireDataEncryption = true;
                entry.Options.RequireEap = true;
                entry.Options.RequireEncryptedPassword = false;
            }
            else
            {
                entry.Options.RequireEncryptedPassword = true;
            }
#else
            entry.Options.RequireEncryptedPassword = true;
#endif

            entry.Options.PreviewUserPassword = true;
            entry.Options.PreviewDomain = true;
            entry.Options.ShowDialingProgress = true;

            if (useRemoteDefaultGateway)
            {
                entry.Options.RemoteDefaultGateway = true;

#if (WIN2K8 || WIN7 || WIN8)
                entry.Options.IPv6RemoteDefaultGateway = true;
#endif
            }

#if (WINXP || WIN2K8 || WIN7 || WIN8)
            entry.RedialCount = 3;
            entry.RedialPause = 60;

            entry.Options.DoNotNegotiateMultilink = true;
            entry.Options.ReconnectIfDropped = true;
#endif
#if (WIN2K8 || WIN7 || WIN8)
            entry.Options.UseTypicalSettings = true;
            entry.NetworkProtocols.IPv6 = true;
#endif
            entry.PhoneNumber = serverAddress;
            entry.VpnStrategy = strategy;

            return entry;
        }
Exemple #7
0
        public void IPv6AddressTest()
        {
            string name = "Test Entry";
            IPAddress expected = IPAddress.IPv6Loopback;

            RasEntry target = new RasEntry(name);
            target.IPv6Address = expected;

            IPAddress actual = target.IPv6Address;

            Assert.AreEqual(expected, actual);
        }
Exemple #8
0
        public void NetworkOutageTimeTest()
        {
            string name = "Test Entry";
            int expected = 1000;

            RasEntry target = new RasEntry(name);
            target.NetworkOutageTime = expected;

            int actual = target.NetworkOutageTime;

            Assert.AreEqual(expected, actual);
        }
Exemple #9
0
        public void DnsAddressAltTest()
        {
            string name = "Test Entry";
            IPAddress expected = IPAddress.Loopback;

            RasEntry target = new RasEntry(name);
            target.DnsAddressAlt = expected;

            IPAddress actual = target.DnsAddressAlt;

            Assert.AreEqual(expected, actual);
        }
Exemple #10
0
        public void AreaCodeTest()
        {
            string name = "Test Entry";
            string expected = "123";

            RasEntry target = new RasEntry(name);
            target.AreaCode = expected;

            string actual = target.AreaCode;

            Assert.AreEqual(expected, actual);
        }
Exemple #11
0
        public void FrameSizeTest()
        {
            string name = "Test Entry";
            int expected = int.MaxValue;

            RasEntry target = new RasEntry(name);
            target.FrameSize = expected;

            int actual = target.FrameSize;

            Assert.AreEqual(expected, actual);
        }
Exemple #12
0
        public void EncryptionTypeTest()
        {
            string name = "Test Entry";
            RasEncryptionType expected = RasEncryptionType.Require;

            RasEntry target = new RasEntry(name);
            target.EncryptionType = expected;

            RasEncryptionType actual = target.EncryptionType;

            Assert.AreEqual(expected, actual);
        }
Exemple #13
0
        public void FramingProtocolTest()
        {
            string name = "Test Entry";
            RasFramingProtocol expected = RasFramingProtocol.Ppp;

            RasEntry target = new RasEntry(name);
            target.FramingProtocol = expected;

            RasFramingProtocol actual = target.FramingProtocol;

            Assert.AreEqual(expected, actual);
        }
Exemple #14
0
        public void HangUpExtraSampleSecondsTest()
        {
            string name = "Test Entry";
            int expected = int.MaxValue;

            RasEntry target = new RasEntry(name);
            target.HangUpExtraSampleSeconds = expected;

            int actual = target.HangUpExtraSampleSeconds;

            Assert.AreEqual(expected, actual);
        }
Exemple #15
0
        public void IdTest()
        {
            string name = "Test Entry";
            Guid expected = Guid.NewGuid();

            RasEntry target = new RasEntry(name);
            target.Id = expected;

            Guid actual = target.Id;

            Assert.AreEqual(expected, actual);
        }
Exemple #16
0
        public void AutoDialDllTest()
        {
            string name = "Test Entry";
            string expected = "Test.dll";

#pragma warning disable 0618
            RasEntry target = new RasEntry(name);
            target.AutoDialDll = expected;

            string actual = target.AutoDialDll;
#pragma warning restore 0618

            Assert.AreEqual(expected, actual);
        }
Exemple #17
0
        public void DialModeTest()
        {
            string name = "Test Entry";
            RasDialMode expected = RasDialMode.DialAsNeeded;

            RasEntry target = new RasEntry(name);
            target.DialMode = expected;

            RasDialMode actual = target.DialMode;

            Assert.AreEqual(expected, actual);
        }
Exemple #18
0
        public void RasEntryConstructorArgumentExceptionTest()
        {
            string name = string.Empty;

            RasEntry target = new RasEntry(name);
        }
Exemple #19
0
        public void DialExtraPercentTest()
        {
            string name = "Test Entry";
            int expected = int.MaxValue;

            RasEntry target = new RasEntry(name);
            target.DialExtraPercent = expected;

            int actual = target.DialExtraPercent;

            Assert.AreEqual(expected, actual);
        }
Exemple #20
0
        public void AlternatePhoneNumbersTest()
        {
            string name = "Test Entry";
            Collection<string> expected = new Collection<string>();
            expected.Add("555-555-1234");
            expected.Add("555-555-2345");

            RasEntry target = new RasEntry(name);
            target.AlternatePhoneNumbers = expected;

            Collection<string> actual = target.AlternatePhoneNumbers;

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #21
0
        public void UpdateCredentialsInvalidOperationExceptionTest()
        {
            string name = "Test Entry";

            RasEntry target = new RasEntry(name);
            target.UpdateCredentials(new NetworkCredential("Test", "User"));
        }
Exemple #22
0
        public void IPv6PrefixLengthTest()
        {
            string name = "Test Entry";
            int expected = 10;

            RasEntry target = new RasEntry(name);
            target.IPv6PrefixLength = expected;

            int actual = target.IPv6PrefixLength;

            Assert.AreEqual(expected, actual);
        }
Exemple #23
0
        /// <summary>
        /// Creates a copy of this object.
        /// </summary>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        public object Clone()
        {
            RasEntry retval = new RasEntry(this.Name);

            if (this.AlternatePhoneNumbers != null && this.AlternatePhoneNumbers.Count > 0)
            {
                retval.AlternatePhoneNumbers = new Collection<string>();
                foreach (string value in this.AlternatePhoneNumbers)
                {
                    retval.AlternatePhoneNumbers.Add(value);
                }
            }

            retval.AreaCode = this.AreaCode;

#pragma warning disable 0618
            retval.AutoDialDll = this.AutoDialDll;
            retval.AutoDialFunc = this.AutoDialFunc;
#pragma warning restore 0618

            retval.Channels = this.Channels;
            retval.CountryCode = this.CountryCode;
            retval.CountryId = this.CountryId;
            retval.CustomAuthKey = this.CustomAuthKey;
            retval.CustomDialDll = this.CustomDialDll;
            retval.Device = this.Device;
            retval.DialExtraPercent = this.DialExtraPercent;
            retval.DialExtraSampleSeconds = this.DialExtraSampleSeconds;
            retval.DialMode = this.DialMode;
            retval.DnsAddress = this.DnsAddress;
            retval.DnsAddressAlt = this.DnsAddressAlt;
            retval.EncryptionType = this.EncryptionType;
            retval.EntryType = this.EntryType;
            retval.FrameSize = this.FrameSize;
            retval.FramingProtocol = this.FramingProtocol;
            retval.HangUpExtraPercent = this.HangUpExtraPercent;
            retval.HangUpExtraSampleSeconds = this.HangUpExtraSampleSeconds;
            retval.IdleDisconnectSeconds = this.IdleDisconnectSeconds;
            retval.IPAddress = this.IPAddress;
            retval.NetworkProtocols = this.NetworkProtocols;
            retval.Options = (RasEntryOptions)this.Options.Clone();
            retval.PhoneNumber = this.PhoneNumber;
            retval.Script = this.Script;

            if (this.SubEntries != null && this.SubEntries.Count > 0)
            {
                foreach (RasSubEntry subEntry in this.SubEntries)
                {
                    retval.SubEntries.Add((RasSubEntry)subEntry.Clone());
                }
            }

            retval.VpnStrategy = this.VpnStrategy;
            retval.WinsAddress = this.WinsAddress;
            retval.WinsAddressAlt = this.WinsAddressAlt;
            retval.X25Address = this.X25Address;
            retval.X25Facilities = this.X25Facilities;
            retval.X25PadType = this.X25PadType;
            retval.X25UserData = this.X25UserData;

#if (WINXP || WIN2K8 || WIN7 || WIN8)

            retval.DnsSuffix = this.DnsSuffix;
            retval.TcpWindowSize = this.TcpWindowSize;
            retval.PrerequisitePhoneBook = this.PrerequisitePhoneBook;
            retval.PrerequisiteEntryName = this.PrerequisiteEntryName;
            retval.RedialCount = this.RedialCount;
            retval.RedialPause = this.RedialPause;

#endif
#if (WIN2K8 || WIN7 || WIN8)

            retval.IPv6DnsAddress = this.IPv6DnsAddress;
            retval.IPv6DnsAddressAlt = this.IPv6DnsAddressAlt;
            retval.IPv4InterfaceMetric = this.IPv4InterfaceMetric;
            retval.IPv6InterfaceMetric = this.IPv6InterfaceMetric;

#endif
#if (WIN7 || WIN8)

            retval.IPv6Address = this.IPv6Address;
            retval.IPv6PrefixLength = this.IPv6PrefixLength;
            retval.NetworkOutageTime = this.NetworkOutageTime;

#endif

            return retval;
        }
Exemple #24
0
        public void RasEntryNullEntryNameConstructorTest()
        {
            string name = null;

            RasEntry target = new RasEntry(name);
        }
Exemple #25
0
        public void NameTest()
        {
            string expected = "Test Entry";

            RasEntry target = new RasEntry(expected);

            string actual = target.Name;

            Assert.AreEqual(expected, actual);
        }
Exemple #26
0
        public void UpdateCredentialsTest()
        {
            string name = "Test Entry";
            NetworkCredential credentials = new NetworkCredential("Test", "User");

            RasPhoneBook pbk = new RasPhoneBook();

            RasEntry target = new RasEntry(name);
            target.Owner = pbk;

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.SetCredentials(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<NativeMethods.RASCREDENTIALS>(), false)).Returns(true);

            bool result = target.UpdateCredentials(credentials);

            Assert.IsTrue(result);
        }
Exemple #27
0
        public void DeviceTest()
        {
            string name = "Test Entry";
            RasDevice expected = RasDevice.Create(name, RasDeviceType.Vpn);

            RasEntry target = new RasEntry(name);
            target.Device = expected;

            RasDevice actual = target.Device;

            Assert.AreEqual(expected, actual);
        }
Exemple #28
0
        /// <summary>
        /// Creates a new dial-up entry.
        /// </summary>
        /// <param name="name">The name of the entry.</param>
        /// <param name="phoneNumber">The phone number to dial.</param>
        /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        /// <exception cref="System.ArgumentException"><paramref name="name"/> or <paramref name="phoneNumber"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasEntry CreateDialUpEntry(string name, string phoneNumber, RasDevice device)
        {
            if (string.IsNullOrEmpty(name))
            {
                ThrowHelper.ThrowArgumentException("name", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (string.IsNullOrEmpty(phoneNumber))
            {
                ThrowHelper.ThrowArgumentException("phoneNumber", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (device == null)
            {
                ThrowHelper.ThrowArgumentNullException("device");
            }

            RasEntry entry = new RasEntry(name);

            entry.Device = device;
            entry.DialMode = RasDialMode.None;
            entry.EntryType = RasEntryType.Phone;
            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.IdleDisconnectSeconds = RasIdleDisconnectTimeout.Default;
            entry.NetworkProtocols.IP = true;

#if (WINXP || WIN2K8 || WIN7 || WIN8)
            entry.RedialCount = 3;
            entry.RedialPause = 60;
#endif
#if (WIN2K8 || WIN7 || WIN8)
            entry.NetworkProtocols.IPv6 = true;
#endif

            entry.PhoneNumber = phoneNumber;
            entry.VpnStrategy = RasVpnStrategy.Default;

            return entry;
        }
Exemple #29
0
        public void CustomDialDllTest()
        {
            string name = "Test Entry";
            string expected = "Test.dll";

            RasEntry target = new RasEntry(name);
            target.CustomDialDll = expected;

            string actual = target.CustomDialDll;

            Assert.AreEqual(expected, actual);
        }
Exemple #30
0
        /// <summary>
        /// Creates a new broadband entry.
        /// </summary>
        /// <param name="name">The name of the entry.</param>
        /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
        /// <param name="useRemoteDefaultGateway"><b>true</b> if the connection should use the remote default gateway, otherwise <b>false</b>.</param>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        /// <remarks>
        /// <para>
        /// The device for this connection is typically a WAN Miniport (PPPOE) device.
        /// </para>
        /// <para>
        /// <b>Windows XP and later: This method is supported.</b>
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentException"><paramref name="name"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasEntry CreateBroadbandEntry(string name, RasDevice device, bool useRemoteDefaultGateway)
        {
            if (string.IsNullOrEmpty(name))
            {
                ThrowHelper.ThrowArgumentException("name", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (device == null)
            {
                ThrowHelper.ThrowArgumentNullException("device");
            }

            RasEntry entry = new RasEntry(name);

            entry.Device = device;
            entry.EncryptionType = RasEncryptionType.Optional;
            entry.EntryType = RasEntryType.Broadband;
            entry.Options.SecureFileAndPrint = true;
            entry.Options.SecureClientForMSNet = true;
            entry.Options.DoNotNegotiateMultilink = true;
            entry.Options.DoNotUseRasCredentials = true;
            entry.Options.Internet = true;
            entry.Options.DisableNbtOverIP = true;
            entry.Options.ModemLights = true;
            entry.Options.SecureLocalFiles = true;
            entry.Options.RequirePap = true;
            entry.Options.PreviewUserPassword = true;
            entry.Options.ShowDialingProgress = true;
            entry.Options.RequireChap = true;
            entry.Options.RequireMSChap2 = true;
            entry.Options.ReconnectIfDropped = true;
            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.NetworkProtocols.IP = true;
            entry.PhoneNumber = string.Empty;
            entry.RedialCount = 3;
            entry.RedialPause = 60;

            if (useRemoteDefaultGateway)
            {
                entry.Options.RemoteDefaultGateway = true;

#if (WIN2K8 || WIN7 || WIN8)
                entry.Options.IPv6RemoteDefaultGateway = true;
#endif
            }

#if (WIN2K8 || WIN7 || WIN8)
            entry.NetworkProtocols.IPv6 = true;
#endif

            return entry;
        }
Exemple #31
0
        public void CustomAuthKeyTest()
        {
            string name = "Test Entry";
            int expected = int.MaxValue;

            RasEntry target = new RasEntry(name);
            target.CustomAuthKey = expected;

            int actual = target.CustomAuthKey;

            Assert.AreEqual(expected, actual);
        }