internal ModelGenerationExtensionDispatcher(WizardKind wizardKind, XDocument dbDocument, XDocument currentDocument, Project project)
 {
     _wizardKind           = wizardKind;
     _fromDatabaseDocument = dbDocument;
     _currentXDocument     = currentDocument;
     _project = project;
 }
 internal ModelGenerationExtensionDispatcher(WizardKind wizardKind, XDocument dbDocument, XDocument currentDocument, Project project)
 {
     _wizardKind = wizardKind;
     _fromDatabaseDocument = dbDocument;
     _currentXDocument = currentDocument;
     _project = project;
 }
 internal ModelGenerationExtensionContextImpl(
     Project project, Version targetSchemaVersion, XDocument currentXDocument, XDocument documentFromDatabase, WizardKind wizardKind)
 {
     _project = project;
     _targetSchemaVersion = targetSchemaVersion;
     _currentXDocument = currentXDocument;
     _documentFromDatabase = documentFromDatabase;
     _wizardKind = wizardKind;
 }
 internal ModelGenerationExtensionContextImpl(
     Project project, Version targetSchemaVersion, XDocument currentXDocument, XDocument documentFromDatabase, WizardKind wizardKind)
 {
     _project              = project;
     _targetSchemaVersion  = targetSchemaVersion;
     _currentXDocument     = currentXDocument;
     _documentFromDatabase = documentFromDatabase;
     _wizardKind           = wizardKind;
 }
 internal UpdateModelFromDBExtensionDispatcher(
     WizardKind wizardKind, XDocument dbDocument, XDocument currentDocument, ProjectItem projectItem, XDocument originalDocument,
     XDocument updateModelDocument)
     :
     base(wizardKind, dbDocument, currentDocument, projectItem.ContainingProject)
 {
     _projectItem         = projectItem;
     _originalDocument    = originalDocument;
     _updateModelDocument = updateModelDocument;
 }
 internal UpdateModelFromDBExtensionDispatcher(
     WizardKind wizardKind, XDocument dbDocument, XDocument currentDocument, ProjectItem projectItem, XDocument originalDocument,
     XDocument updateModelDocument)
     :
         base(wizardKind, dbDocument, currentDocument, projectItem.ContainingProject)
 {
     _projectItem = projectItem;
     _originalDocument = originalDocument;
     _updateModelDocument = updateModelDocument;
 }
        private void UpdateModel(Project project, XDocument currentDocument, WizardKind mode)
        {
            bool isEFv2Model = project.IsEntityFrameworkV2Model();

            if (!isEFv2Model)
            {
                _logger.Log("Could not generate documentation because the entity model targets an older framework.");
                return;
            }

            _logger.Log("{0:yyyy-MM-dd HH:mm:ss:ffff}: ------ Starting documentation generation for project: {1} ------", DateTime.Now, project.UniqueName);

            // Attempt to find the database connection string.
            SqlConnectionStringBuilder connectionString;

            try
            {
                connectionString = _connectionStringLocator.Locate(project);
            }
            catch (ConnectionStringLocationException exception)
            {
                _logger.Log("Connection string could not be located for project '{0}': {1}", project.Name, exception.Message);
                if (mode == WizardKind.Generate)
                {
                    _logger.Log("Try updating the model after initial generation and the connection string has been saved to a config file.");
                }

                _logger.Log("{0:yyyy-MM-dd HH:mm:ss:ffff}: Documentation generation failed", DateTime.Now);
                return;
            }

            using (var docSource = _customAttributeSourceFactory(connectionString.ToString()))
            {
                _modelUpdaterFactory(docSource).UpdateDocumentation(currentDocument);
            }

            _logger.Log("{0:yyyy-MM-dd HH:mm:ss:ffff}: Documentation generation succeeded", DateTime.Now);
        }
Пример #8
0
        private static void ValidateArtifact(EntityDesignModelManager modelManager, EFArtifact artifact, WizardKind kind)
        {
            var       errorsFound     = false;
            Exception caughtException = null;

            try
            {
                VsUtils.EnsureProvider(artifact);
                var artifactSet = (EntityDesignArtifactSet)modelManager.GetArtifactSet(artifact.Uri);
                modelManager.ValidateAndCompileMappings(artifactSet, false); // just run the runtime's validation
                var errors = artifactSet.GetAllErrorsForArtifact(artifact);
                if (errors != null &&
                    errors.Count > 0)
                {
                    foreach (var error in errors)
                    {
                        if (error.IsError())
                        {
                            errorsFound = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                caughtException = e;
            }

            if (errorsFound || caughtException != null)
            {
                var message = string.Empty;
                if (kind == WizardKind.Generate)
                {
                    message = Resources.Extensibility_ExtensionMadeBadModel;
                }
                else if (kind == WizardKind.UpdateModel)
                {
                    message = Resources.Extensibility_ExtensionMadeBadModel_Update;
                }

                if (caughtException == null)
                {
                    throw new InvalidOperationException(message);
                }
                else
                {
                    throw new InvalidOperationException(message, caughtException);
                }
            }
        }
        private static void ValidateArtifact(EntityDesignModelManager modelManager, EFArtifact artifact, WizardKind kind)
        {
            var errorsFound = false;
            Exception caughtException = null;

            try
            {
                VsUtils.EnsureProvider(artifact);
                var artifactSet = (EntityDesignArtifactSet)modelManager.GetArtifactSet(artifact.Uri);
                modelManager.ValidateAndCompileMappings(artifactSet, false); // just run the runtime's validation
                var errors = artifactSet.GetAllErrorsForArtifact(artifact);
                if (errors != null
                    && errors.Count > 0)
                {
                    foreach (var error in errors)
                    {
                        if (error.IsError())
                        {
                            errorsFound = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                caughtException = e;
            }

            if (errorsFound || caughtException != null)
            {
                var message = string.Empty;
                if (kind == WizardKind.Generate)
                {
                    message = Resources.Extensibility_ExtensionMadeBadModel;
                }
                else if (kind == WizardKind.UpdateModel)
                {
                    message = Resources.Extensibility_ExtensionMadeBadModel_Update;
                }

                if (caughtException == null)
                {
                    throw new InvalidOperationException(message);
                }
                else
                {
                    throw new InvalidOperationException(message, caughtException);
                }
            }
        }
        private void UpdateModel(Project project, XDocument currentDocument, WizardKind mode)
        {
            bool isEFv2Model = project.IsEntityFrameworkV2Model();
            if (!isEFv2Model)
                return;

            _logger.Log("{0:yyyy-MM-dd HH:mm:ss:ffff}: ------------ Starting documentation generation for project: {1} ------------", DateTime.Now, project.UniqueName);

            // Attempt to find the database connection string.
            SqlConnectionStringBuilder connectionString;
            try
            {
                connectionString = _connectionStringLocator.Locate(project);
            }
            catch (ConnectionStringLocationException exception)
            {
                _logger.Log("Connection string could not be located for project '{0}': {1}.", project.Name, exception.Message);
                if (mode == WizardKind.Generate)
                    _logger.Log("Try updating the model after initial generation and connection string has been saved to App.config.");

                _logger.Log("{0:yyyy-MM-dd HH:mm:ss:ffff}: Documentation generation failed", DateTime.Now);
                return;
            }

            using (var docSource = _documentationSourceFactory(connectionString.ToString()))
            {
                _modelUpdaterFactory(docSource).UpdateDocumentation(currentDocument);
            }

            _logger.Log("{0:yyyy-MM-dd HH:mm:ss:ffff}: Documentation generation succeeded", DateTime.Now);
        }