Ejemplo n.º 1
0
        protected override void InnerExecute(object parameter)
        {
            OpenFileDialog openEnvironmentConfigurationDeltaDialog = new OpenFileDialog
            {
                Filter = DesignResources.DeltaDialogFilter,
                Title  = DesignResources.OpenDeltaDialogTitle
            };

            var openFileResult = UIService.ShowFileDialog(openEnvironmentConfigurationDeltaDialog);

            if (openFileResult.DialogResult != true)
            {
                return;
            }

            try
            {
                var configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap {
                    ExeConfigFilename = openFileResult.FileName
                }, ConfigurationUserLevel.None);
                EnvironmentalOverridesSection mergeSection = (EnvironmentalOverridesSection)configuration.GetSection(EnvironmentalOverridesSection.EnvironmentallyOverriddenProperties);

                sourceModel.LoadEnvironment(mergeSection, openFileResult.FileName);
            }
            catch (Exception ex)
            {
                ConfigurationLogWriter.LogException(ex);
                UIService.ShowMessageWpf(string.Format(CultureInfo.CurrentCulture, Resources.ErrorLoadingDeltaFile, ex.Message),
                                         Resources.ErrorTitle,
                                         MessageBoxButton.OK);
            }
        }
Ejemplo n.º 2
0
        private void UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            ConfigurationLogWriter.LogException(e.Exception);
            MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Console.Properties.Resources.UnhandledExceptionMessageFormat, e.Exception.Message),
                            Console.Properties.Resources.UnhandledExceptionMessageTitle, MessageBoxButton.OK,
                            MessageBoxImage.Error);

            this.Shutdown(ExitWithFailureCode);
        }
 /// <summary>
 /// Filters an exception by comparing it to an internal type list.  If the exception type matches one in the list, it logs a warning.
 /// Exceptions not matching the list are rethrown.
 /// </summary>
 /// <param name="ex"></param>
 /// <seealso cref="ConfigurationLogWriter.LogWarning"/>
 public static void FilterException(Exception ex)
 {
     if (FilterTypeList.Contains(ex.GetType()))
     {
         ConfigurationLogWriter.LogWarning(
             string.Format(CultureInfo.CurrentCulture, Resources.WarningAssemblyLoadNonFatal, ex.ToString()));
     }
     else
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
        public bool Load(IDesignConfigurationSource configSource)
        {
            Clear();
            Initialize();

            IDesignConfigurationSource sectionConfigurationSource = null;

            try
            {
                sectionConfigurationSource = GetSectionSource(configSource);
            }
            catch (Exception ex)
            {
                ConfigurationLogWriter.LogException(ex);
                uiService.ShowMessageWpf(string.Format(CultureInfo.CurrentCulture, Resources.ErrorLoadingConfigSourceFile, ex.Message),
                                         Resources.ErrorTitle,
                                         MessageBoxButton.OK);
                return(false);
            }

            if (sectionConfigurationSource != null)
            {
                try
                {
                    AddSection(ConfigurationSourceSection.SectionName,
                               configSource.GetLocalSection(ConfigurationSourceSection.SectionName),
                               new InitializeContext(configSource));

                    LoadSectionsFromSource(sectionConfigurationSource);
                }
                catch
                {
                    var disposable = sectionConfigurationSource as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }

                    throw;
                }
            }
            else
            {
                LoadSectionsFromSource(configSource);
            }


            Validate();

            return(true);
        }
Ejemplo n.º 5
0
        public bool Save(IDesignConfigurationSource configurationSource)
        {
            saveOperation.BeginPerformSaveOperation();
            try
            {
                var sectionsToSave = Sections.Where(x => null == x as EnvironmentSourceViewModel);

                var sectionSaveSource = GetSectionSourceFromModel(configurationSource);
                if (sectionSaveSource != null)
                {
                    try
                    {
                        try
                        {
                            SaveConfigurationSource(configurationSource);
                        }
                        catch (Exception e)
                        {
                            ConfigurationLogWriter.LogException(e);
                            uiService.ShowError(e, Resources.ErrorSavingConfigurationSourceOnMainFile);
                            return(false);
                        }
                        try
                        {
                            SaveSections(
                                sectionsToSave.Where(
                                    x => !typeof(ConfigurationSourceSection).IsAssignableFrom(x.ConfigurationType)),
                                sectionSaveSource);
                        }
                        catch (Exception e)
                        {
                            ConfigurationLogWriter.LogException(e);
                            uiService.ShowError(e, Resources.ErrorSavingConfigurationSectionsOnSelectedSource);
                            return(false);
                        }
                        return(true);
                    }
                    finally
                    {
                        var disposable = sectionSaveSource as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }

                try
                {
                    SaveSections(sectionsToSave, configurationSource);
                }
                catch (Exception e)
                {
                    ConfigurationLogWriter.LogException(e);
                    uiService.ShowError(e, Resources.ErrorSavingConfigurationSectionsOnMainFile);
                    return(false);
                }
            }
            finally
            {
                saveOperation.EndPerformSaveOperation();
            }
            return(true);
        }