public CancelOperationDialog(GarminDeviceManager.CancelOperationDelegate cancelDelegate)
        {
            Debug.Assert(cancelDelegate != null);

            InitializeComponent();

            m_CancelDelegate = cancelDelegate;

            ProgressBar.MarqueeAnimationSpeed = 10;

            Cancel_Button.Text = CommonResources.Text.ActionCancel;
        }
        void OnDeviceManagerTaskCompleted(GarminDeviceManager manager, GarminDeviceManager.BasicTask task, bool succeeded, String errorText)
        {
            if (!succeeded)
            {
                if (!String.IsNullOrEmpty(errorText))
                {
                    MessageBox.Show(errorText,
                                    GarminFitnessView.GetLocalizedString("ErrorText"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.Initialize)
                {
                    MessageBox.Show(GarminFitnessView.GetLocalizedString("DeviceCommunicationErrorText"),
                                    GarminFitnessView.GetLocalizedString("ErrorText"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (manager.AreAllTasksFinished)
            {
                Utils.ReleaseMainWindow();

                manager.TaskCompleted -= new GarminDeviceManager.TaskCompletedEventHandler(OnDeviceManagerTaskCompleted);
            }
        }
        private void OnManagerTaskCompleted(GarminDeviceManager manager, GarminDeviceManager.BasicTask task, bool succeeded, String errorText)
        {
            if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.RefreshDevices)
            {
                OKButton.Enabled = true;
                Cancel_Button.Enabled = true;
                RefreshButton.Enabled = true;
                DevicesComboBox.Enabled = true;
                Cursor = Cursors.Default;

                RefreshDeviceComboBox();
            }
        }
        void OnDeviceManagerTaskCompleted(GarminDeviceManager manager, GarminDeviceManager.BasicTask task, bool succeeded, String errorText)
        {
            if (!succeeded)
            {
                if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.Initialize)
                {
                    MessageBox.Show(GarminFitnessView.GetLocalizedString("DeviceCommunicationErrorText"),
                                    GarminFitnessView.GetLocalizedString("ErrorText"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (!String.IsNullOrEmpty(errorText))
                {
                    MessageBox.Show(errorText,
                                    GarminFitnessView.GetLocalizedString("ErrorText"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                manager.CancelAllTasks();
            }
            else
            {
                if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.SetOperatingDevice)
                {
                    if (GarminDeviceManager.Instance.OperatingDevice == null ||
                        !GarminDeviceManager.Instance.OperatingDevice.SupportsReadProfile)
                    {
                        IExtendedWizardPage nextPage = Wizard.GetPageByType(typeof(SetupWizardEditProfile));

                        MessageBox.Show(String.Format(GarminFitnessView.GetLocalizedString("NoDeviceSupportText"),
                                                      GarminDeviceManager.Instance.OperatingDevice.DisplayName, GarminFitnessView.GetLocalizedString("ImportProfileText")) +
                                        "\n" +
                                        GarminFitnessView.GetLocalizedString("ManualProfileConfigurationText"),
                                        GarminFitnessView.GetLocalizedString("ErrorText"),
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        Wizard.ShowPage(nextPage);
                    }
                }
                else if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.ImportProfile)
                {
                    Wizard.GoNext();
                }
            }

            if (manager.AreAllTasksFinished)
            {
                Wizard.Enabled = true;
                Wizard.Cursor = Cursors.Default;

                manager.TaskCompleted -= new GarminDeviceManager.TaskCompletedEventHandler(OnDeviceManagerTaskCompleted);

                if (!succeeded)
                {
                    IExtendedWizardPage nextPage = Wizard.GetPageByType(typeof(SetupWizardEditProfile));

                    Wizard.ShowPage(nextPage);
                }
            }
        }
        void OnDeviceManagerTaskCompleted(GarminDeviceManager manager, GarminDeviceManager.BasicTask task, bool succeeded, String errorText)
        {
            bool exportCancelled = false;

            if (!succeeded)
            {
                if (!String.IsNullOrEmpty(errorText))
                {
                    MessageBox.Show(errorText,
                                    GarminFitnessView.GetLocalizedString("ErrorText"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.Initialize)
                {
                    MessageBox.Show(GarminFitnessView.GetLocalizedString("DeviceCommunicationErrorText"),
                                    GarminFitnessView.GetLocalizedString("ErrorText"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.SetOperatingDevice)
                {
                    exportCancelled = true;
                }
                else if (task.Type == GarminDeviceManager.BasicTask.TaskTypes.ExportWorkout)
                {
                    GarminDeviceManager.ExportWorkoutTask concreteTask = (GarminDeviceManager.ExportWorkoutTask)task;

                    m_FailedExportList.AddRange(concreteTask.Workouts);
                    m_FailedExportErrors.Add(errorText);
                }
            }

            if (manager.AreAllTasksFinished)
            {
                Utils.ReleaseMainWindow();

                manager.TaskCompleted -= new GarminDeviceManager.TaskCompletedEventHandler(OnDeviceManagerTaskCompleted);

                if (!exportCancelled)
                {
                    if (m_FailedExportList.Count == 0)
                    {

                        MessageBox.Show(GarminFitnessView.GetLocalizedString("ExportWorkoutsSuccessText"),
                                        GarminFitnessView.GetLocalizedString("SuccessText"),
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        String allErrors = String.Empty;

                        if (m_FailedExportErrors.Count > 0)
                        {
                            allErrors = "\n\n";

                            foreach (String error in m_FailedExportErrors)
                            {
                                allErrors += error + "\n";
                            }
                        }

                        m_FailedExportList.Clear();
                        m_FailedExportErrors.Clear();

                        MessageBox.Show(GarminFitnessView.GetLocalizedString("ExportWorkoutsFailedText") + allErrors,
                                        GarminFitnessView.GetLocalizedString("ErrorText"),
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }