private async System.Threading.Tasks.Task GenerateFilesAsync(Project project, ReverseEngineerOptions options, Tuple <bool, string> containsEfCoreReference)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var startTime = DateTime.Now;

            if (options.UseHandleBars)
            {
                DropTemplates(options.OptionsPath, options.CodeGenerationMode);
            }

            options.UseNullableReferences = await project.IsNetFrameworkAsync() ? false : options.UseNullableReferences;

            //TODO Disable for now - see #1164  await SetNullableAsync(options, project);

            await VS.StatusBar.StartAnimationAsync(StatusAnimation.Build);

            await VS.StatusBar.ShowMessageAsync(ReverseEngineerLocale.GeneratingCode);

            var revEngResult = await EfRevEngLauncher.LaunchExternalRunnerAsync(options, options.CodeGenerationMode);

            await VS.StatusBar.EndAnimationAsync(StatusAnimation.Build);

            var tfm = await project.GetAttributeAsync("TargetFrameworkMoniker");

            bool isNetStandard = tfm?.Contains(".NETStandard,Version=v2.") ?? false;

            if (options.SelectedToBeGenerated == 0 || options.SelectedToBeGenerated == 2)
            {
                if (!await project.IsNetCore31OrHigherAsync() && !isNetStandard)
                {
                    foreach (var filePath in revEngResult.EntityTypeFilePaths)
                    {
                        await project.AddExistingFilesAsync(new List <string> {
                            filePath
                        }.ToArray());
                    }
                }
            }

            if (options.SelectedToBeGenerated == 0 || options.SelectedToBeGenerated == 1)
            {
                if (!await project.IsNetCore31OrHigherAsync() && !isNetStandard)
                {
                    foreach (var filePath in revEngResult.ContextConfigurationFilePaths)
                    {
                        await project.AddExistingFilesAsync(new List <string> {
                            filePath
                        }.ToArray());
                    }
                    await project.AddExistingFilesAsync(new List <string> {
                        revEngResult.ContextFilePath
                    }.ToArray());
                }

                if (Properties.Settings.Default.OpenGeneratedDbContext)
                {
                    await VS.Documents.OpenAsync(revEngResult.ContextFilePath);
                }
            }

            var duration = DateTime.Now - startTime;

            var missingProviderPackage = containsEfCoreReference.Item1 ? null : containsEfCoreReference.Item2;

            if (options.InstallNuGetPackage || options.SelectedToBeGenerated == 2)
            {
                missingProviderPackage = null;
            }

            await VS.StatusBar.ShowMessageAsync(ReverseEngineerLocale.ReportingResult);

            var errors = reverseEngineerHelper.ReportRevEngErrors(revEngResult, missingProviderPackage);

            await VS.StatusBar.ShowMessageAsync(string.Format(ReverseEngineerLocale.ReverseEngineerCompleted, duration.ToString("h\\:mm\\:ss")));

            if (errors != ReverseEngineerLocale.ModelGeneratedSuccesfully + Environment.NewLine)
            {
                VSHelper.ShowMessage(errors);
            }

            if (revEngResult.EntityErrors.Count > 0)
            {
                _package.LogError(revEngResult.EntityErrors, null);
            }
            if (revEngResult.EntityWarnings.Count > 0)
            {
                _package.LogError(revEngResult.EntityWarnings, null);
            }
        }
示例#2
0
        private async System.Threading.Tasks.Task GenerateFilesAsync(Project project, ReverseEngineerOptions options, Tuple <bool, string> containsEfCoreReference)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var startTime = DateTime.Now;

            if (options.UseHandleBars)
            {
                var dropped = (DropTemplates(options.ProjectPath, options.CodeGenerationMode == CodeGenerationMode.EFCore5));
                if (dropped)
                {
                    project.ProjectItems.AddFromDirectory(Path.Combine(options.ProjectPath, "CodeTemplates"));
                }
            }

            options.UseNullableReferences = project.IsNetFramework() ? false : options.UseNullableReferences;

            _package.Dte2.StatusBar.Animate(true, _icon);
            _package.Dte2.StatusBar.Text = ReverseEngineerLocale.GeneratingCode;
            var revEngResult = await EfRevEngLauncher.LaunchExternalRunnerAsync(options, options.CodeGenerationMode);

            _package.Dte2.StatusBar.Animate(false, _icon);

            var  tfm           = project.Properties.Item("TargetFrameworkMoniker").Value.ToString();
            bool isNetStandard = tfm.Contains(".NETStandard,Version=v2.");

            if (options.SelectedToBeGenerated == 0 || options.SelectedToBeGenerated == 2)
            {
                if (!project.IsNetCore31OrHigher() && !isNetStandard)
                {
                    foreach (var filePath in revEngResult.EntityTypeFilePaths)
                    {
                        project.ProjectItems.AddFromFile(filePath);
                    }
                }
            }

            if (options.SelectedToBeGenerated == 0 || options.SelectedToBeGenerated == 1)
            {
                if (!project.IsNetCore31OrHigher() && !isNetStandard)
                {
                    foreach (var filePath in revEngResult.ContextConfigurationFilePaths)
                    {
                        project.ProjectItems.AddFromFile(filePath);
                    }

                    project.ProjectItems.AddFromFile(revEngResult.ContextFilePath);
                }

                _package.Dte2.ItemOperations.OpenFile(revEngResult.ContextFilePath);
            }

            var duration = DateTime.Now - startTime;

            var missingProviderPackage = containsEfCoreReference.Item1 ? null : containsEfCoreReference.Item2;

            if (options.InstallNuGetPackage || options.SelectedToBeGenerated == 2)
            {
                missingProviderPackage = null;
            }

            _package.Dte2.StatusBar.Text = ReverseEngineerLocale.ReportingResult;
            var errors = reverseEngineerHelper.ReportRevEngErrors(revEngResult, missingProviderPackage);

            _package.Dte2.StatusBar.Text = String.Format(ReverseEngineerLocale.ReverseEngineerCompleted, duration.ToString("h\\:mm\\:ss"));

            EnvDteHelper.ShowMessage(errors);

            if (revEngResult.EntityErrors.Count > 0)
            {
                _package.LogError(revEngResult.EntityErrors, null);
            }
            if (revEngResult.EntityWarnings.Count > 0)
            {
                _package.LogError(revEngResult.EntityWarnings, null);
            }
        }
示例#3
0
        private async System.Threading.Tasks.Task GenerateFilesAsync(Project project, ReverseEngineerOptions options, Tuple <bool, string> containsEfCoreReference)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var startTime = DateTime.Now;

            if (options.UseHandleBars)
            {
                DropTemplates(options.OptionsPath, options.CodeGenerationMode);
            }

            options.UseNullableReferences = !await project.IsLegacyAsync() && options.UseNullableReferences;

            await VS.StatusBar.ShowProgressAsync(ReverseEngineerLocale.GeneratingCode, 1, 3);

            var revEngResult = await EfRevEngLauncher.LaunchExternalRunnerAsync(options, options.CodeGenerationMode, project);

            await VS.StatusBar.ShowProgressAsync(ReverseEngineerLocale.GeneratingCode, 2, 3);

            var tfm = await project.GetAttributeAsync("TargetFrameworkMoniker");

            bool isNetStandard = tfm?.Contains(".NETStandard,Version=v2.") ?? false;

            if ((options.SelectedToBeGenerated == 0 || options.SelectedToBeGenerated == 2) &&
                !await project.IsNetCore31OrHigherAsync() && !isNetStandard)
            {
                foreach (var filePath in revEngResult.EntityTypeFilePaths)
                {
                    await project.AddExistingFilesAsync(new List <string> {
                        filePath
                    }.ToArray());
                }
            }

            if (options.SelectedToBeGenerated == 0 || options.SelectedToBeGenerated == 1)
            {
                if (!await project.IsNetCore31OrHigherAsync() && !isNetStandard)
                {
                    foreach (var filePath in revEngResult.ContextConfigurationFilePaths)
                    {
                        await project.AddExistingFilesAsync(new List <string> {
                            filePath
                        }.ToArray());
                    }

                    await project.AddExistingFilesAsync(new List <string> {
                        revEngResult.ContextFilePath
                    }.ToArray());
                }

                if (AdvancedOptions.Instance.OpenGeneratedDbContext)
                {
                    var readmeName = "PowerToolsReadMe.txt";
                    var finalText  = reverseEngineerHelper.GetReadMeText(options, File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), readmeName), Encoding.UTF8));
                    var readmePath = Path.Combine(Path.GetTempPath(), readmeName);

                    File.WriteAllText(readmePath, finalText, Encoding.UTF8);

                    await VS.Documents.OpenAsync(readmePath);

                    await VS.Documents.OpenAsync(revEngResult.ContextFilePath);
                }
            }

            await VS.StatusBar.ShowProgressAsync(ReverseEngineerLocale.GeneratingCode, 3, 3);

            var duration = DateTime.Now - startTime;

            var missingProviderPackage = containsEfCoreReference.Item1 ? null : containsEfCoreReference.Item2;

            if (options.InstallNuGetPackage || options.SelectedToBeGenerated == 2)
            {
                missingProviderPackage = null;
            }

            var errors = reverseEngineerHelper.ReportRevEngErrors(revEngResult, missingProviderPackage);

            await VS.StatusBar.ShowMessageAsync(string.Format(ReverseEngineerLocale.ReverseEngineerCompleted, duration.ToString("h\\:mm\\:ss")));

            if (errors != ReverseEngineerLocale.ModelGeneratedSuccesfully + Environment.NewLine)
            {
                VSHelper.ShowMessage(errors);
            }

            if (revEngResult.EntityErrors.Count > 0)
            {
                package.LogError(revEngResult.EntityErrors, null);
            }

            if (revEngResult.EntityWarnings.Count > 0)
            {
                package.LogError(revEngResult.EntityWarnings, null);
            }

            Telemetry.TrackFrameworkUse(nameof(ReverseEngineerHandler), options.CodeGenerationMode);
        }