private void ButtonImportDeviceConfig_Click(object sender, EventArgs e) { labelStatus.Text = ""; System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();; openFileDialog1.Filter = "Configuration Files (*.cfg)|*.cfg"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { GlobalsatDeviceConfiguration importedDeviceConfig = null; try { importedDeviceConfig = GlobalsatDeviceConfiguration.Load(openFileDialog1.FileName); } catch (Exception) { importedDeviceConfig = null; } if (importedDeviceConfig == null || importedDeviceConfig.SystemConfigDataRaw == null) { MessageDialog.Show(Properties.Resources.UI_Settings_ImportConfig_InvalidConfiguration, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } JobMonitor jobMonitor = new JobMonitor(); try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); if (device2 != null) { GlobalsatDeviceConfiguration currentDeviceConfig = device2.GetSystemConfiguration2(jobMonitor); if (importedDeviceConfig != null && currentDeviceConfig != null && importedDeviceConfig.DeviceName == currentDeviceConfig.DeviceName && importedDeviceConfig.SystemConfigDataRaw.Length == currentDeviceConfig.SystemConfigDataRaw.Length) { device2.SetSystemConfiguration2(importedDeviceConfig, jobMonitor); labelStatus.Text = CommonResources.Text.Devices.ImportJob_Status_ImportComplete; } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error + "Received " + importedDeviceConfig.SystemConfigDataRaw.Length + " bytes "; //MessageDialog.Show(Properties.Resources.UI_Settings_ImportConfig_InvalidConfiguration, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error; } } catch (Exception ex) { jobMonitor.ErrorText += ex.Message; } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void ButtonExportDeviceConfig_Click(object sender, EventArgs e) { labelStatus.Text = ""; try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); GlobalsatDeviceConfiguration currentDeviceConfig = null; JobMonitor jobMonitor = new JobMonitor(); if (device2 != null) { currentDeviceConfig = device2.GetSystemConfiguration2(jobMonitor); } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ExportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currentDeviceConfig != null) { System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog() { Filter = "Configuration Files (*.cfg)|*.cfg", FileName = currentDeviceConfig.DeviceName }; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { currentDeviceConfig.Save(saveFileDialog1.FileName); labelStatus.Text = CommonResources.Text.MessageExportComplete; //MessageDialog.Show(CommonResources.Text.MessageExportComplete, Properties.Resources.UI_Settings_ExportConfigButton_Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error; } } catch (Exception ex) { MessageDialog.Show(ex.Message, Properties.Resources.UI_Settings_ExportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }