Esempio n. 1
0
 // testing only
 internal OneEFWizard(ConfigFileUtils configFileUtils = null, IVsUtils vsUtils = null, IErrorListHelper errorListHelper = null, ModelGenErrorCache errorCache = null,
                      List <KeyValuePair <string, string> > generatedCode = null)
 {
     _configFileUtils = configFileUtils;
     _generatedCode   = generatedCode ?? new List <KeyValuePair <string, string> >();
     _vsUtils         = vsUtils;
     _errorListHelper = errorListHelper;
     _errorCache      = errorCache;
 }
Esempio n. 2
0
 // testing only
 internal OneEFWizard(ConfigFileUtils configFileUtils = null, IVsUtils vsUtils = null, IErrorListHelper errorListHelper = null, ModelGenErrorCache errorCache = null, 
     List<KeyValuePair<string, string>> generatedCode = null)
 {
     _configFileUtils = configFileUtils;
     _generatedCode = generatedCode ?? new List<KeyValuePair<string, string>>();
     _vsUtils = vsUtils;
     _errorListHelper = errorListHelper;
     _errorCache = errorCache;
 }
Esempio n. 3
0
        public virtual void GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils = null,
                                          ModelBuilderEngineHostContext hostContext       = null)
        {
            if (settings.GenerationOption == ModelGenerationOption.GenerateFromDatabase &&
                String.IsNullOrEmpty(settings.DesignTimeConnectionString))
            {
                throw new ArgumentOutOfRangeException(Resources.Engine_EmptyConnStringErrorMsg);
            }

            var generatingModelWatch = Stopwatch.StartNew();

            hostContext = hostContext ?? new VSModelBuilderEngineHostContext(settings);
            vsUtils     = vsUtils ?? new VsUtilsWrapper();

            // Clear out the ModelGenErrorCache before ModelGen begins
            PackageManager.Package.ModelGenErrorCache.RemoveErrors(settings.ModelPath);

            var errors = new List <EdmSchemaError>();

            try
            {
                var storeModelNamespace = GetStoreNamespace(settings);
                Model = GenerateModels(storeModelNamespace, settings, errors);

                ProcessModel(Model, storeModelNamespace, settings, hostContext, errors);

                hostContext.LogMessage(
                    FormatMessage(
                        errors.Any()
                            ? Resources.Engine_ModelGenErrors
                            : Resources.Engine_ModelGenSuccess,
                        Path.GetFileName(settings.ModelPath)));

                if (errors.Any())
                {
                    PackageManager.Package.ModelGenErrorCache.AddErrors(settings.ModelPath, errors);
                }
            }
            catch (Exception e)
            {
                hostContext.LogMessage(FormatMessage(Resources.Engine_ModelGenException, e));
                // The exception we re-throw will get swallowed in the message pump and therefore we need to show the message box here.
                // It will also prevent the form.WizardFinished from being set to true which will cause cancelling the wizard and
                // therefore block adding new project items to the project as well as ModelObjectItemWizardFrom.RunFinished method.
                vsUtils.ShowErrorDialog(FormatMessage(Resources.Engine_ModelGenExceptionMessageBox, e.GetType().Name, e.Message));
                throw;
            }
            finally
            {
                generatingModelWatch.Stop();

                hostContext.LogMessage(FormatMessage(Resources.LoadingDBMetadataTimeMsg, settings.LoadingDBMetadataTime));
                hostContext.LogMessage(FormatMessage(Resources.GeneratingModelTimeMsg, generatingModelWatch.Elapsed));
            }
        }
        public virtual void GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils = null, 
            ModelBuilderEngineHostContext hostContext = null)
        {
            if (settings.GenerationOption == ModelGenerationOption.GenerateFromDatabase
                && String.IsNullOrEmpty(settings.DesignTimeConnectionString))
            {
                throw new ArgumentOutOfRangeException(Resources.Engine_EmptyConnStringErrorMsg);
            }

            var generatingModelWatch = Stopwatch.StartNew();

            hostContext = hostContext ?? new VSModelBuilderEngineHostContext(settings);
            vsUtils = vsUtils ?? new VsUtilsWrapper();

            // Clear out the ModelGenErrorCache before ModelGen begins
            PackageManager.Package.ModelGenErrorCache.RemoveErrors(settings.ModelPath);

            var errors = new List<EdmSchemaError>();

            try
            {
                var storeModelNamespace = GetStoreNamespace(settings);
                Model = GenerateModels(storeModelNamespace, settings, errors);

                ProcessModel(Model, storeModelNamespace, settings, hostContext, errors);

                hostContext.LogMessage(
                    FormatMessage(
                        errors.Any()
                            ? Resources.Engine_ModelGenErrors
                            : Resources.Engine_ModelGenSuccess,
                        Path.GetFileName(settings.ModelPath)));

                if (errors.Any())
                {
                    PackageManager.Package.ModelGenErrorCache.AddErrors(settings.ModelPath, errors);
                }
            }
            catch (Exception e)
            {
                hostContext.LogMessage(FormatMessage(Resources.Engine_ModelGenException, e));
                // The exception we re-throw will get swallowed in the message pump and therefore we need to show the message box here.
                // It will also prevent the form.WizardFinished from being set to true which will cause cancelling the wizard and 
                // therefore block adding new project items to the project as well as ModelObjectItemWizardFrom.RunFinished method.
                vsUtils.ShowErrorDialog(FormatMessage(Resources.Engine_ModelGenExceptionMessageBox, e.GetType().Name, e.Message));
                throw;
            }
            finally
            {
                generatingModelWatch.Stop();

                hostContext.LogMessage(FormatMessage(Resources.LoadingDBMetadataTimeMsg, settings.LoadingDBMetatdataTime));
                hostContext.LogMessage(FormatMessage(Resources.GeneratingModelTimeMsg, generatingModelWatch.Elapsed));
            }
        }
Esempio n. 5
0
        public ConfigFileUtils(Project project, IServiceProvider serviceProvider, VisualStudioProjectSystem?applicationType = null, IVsUtils vsUtils = null, IVsHelpers vsHelpers = null)
        {
            Debug.Assert(project != null, "project is null");
            Debug.Assert(serviceProvider != null, "serviceProvider is null");

            _vsUtils   = vsUtils ?? new VsUtilsWrapper();
            _vsHelpers = vsHelpers ?? new VsHelpersWrapper();

            _project         = project;
            _serviceProvider = serviceProvider;
            _applicationType = applicationType ?? _vsUtils.GetApplicationType(_serviceProvider, _project);
            _configFileName  = VsUtils.IsWebProject(_applicationType)
                ? VsUtils.WebConfigFileName
                : VsUtils.AppConfigFileName;
        }
        public ConfigFileUtils(Project project, IServiceProvider serviceProvider, VisualStudioProjectSystem? applicationType = null, IVsUtils vsUtils = null, IVsHelpers vsHelpers = null)
        {
            Debug.Assert(project != null, "project is null");
            Debug.Assert(serviceProvider != null, "serviceProvider is null");

            _vsUtils = vsUtils ?? new VsUtilsWrapper();
            _vsHelpers = vsHelpers ?? new VsHelpersWrapper();

            _project = project;
            _serviceProvider = serviceProvider;
            _applicationType = applicationType ?? _vsUtils.GetApplicationType(_serviceProvider, _project);
            _configFileName = VsUtils.IsWebProject(_applicationType)
                ? VsUtils.WebConfigFileName
                : VsUtils.AppConfigFileName;
        }
Esempio n. 7
0
 /// <summary>
 /// This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 public OneEFWizard()
 {
     _vsUtils         = new VsUtilsWrapper();
     _errorListHelper = new ErrorListHelperWrapper();
     _errorCache      = PackageManager.Package.ModelGenErrorCache;
 }
Esempio n. 8
0
 /// <summary>
 /// This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 public OneEFWizard()
 {
     _vsUtils = new VsUtilsWrapper();
     _errorListHelper = new ErrorListHelperWrapper();
     _errorCache = PackageManager.Package.ModelGenErrorCache;
 }