예제 #1
0
        //
        // Event handlers
        //
        private void Application_Startup( object sender, StartupEventArgs ev )
        {
            Debug.Print( "Application_Startup:" );

            try {
                _configurationPathName = Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create ) + @"\Zive Technology Research\ZiveIRC";
                _configurationFileName = _configurationPathName + @"\configuration.xml";
            }
            catch ( Exception e ) {
                Debug.Print( "App.Application_Startup: Caught exception trying to obtain path of configuration folder:\n{0}", e );
                return;
            }

            try {
                if ( !string.IsNullOrWhiteSpace( _configurationPathName ) && !Directory.Exists( _configurationPathName ) ) {
                    Directory.CreateDirectory( _configurationPathName );
                }
            }
            catch ( Exception e ) {
                Debug.Print( "App.Application_Startup: Caught exception trying to create configuration folder '{0}':\n{1}", _configurationPathName, e );
            }

            Debug.Print( "App.Application_Startup: Creating ConfigurationManager object." );
            ConfigurationManager = new ConfigurationManager( );

            try {
                ConfigurationManager.Load( _configurationFileName );
                return;
            }
            catch ( Exception e ) {
                Debug.Print( "App.Application_Startup: Caught exception trying to load configuration from file '{0}':\n{1}", _configurationFileName, e );
            }

            try {
                Debug.Print( "App.Application_Startup: Making up configuration." );
                ConfigurationManager.Configuration = MakeUpConfiguration( );

                Debug.Print( "App.Application_Startup: Saving new made-up configuration." );
                ConfigurationManager.Save( _configurationFileName );
            }
            catch ( Exception e ) {
                Debug.Print( "App.Application_Startup: Caught exception trying to save default configuration to file '{0}':\n{1}", _configurationFileName, e );
            }
        }
예제 #2
0
        //
        // Private methods
        //
        private void _LoadConfiguration( )
        {
            try {
                _configurationPathName = Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create ) + @"\Zive Technology Research\ZiveIRC";
                _configurationFileName = _configurationPathName + @"\Configuration.xml";
            }
            catch ( Exception e ) {
                Debug.Print( "App._LoadConfiguration: Caught exception trying to obtain path of configuration folder:\n{0}", e );
                return;
            }

            try {
                if ( !string.IsNullOrWhiteSpace( _configurationPathName ) && !Directory.Exists( _configurationPathName ) ) {
                    Directory.CreateDirectory( _configurationPathName );
                }
            }
            catch ( Exception e ) {
                Debug.Print( "App._LoadConfiguration: Caught exception trying to create configuration folder '{0}':\n{1}", _configurationPathName, e );
            }

            ConfigurationManager = new ConfigurationManager( );

            try {
                ConfigurationManager.Load( _configurationFileName );
            }
            catch ( Exception) {
                try {
                    ConfigurationManager.Configuration = MakeUpConfiguration( );
                }
                catch ( Exception e ) {
                    Debug.Print( "App._LoadConfiguration: Caught exception trying to generate default configuration:\n{1}", e );
                }

                try {
                    ConfigurationManager.Save( _configurationFileName );
                }
                catch ( Exception e ) {
                    Debug.Print( "App._LoadConfiguration: Caught exception trying to save default configuration to file '{0}':\n{1}", _configurationFileName, e );
                }
            }
        }