From: <mcu...@us...> - 2007-09-20 20:46:19
|
Revision: 1137 http://orm.svn.sourceforge.net/orm/?rev=1137&view=rev Author: mcurland Date: 2007-09-20 13:46:20 -0700 (Thu, 20 Sep 2007) Log Message: ----------- Do some additional work on the database importer. The import works fine for a DB with one schema, but does not allow tables from multiple schemas to be imported, which is a fundamental issue that will take some redesign. Also, our layout on import is not looking very good. Decline adding to setup for now until these issues are fixed. refs #305 Modified Paths: -------------- trunk/ORMModel/Shell/ORMGeneralTemplateWizard.cs trunk/ORMModel/Shell/PackageResources/PackageResources.cs trunk/ORMModel/Shell/PackageResources/VSPackage.resx trunk/Tools/DatabaseImport/Install.bat trunk/Tools/DatabaseImport/ORMDatabaseImportWizard.cs trunk/Tools/DatabaseImport/SqlServer2005DcilSchemaProvider.cs Added Paths: ----------- trunk/Tools/DatabaseImport/ProjectItems/ trunk/Tools/DatabaseImport/ProjectItems/CSharp.zip trunk/Tools/DatabaseImport/ProjectItems/General.zip trunk/Tools/DatabaseImport/ProjectItems/JSharp.zip trunk/Tools/DatabaseImport/ProjectItems/VisualBasic.zip trunk/Tools/DatabaseImport/ProjectItems/VisualC.zip trunk/Tools/DatabaseImport/ProjectItems/Web/ trunk/Tools/DatabaseImport/ProjectItems/Web/CSharp.zip trunk/Tools/DatabaseImport/ProjectItems/Web/JSharp.zip trunk/Tools/DatabaseImport/ProjectItems/Web/VisualBasic.zip Removed Paths: ------------- trunk/Tools/DatabaseImport/OrmDatabaseImportTemplate.zip Modified: trunk/ORMModel/Shell/ORMGeneralTemplateWizard.cs =================================================================== --- trunk/ORMModel/Shell/ORMGeneralTemplateWizard.cs 2007-09-20 20:41:26 UTC (rev 1136) +++ trunk/ORMModel/Shell/ORMGeneralTemplateWizard.cs 2007-09-20 20:46:20 UTC (rev 1137) @@ -37,6 +37,7 @@ // Given that we can't make a non-nested class 'private', 'internal' is at least better than 'public'. internal sealed class ORMGeneralTemplateWizard : IWizard { + // This code is duplicated in Tools/DatabaseImport/ORMDatabaseImportWizard.cs (ORMDatabaseImportGeneralProjectWizard class) private static bool? TemplateWizardIsOrcasOrLater; /// <summary> Modified: trunk/ORMModel/Shell/PackageResources/PackageResources.cs =================================================================== --- trunk/ORMModel/Shell/PackageResources/PackageResources.cs 2007-09-20 20:41:26 UTC (rev 1136) +++ trunk/ORMModel/Shell/PackageResources/PackageResources.cs 2007-09-20 20:46:20 UTC (rev 1137) @@ -21,6 +21,11 @@ public const int AboutBoxIcon = 110; public const int ORMFileIcon = 111; + // Favor for the DatabaseImport project, the resources + // need to be in a package. + // public const int ORMFileDBImportDisplayName = 112; + // public const int ORMFileDBImportDescription = 113; + public const int ToolWindowIcons = 125; public const int PackageLoadKey = 150; Modified: trunk/ORMModel/Shell/PackageResources/VSPackage.resx =================================================================== --- trunk/ORMModel/Shell/PackageResources/VSPackage.resx 2007-09-20 20:41:26 UTC (rev 1136) +++ trunk/ORMModel/Shell/PackageResources/VSPackage.resx 2007-09-20 20:46:20 UTC (rev 1137) @@ -106,6 +106,14 @@ <value>../../Resources/ORM.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <comment>PackageResources.Id.ORMFileIcon</comment> </data> + <data name="112"> + <value>Object-Role Modeling (DB Import)</value> + <comment>PackageResources.Id.ORMFileDBImportDisplayName</comment> + </data> + <data name="113"> + <value>Object-Role Modeling File for Neumont ORM Architect (Reverse Engineer from Database)</value> + <comment>PackageResources.Id.ORMFileDBImportDescription</comment> + </data> <data name="125" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>../../Resources/ToolWindowIcons.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <comment>PackageResources.Id.ToolWindowIcons and IDB_TOOLWINDOWICONS</comment> Modified: trunk/Tools/DatabaseImport/Install.bat =================================================================== --- trunk/Tools/DatabaseImport/Install.bat 2007-09-20 20:41:26 UTC (rev 1136) +++ trunk/Tools/DatabaseImport/Install.bat 2007-09-20 20:46:20 UTC (rev 1137) @@ -3,4 +3,5 @@ SET RootDir=%~dp0. CALL "%RootDir%\..\..\SetupEnvironment.bat" %* -XCOPY /Y /D /V /Q "%RootDir%\OrmDatabaseImportTemplate.zip" "%VSItemTemplatesDir%\CSharp\" +FOR %%A IN ("%RootDir%\ProjectItems\*.zip") DO ECHO F | XCOPY /Y /D /V /Q "%%~fA" "%VSItemTemplatesDir%\%%~nA\ORMModelFromDatabase.zip" +FOR %%A IN ("%RootDir%\ProjectItems\Web\*.zip") DO ECHO F | XCOPY /Y /D /V /Q "%%~fA" "%VSItemTemplatesDir%\Web\%%~nA\ORMModelFromDatabase.zip" Modified: trunk/Tools/DatabaseImport/ORMDatabaseImportWizard.cs =================================================================== --- trunk/Tools/DatabaseImport/ORMDatabaseImportWizard.cs 2007-09-20 20:41:26 UTC (rev 1136) +++ trunk/Tools/DatabaseImport/ORMDatabaseImportWizard.cs 2007-09-20 20:46:20 UTC (rev 1137) @@ -3,6 +3,7 @@ using System.Data; using System.Diagnostics; using System.Text; +using Microsoft.VisualStudio; using Microsoft.VisualStudio.TemplateWizard; using Microsoft.VisualStudio.Data; using Microsoft.VisualStudio.Shell; @@ -20,28 +21,56 @@ /// <summary> /// Wizard interface used when loading a DcilREFromDB template /// </summary> + [CLSCompliant(false)] + [TemplateWizardDisallowUserTemplatesSecurity(true)] public class ORMDatabaseImportWizard : IWizard { #region Member variables - private bool myAddToProject = true; + private bool myAddToProject = false; #endregion // Member variables #region IWizard Members + /// <summary> + /// Implements <see cref="IWizard.BeforeOpeningFile"/> + /// </summary> + protected void BeforeOpeningFile(EnvDTE.ProjectItem projectItem) + { + } void IWizard.BeforeOpeningFile(EnvDTE.ProjectItem projectItem) { + BeforeOpeningFile(projectItem); } + /// <summary> + /// Implements <see cref="IWizard.ProjectFinishedGenerating"/> + /// </summary> + protected void ProjectFinishedGenerating(EnvDTE.Project project) + { + } void IWizard.ProjectFinishedGenerating(EnvDTE.Project project) { + ProjectFinishedGenerating(project); } + /// <summary> + /// Implements <see cref="IWizard.ProjectItemFinishedGenerating"/> + /// </summary> + protected void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) + { + } void IWizard.ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem) { - + ProjectItemFinishedGenerating(projectItem); + } + /// <summary> + /// Implements <see cref="IWizard.RunFinished"/> + /// </summary> + protected void RunFinished() + { } - void IWizard.RunFinished() { + RunFinished(); } /// <summary> @@ -55,7 +84,10 @@ return ((provider != null) ? provider.GetService(serviceType) as T : null) ?? Package.GetGlobalService(serviceType) as T; } - void IWizard.RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) + /// <summary> + /// Implements <see cref="IWizard.RunStarted"/> + /// </summary> + protected void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { IOleServiceProvider oleServiceProvider = automationObject as IOleServiceProvider; ServiceProvider serviceProvider = (oleServiceProvider != null) ? new ServiceProvider(oleServiceProvider) : null; @@ -120,14 +152,189 @@ replacementsDictionary.Add("$DcilFile$", replacementString); } } - } + myAddToProject = true; + } } + void IWizard.RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + RunStarted(automationObject, replacementsDictionary, runKind, customParams); + } - bool IWizard.ShouldAddProjectItem(string filePath) + /// <summary> + /// Implements <see cref="IWizard.ShouldAddProjectItem"/> + /// </summary> + protected bool ShouldAddProjectItem(string filePath) { return myAddToProject; } - + bool IWizard.ShouldAddProjectItem(string filePath) + { + return ShouldAddProjectItem(filePath); + } #endregion } + // Following code is lifted directly from ORMModel/Shell/ORMGeneralTemplateWizard.cs + + /// <summary> + /// Works around Visual Studio bugs in order to allow <c>.vstemplate</c> files + /// to be used for the "<c>General</c>" <c>ProjectType</c>. + /// </summary> + [CLSCompliant(false)] + public class ORMDatabaseImportGeneralProjectWizard : ORMDatabaseImportWizard, IWizard + { + private static bool? TemplateWizardIsOrcasOrLater; + + /// <summary> + /// Prevents the pre-Orcas version of <c>Microsoft.VisualStudio.TemplateWizard.Wizard</c> from crashing in <c>OpenNotedItems</c>. + /// </summary> + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + protected new void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + base.RunStarted(automationObject, replacementsDictionary, runKind, customParams); + if (!base.ShouldAddProjectItem(null)) + { + return; + } + const int OrcasMajorVersionNumber = 9; + const string TemplateWizardAssemblyName = "Microsoft.VisualStudio.TemplateWizard"; + const string SuppressOpeningItems = "$__suppress_opening_items__$"; + + bool? templateWizardIsOrcasOrLater = TemplateWizardIsOrcasOrLater; + + // If we haven't yet determined whether we are being called by the pre-Orcas version of TemplateWizard or not, do so now. + if (!templateWizardIsOrcasOrLater.HasValue) + { + System.Reflection.Assembly callingAssembly = System.Reflection.Assembly.GetCallingAssembly(); + + // UNDONE: This is asserting at this point, figure out how to determine if we're Whidbey or Orcas + //Debug.Assert(callingAssembly != null && callingAssembly.FullName.StartsWith(TemplateWizardAssemblyName, StringComparison.Ordinal)); + + // If for any reason we can't tell what version we're running under, we assume it is pre-Orcas. + templateWizardIsOrcasOrLater = TemplateWizardIsOrcasOrLater = + (callingAssembly != null && (callingAssembly.GetName().Version.Major >= OrcasMajorVersionNumber)); + } + + if (templateWizardIsOrcasOrLater.GetValueOrDefault()) + { + // The Orcas version of TemplateWizard correctly checks Project.FullName for null / empty string before + // trying to create a Uri from it. Therefore, this workaround is only needed for pre-Orcas versions. + return; + } + + Debug.Assert(runKind == WizardRunKind.AsNewItem); + + if (replacementsDictionary == null) + { + // If we don't have a replacements dictionary, we can't do anything anyway, so just bail out. + return; + } + + if (!replacementsDictionary.ContainsKey(SuppressOpeningItems)) + { + // The value that we add doesn't really matter (only the key does), + // but just in case they start doing anything with it, we'll use "true". + replacementsDictionary.Add(SuppressOpeningItems, "true"); + } + } + void IWizard.RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + RunStarted(automationObject, replacementsDictionary, runKind, customParams); + } + + /// <summary> + /// Ensures that only the file name portion of the new <see cref="ProjectItem"/>'s path is used as the + /// title for the document window. + /// </summary> + protected new void ProjectItemFinishedGenerating(ProjectItem projectItem) + { + base.ProjectItemFinishedGenerating(projectItem); + + // UNDONE: This may or may not be needed for Orcas. This needs to be tested, and if it is not needed, + // the following code block should be uncommented. + //Debug.Assert(TemplateWizardIsOrcasOrLater.HasValue, "RunStarted should have been called before ProjectItemFinishedGenerating is called."); + //if (TemplateWizardIsOrcasOrLater.GetValueOrDefault()) + //{ + // return; + //} + + if (projectItem == null) + { + throw new ArgumentNullException("projectItem"); + } + + DTE application = projectItem.DTE; + if (application == null) + { + // If we can't get the DTE, just bail out. + return; + } + + Document document = projectItem.Document; + if (document == null) + { + // At the point this is called, the ProjectItem seems to not have the Document associated with it yet. + // In that case, we need to look through the documents to find it. We'll try ActiveDocument first... + document = application.ActiveDocument; + if (document.ProjectItem != projectItem) + { + document = null; + Documents documents = application.Documents; + if (documents != null) + { + foreach (Document potentialDocument in documents) + { + if (potentialDocument.ProjectItem == projectItem) + { + document = potentialDocument; + break; + } + } + } + } + } + + if (document != null) + { + IOleServiceProvider oleServiceProvider = application as IOleServiceProvider; + if (oleServiceProvider == null) + { + // If we can't get an IOleServiceProvider, just bail out. + return; + } + + IVsUIHierarchy uiHierarchy; + uint itemId; + IVsWindowFrame windowFrame; + bool documentIsOpen = VsShellUtilities.IsDocumentOpen(new ServiceProvider(oleServiceProvider), document.FullName, Guid.Empty, out uiHierarchy, out itemId, out windowFrame); + Debug.Assert(documentIsOpen); + + if (windowFrame != null) + { + object pVar; + ErrorHandler.ThrowOnFailure(uiHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_Caption, out pVar)); + string caption = pVar as string; + if (!string.IsNullOrEmpty(caption)) + { + try + { + caption = Path.GetFileName(caption); + } + catch (ArgumentException) + { + // Ignore any ArgumentException (which can occur if the caption contains characters invalid in a path). + return; + } + // Set the new caption on the backend document. + ErrorHandler.ThrowOnFailure(uiHierarchy.SetProperty(itemId, (int)__VSHPROPID.VSHPROPID_Caption, caption)); + // Set the new caption on the window. + ErrorHandler.ThrowOnFailure(windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption)); + } + } + } + } + void IWizard.ProjectItemFinishedGenerating(ProjectItem projectItem) + { + ProjectItemFinishedGenerating(projectItem); + } + } } Deleted: trunk/Tools/DatabaseImport/OrmDatabaseImportTemplate.zip =================================================================== (Binary files differ) Added: trunk/Tools/DatabaseImport/ProjectItems/CSharp.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/CSharp.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/General.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/General.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/JSharp.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/JSharp.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/VisualBasic.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/VisualBasic.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/VisualC.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/VisualC.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/Web/CSharp.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/Web/CSharp.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/Web/JSharp.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/Web/JSharp.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/Tools/DatabaseImport/ProjectItems/Web/VisualBasic.zip =================================================================== (Binary files differ) Property changes on: trunk/Tools/DatabaseImport/ProjectItems/Web/VisualBasic.zip ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/Tools/DatabaseImport/SqlServer2005DcilSchemaProvider.cs =================================================================== --- trunk/Tools/DatabaseImport/SqlServer2005DcilSchemaProvider.cs 2007-09-20 20:41:26 UTC (rev 1136) +++ trunk/Tools/DatabaseImport/SqlServer2005DcilSchemaProvider.cs 2007-09-20 20:46:20 UTC (rev 1137) @@ -143,15 +143,12 @@ _conn.Open(); IDbCommand cmd = _conn.CreateCommand(); cmd.CommandType = CommandType.Text; - string commandText = "SELECT COLUMN_NAME, IS_NULLABLE, COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'IsIdentity') IS_IDENTITY, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COALESCE(NUMERIC_PRECISION, DATETIME_PRECISION), NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IS NOT NULL"; - if (!String.IsNullOrEmpty(schemaName)) - { - commandText += " AND TABLE_SCHEMA = '" + schemaName + "'"; - } - if (!String.IsNullOrEmpty(tableName)) - { - commandText += " AND TABLE_NAME = '" + tableName + "'"; - } + bool haveSchema = !string.IsNullOrEmpty(schemaName); + string commandText = "SELECT COLUMN_NAME, IS_NULLABLE, COLUMNPROPERTY(OBJECT_ID(" + + (haveSchema ? "TABLE_SCHEMA + '.' + " : "") + + "TABLE_NAME), COLUMN_NAME, 'IsIdentity') IS_IDENTITY, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COALESCE(NUMERIC_PRECISION, DATETIME_PRECISION), NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IS NOT NULL" + + (haveSchema ? " AND TABLE_SCHEMA = '" + schemaName + "'" : "") + + " AND TABLE_NAME = '" + tableName + "'"; cmd.CommandText = commandText; using (IDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |