src/Misc/EFTools/EntityDesign/VisualStudio/ModelWizard/engine/DatabaseGenerationEngine.cs
// <summary>
//     Create the WF workflow application used by the Database Script Generation wizard:
//     1. Deserialize the XAML file specified by the user
//     2. Add inputs
//     3. Add parameters to the EdmParameterBag, added to the workflow via an extension
// </summary>
// <param name="syncContext">SynchronizationContext of VS's UI thread that can be used by the workflow to spawn UIs</param>
// <param name="project"></param>
// <param name="artifactPath"></param>
// <param name="workflowFileInfo"></param>
// <param name="templatePath">DDL template path. We will resolve/validate this at runtime within the appropriate TemplateActivity</param>
// <param name="edmItemCollection"></param>
// <param name="existingSsdl"></param>
// <param name="existingMsl"></param>
// <param name="databaseSchemaName"></param>
// <param name="databaseName"></param>
// <param name="providerInvariantName"></param>
// <param name="providerConnectionString"></param>
// <param name="providerManifestToken"></param>
// <param name="targetVersion"></param>
// <param name="workflowCompletedHandler"></param>
// <param name="unhandledExceptionHandler"></param>
Create the WF workflow application used by the Database Script Generation wizard:
1. Deserialize the XAML file specified by the user
2. Add inputs
3. Add parameters to the EdmParameterBag, added to the workflow via an extension
Create the WF workflow application used by the Database Script Generation wizard : 1 . Deserialize the XAML file specified by the user 2 . Add inputs 3 . Add parameters to the EdmParameterBag added to the workflow via an extension
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1614:ElementParameterDocumentationMustHaveText")]
        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)
        {
            var inputs = new Dictionary<string, object>
                {
                    { EdmConstants.csdlInputName, edmItemCollection },
                    { EdmConstants.existingSsdlInputName, existingSsdl },
                    { EdmConstants.existingMslInputName, existingMsl }
                };
            var assemblyLoader = new DatabaseGenerationAssemblyLoader(project, VsUtils.GetVisualStudioInstallDir());
            var edmWorkflowSymbolResolver = new EdmParameterBag(
                syncContext, assemblyLoader, targetVersion, providerInvariantName, providerManifestToken, providerConnectionString,
                databaseSchemaName, databaseName, templatePath, artifactPath);
            Activity modelFirstWorkflowElement;
            using (var stream = workflowFileInfo.OpenRead())
            {
                using (
                    var xamlXmlReader = new XamlXmlReader(XmlReader.Create(stream), new DatabaseGenerationXamlSchemaContext(assemblyLoader))
                    )
                {
                    modelFirstWorkflowElement = ActivityXamlServices.Load(xamlXmlReader);
                }
            }
            var workflowInstance = new WorkflowApplication(modelFirstWorkflowElement, inputs);
            var symbolResolver = new SymbolResolver();
            symbolResolver.Add(typeof(EdmParameterBag).Name, edmWorkflowSymbolResolver);
            workflowInstance.Extensions.Add(symbolResolver);
            workflowInstance.Completed = workflowCompletedHandler;
            workflowInstance.OnUnhandledException = unhandledExceptionHandler;
            return workflowInstance;
        }
[ SuppressMessage ( " " , " " ) ] 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 ) { var inputs = new Dictionary < string , object > { { EdmConstants . csdlInputName , edmItemCollection } , { EdmConstants . existingSsdlInputName , existingSsdl } , { EdmConstants . existingMslInputName , existingMsl } } ; var assemblyLoader = new DatabaseGenerationAssemblyLoader ( project , VsUtils . GetVisualStudioInstallDir ( ) ) ; var edmWorkflowSymbolResolver = new EdmParameterBag ( syncContext , assemblyLoader , targetVersion , providerInvariantName , providerManifestToken , providerConnectionString , databaseSchemaName , databaseName , templatePath , artifactPath ) ; Activity modelFirstWorkflowElement ; using ( var stream = workflowFileInfo . OpenRead ( ) ) { using ( var xamlXmlReader = new XamlXmlReader ( XmlReader . Create ( stream ) , new DatabaseGenerationXamlSchemaContext ( assemblyLoader ) ) ) { modelFirstWorkflowElement = ActivityXamlServices . Load ( xamlXmlReader ) ; } } var workflowInstance = new WorkflowApplication ( modelFirstWorkflowElement , inputs ) ; var symbolResolver = new SymbolResolver ( ) ; symbolResolver . Add ( typeof ( EdmParameterBag ) . Name , edmWorkflowSymbolResolver ) ; workflowInstance . Extensions . Add ( symbolResolver ) ; workflowInstance . Completed = workflowCompletedHandler ; workflowInstance . OnUnhandledException = unhandledExceptionHandler ; return workflowInstance ; }
Create the WF workflow application used by the Database Script Generation wizard:
1.
Create the WF workflow application used by the Database Script Generation wizard : 1 .
// Inputs are specific to the workflow. No need to provide a strongly typed bag here // because the workflow has to define these. // Initialize the AssemblyLoader. This will cache project/website references and proffer assembly // references to the XamlSchemaContext as well as the OutputGeneratorActivities // 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. // Deserialize the XAML file into a Activity // Create a WorkflowInstance from the WorkflowElement and pass in the inputs // Attach a SymbolResolver for external parameters; this is like the ParameterBag
syncContext
SynchronizationContext
SynchronizationContext of VS's UI thread that can be used by the workflow to spawn UIs
SynchronizationContext of VS ' s UI thread that can be used by the workflow to spawn UIs
project
Project
None
artifactPath
string
None
workflowFileInfo
FileInfo
None
templatePath
string
DDL template path. We will resolve/validate this at runtime within the appropriate TemplateActivity
DDL template path . We will resolve / validate this at runtime within the appropriate TemplateActivity
edmItemCollection
EdmItemCollection
None
existingSsdl
string
None
existingMsl
string
None
databaseSchemaName
string
None
databaseName
string
None
providerInvariantName
string
None
providerConnectionString
string
None
providerManifestToken
string
None
targetVersion
Version
None
workflowCompletedHandler
Action<WorkflowApplicationCompletedEventArgs>
None
unhandledExceptionHandler
Func<WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction>
None