Exemplo n.º 1
0
        static void Main(string[] args)
        {
            PortingAssistantCLI cli = new PortingAssistantCLI();

            cli.HandleCommand(args);
            try
            {
                var configuration           = new PortingAssistantConfiguration();
                var portingAssistantBuilder = PortingAssistantBuilder.Build(configuration, logConfig => logConfig.AddConsole());
                var portingAssistantClient  = portingAssistantBuilder.GetPortingAssistant();
                var reportExporter          = portingAssistantBuilder.GetReportExporter();
                var solutionSettings        = cli.IgnoreProjects != null && cli.IgnoreProjects.Count != 0 ?
                                              new AnalyzerSettings
                {
                    IgnoreProjects  = cli.IgnoreProjects,
                    TargetFramework = cli.Target
                } : new AnalyzerSettings
                {
                    IgnoreProjects  = new List <string>(),
                    TargetFramework = cli.Target
                };

                var analyzeResults = portingAssistantClient.AnalyzeSolutionAsync(cli.SolutionPath, solutionSettings);
                analyzeResults.Wait();
                if (analyzeResults.IsCompletedSuccessfully)
                {
                    reportExporter.GenerateJsonReport(analyzeResults.Result, cli.OutputPath);
                }
                else
                {
                    Console.WriteLine("err generated solution analysis report");
                }
                if (cli.PortingProjects != null && cli.PortingProjects.Count != 0)
                {
                    var PortingProjectResults = analyzeResults.Result.ProjectAnalysisResults
                                                .Where(project => cli.PortingProjects.Contains(project.ProjectName));
                    var FilteredRecommendedActions = PortingProjectResults
                                                     .SelectMany(project => project.PackageAnalysisResults.Values
                                                                 .SelectMany(package => package.Result.Recommendations.RecommendedActions));
                    var PortingRequest = new PortingRequest
                    {
                        ProjectPaths       = cli.PortingProjects,
                        SolutionPath       = cli.SolutionPath,
                        TargetFramework    = cli.Target.ToString(),
                        RecommendedActions = FilteredRecommendedActions.ToList()
                    };
                    var portingResults = portingAssistantClient.ApplyPortingChanges(PortingRequest);
                    reportExporter.GenerateJsonReport(portingResults, cli.SolutionPath, cli.OutputPath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("error when using the tools :" + ex);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            PortingAssistantCLI cli = new PortingAssistantCLI();

            cli.HandleCommand(args);

            var logConfiguration = new LoggerConfiguration().Enrich.FromLogContext()
                                   .MinimumLevel.Debug()
                                   .WriteTo.Console();

            var assemblypath           = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var telemetryConfiguration = JsonSerializer.Deserialize <TelemetryConfiguration>(File.ReadAllText(Path.Combine(assemblypath, "PortingAssistantTelemetryConfig.json")));

            var configuration   = new PortingAssistantConfiguration();
            var roamingFolder   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var logs            = Path.Combine(roamingFolder, "Porting Assistant for .NET", "logs");
            var logFilePath     = Path.Combine(logs, "portingAssistant-client-cli.log");
            var metricsFilePath = Path.Combine(logs, "portingAssistant-client-cli.metrics");

            string version        = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
            var    outputTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] (Porting Assistant Client CLI) (" + version + ") (" + cli.Tag + ") {SourceContext}: {Message:lj}{NewLine}{Exception}";

            Serilog.Formatting.Display.MessageTemplateTextFormatter tf =
                new Serilog.Formatting.Display.MessageTemplateTextFormatter(outputTemplate, CultureInfo.InvariantCulture);

            logConfiguration.WriteTo.File(
                logFilePath,
                rollingInterval: RollingInterval.Infinite,
                rollOnFileSizeLimit: false,
                outputTemplate: outputTemplate);
            Log.Logger = logConfiguration.CreateLogger();

            if (cli.isSchema)
            {
                if (cli.schemaVersion)
                {
                    Console.WriteLine(Common.Model.Schema.version);
                }
            }

            if (cli.isAssess)
            {
                try
                {
                    TelemetryCollector.Builder(Log.Logger, metricsFilePath);

                    var portingAssistantBuilder = PortingAssistantBuilder.Build(configuration, logConfig =>
                                                                                logConfig.SetMinimumLevel(LogLevel.Debug)
                                                                                .AddSerilog(logger: Log.Logger, dispose: true));

                    var portingAssistantClient = portingAssistantBuilder.GetPortingAssistant();
                    var reportExporter         = portingAssistantBuilder.GetReportExporter();
                    var solutionSettings       = cli.IgnoreProjects != null && cli.IgnoreProjects.Count != 0 ?
                                                 new AnalyzerSettings
                    {
                        IgnoreProjects  = cli.IgnoreProjects,
                        TargetFramework = cli.Target
                    } : new AnalyzerSettings
                    {
                        IgnoreProjects  = new List <string>(),
                        TargetFramework = cli.Target
                    };

                    var startTime = DateTime.Now;
                    Task <SolutionAnalysisResult> analyzeResults;

                    if (solutionSettings.UseGenerator)
                    {
                        analyzeResults = AnalyzeSolutionGenerator(portingAssistantClient, cli.SolutionPath, solutionSettings);
                    }
                    else
                    {
                        analyzeResults = portingAssistantClient.AnalyzeSolutionAsync(cli.SolutionPath, solutionSettings);
                        analyzeResults.Wait();
                    }
                    if (analyzeResults.IsCompletedSuccessfully)
                    {
                        reportExporter.GenerateJsonReport(analyzeResults.Result, cli.OutputPath);
                        TelemetryCollector.SolutionAssessmentCollect(analyzeResults.Result, cli.Target, "1.8.0", $"Porting Assistant Client CLI", DateTime.Now.Subtract(startTime).TotalMilliseconds, cli.Tag);
                    }
                    else
                    {
                        Log.Logger.Error("err generated solution analysis report");
                    }
                    if (cli.PortingProjects != null && cli.PortingProjects.Count != 0)
                    {
                        var PortingProjectResults = analyzeResults.Result.ProjectAnalysisResults
                                                    .Where(project => cli.PortingProjects.Contains(project.ProjectName));
                        var FilteredRecommendedActions = PortingProjectResults
                                                         .SelectMany(project => project.PackageAnalysisResults.Values
                                                                     .Where(package =>
                        {
                            var comp = package.Result.CompatibilityResults.GetValueOrDefault(cli.Target);
                            return(comp.Compatibility != Compatibility.COMPATIBLE && comp.CompatibleVersions.Count != 0);
                        })
                                                                     .SelectMany(package => package.Result.Recommendations.RecommendedActions));
                        var PortingRequest = new PortingRequest
                        {
                            Projects           = analyzeResults.Result.SolutionDetails.Projects.Where(p => cli.PortingProjects.Contains(p.ProjectName)).ToList(),
                            SolutionPath       = cli.SolutionPath,
                            TargetFramework    = cli.Target.ToString(),
                            RecommendedActions = FilteredRecommendedActions.ToList(),
                            IncludeCodeFix     = true
                        };
                        var portingResults = portingAssistantClient.ApplyPortingChanges(PortingRequest);
                        reportExporter.GenerateJsonReport(portingResults, cli.SolutionPath, cli.OutputPath);
                    }
                    UploadLogs(cli.Profile, telemetryConfiguration, logFilePath, metricsFilePath, logs);
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex, "error when using the tools :");
                    UploadLogs(cli.Profile, telemetryConfiguration, logFilePath, metricsFilePath, logs);
                    Environment.Exit(-1);
                }
            }
        }