Esempio n. 1
0
        void _updateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            DeviceUpdateOperation operation = (DeviceUpdateOperation)e.Argument;

            this.Dispatcher.Invoke(new Action(delegate()
            {
                // reset and show the progress bar
                ProgressBar.Value      = 0.0;
                ProgressBar.Visibility = System.Windows.Visibility.Visible;
            }));

            if (_updateWorker.CancellationPending)
            {
                return;
            }

            try
            {
                switch (operation.OperationMethod)
                {
                case DeviceUpdateOperationMethod.EraseDeploymentSectors:
                    EraseDeploymentSectors(operation.DevicePath, operation.UpdateFirmware);
                    break;
                }
            }
            catch (Exception ex)
            {
                this.Dispatcher.Invoke(new Action(delegate()
                {
                    MessageBox.Show("Error: " + ex.Message);
                }));
            }
        }
        private void eraseAndUploadButton_Click(object sender, RoutedEventArgs e)
        {
            string buttonContent = ((Button)sender).Content.ToString();

            if (string.Compare(buttonContent, "Upgrade", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // create a list of all devices selected for upgrade
                List <DeviceUpdateOperation> updateOperations = new List <DeviceUpdateOperation>();
                foreach (DeviceInfo deviceInfo in _devices)
                {
                    if (deviceInfo.IsChecked)
                    {
                        DeviceUpdateOperation operation = new DeviceUpdateOperation();
                        operation.DevicePath      = deviceInfo.DevicePath;
                        operation.OperationMethod = DeviceUpdateOperationMethod.EraseAndUpload;
                        operation.UpdateFirmware  = deviceInfo.UpgradeFirmware;
                        updateOperations.Add(operation);
                    }
                }
                _updateWorker.RunWorkerAsync(updateOperations);
            }
            else if (string.Compare(buttonContent, "Cancel", StringComparison.OrdinalIgnoreCase) == 0)
            {
                eraseAndUploadButton.IsEnabled = false;
                _updateWorker.CancelAsync();
            }
        }
Esempio n. 3
0
        private void EraseDeploymentSectorButton_Click(object sender, RoutedEventArgs e)
        {
            EraseDeploymentSectorButton.IsEnabled = false;
            this.IsHitTestVisible = false;

            DeviceUpdateOperation operation = new DeviceUpdateOperation();

            operation.DevicePath      = _deviceInfo.DevicePath;
            operation.UpdateFirmware  = _deviceInfo.UpgradeFirmware;
            operation.OperationMethod = DeviceUpdateOperationMethod.EraseDeploymentSectors;
            _updateWorker.RunWorkerAsync(operation);
        }
        void _updateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <DeviceUpdateOperation> updateOperations = (List <DeviceUpdateOperation>)e.Argument;

            this.Dispatcher.Invoke(new Action(delegate()
            {
                // change our button to a Cancel button
                eraseAndUploadButton.Content = "Cancel";

                // reset and show the progress bar
                progressBar.Value      = 0.0;
                progressBar.Visibility = System.Windows.Visibility.Visible;

                // shrink and disable the listview
                devicesListView.Height   -= progressBar.Height;
                devicesListView.IsEnabled = false;
            }));

            // upgrade the firmware on each of the selected devices
            for (int iDevice = 0; iDevice < updateOperations.Count; iDevice++)
            {
                if (_updateWorker.CancellationPending)
                {
                    return;
                }

                DeviceUpdateOperation operation = updateOperations[iDevice];
                _progressValue = ((double)iDevice / (double)updateOperations.Count);
                try
                {
                    switch (operation.OperationMethod)
                    {
                    case DeviceUpdateOperationMethod.EraseAndUpload:
                        EraseAndUploadDevice(operation.DevicePath, operation.UpdateFirmware, _progressValue, ((double)1 / (double)updateOperations.Count));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    this.Dispatcher.Invoke(new Action(delegate()
                    {
                        MessageBox.Show("Error: " + ex.Message);
                    }));
                }
            }
        }