/// <summary> /// Ask the user to select an XML data dictionary and then load this data dictionary into the PTU application. /// </summary> /// <param name="mainWindow">Reference to the main application window interface.</param> public static void LoadDataDictionary(IMainWindow mainWindow) { string fullyQualifiedSourceFilename = General.FileDialogOpenFile(Resources.FileDialogOpenTitleDataDictionary, CommonConstants.ExtensionDataDictionary, Resources.FileDialogOpenFilterDataDictionary, DirectoryManager.PathPTUConfigurationFiles); // Skip, if the user didn't select a data dictionary XML file. if (fullyQualifiedSourceFilename == string.Empty) { return; } #region - [Exclude 'PTU Configuration.xml' or '*.PTU Configuration.xml'] - // if the user has selected either the default configuration file, 'PTU Configuration.xml', or one of the project default configuration files, // '<project-identifier>.PTU Configuration.xml', terminate the operation. if (Path.GetFileName(fullyQualifiedSourceFilename).ToLower().Contains(Resources.FilenameDefaultDataDictionary.ToLower())) { MessageBox.Show(string.Format(Resources.MBTConfigSelectionInvalid, Resources.FilenameDefaultDataDictionary), Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion - [Exclude 'PTU Configuration.xml' or '*.PTU Configuration.xml'] - FileInfo fileInfoSource = new FileInfo(fullyQualifiedSourceFilename); DataDictionary dataDictionary = new DataDictionary(); try { // Load the specified XML configuration file. FileHandling.LoadDataSet<DataDictionary>(fullyQualifiedSourceFilename, ref dataDictionary); #region - [Check whether the selected data dictionary is valid for the current project] - // If the project identifier was passed to the application as a desktop shortcut parameter, ensure that the project identifier associated with // the selected data dictionary matches this, and if not, terminate the operation. if (mainWindow.ProjectIdentifierPassedAsParameter.Equals(string.Empty)) { // Do nothing. It is perfectly acceptable to select the configuration file associated with ANY project if no project identifier was passed to the // application as the desktop shortcut parameter. Indeed, this is the recommended way of quickly changing between different projects // for Bombardier field engineers. Simply set up a desktop shortcut that points to the PTU application but do not supply any shortcuts. ; } else { // The project identifier was passed to the application as a desktop shortcut parameter. Check that the project identifier associated with the // selected configuration file matches this and, if not, terminate the operation. if (dataDictionary.FILEINFO[0].PROJECTSTRING != mainWindow.ProjectIdentifierPassedAsParameter) { // The data dictionary is not associated with the current project, terminate the operation. MessageBox.Show(string.Format(Resources.MBTConfigProjectAsParameterMismatch, mainWindow.ProjectIdentifierPassedAsParameter), Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } #endregion - [Check whether the selected data dictionary is valid for the current project] - // Update the appropriate default configuration file.\ string fullyQualifiedDestinationFilename; if (mainWindow.ProjectIdentifierPassedAsParameter.Equals(string.Empty)) { // Copy to the default configuration file. fullyQualifiedDestinationFilename = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename + Resources.FilenameDefaultDataDictionary; } else { // Copy to the default project configuration file. fullyQualifiedDestinationFilename = DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename + dataDictionary.FILEINFO[0].PROJECTSTRING + CommonConstants.Period + Resources.FilenameDefaultDataDictionary; } FileInfo fileInfoDestination = new FileInfo(fullyQualifiedDestinationFilename); fileInfoSource.CopyTo(fullyQualifiedDestinationFilename, true); if (mainWindow != null) { mainWindow.SetRestart(true); mainWindow.Close(); } } catch (ArgumentNullException) { MessageBox.Show(Resources.MBTConfigurationFileLoadFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); } }