コード例 #1
0
 /// <summary>
 /// Reads the configuration.
 /// </summary>
 /// <param name="fileName">The fully qualified name of the file, or the relative file name.</param>
 /// <exception cref="FileNotFoundException">The exception that is thrown when an attempt to access a file that does not exist on disk fails.</exception>
 /// <exception cref="InvalidOperationException">An error occurred during deserialization. The original exception is available using the System.Exception.InnerException property.</exception>
 internal static Type4Serialization ReadConfiguration(string fileName, IGraphicalUserInterface gui)
 {
     if (!File.Exists(fileName))
     {
         throw new FileNotFoundException(fileName);
     }
     try
     {
         gui.UseWaitCursor = true;
         Type4Serialization _graph = XmlFile.ReadXmlFile <Type4Serialization>(fileName);
         return(_graph);
     }
     catch (InvalidOperationException _ioe)
     {
         gui.MessageBoxShowExclamation(string.Format(Resources.TypeGenericConfigurationManagement_ReadError, _ioe.GetMessageFromException()), Resources.SolutionFileOpenError);
         return(null);
     }
     catch (Exception _ex)
     {
         gui.MessageBoxShowExclamation(string.Format(Resources.TypeGenericConfigurationManagement_ReadError, _ex.GetMessageFromException()), Resources.SolutionFileOpenError);
         return(null);
     }
     finally
     {
         gui.UseWaitCursor = false;
     }
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationWrapper" /> class that is to manage the sever configuration file.
 /// </summary>
 /// <param name="file">The file containing the configuration.</param>
 /// <param name="configurationEditor">The server configuration editor main interface.</param>
 /// <param name="userInterface">The user interface that provides basic functionality to implement user interactivity.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The server configuration editor main interface cannot be null
 /// or
 /// userInterface
 /// </exception>
 public ConfigurationWrapper(FileInfo file, IConfiguration configurationEditor, IGraphicalUserInterface userInterface)
 {
     if (configurationEditor == null)
     {
         throw new System.ArgumentNullException("The server configuration editor main interface cannot be null");
     }
     if (userInterface == null)
     {
         throw new System.ArgumentNullException($"The {nameof(userInterface)} cannot be null");
     }
     m_ServerConfiguration = configurationEditor;
     m_userInterface       = userInterface;
     if (file != null)
     {
         ConfigurationFile = file;
     }
     else
     {
         ConfigurationFile = FindConfigurationFile();
     }
     if (ConfigurationFile != null)
     {
         file = ConfigurationFile;
         Read(file);
     }
     else
     {
         m_userInterface.MessageBoxShowExclamation(Resources.ConfigurationWrapper_NoConfigurationFileSelectedInfo, Resources.ConfigurationWrapper_NoConfigurationFileSelectedHeader);
         string selectedPath = String.Empty;
         using (IFolderBrowserDialog _fbd = m_userInterface.OpenFolderBrowserDialogFunc())
         {
             if (_fbd.ShowDialog())
             {
                 selectedPath = _fbd.SelectedPath;
             }
         }
         if (string.IsNullOrEmpty(selectedPath))
         {
             m_userInterface.MessageBoxShowExclamation(Resources.ConfigurationWrapperNoFolderSelectedInfo, Resources.ConfigurationWrapperNoFolderSelectedHeader);
             selectedPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
         }
         configurationEditor.CreateDefaultConfiguration();
         try
         {
             file = new FileInfo(Path.Combine(selectedPath, configurationEditor.DefaultFileName));
         }
         catch (Exception exception)
         {
             m_userInterface.MessageBoxShowError(Resources.ConfigurationWrapperProblemWithOpeningOfTheFileInfo + exception.Message, Resources.ConfigurationWrapperProblemWithOpeningOfTheFileHeader);
         }
         configurationEditor.SaveConfiguration(String.Empty, file);
         Read(file);
     }
 }