Example #1
0
        public async Task DisconnectAsync()
        {
            Log.Information("VPN Disconnecting");
            _cts.Cancel();
            await _disconnected.Task;

            VpnApi.DeleteEntry(EntryName);
        }
Example #2
0
        private async Task <IntPtr> ReconnectAsync(VpnData vpnData, CancellationToken cancellationToken)
        {
            var connection = VpnApi.GetConnections().FirstOrDefault(s => s.szEntryName == EntryName);

            if (connection.szEntryName == EntryName && connection.hrasconn != IntPtr.Zero)
            {
                var state = VpnApi.GetState(connection.hrasconn);
                if (state.connectionState == RasConnectionState.Connected)
                {
                    Log.Information("Vpn is already connected");
                    return(connection.hrasconn);
                }
                else
                {
                    Log.Information($"Vpn is active but state is '{state.connectionState}'");
                    await HangUpAsync(connection.hrasconn);
                }
            }

            var entries = VpnApi.GetEntryNames();

            var myEntry = entries.FirstOrDefault(s => s.szEntryName == EntryName);

            if (myEntry.szEntryName == EntryName)
            {
                Log.Information($"VPN removing entry");
                VpnApi.DeleteEntry(EntryName);
            }

            CreateEntry(vpnData);

            var id = await DialAsync(vpnData, cancellationToken);

            //var info = VpnApi.GetProjectionInfoEx(id);

            return(id);
        }