1
Vote

Validate network connectivity

description

Hi , fix validated issue , if Device not connected to wifi internet it will be
System.InvalidOperationException
the validate issue here
Ip = _activeAdapter?.IpAddress.ToString();
                _activeAdapter?.DownloadCurrent.Select(ConvertUnit).Subscribe(x =>
                {
                    DownloadSpeed = x.Item1;
                    DownloadSpeedUnit = x.Item2;
                });

                _activeAdapter?.UploadCurrent.Select(ConvertUnit).Subscribe(x =>
                {
                    UploadSpeed = x.Item1;
                    UploadSpeedUnit = x.Item2;
                });

                _activeAdapter?.DownloadTotal.Select(ConvertUnit).Subscribe(x =>
                {
                    DownloadTotal = x.Item1;
                    DownloadTotalUnit = x.Item2;
                });

                _activeAdapter?.UploadTotal.Select(ConvertUnit).Subscribe(x =>
                {
                    UploadTotal = x.Item1;
                    UploadTotalUnit = x.Item2;
                });
it is because _networkAdapterList not valid
so change you code to
_networkAdapterList = AdapterFacade.GetNetworkAdapters();
        bool isValid = _networkAdapterList.Any();
        if (isValid) { 
                _activeAdapter = _networkAdapterList?.First();

                Ip = _activeAdapter?.IpAddress.ToString();

                _activeAdapter?.DownloadCurrent.Select(ConvertUnit).Subscribe(x =>
                {
                    DownloadSpeed = x.Item1;
                    DownloadSpeedUnit = x.Item2;
                });

                _activeAdapter?.UploadCurrent.Select(ConvertUnit).Subscribe(x =>
                {
                    UploadSpeed = x.Item1;
                    UploadSpeedUnit = x.Item2;
                });

                _activeAdapter?.DownloadTotal.Select(ConvertUnit).Subscribe(x =>
                {
                    DownloadTotal = x.Item1;
                    DownloadTotalUnit = x.Item2;
                });

                _activeAdapter?.UploadTotal.Select(ConvertUnit).Subscribe(x =>
                {
                    UploadTotal = x.Item1;
                    UploadTotalUnit = x.Item2;
                });

            }

comments