public void AssemblyLoader_passed_null_project_can_find_paths_for_standard_DLLs_case_insensitive()
 {
     const string vsInstallPath = @"C:\My\Test\VS\InstallPath";
     var assemblyLoader = new DatabaseGenerationAssemblyLoader(null, vsInstallPath);
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.dll"),
         assemblyLoader.GetAssemblyPath("EntityFramework"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.dll"),
         assemblyLoader.GetAssemblyPath("entityframework"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.dll"),
         assemblyLoader.GetAssemblyPath("ENTITYFRAMEWORK"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
         assemblyLoader.GetAssemblyPath("EntityFramework.SqlServer"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
         assemblyLoader.GetAssemblyPath("entityframework.sqlserver"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
         assemblyLoader.GetAssemblyPath("ENTITYFRAMEWORK.SQLSERVER"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
         assemblyLoader.GetAssemblyPath("EntityFramework.SqlServerCompact"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
         assemblyLoader.GetAssemblyPath("entityframework.sqlservercompact"));
     Assert.Equal(
         Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
         assemblyLoader.GetAssemblyPath("ENTITYFRAMEWORK.SQLSERVERCOMPACT"));
 }
        public void AssemblyLoader_passed_null_project_can_find_paths_for_standard_DLLs_case_insensitive()
        {
            const string vsInstallPath  = @"C:\My\Test\VS\InstallPath";
            var          assemblyLoader = new DatabaseGenerationAssemblyLoader(null, vsInstallPath);

            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("entityframework"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("ENTITYFRAMEWORK"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServer"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("entityframework.sqlserver"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("ENTITYFRAMEWORK.SQLSERVER"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServerCompact"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("entityframework.sqlservercompact"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("ENTITYFRAMEWORK.SQLSERVERCOMPACT"));
        }
        public void AssemblyLoader_passed_non_WebsiteProject_can_find_correct_paths_to_DLLs()
        {
            const string vsInstallPath = @"C:\My\Test\VS\InstallPath";
            const string projectPath = @"C:\My\Test\ProjectPath";
            var project =
                MockDTE.CreateProject(
                    new[]
                        {
                            MockDTE.CreateReference3(
                                "EntityFramework", "6.0.0.0", "EntityFramework",
                                Path.Combine(projectPath, "EntityFramework.dll")),
                            MockDTE.CreateReference3(
                                "EntityFramework.SqlServer", "6.0.0.0", "EntityFramework.SqlServer",
                                Path.Combine(projectPath, "EntityFramework.SqlServer.dll")),
                            MockDTE.CreateReference3(
                                "EntityFramework.SqlServerCompact", "6.0.0.0",
                                "EntityFramework.SqlServerCompact",
                                Path.Combine(projectPath, "EntityFramework.SqlServerCompact.dll")),
                            MockDTE.CreateReference3(
                                "My.Project.Reference", "6.0.0.0", "My.Project.Reference",
                                Path.Combine(projectPath, "My.Project.Reference.dll"), true)
                        });
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, vsInstallPath);

            // assert that the DLLs installed under VS are resolved there
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServer"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServerCompact"));

            // assert that other project references are resolved to wherever their reference points to
            Assert.Equal(
                Path.Combine(projectPath, "My.Project.Reference.dll"),
                assemblyLoader.GetAssemblyPath("My.Project.Reference"));
        }
        public void AssemblyLoader_passed_non_WebsiteProject_can_find_correct_paths_to_DLLs()
        {
            const string vsInstallPath = @"C:\My\Test\VS\InstallPath";
            const string projectPath   = @"C:\My\Test\ProjectPath";
            var          project       =
                MockDTE.CreateProject(
                    new[]
            {
                MockDTE.CreateReference3(
                    "EntityFramework", "6.0.0.0", "EntityFramework",
                    Path.Combine(projectPath, "EntityFramework.dll")),
                MockDTE.CreateReference3(
                    "EntityFramework.SqlServer", "6.0.0.0", "EntityFramework.SqlServer",
                    Path.Combine(projectPath, "EntityFramework.SqlServer.dll")),
                MockDTE.CreateReference3(
                    "EntityFramework.SqlServerCompact", "6.0.0.0",
                    "EntityFramework.SqlServerCompact",
                    Path.Combine(projectPath, "EntityFramework.SqlServerCompact.dll")),
                MockDTE.CreateReference3(
                    "My.Project.Reference", "6.0.0.0", "My.Project.Reference",
                    Path.Combine(projectPath, "My.Project.Reference.dll"), true)
            });
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, vsInstallPath);

            // assert that the DLLs installed under VS are resolved there
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServer"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServerCompact"));

            // assert that other project references are resolved to wherever their reference points to
            Assert.Equal(
                Path.Combine(projectPath, "My.Project.Reference.dll"),
                assemblyLoader.GetAssemblyPath("My.Project.Reference"));
        }
        public void AssemblyLoader_passed_WebsiteProject_can_find_correct_paths_to_DLLs()
        {
            const string vsInstallPath = @"C:\My\Test\VS\InstallPath";
            const string projectPath   = @"C:\My\Test\WebsitePath";
            var          project       =
                MockDTE.CreateWebSite(
                    new[]
            {
                MockDTE.CreateAssemblyReference(
                    "EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                    Path.Combine(projectPath, "EntityFramework.dll")),
                MockDTE.CreateAssemblyReference(
                    "EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                    Path.Combine(projectPath, "EntityFramework.SqlServer.dll")),
                MockDTE.CreateAssemblyReference(
                    "EntityFramework.SqlServerCompact, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                    Path.Combine(projectPath, "EntityFramework.SqlServerCompact.dll")),
                MockDTE.CreateAssemblyReference(
                    "My.WebsiteProject.Reference, Version=4.1.0.0, Culture=neutral, PublicKeyToken=bbbbbbbbbbbbbbbb",
                    Path.Combine(projectPath, "My.WebsiteProject.Reference.dll"))
            });
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, vsInstallPath);

            // assert that the DLLs installed under VS are resolved there
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServer"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServerCompact"));

            // assert that other project references are resolved to wherever their reference points to
            Assert.Equal(
                Path.Combine(projectPath, "My.WebsiteProject.Reference.dll"),
                assemblyLoader.GetAssemblyPath("My.WebsiteProject.Reference"));
        }
        internal static WorkflowApplication CreateDatabaseScriptGenerationWorkflow(
            SynchronizationContext syncContext,
            Project project,
            string artifactPath,
            FileInfo workflowFileInfo,
            string templatePath,
            EdmItemCollection edmItemCollection,
            string existingSsdl,
            string existingMsl,
            string databaseSchemaName,
            string databaseName,
            string providerInvariantName,
            string providerConnectionString,
            string providerManifestToken,
            Version targetVersion,
            Action <WorkflowApplicationCompletedEventArgs> workflowCompletedHandler,
            Func <WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction> unhandledExceptionHandler)
        {
            // Inputs are specific to the workflow. No need to provide a strongly typed bag here
            // because the workflow has to define these.
            var inputs = new Dictionary <string, object>
            {
                { EdmConstants.csdlInputName, edmItemCollection },
                { EdmConstants.existingSsdlInputName, existingSsdl },
                { EdmConstants.existingMslInputName, existingMsl }
            };

            // Initialize the AssemblyLoader. This will cache project/website references and proffer assembly
            // references to the XamlSchemaContext as well as the OutputGeneratorActivities
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, VsUtils.GetVisualStudioInstallDir());

            // Parameters can be used throughout the workflow. These are more ubiquitous than inputs and
            // so they do not need to be defined ahead of time in the workflow.
            var edmWorkflowSymbolResolver = new EdmParameterBag(
                syncContext, assemblyLoader, targetVersion, providerInvariantName, providerManifestToken, providerConnectionString,
                databaseSchemaName, databaseName, templatePath, artifactPath);

            // Deserialize the XAML file into a Activity
            Activity modelFirstWorkflowElement;

            using (var stream = workflowFileInfo.OpenRead())
            {
                using (
                    var xamlXmlReader = new XamlXmlReader(XmlReader.Create(stream), new DatabaseGenerationXamlSchemaContext(assemblyLoader))
                    )
                {
                    modelFirstWorkflowElement = ActivityXamlServices.Load(xamlXmlReader);
                }
            }

            // Create a WorkflowInstance from the WorkflowElement and pass in the inputs
            var workflowInstance = new WorkflowApplication(modelFirstWorkflowElement, inputs);

            // Attach a SymbolResolver for external parameters; this is like the ParameterBag
            var symbolResolver = new SymbolResolver();

            symbolResolver.Add(typeof(EdmParameterBag).Name, edmWorkflowSymbolResolver);

            workflowInstance.Extensions.Add(symbolResolver);
            workflowInstance.Completed            = workflowCompletedHandler;
            workflowInstance.OnUnhandledException = unhandledExceptionHandler;

            return(workflowInstance);
        }
        internal static WorkflowApplication CreateDatabaseScriptGenerationWorkflow(
            SynchronizationContext syncContext,
            Project project,
            string artifactPath,
            FileInfo workflowFileInfo,
            string templatePath,
            EdmItemCollection edmItemCollection,
            string existingSsdl,
            string existingMsl,
            string databaseSchemaName,
            string databaseName,
            string providerInvariantName,
            string providerConnectionString,
            string providerManifestToken,
            Version targetVersion,
            Action<WorkflowApplicationCompletedEventArgs> workflowCompletedHandler,
            Func<WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction> unhandledExceptionHandler)
        {
            // Inputs are specific to the workflow. No need to provide a strongly typed bag here
            // because the workflow has to define these.
            var inputs = new Dictionary<string, object>
                {
                    { EdmConstants.csdlInputName, edmItemCollection },
                    { EdmConstants.existingSsdlInputName, existingSsdl },
                    { EdmConstants.existingMslInputName, existingMsl }
                };

            // Initialize the AssemblyLoader. This will cache project/website references and proffer assembly
            // references to the XamlSchemaContext as well as the OutputGeneratorActivities
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, VsUtils.GetVisualStudioInstallDir());

            // Parameters can be used throughout the workflow. These are more ubiquitous than inputs and
            // so they do not need to be defined ahead of time in the workflow.
            var edmWorkflowSymbolResolver = new EdmParameterBag(
                syncContext, assemblyLoader, targetVersion, providerInvariantName, providerManifestToken, providerConnectionString,
                databaseSchemaName, databaseName, templatePath, artifactPath);

            // Deserialize the XAML file into a Activity
            Activity modelFirstWorkflowElement;
            using (var stream = workflowFileInfo.OpenRead())
            {
                using (
                    var xamlXmlReader = new XamlXmlReader(XmlReader.Create(stream), new DatabaseGenerationXamlSchemaContext(assemblyLoader))
                    )
                {
                    modelFirstWorkflowElement = ActivityXamlServices.Load(xamlXmlReader);
                }
            }

            // Create a WorkflowInstance from the WorkflowElement and pass in the inputs
            var workflowInstance = new WorkflowApplication(modelFirstWorkflowElement, inputs);

            // Attach a SymbolResolver for external parameters; this is like the ParameterBag
            var symbolResolver = new SymbolResolver();
            symbolResolver.Add(typeof(EdmParameterBag).Name, edmWorkflowSymbolResolver);

            workflowInstance.Extensions.Add(symbolResolver);
            workflowInstance.Completed = workflowCompletedHandler;
            workflowInstance.OnUnhandledException = unhandledExceptionHandler;

            return workflowInstance;
        }
        public void AssemblyLoader_passed_WebsiteProject_can_find_correct_paths_to_DLLs()
        {
            const string vsInstallPath = @"C:\My\Test\VS\InstallPath";
            const string projectPath = @"C:\My\Test\WebsitePath";
            var project =
                MockDTE.CreateWebSite(
                    new[]
                        {
                            MockDTE.CreateAssemblyReference(
                                "EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                                Path.Combine(projectPath, "EntityFramework.dll")),
                            MockDTE.CreateAssemblyReference(
                                "EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                                Path.Combine(projectPath, "EntityFramework.SqlServer.dll")),
                            MockDTE.CreateAssemblyReference(
                                "EntityFramework.SqlServerCompact, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                                Path.Combine(projectPath, "EntityFramework.SqlServerCompact.dll")),
                            MockDTE.CreateAssemblyReference(
                                "My.WebsiteProject.Reference, Version=4.1.0.0, Culture=neutral, PublicKeyToken=bbbbbbbbbbbbbbbb",
                                Path.Combine(projectPath, "My.WebsiteProject.Reference.dll"))
                        });
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, vsInstallPath);

            // assert that the DLLs installed under VS are resolved there
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServer"));
            Assert.Equal(
                Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"),
                assemblyLoader.GetAssemblyPath("EntityFramework.SqlServerCompact"));

            // assert that other project references are resolved to wherever their reference points to
            Assert.Equal(
                Path.Combine(projectPath, "My.WebsiteProject.Reference.dll"),
                assemblyLoader.GetAssemblyPath("My.WebsiteProject.Reference"));
        }
 internal DatabaseGenerationXamlSchemaContext(DatabaseGenerationAssemblyLoader assemblyLoader)
 {
     _assemblyLoader = assemblyLoader;
 }
 internal DatabaseGenerationXamlSchemaContext(DatabaseGenerationAssemblyLoader assemblyLoader)
 {
     _assemblyLoader = assemblyLoader;
 }