Esempio n. 1
0
        private BackgroundWorker getExtenderWorker(Extender extender, string user, string pass)
        {
            var bw = new BackgroundWorker();

            bw.DoWork += (s, e) =>
            {
                var device = getDevice(extender.IP);
                device.DoReboot            = extender.Restart;
                device.IsLoading           = true;
                device.IsNetworkAccessible = extender.IsNetworkAccessible();
                //if (device.IsNetworkAccessible)
                {
                    var state = extender.GetState();
                    device.IsHttpAccessible = state.Accessible;
                    device.IsAuthenticated  = state.Authenticated;
                    if (device.IsHttpAccessible == true)
                    {
                        if (!state.Authenticated)
                        {
                            var result = extender.Authenticate(user, pass);
                            if (result == null)
                            {
                                device.IsAuthenticated = true;
                                state = extender.GetState();
                            }
                        }
                        if (device.IsAuthenticated == true)
                        {
                            device.IsActive = state.IPConnStatus == Extender.DeviceState.ConnStatusEnum.Success;
                            var speedFormat = "{0:N0}KBps | {1}";
                            device.RxSpeed = string.Format(speedFormat, state.AverageReceive / 1024, state.RxRate);
                            device.TxSpeed = string.Format(speedFormat, state.AverageTransmit / 1024, state.TxRate);
                            device.UpTime  = state.ConnTime;
                            device.Users.AddRange(state.Users.Select(u => new DeviceModel.UserInfo(u)), true);
                            device.Throughputs.AddRange(extender.Throughputs, true);
                            fillUsers();
                            autoExtenderReboot(device);
                            this.Dispatcher.BeginInvoke(new Action(device.Users.ResetBindings), DispatcherPriority.Normal);
                        }
                    }
                }
                //RefreshButtons();
                device.IsLoading = false;
            };
            bw.RunWorkerCompleted += (s, e) =>
            {
                OnPropertyChanged("Devices");
            };
            return(bw);
        }