예제 #1
0
        private async Task <bool> ChooseDataBaseConnectionByUiHintAsync(ReverseEngineerOptions options)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var databaseList = vsDataHelper.GetDataConnections(package);

            if (databaseList != null && databaseList.Any())
            {
                var dataBaseInfo = databaseList.Values.FirstOrDefault(m => m.ConnectionName == options.UiHint);
                if (dataBaseInfo != null)
                {
                    options.ConnectionString = dataBaseInfo.ConnectionString;
                    options.DatabaseType     = dataBaseInfo.DatabaseType;
                    return(true);
                }
            }

            var dacpacList = await EnvDteExtensions.GetDacpacFilesInActiveSolutionAsync();

            if (dacpacList != null && dacpacList.Any() && !string.IsNullOrEmpty(options.UiHint) &&
                options.UiHint.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase))
            {
                var candidate = dacpacList
                                .Where(m => !string.IsNullOrWhiteSpace(m) && m.EndsWith(".sqlproj"))
                                .FirstOrDefault(m => m.Equals(options.UiHint, StringComparison.OrdinalIgnoreCase));

                if (candidate != null)
                {
                    options.Dacpac = candidate;
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        private async Task <bool> ChooseDataBaseConnectionAsync(ReverseEngineerOptions options)
        {
            var databaseList = vsDataHelper.GetDataConnections(package);
            var dacpacList   = await EnvDteExtensions.GetDacpacFilesInActiveSolutionAsync();

            var psd = package.GetView <IPickServerDatabaseDialog>();

            if (databaseList != null && databaseList.Any())
            {
                psd.PublishConnections(databaseList.Select(m => new DatabaseConnectionModel
                {
                    ConnectionName   = m.Value.ConnectionName,
                    ConnectionString = m.Value.ConnectionString,
                    DatabaseType     = m.Value.DatabaseType,
                    DataConnection   = m.Value.DataConnection,
                }));
            }

            if (dacpacList != null && dacpacList.Any())
            {
                psd.PublishDefinitions(dacpacList.Select(m => new DatabaseDefinitionModel
                {
                    FilePath = m,
                }));
            }

            if (options.FilterSchemas && options.Schemas != null && options.Schemas.Any())
            {
                psd.PublishSchemas(options.Schemas);
            }

            psd.PublishCodeGenerationMode(options.CodeGenerationMode);

            if (!string.IsNullOrEmpty(options.UiHint))
            {
                psd.PublishUiHint(options.UiHint);
            }

            var pickDataSourceResult = psd.ShowAndAwaitUserResponse(true);

            if (!pickDataSourceResult.ClosedByOK)
            {
                return(false);
            }

            options.CodeGenerationMode = pickDataSourceResult.Payload.CodeGenerationMode;
            options.FilterSchemas      = pickDataSourceResult.Payload.FilterSchemas;
            options.Schemas            = options.FilterSchemas ? pickDataSourceResult.Payload.Schemas?.ToList() : null;
            options.UiHint             = pickDataSourceResult.Payload.UiHint;
            options.Dacpac             = pickDataSourceResult.Payload.Definition?.FilePath;

            if (pickDataSourceResult.Payload.Connection != null)
            {
                options.ConnectionString = pickDataSourceResult.Payload.Connection.ConnectionString;
                options.DatabaseType     = pickDataSourceResult.Payload.Connection.DatabaseType;
            }

            return(true);
        }