Ejemplo n.º 1
0
        public static IEnumerable<Connection> EnumerateConnections()
        {
            var activeConnections = RasConnection.GetActiveConnections();

            using (var phoneBook = new RasPhoneBook())
            {
                phoneBook.Open(PhoneBookPath);

                foreach (var e in phoneBook.Entries)
                {
                    var connection = new Connection(e)
                    {
                        Name = e.Name,
                        Status = RasConnectionState.Disconnected
                    };

                    var activeConnection = activeConnections.FirstOrDefault(a => a.EntryName == e.Name);
                    if (activeConnection != null)
                    {
                        connection.SetConnected(activeConnection);
                        connection.Status
                            = activeConnection.GetConnectionStatus().ConnectionState;
                    }

                    yield return connection;
                }
            }
        }
Ejemplo n.º 2
0
        private Result Transform(Connection connection)
        {
            var result = new Result
            {
                Title = connection.Name,
                IcoPath = "Images\\disconnect.png"
            };

            switch (connection.Status)
            {
                case RasConnectionState.Disconnected:
                    result.IcoPath = "Images\\connect.png";
                    result.SubTitle = "Connect to VPN";
                    result.Action = context =>
                    {
                        _context.API.StartLoadingBar();
                        connection.Connect();
                        _context.API.StopLoadingBar();
                        return true;
                    };
                    break;

                case RasConnectionState.Connected:
                    result.IcoPath = "Images\\disconnect.png";
                    result.SubTitle = "Disconnect from VPN";
                    result.Action = context =>
                    {
                        _context.API.StartLoadingBar();
                        connection.Disconnect();
                        _context.API.StopLoadingBar();
                        return true;
                    };
                    break;

                default:
                    result.SubTitle = "Status: " + connection.Status;
                    break;
            }
            return result;
        }