private void WriteOutput(AnalyzeRequest a)
        {
            var sortedAnalyzeRequest = new AnalyzeRequest
            {
                RequestFlags = a.RequestFlags,
                Dependencies = a.Dependencies
                    .OrderBy(t => t.Key.MemberDocId)
                    .ThenBy(t => t.Key.TypeDocId)
                    .ToDictionary(t => t.Key, t => t.Value.OrderBy(tt => tt.AssemblyIdentity).ToList() as ICollection<AssemblyInfo>),
                UnresolvedAssemblies = new SortedSet<string>(a.UnresolvedAssemblies, StringComparer.Ordinal),
                UnresolvedAssembliesDictionary = a.UnresolvedAssembliesDictionary
                    .OrderBy(t => t.Key)
                    .ToDictionary(t => t.Key, t => new SortedSet<string>(t.Value) as ICollection<string>),
                UserAssemblies = new SortedSet<AssemblyInfo>(a.UserAssemblies),
                AssembliesWithErrors = new SortedSet<string>(a.AssembliesWithErrors, StringComparer.Ordinal),
                Targets = new SortedSet<string>(a.Targets, StringComparer.Ordinal),
                ApplicationName = a.ApplicationName,
                Version = a.Version,
                BreakingChangesToSuppress = new SortedSet<string>(a.BreakingChangesToSuppress ?? Enumerable.Empty<string>(), StringComparer.Ordinal),
                AssembliesToIgnore = a.AssembliesToIgnore.OrderBy(i => i.AssemblyIdentity)
            };

            var tmp = $"{Path.GetTempFileName()}.json";

            using (var ms = new MemoryStream(sortedAnalyzeRequest.Serialize()))
            using (var fs = File.OpenWrite(tmp))
            {
                ms.CopyTo(fs);
            }

            Process.Start(tmp);
        }
        public async Task<ServiceResponse<byte[]>> SendAnalysisAsync(AnalyzeRequest a, string format)
        {
            var formatInformation = await GetResultFormat(format);
            var sendAnalysis = _endpoint + Endpoints.Analyze;

            return await _client.CallAsync(HttpMethod.Post, sendAnalysis, a, formatInformation);
        }
        public AnalyzeResponse AnalyzeRequest(AnalyzeRequest request, string submissionId)
        {
            // Get the list of targets we should consider in the analysis
            var targets = _targetNameParser
                .MapTargetsToExplicitVersions(request.Targets.SelectMany(_targetMapper.GetNames))
                .OrderBy(x => x.FullName, StringComparer.OrdinalIgnoreCase)
                .ToList();

            var userAssemblies = new HashSet<string>(request.UserAssemblies.Select(a => a.AssemblyIdentity), StringComparer.OrdinalIgnoreCase);

            var notInAnyTarget = request.RequestFlags.HasFlag(AnalyzeRequestFlags.ShowNonPortableApis)
                ? _analysisEngine.FindMembersNotInTargets(targets, userAssemblies, request.Dependencies)
                : new List<MemberInfo>();

            var unresolvedAssemblies = request.UnresolvedAssembliesDictionary != null
                ? request.UnresolvedAssembliesDictionary.Keys
                : request.UnresolvedAssemblies;

            var missingUserAssemblies = _analysisEngine.FindUnreferencedAssemblies(unresolvedAssemblies, request.UserAssemblies).ToList();

            var breakingChangeSkippedAssemblies = request.RequestFlags.HasFlag(AnalyzeRequestFlags.ShowBreakingChanges)
                ? _analysisEngine.FindBreakingChangeSkippedAssemblies(targets, request.UserAssemblies, request.AssembliesToIgnore).ToList()
                : new List<AssemblyInfo>();

            var breakingChanges = request.RequestFlags.HasFlag(AnalyzeRequestFlags.ShowBreakingChanges)
                ? _analysisEngine.FindBreakingChanges(targets, request.Dependencies, breakingChangeSkippedAssemblies, request.BreakingChangesToSuppress, userAssemblies, request.RequestFlags.HasFlag(AnalyzeRequestFlags.ShowRetargettingIssues)).ToList()
                : new List<BreakingChangeDependency>();

            var reportingResult = _reportGenerator.ComputeReport(
                targets,
                submissionId,
                request.RequestFlags,
                request.Dependencies,
                notInAnyTarget,
                request.UnresolvedAssembliesDictionary,
                missingUserAssemblies,
                request.AssembliesWithErrors);

            return new AnalyzeResponse
            {
                CatalogLastUpdated = _analysisEngine.CatalogLastUpdated,
                ApplicationName = request.ApplicationName,
                MissingDependencies = notInAnyTarget,
                UnresolvedUserAssemblies = missingUserAssemblies,
                Targets = targets,
                ReportingResult = reportingResult,
                SubmissionId = submissionId,
                BreakingChanges = breakingChanges,
                BreakingChangeSkippedAssemblies = breakingChangeSkippedAssemblies
            };
        }
        /// <summary>
        /// Gets the Portability report for the request.
        /// </summary>
        /// <returns>An array of bytes corresponding to the report.</returns>
        private async Task<byte[]> GetResultFromServiceAsync(AnalyzeRequest request, string format)
        {
            using (var progressTask = _progressReport.StartTask(LocalizedStrings.SendingDataToService))
            {
                try
                {
                    var response = await _apiPortService.SendAnalysisAsync(request, format);

                    CheckEndpointStatus(response.Headers.Status);

                    return response.Response;
                }
                catch (Exception)
                {
                    progressTask.Abort();
                    throw;
                }
            }
        }
 private async Task<ServiceResponse<AnalyzeResponse>> RetrieveResultAsync(AnalyzeRequest request)
 {
     using (var progressTask = _progressReport.StartTask(LocalizedStrings.SendingDataToService))
     {
         try
         {
             return await _apiPortService.SendAnalysisAsync(request);
         }
         catch (Exception)
         {
             progressTask.Abort();
             throw;
         }
     }
 }
        /// <summary>
        /// Gets the Portability of an application as a ReportingResult.
        /// </summary>
        /// <returns>Set of APIs/assemblies that are not portable/missing.</returns>
        private async Task<ReportingResult> GetResultFromServiceAsync(AnalyzeRequest request, IDependencyInfo dependencyInfo)
        {
            var fullResponse = await RetrieveResultAsync(request);

            CheckEndpointStatus(fullResponse.Headers.Status);

            using (var progressTask = _progressReport.StartTask(LocalizedStrings.ComputingReport))
            {
                try
                {
                    var response = fullResponse.Response;

                    return _reportGenerator.ComputeReport(
                        response.Targets,
                        response.SubmissionId,
                        request.RequestFlags,
                        dependencyInfo?.Dependencies,
                        response.MissingDependencies,
                        dependencyInfo?.UnresolvedAssemblies,
                        response.UnresolvedUserAssemblies,
                        dependencyInfo?.AssembliesWithErrors
                    );
                }
                catch (Exception)
                {
                    progressTask.Abort();
                    throw;
                }
            }
        }
        /// <summary>
        /// Gets the Portability report for the request.
        /// </summary>
        /// <returns>An array of bytes corresponding to the report.</returns>
        private async Task<byte[]> GetResultFromServiceAsync(AnalyzeRequest request, string format)
        {
            var response = await _apiPortService.SendAnalysisAsync(request, format);

            CheckEndpointStatus(response.Headers.Status);

            return response.Response;
        }
        public Task<ServiceResponse<byte[]>> SendAnalysisAsync(AnalyzeRequest a, string format)
        {
            var sortedAnalyzeRequest = new AnalyzeRequest
            {
                RequestFlags = a.RequestFlags,
                Dependencies = a.Dependencies
                    .OrderBy(t => t.Key.MemberDocId)
                    .ThenBy(t => t.Key.TypeDocId)
                    .ToDictionary(t => t.Key, t => t.Value.OrderBy(tt => tt.AssemblyIdentity).ToList() as ICollection<AssemblyInfo>),
                UnresolvedAssemblies = new SortedSet<string>(a.UnresolvedAssemblies, StringComparer.Ordinal),
                UnresolvedAssembliesDictionary = a.UnresolvedAssembliesDictionary
                    .OrderBy(t => t.Key)
                    .ToDictionary(t => t.Key, t => new SortedSet<string>(t.Value) as ICollection<string>),
                UserAssemblies = new SortedSet<AssemblyInfo>(a.UserAssemblies),
                AssembliesWithErrors = new SortedSet<string>(a.AssembliesWithErrors, StringComparer.Ordinal),
                Targets = new SortedSet<string>(a.Targets, StringComparer.Ordinal),
                ApplicationName = a.ApplicationName,
                Version = a.Version,
                BreakingChangesToSuppress = new SortedSet<string>(a.BreakingChangesToSuppress ?? Enumerable.Empty<string>(), StringComparer.Ordinal),
                AssembliesToIgnore = a.AssembliesToIgnore.OrderBy(i => i.AssemblyIdentity)
            };

            var result = sortedAnalyzeRequest.Serialize();

            return Task.FromResult(ServiceResponse.Create(result));
        }
        public Task<ServiceResponse<AnalyzeResponse>> SendAnalysisAsync(AnalyzeRequest a)
        {
            _progress.ReportIssue(LocalizedStrings.FileOutputServiceNotSupported);

            return Task.FromResult(new ServiceResponse<AnalyzeResponse>(new AnalyzeResponse()));
        }
 public async Task<ServiceResponse<AnalyzeResponse>> SendAnalysisAsync(AnalyzeRequest a)
 {
     return await _client.CallAsync<AnalyzeRequest, AnalyzeResponse>(HttpMethod.Post, Endpoints.Analyze, a);
 }
        private ReportingResult GetReportingResult(AnalyzeRequest request, AnalyzeResponse response, IDependencyInfo dependencyInfo)
        {
            if (response == null)
            {
                return null;
            }

            using (var progressTask = _progressReport.StartTask(LocalizedStrings.ComputingReport))
            {
                try
                {
                    return _reportGenerator.ComputeReport(
                        response.Targets,
                        response.SubmissionId,
                        request.RequestFlags,
                        dependencyInfo?.Dependencies,
                        response.MissingDependencies,
                        dependencyInfo?.UnresolvedAssemblies,
                        response.UnresolvedUserAssemblies,
                        dependencyInfo?.AssembliesWithErrors
                    );
                }
                catch (Exception)
                {
                    progressTask.Abort();
                    throw;
                }
            }
        }
        /// <summary>
        /// Gets the Portability of an application as a ReportingResult.
        /// </summary>
        /// <returns>Set of APIs/assemblies that are not portable/missing.</returns>
        private async Task<ReportingResult> GetResultFromServiceAsync(AnalyzeRequest request, IDependencyInfo dependencyInfo)
        {
            var fullResponse = await RetrieveResultAsync(request);

            CheckEndpointStatus(fullResponse.Headers.Status);

            return GetReportingResult(request, fullResponse.Response, dependencyInfo);
        }
        public async Task<ServiceResponse<IEnumerable<ReportingResultWithFormat>>> SendAnalysisAsync(AnalyzeRequest a, IEnumerable<string> format)
        {
            var formatInformation = await GetResultFormat(format);

            return await _client.CallAsync(HttpMethod.Post, Endpoints.Analyze, a, formatInformation);
        }
        public Task<ServiceResponse<byte[]>> SendAnalysisAsync(AnalyzeRequest a, string format)
        {
            WriteOutput(a);

            return Task.FromResult(new ServiceResponse<byte[]>(new byte[] { }));
        }
        public Task<ServiceResponse<AnalyzeResponse>> SendAnalysisAsync(AnalyzeRequest a)
        {
            WriteOutput(a);

            return Task.FromResult(new ServiceResponse<AnalyzeResponse>(new AnalyzeResponse()));
        }
        public Task<ServiceResponse<IEnumerable<ReportingResultWithFormat>>> SendAnalysisAsync(AnalyzeRequest a, IEnumerable<string> formats)
        {
            var result = formats.Select(f => new ReportingResultWithFormat
            {
                Data = SendAnalysisAsync(a, f),
                Format = f
            });

            return Task.FromResult(new ServiceResponse<IEnumerable<ReportingResultWithFormat>>(result.ToList()));
        }