src/Misc/EFTools/EntityDesign/VisualStudio/ModelWizard/ModelObjectItemWizard.cs
/// <summary>
///     This method is called at the beginning of a template wizard run
///     This lets us run custom wizard logic before anything is created and is a good place, for example,
///     to collect user input that will alter the run in some way
/// </summary>
/// <param name="automationObject">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
/// <param name="replacementsDictionary">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
/// <param name="runKind">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
/// <param name="customParams">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
This method is called at the beginning of a template wizard run
This lets us run custom wizard logic before anything is created and is a good place, for example,
to collect user input that will alter the run in some way
This method is called at the beginning of a template wizard run This lets us run custom wizard logic before anything is created and is a good place for example to collect user input that will alter the run in some way
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        [SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        public void RunStarted(
            object automationObject,
            Dictionary<string, string> replacementsDictionary,
            WizardRunKind runKind,
            object[] customParams)
        {
            var dte = (DTE2)automationObject;
            var serviceProvider = new ServiceProvider((IOleServiceProvider)dte);
            var project = VsUtils.GetActiveProject(dte);
            Debug.Assert(project != null, "Unable to retrieve ActiveSolutionProject from DTE");
            EnsureCanStartWizard(project, serviceProvider);
            string modelName;
            replacementsDictionary.TryGetValue("$rootname$", out modelName);
            Debug.Assert(modelName != null, "Unable to get $rootname$ from replacementsDictionary");
            modelName = SanitizeModelName(modelName);
            PopluateReplacementDictionary(project, replacementsDictionary, modelName);
            _modelBuilderSettings = new ModelBuilderSettings
            {
                VSApplicationType = VsUtils.GetApplicationType(serviceProvider, project),
                WizardKind = WizardKind.Generate,
                TargetSchemaVersion =
                    EdmUtils.GetEntityFrameworkVersion(project, serviceProvider, useLatestIfNoEF: false),
                NewItemFolder = GetFolderNameForNewItems(dte, project),
                Project = project,
                ModelName = modelName,
                VsTemplatePath = customParams[0] as string,
                ReplacementDictionary = replacementsDictionary
            };
            var form = new ModelBuilderWizardForm(
                serviceProvider,
                _modelBuilderSettings,
                ModelBuilderWizardForm.WizardMode.PerformAllFunctionality)
            {
                FileAlreadyExistsError = false
            };
            try
            {
                form.Start();
            }
            catch (Exception ex)
            {
                VsUtils.ShowErrorDialog(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.ModelObjectItemWizard_UnexpectedExceptionHasOccurred,
                        ex.Message));
                ClearErrors();
                throw new WizardCancelledException();
            }
            if (form.FileAlreadyExistsError)
            {
                Marshal.ThrowExceptionForHR(VSConstants.E_ABORT);
            }
            if (form.WizardCancelled
                || !form.WizardFinished)
            {
                ClearErrors();
                throw new WizardCancelledException();
            }
            Debug.Assert(ReferenceEquals(_modelBuilderSettings, form.ModelBuilderSettings));
        }
[ SuppressMessage ( " " , " " ) ] [ SuppressMessage ( " " , " " ) ] public void RunStarted ( object automationObject , Dictionary < string , string > replacementsDictionary , WizardRunKind runKind , object [ ] customParams ) { var dte = ( DTE2 ) automationObject ; var serviceProvider = new ServiceProvider ( ( IOleServiceProvider ) dte ) ; var project = VsUtils . GetActiveProject ( dte ) ; Debug . Assert ( project != null , " " ) ; EnsureCanStartWizard ( project , serviceProvider ) ; string modelName ; replacementsDictionary . TryGetValue ( " " , out modelName ) ; Debug . Assert ( modelName != null , " " ) ; modelName = SanitizeModelName ( modelName ) ; PopluateReplacementDictionary ( project , replacementsDictionary , modelName ) ; _modelBuilderSettings = new ModelBuilderSettings { VSApplicationType = VsUtils . GetApplicationType ( serviceProvider , project ) , WizardKind = WizardKind . Generate , TargetSchemaVersion = EdmUtils . GetEntityFrameworkVersion ( project , serviceProvider , useLatestIfNoEF : false ) , NewItemFolder = GetFolderNameForNewItems ( dte , project ) , Project = project , ModelName = modelName , VsTemplatePath = customParams [ 0 ] as string , ReplacementDictionary = replacementsDictionary } ; var form = new ModelBuilderWizardForm ( serviceProvider , _modelBuilderSettings , ModelBuilderWizardForm . WizardMode . PerformAllFunctionality ) { FileAlreadyExistsError = false } ; try { form . Start ( ) ; } catch ( Exception ex ) { VsUtils . ShowErrorDialog ( string . Format ( CultureInfo . CurrentCulture , Resources . ModelObjectItemWizard_UnexpectedExceptionHasOccurred , ex . Message ) ) ; ClearErrors ( ) ; throw new WizardCancelledException ( ) ; } if ( form . FileAlreadyExistsError ) { Marshal . ThrowExceptionForHR ( VSConstants . E_ABORT ) ; } if ( form . WizardCancelled || ! form . WizardFinished ) { ClearErrors ( ) ; throw new WizardCancelledException ( ) ; } Debug . Assert ( ReferenceEquals ( _modelBuilderSettings , form . ModelBuilderSettings ) ) ; }
This method is called at the beginning of a template wizard run
This lets us run custom wizard logic before anything is created and is a good place, for example,
to collect user input that will alter the run in some way
This method is called at the beginning of a template wizard run This lets us run custom wizard logic before anything is created and is a good place for example to collect user input that will alter the run in some way
// the dte is the handle into the VS environment // get the current project that the wizard is running in // get file name the user chose  // the form.FileAlreadyExistsError flag is set in the WizardPageStart. We do it because if we  // threw this exception directly from the WizardPageStart it would be swallowed and the // "Add New Item" dialog would not show up. Throwing the exception from here will make // the "Add New Item" dialog re-appear which allows the user to enter a different model name. // if they cancelled or they didn't cancel, and we didn't log that Finish was pressed,  // they must have hit the X or an exception happened so cancel
automationObject
object
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code .
replacementsDictionary
Dictionary<string, string>
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code .
runKind
WizardRunKind
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code .
customParams
object[]
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
This API supports the Entity Framework infrastructure and is not intended to be used directly from your code .