public async Task <string> Analyze(string path)
        {
            var    productInformation = new ProductInformation("ApiPort_Console");
            string reportPath         = string.Empty;

            string[] args = { "analyze", "-f", path };

            var options = CommandLineOptions.ParseCommandLineOptions(args);

            using (var container = DependencyBuilder.Build(options, productInformation))
            {
                var progressReport = container.Resolve <IProgressReporter>();

                try
                {
                    var client = container.Resolve <ConsoleApiPort>();

                    reportPath = await client.AnalyzeAssembliesAsync();

                    return(reportPath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(reportPath);
                }
            }
        }
示例#2
0
        public static async Task <int> Main(string[] args)
        {
            var productInformation = new ProductInformation("ApiPort_Console");

            Console.WriteLine(LocalizedStrings.Header, LocalizedStrings.ApplicationName, productInformation.InformationalVersion, DocumentationLinks.About, DocumentationLinks.PrivacyPolicy);

            var options = CommandLineOptions.ParseCommandLineOptions(args);

            if (options.Command == AppCommand.Exit)
            {
                return(-1);
            }

            Console.WriteLine();

            using (var container = DependencyBuilder.Build(options, productInformation))
            {
                var progressReport = container.Resolve <IProgressReporter>();

                try
                {
                    var client = container.Resolve <ConsoleApiPort>();

                    switch (options.Command)
                    {
                    case AppCommand.ListTargets:
                        await client.ListTargetsAsync();

                        break;

                    case AppCommand.AnalyzeAssemblies:
                    case AppCommand.DumpAnalysis:
                        await client.AnalyzeAssembliesAsync();

                        break;

                    case AppCommand.DocIdSearch:
                        await client.RunDocIdSearchAsync();

                        break;

                    case AppCommand.ListOutputFormats:
                        await client.ListOutputFormatsAsync();

                        break;
                    }

                    return(0);
                }
                catch (Autofac.Core.DependencyResolutionException ex) when(GetPortabilityException(ex) is PortabilityAnalyzerException p)
                {
                    Trace.TraceError(ex.ToString());

                    WriteException(p);
                }
                catch (PortabilityAnalyzerException ex)
                {
                    WriteException(ex);
                }
                catch (ProxyAuthenticationRequiredException ex)
                {
                    WriteException(ex);
                }
                catch (AggregateException ex)
                {
                    Trace.TraceError(ex.ToString());

                    // If the exception is known, display the message as it has already been localized
                    if (GetRecursiveInnerExceptions(ex).Any(x => x is PortabilityAnalyzerException))
                    {
                        foreach (PortabilityAnalyzerException portEx in GetRecursiveInnerExceptions(ex).Where(x => x is PortabilityAnalyzerException))
                        {
                            WriteException(portEx);
                        }
                    }
                    else if (!IsWebSecurityFailureOnMono(ex))
                    {
                        WriteError(LocalizedStrings.UnknownException);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());

                    WriteError(LocalizedStrings.UnknownException);
                }
                finally
                {
                    if (progressReport != null)
                    {
                        Console.WriteLine();

                        foreach (var issue in progressReport.Issues)
                        {
                            WriteWarning("* " + issue);
                        }
                    }
                }

                return(-1);
            }
        }
示例#3
0
        public static int Main(string[] args)
        {
            var productInformation = new ProductInformation("ApiPort_Console");

            Console.WriteLine(LocalizedStrings.Header, LocalizedStrings.ApplicationName, productInformation.Version);

            var options = CommandLineOptions.ParseCommandLineOptions(args);

            if (options == null)
            {
                // we could not parse the options. nothing to do.
                return(-1);
            }

            using (var container = DependencyBuilder.Build(options, productInformation))
            {
                var progressReport = container.Resolve <IProgressReporter>();

                try
                {
                    var apiPortClient = container.Resolve <ApiPortClient>();

                    switch (options.Command)
                    {
                    case AppCommands.ListTargets:
                        ListTargets(apiPortClient, container.Resolve <ITargetMapper>()).Wait();
                        break;

                    case AppCommands.AnalyzeAssemblies:
                        AnalyzeAssembliesAsync(apiPortClient, options, progressReport, container.Resolve <IFileWriter>()).Wait();
                        break;

#if DOCID_SEARCH
                    case AppCommands.DocIdSearch:
                        var docIdSearch = container.Resolve <DocIdSearchRepl>();
                        docIdSearch.DocIdSearch();
                        break;
#endif
                    case AppCommands.ListOutputFormats:
                        ListOutputFormats(apiPortClient).Wait();
                        break;
                    }

                    return(0);
                }
                catch (PortabilityAnalyzerException ex)
                {
                    Trace.TraceError(ex.ToString());

                    // Display the message as it has already been localized
                    WriteError(ex.Message);
                }
                catch (AggregateException ex)
                {
                    Trace.TraceError(ex.ToString());

                    // If the exception is known, display the message as it has already been localized
                    if (GetRecursiveInnerExceptions(ex).Any(x => x is PortabilityAnalyzerException))
                    {
                        foreach (PortabilityAnalyzerException portEx in GetRecursiveInnerExceptions(ex).Where(x => x is PortabilityAnalyzerException))
                        {
                            WriteError(portEx.Message);
                        }
                    }
                    else if (!IsWebSecurityFailureOnMono(ex))
                    {
                        WriteError(LocalizedStrings.UnknownException);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());

                    WriteError(LocalizedStrings.UnknownException);
                }
                finally
                {
                    if (progressReport != null)
                    {
                        Console.WriteLine();

                        foreach (var issue in progressReport.Issues)
                        {
                            WriteWarning("* " + issue);
                        }
                    }
                }

                return(-1);
            }
        }
示例#4
0
        public static int Main(string[] args)
        {
            var productInformation = new ProductInformation("ApiPort_Console", typeof(Program));

            Console.WriteLine(LocalizedStrings.Header, LocalizedStrings.ApplicationName, productInformation.Version);

            var options = CommandLineOptions.ParseCommandLineOptions(args);

            if (options.Command == AppCommands.Exit)
            {
                return(-1);
            }

            Console.WriteLine();

            using (var container = DependencyBuilder.Build(options, productInformation))
            {
                var progressReport = container.Resolve <IProgressReporter>();

                try
                {
                    var client = container.Resolve <ConsoleApiPort>();

                    switch (options.Command)
                    {
                    case AppCommands.ListTargets:
                        client.ListTargetsAsync().Wait();
                        break;

                    case AppCommands.AnalyzeAssemblies:
                        client.AnalyzeAssembliesAsync().Wait();
                        break;

                    case AppCommands.DocIdSearch:
                        client.RunDocIdSearchAsync().Wait();
                        break;

                    case AppCommands.ListOutputFormats:
                        client.ListOutputFormatsAsync().Wait();
                        break;
                    }

                    return(0);
                }
                catch (PortabilityAnalyzerException ex)
                {
                    Trace.TraceError(ex.ToString());

                    // Display the message as it has already been localized
                    WriteError(ex.Message);
#if DEBUG
                    // Provide additional info on inner exceptions if built for debug
                    if (ex.InnerException != null)
                    {
                        WriteError(ex.InnerException.ToString());
                    }
#endif // DEBUG
                }
                catch (AggregateException ex)
                {
                    Trace.TraceError(ex.ToString());

                    // If the exception is known, display the message as it has already been localized
                    if (GetRecursiveInnerExceptions(ex).Any(x => x is PortabilityAnalyzerException))
                    {
                        foreach (PortabilityAnalyzerException portEx in GetRecursiveInnerExceptions(ex).Where(x => x is PortabilityAnalyzerException))
                        {
                            WriteError(portEx.Message);
#if DEBUG
                            // Provide additional info on inner exceptions if built for debug
                            if (portEx.InnerException != null)
                            {
                                WriteError(portEx.InnerException.ToString());
                            }
#endif // DEBUG
                        }
                    }
                    else if (!IsWebSecurityFailureOnMono(ex))
                    {
                        WriteError(LocalizedStrings.UnknownException);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());

                    WriteError(LocalizedStrings.UnknownException);
                }
                finally
                {
                    if (progressReport != null)
                    {
                        Console.WriteLine();

                        foreach (var issue in progressReport.Issues)
                        {
                            WriteWarning("* " + issue);
                        }
                    }
                }

                return(-1);
            }
        }