Beispiel #1
0
        internal ConnectionDetail(CONNMGR_CONNECTION_DETAILED_STATUS item)
        {
            this.Version           = item.dwVer;
            this.AdapterName       = item.szAdapterName;
            this.ConnectionOption  = item.dwFlags;
            this.ConnectionStatus  = item.dwConnectionStatus;
            this.ConnectionSubType = GetConnSubtype(item);
            this.ConnectionType    = item.dwType;
            this.Description       = item.szDescription;
            this.DestinatonNetwork = item.guidDestNet;
            this.DetailStatusParam = item.dwParams;
            this.IPAddress         = item.pIPAddr;
            SYSTEMTIME st = new SYSTEMTIME();

            st.wYear   = item.LastConnectTime[0];
            st.wMonth  = item.LastConnectTime[1];
            st.wDay    = item.LastConnectTime[3];
            st.wHour   = item.LastConnectTime[4];
            st.wMinute = item.LastConnectTime[5];
            st.wSecond = item.LastConnectTime[6];
            this.LastConnectionTime = st.ToDateTime();
        }
        /// <summary> Returns collection of detailed connection manager items </summary>
        public ConnectionDetailCollection GetConnectionDetailItems(bool refresh)
        {
            bool newCollection = m_connectionDetailColllection == null;

            if (newCollection || refresh)
            {
                // jsm - Do this only on first-time initialization
                if (newCollection)
                {
                    m_connectionDetailColllection = new ConnectionDetailCollection();

                    m_statusChangeWnd = new StatusNotificationPump(m_connectionDetailColllection);
                    SafeNativeMethods.ConnMgrRegisterForStatusChangeNotification(true, m_statusChangeWnd.Hwnd);
                }

                // jsm - Bug 363 - We're not refreshing
                if (newCollection || refresh)
                {
                    int  cb  = 0;
                    uint ret = 0;

                    try
                    {
                        ret = SafeNativeMethods.ConnMgrQueryDetailedStatus(IntPtr.Zero, ref cb);
                    }
                    catch (MissingMethodException)
                    {
                        throw new PlatformNotSupportedException("Detailed connection status is not supported on this platform");
                    }

                    if (ret != SafeNativeMethods.INSUFFICIENT_BUFFER)
                    {
                        throw new System.ComponentModel.Win32Exception();
                    }

                    IntPtr pStat = Marshal.AllocHGlobal(cb);
                    try
                    {
                        ret = SafeNativeMethods.ConnMgrQueryDetailedStatus(pStat, ref cb);
                        if (ret == 0)
                        {
                            IntPtr pObj = pStat;
                            while (pObj != IntPtr.Zero)
                            {
                                CONNMGR_CONNECTION_DETAILED_STATUS stat = (CONNMGR_CONNECTION_DETAILED_STATUS)Marshal.PtrToStructure(pObj, typeof(CONNMGR_CONNECTION_DETAILED_STATUS));
                                m_connectionDetailColllection.Add(new ConnectionDetail(stat));
                                pObj = stat.pNext;
                            }
                        }
                        else
                        {
                            throw new System.ComponentModel.Win32Exception();
                        }
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pStat);
                    }
                }
            }
            return(m_connectionDetailColllection);
        }
Beispiel #3
0
        private ConnectionSubType GetConnSubtype(CONNMGR_CONNECTION_DETAILED_STATUS item)
        {
            ConnectionType conType = item.dwType;
            int            subType = (int)item.dwSubtype;

            #region Case Statement to deterimne subconnection type
            switch (conType)
            {
            case ConnectionType.Bluetooth:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.RAS);

                case 2:
                    return(ConnectionSubType.PAN);

                default:
                    return(ConnectionSubType.Unknown);
                }

            case ConnectionType.Cellular:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.CSD);

                case 2:
                    return(ConnectionSubType.GPRS);

                case 3:
                    return(ConnectionSubType.XRTT);

                case 4:
                    return(ConnectionSubType.EVDO);

                case 5:
                    return(ConnectionSubType.XEVDV);

                case 6:
                    return(ConnectionSubType.EDGE);

                case 7:
                    return(ConnectionSubType.UMTS);

                case 8:
                    return(ConnectionSubType.Voice);

                case 9:
                    return(ConnectionSubType.PTT);

                case 10:
                    return(ConnectionSubType.HSDPA);

                default:
                    return(ConnectionSubType.Unknown);
                }

            case ConnectionType.NIC:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.Ethernet);

                case 2:
                    return(ConnectionSubType.WiFi);

                default:
                    return(ConnectionSubType.Unknown);
                }

            case ConnectionType.PC:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.DesktopPassthrough);

                case 2:
                    return(ConnectionSubType.IR);

                case 3:
                    return(ConnectionSubType.ModemLink);

                default:
                    return(ConnectionSubType.Unknown);
                }

            case ConnectionType.Proxy:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.NullProxy);

                case 2:
                    return(ConnectionSubType.HTTP);

                case 3:
                    return(ConnectionSubType.WAP);

                case 4:
                    return(ConnectionSubType.Sockets4);

                case 5:
                    return(ConnectionSubType.Sockets5);

                default:
                    return(ConnectionSubType.Unknown);
                }

            case ConnectionType.Unimodem:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.CSD);

                case 2:
                    return(ConnectionSubType.OutOfBandCSD);

                case 3:
                    return(ConnectionSubType.NullModem);

                case 4:
                    return(ConnectionSubType.ExternalModem);

                case 5:
                    return(ConnectionSubType.InternalModem);

                case 6:
                    return(ConnectionSubType.PCMCIAModem);

                case 7:
                    return(ConnectionSubType.IRCommModem);

                case 8:
                    return(ConnectionSubType.DynamicModem);

                case 9:
                    return(ConnectionSubType.DynamicPort);

                default:
                    return(ConnectionSubType.Unknown);
                }

            case ConnectionType.VPN:
                switch (subType)
                {
                case 1:
                    return(ConnectionSubType.L2TP);

                case 2:
                    return(ConnectionSubType.PPTP);

                default:
                    return(ConnectionSubType.Unknown);
                }

            default:
                return(ConnectionSubType.Unknown);
            }
            #endregion
        }
 extern public static uint ConnMgrQueryDetailedStatus(CONNMGR_CONNECTION_DETAILED_STATUS stat, ref int size);