Beispiel #1
0
            public bool Execute()
            {
                var showLog = _showLog.Value;
                var runner  = DbInitProjectRunner.CreateDbInit(_project, _dbSessionProviderType, _input, null, _showLog.Value, _dte);

                return(ConsoleWindow.Run(_window.Title, runner.RunAsync));
            }
            public bool Execute()
            {
                var project           = _dbSessionProvider.Value.Project;
                var dbSessionProvider = _dbSessionProvider.Value.TypeSymbol;

                project.TryGetCompilation(out var compilation);
                Debug.Assert(compilation != null);
                var input   = dbSessionProvider.GetDbInitInput(compilation);
                var showLog = _showLog.Value;
                var runner  = DbInitProjectRunner.CreateDbInit(project, dbSessionProvider, input, _dbInitializerType, _showLog.Value, _dte);

                return(ConsoleWindow.Run(_window.Title, runner.RunAsync));
            }
            private async Task <int> RunAsync(IProgress <string> progress, CancellationToken ct)
            {
                var project           = _dbSessionProvider.Value.Project;
                var dbSessionProvider = _dbSessionProvider.Value.TypeSymbol;
                var input             = dbSessionProvider.GetDbInitInput(_codeContext.Compilation);
                var showLog           = _showDbLog.Value;

                var tableNames = new string[DataSet.Count];

                for (int i = 0; i < DataSet.Count; i++)
                {
                    tableNames[i] = _.DbTableProperty[i].Name;
                }
                var outputDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

                Directory.CreateDirectory(outputDir);

                var runner = DbInitProjectRunner.CreateDataSetGen(project, dbSessionProvider, input, _showDbLog.Value, tableNames, outputDir, _dte);
                var result = await runner.RunAsync(progress, ct);

                if (result != ExitCodes.Succeeded)
                {
                    DeleteDirectoryIfExists(outputDir);
                    return(result);
                }

                for (int i = 0; i < DataSet.Count; i++)
                {
                    var dbTable = _.DbTableProperty[i].Name;
                    _.ReferencedTypes[i]   = File.ReadAllText(Path.Combine(outputDir, dbTable + ".types"));
                    _.DataSetMethodBody[i] = File.ReadAllText(Path.Combine(outputDir, dbTable + ".statements"));
                }

                DeleteDirectoryIfExists(outputDir);

                var document = await DbInitMapper.GenerateDataSetsAsync(_codeContext, DataSet, ct);

                var workspace = project.Solution.Workspace;

                workspace.TryApplyChanges(document.Project.Solution);

                return(ExitCodes.Succeeded);
            }