Example #1
0
        public RasDisplay()
        {
            _mConnected = true;

            Rasconn lprasConn = new Rasconn();

            lprasConn.DwSize   = Marshal.SizeOf(typeof(Rasconn));
            lprasConn.Hrasconn = IntPtr.Zero;

            int lpcb           = 0;
            int lpcConnections = 0;
            int nRet           = 0;

            lpcb = Marshal.SizeOf(typeof(Rasconn));

            nRet = RasEnumConnections(ref lprasConn, ref lpcb, ref
                                      lpcConnections);

            if (nRet != 0)
            {
                _mConnected = false;
                return;
            }

            if (lpcConnections > 0)
            {
                //for (int i = 0; i < lpcConnections; i++)

                //{
                RasStats stats = new RasStats();

                _mConnectedRasHandle = lprasConn.Hrasconn;
                RasGetConnectionStatistics(lprasConn.Hrasconn, stats);


                _mConnectionName = lprasConn.SzEntryName;

                var hours   = ((stats.dwConnectionDuration / 1000) / 3600);
                var minutes = ((stats.dwConnectionDuration / 1000) / 60) - (hours * 60);
                var seconds = ((stats.dwConnectionDuration / 1000)) - (minutes * 60) - (hours * 3600);


                _mDuration = hours + " hours " + minutes + " minutes " + seconds + " secs";
                _mTx       = stats.dwBytesXmited;
                _mRx       = stats.dwBytesRcved;
                //}
            }
            else
            {
                _mConnected = false;
            }


            int lpNames       = 1;
            var entryNameSize = 0;
            int lpSize        = 0;

            RasEntryName[] names = null;

            entryNameSize = Marshal.SizeOf(typeof(RasEntryName));
            lpSize        = lpNames * entryNameSize;

            names           = new RasEntryName[lpNames];
            names[0].dwSize = entryNameSize;

            uint retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);

            //if we have more than one connection, we need to do it again
            if (lpNames > 1)
            {
                names = new RasEntryName[lpNames];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i].dwSize = entryNameSize;
                }

                retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);
            }
            _mConnectionNames = new string[names.Length];


            if (lpNames > 0)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    _mConnectionNames[i] = names[i].szEntryName;
                }
            }
        }
Example #2
0
        public RasDisplay()
        {
            _mConnected = true;

            Rasconn lprasConn = new Rasconn();

            lprasConn.DwSize = Marshal.SizeOf(typeof(Rasconn));
            lprasConn.Hrasconn = IntPtr.Zero;

            int lpcb = 0;
            int lpcConnections = 0;
            int nRet = 0;
            lpcb = Marshal.SizeOf(typeof(Rasconn));

            nRet = RasEnumConnections(ref lprasConn, ref lpcb, ref
                lpcConnections);

            if (nRet != 0)
            {
                _mConnected = false;
                return;

            }

            if (lpcConnections > 0)
            {
                //for (int i = 0; i < lpcConnections; i++)

                //{
                RasStats stats = new RasStats();

                _mConnectedRasHandle = lprasConn.Hrasconn;
                RasGetConnectionStatistics(lprasConn.Hrasconn, stats);

                _mConnectionName = lprasConn.SzEntryName;

                var hours = ((stats.dwConnectionDuration / 1000) / 3600);
                var minutes = ((stats.dwConnectionDuration / 1000) / 60) - (hours * 60);
                var seconds = ((stats.dwConnectionDuration / 1000)) - (minutes * 60) - (hours * 3600);

                _mDuration = hours + " hours " + minutes + " minutes " + seconds + " secs";
                _mTx = stats.dwBytesXmited;
                _mRx = stats.dwBytesRcved;
                //}
            }
            else
            {
                _mConnected = false;
            }

            int lpNames = 1;
            var entryNameSize = 0;
            int lpSize = 0;
            RasEntryName[] names = null;

            entryNameSize = Marshal.SizeOf(typeof(RasEntryName));
            lpSize = lpNames * entryNameSize;

            names = new RasEntryName[lpNames];
            names[0].dwSize = entryNameSize;

            uint retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);

            //if we have more than one connection, we need to do it again
            if (lpNames > 1)
            {
                names = new RasEntryName[lpNames];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i].dwSize = entryNameSize;
                }

                retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);

            }
            _mConnectionNames = new string[names.Length];

            if (lpNames > 0)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    _mConnectionNames[i] = names[i].szEntryName;
                }
            }
        }