private static async Task RunAsync(Options opts, string usageReportContent) { var azureEnvironmentHelper = new AzureEnvironmentHelper(opts.AzureEnvironmentName); ParsedUsageReport usageReport = null; string accessToken = null; if (usageReportContent == null) { var authenticationResult = await TokenProvider.AcquireTokenAsync( azureEnvironmentHelper.AuthenticationEndpoint, opts.TenantId, azureEnvironmentHelper.ResourceManagerEndpoint); accessToken = authenticationResult.AccessToken; } else { usageReport = UsageFileHelper.Parse(usageReportContent); } var context = new AssessmentContext( usageReport: usageReport, subscriptionNames: opts.SubscriptionNames, subscriptionIds: opts.SubscriptionIds, resourceGroupNames: opts.ResourceGroupNames, accessToken: accessToken, armBaseUri: azureEnvironmentHelper.ResourceManagerEndpoint, resourceCachePath: opts.ResourceCachePath, configManager: ConfigManagerFactory.CreateStorageAccountConfigManager(Settings.Default.ConnectionString), telemetryManager: new TelemetryManager( new AppInsightsTelemetryProvider(ConfigurationManager.AppSettings["ApplicationInsightsKey"]), new Dictionary <string, string> { { "DeploymentId", $"console_debug_{Environment.MachineName}" } })); var assessmentService = new AssessmentService(); var assessmentReport = await assessmentService.GenerateReportAsync(context, opts.TargetLocation); if (File.Exists(assessmentReport.ReportFilePath)) { Process.Start(assessmentReport.ReportFilePath); } }
public async Task <ActionResult> Run(AssessmentWithUsageReportModel model) { try { if (model.UsageReportFile == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Please upload a file")); } var inputFileName = model.UsageReportFile.FileName; var outputFileName = $"{Path.GetFileNameWithoutExtension(inputFileName)}-AssessmentReport.pdf"; string inputContent; using (var reader = new StreamReader(model.UsageReportFile.InputStream)) { inputContent = await reader.ReadToEndAsync(); } var context = AssessmentHelper.GetEnvironmentContext( TelemetryHelper.CreateTelemetryManager(new TelemetryContext { Properties = new Dictionary <string, string> { { "UsageReportFileName", model.UsageReportFile.FileName }, { "TargetRegion", model.SelectedTargetRegion } } }), UsageFileHelper.Parse(inputContent)); var assessmentService = new AssessmentService(); var assessmentReport = await assessmentService.GenerateReportAsync(context, model.SelectedTargetRegion); var outputContent = System.IO.File.ReadAllBytes(assessmentReport.ReportFilePath); System.IO.File.Delete(assessmentReport.ReportFilePath); return(this.File(outputContent, "application/pdf", outputFileName)); } catch (Exception ex) { Trace.TraceError(FormattableString.Invariant($"Assessment with usage report failed: {ex}")); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message)); } }