示例#1
0
        /// <summary>
        /// Attempts to run the template wizard.
        /// </summary>
        /// <param name="shell">The <see cref="IVsUIShell">shell</see> associated with the wizard.</param>
        /// <returns>True if the wizard completed successfully; otherwise, false if the wizard was canceled.</returns>
        protected override bool TryRunWizard( IVsUIShell shell )
        {
            Arg.NotNull( shell, nameof( shell ) );

            createNewViewModel = false;

            var mapper = new ViewReplacementsMapper( Project );
            var model = new ViewItemTemplateWizardViewModel();

            // map replacements to model
            mapper.Map( Context.Replacements, model );

            // only show the dialog if the context is interactive
            if ( Context.IsInteractive )
            {
                var projectInfo = new ProjectInformation( Project );
                var view = new ViewItemTemplateWizard( model, projectInfo );

                // show the wizard
                if ( !( view.ShowDialog( shell ) ?? false ) )
                    return false;
            }

            // map model back to replacements
            mapper.Map( model, Context.Replacements );

            // store information for view model template, which typically follows
            createNewViewModel = model.ViewModelOption == 1;
            viewModelTemplateKey = model.IsTopLevelSupported && model.IsTopLevel ? "_topLevelViewModelTemplateName" : "_viewModelTemplateName";

            return true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DbContextItemTemplateWizard"/> class.
        /// </summary>
        /// <param name="model">The <see cref="ViewItemTemplateWizardViewModel">model</see> for the view.</param>
        /// <param name="projectInformation">The source <see cref="ProjectInformation">project information</see> used for browsing existing types.</param>
        /// <param name="shell">The <see cref="IVsUIShell">shell</see> used to provide user feedback.</param>
        /// <param name="dataExplorerConnectionManager">The <see cref="Lazy{T}">on-demand</see> <see cref="IVsDataConnectionDialogFactory"/> used to create new data connections.</param>
        /// <param name="dataConnectionDialogFactory">The <see cref="Lazy{T}">on-demand</see> <see cref="IVsDataExplorerConnectionManager">data explorer connection manager</see> used to add created data connections.</param>
        public DbContextItemTemplateWizard(
            DbContextItemTemplateWizardViewModel model,
            ProjectInformation projectInformation,
            IVsUIShell shell,
            Lazy<IVsDataConnectionDialogFactory> dataConnectionDialogFactory,
            Lazy<IVsDataExplorerConnectionManager> dataExplorerConnectionManager )
        {
            Arg.NotNull( shell, nameof( shell ) );
            Arg.NotNull( dataConnectionDialogFactory, nameof( dataConnectionDialogFactory ) );
            Arg.NotNull( dataExplorerConnectionManager, nameof( dataExplorerConnectionManager ) );

            InitializeComponent();
            Model = model;
            projectInfo = projectInformation;
            this.shell = shell;
            this.dataConnectionDialogFactory = dataConnectionDialogFactory;
            this.dataExplorerConnectionManager = dataExplorerConnectionManager;
        }
示例#3
0
            private static Assembly LoadLocalAssemblyFromExistingBuild( ProjectInformation projectInfo )
            {
                if ( projectInfo == null )
                    return null;

                var assemblyFile = projectInfo.TargetPath;

                if ( !File.Exists( assemblyFile ) )
                    return null;

                Debug.WriteLine( "Attempting to load existing assembly from {0}.", new object[] { assemblyFile } );
                return Assembly.ReflectionOnlyLoadFrom( assemblyFile );
            }
示例#4
0
            private static async Task<Tuple<Assembly, IReadOnlyList<AssemblyName>>> CreateDynamicAssemblyAsync( ProjectInformation projectInfo, AssemblyContentType contentType )
            {
                Contract.Ensures( Contract.Result<Task<Tuple<Assembly, IReadOnlyList<AssemblyName>>>>() != null );

                if ( projectInfo == null )
                    return new Tuple<Assembly, IReadOnlyList<AssemblyName>>( null, new AssemblyName[0] );

                byte[] rawAssembly;
                IReadOnlyList<AssemblyName> referencedAssemblies;

                // create a msbuild workspace and get the compilation unit for the current project
                using ( var workspace = MSBuildWorkspace.Create() )
                {
                    var project = await workspace.OpenProjectAsync( projectInfo.ProjectPath ).ConfigureAwait( false );
                    var compilation = await project.GetCompilationAsync().ConfigureAwait( false );

                    using ( var stream = new MemoryStream() )
                    {
                        // compile into an in-memory assembly
                        var result = compilation.Emit( stream );

                        // handled failed compilation gracefully
                        if ( !result.Success )
                            return new Tuple<Assembly, IReadOnlyList<AssemblyName>>( null, new AssemblyName[0] );

                        rawAssembly = stream.ToArray();
                    }

                    // loading assemblies from binary will result in no location information being available. to ensure that referenced
                    // assemblies can be resolved, build a list of referenced assembly names from the metadata
                    referencedAssemblies = project.MetadataReferences.Select( mr => AssemblyName.GetAssemblyName( mr.Display ) ).ToArray();
                }

                // we only need the type name so we use a reflection-only load
                var assembly = Assembly.ReflectionOnlyLoad( rawAssembly );

                return Tuple.Create( assembly, referencedAssemblies );
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewItemTemplateWizard"/> class.
 /// </summary>
 /// <param name="model">The <see cref="ViewItemTemplateWizardViewModel">model</see> for the view.</param>
 /// <param name="projectInformation">The source <see cref="ProjectInformation">project information</see> used for browsing existing types.</param>
 public ViewItemTemplateWizard( ViewItemTemplateWizardViewModel model, ProjectInformation projectInformation )
     : this()
 {
     Model = model;
     projectInfo = projectInformation;
 }