Beispiel #1
0
        public Task ConnectAsync(
            IVpnEndpoint vpnEndpoint,
            Dictionary <string, object> parameters,
            CancellationToken cancellationToken
            )
        {
            if (vpnEndpoint == null)
            {
                throw new ArgumentNullException(nameof(vpnEndpoint));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (!parameters.ContainsKey("username"))
            {
                throw new ArgumentException($"{nameof(parameters)} does not contain key \"username\"");
            }

            if (!parameters.ContainsKey("password"))
            {
                throw new ArgumentException($"{nameof(parameters)} does not contain key \"password\"");
            }

            if (!parameters.ContainsKey("IpSecConnectionName"))
            {
                throw new ArgumentException($"{nameof(parameters)} does not contain key \"IpSecConnectionName\"");
            }

            var ipAddress = vpnEndpoint.IpAddress;

            if (String.IsNullOrEmpty(ipAddress))
            {
                throw new ArgumentException("ipAddress is null or empty string");
            }

            var username = (string)parameters["username"];

            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentException("username is null or empty string");
            }

            var password = (string)parameters["password"];

            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("password is null or empty string");
            }

            var ipSecConnectionName = (string)parameters["IpSecConnectionName"];

            if (String.IsNullOrEmpty(ipSecConnectionName))
            {
                throw new ArgumentException("IpSecConnectionName is null or empty string");
            }

            this._vpnConnectionName = ipSecConnectionName;

            this.VpnConnectionBind();
            var rasEntry = this.IpSecRasEntryGet(ipSecConnectionName);

            this._rasDialer.PhoneNumber   = ipAddress;
            this._rasDialer.EntryName     = ipSecConnectionName;
            this._rasDialer.PhoneBookPath = IpSecClient._phoneBookPath;
            this._rasDialer.Credentials   = new System.Net.NetworkCredential(username, password);

            this._taskCompletionSource = new TaskCompletionSource <object>();

            var rasHandle = this._rasDialer.DialAsync();

            return(this._taskCompletionSource.Task);
        }
Beispiel #2
0
        public Task ConnectAsync(
            IVpnEndpoint vpnEndpoint, 
            Dictionary<string, object> parameters, 
            CancellationToken cancellationToken
        )
        {
            if (vpnEndpoint == null)
            {
                throw new ArgumentNullException(nameof(vpnEndpoint));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (!parameters.ContainsKey("username"))
            {
                throw new ArgumentException($"{nameof(parameters)} does not contain key \"username\"");
            }

            if (!parameters.ContainsKey("password"))
            {
                throw new ArgumentException($"{nameof(parameters)} does not contain key \"password\"");
            }

            if (!parameters.ContainsKey("IpSecConnectionName"))
            {
                throw new ArgumentException($"{nameof(parameters)} does not contain key \"IpSecConnectionName\"");
            }

            var ipAddress = vpnEndpoint.IpAddress;

            if (String.IsNullOrEmpty(ipAddress))
            {
                throw new ArgumentException("ipAddress is null or empty string");
            }

            var username = (string)parameters["username"];
            
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentException("username is null or empty string");
            }

            var password = (string)parameters["password"];

            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("password is null or empty string");
            }

            var ipSecConnectionName = (string)parameters["IpSecConnectionName"];

            if (String.IsNullOrEmpty(ipSecConnectionName))
            {
                throw new ArgumentException("IpSecConnectionName is null or empty string");
            }

            this._vpnConnectionName = ipSecConnectionName;

            this.VpnConnectionBind();
            var rasEntry = this.IpSecRasEntryGet(ipSecConnectionName);

            this._rasDialer.PhoneNumber = ipAddress;
            this._rasDialer.EntryName = ipSecConnectionName;
            this._rasDialer.PhoneBookPath = IpSecClient._phoneBookPath;
            this._rasDialer.Credentials = new System.Net.NetworkCredential(username, password);

           this._taskCompletionSource = new TaskCompletionSource<object>();
            
            var rasHandle = this._rasDialer.DialAsync();
            return this._taskCompletionSource.Task;
        }