public ApiPortService(string endpoint, ProductInformation info, IProxyProvider proxyProvider) { if (string.IsNullOrWhiteSpace(endpoint)) { throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, "Must be a valid endpoint"); } if (proxyProvider == null) { throw new ArgumentNullException(nameof(proxyProvider)); } var uri = new Uri(endpoint); var proxy = proxyProvider.GetProxy(uri); // replace the handler with the proxy aware handler var clientHandler = new HttpClientHandler { Proxy = proxy, AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate) }; // HTTP handler pipeline can be injected here, around the client handler HttpMessageHandler messageHandler = clientHandler; if (proxy != null) { messageHandler = new ProxyAuthenticationHandler(clientHandler, proxyProvider); } _client = new CompressedHttpClient(info, messageHandler) { BaseAddress = new Uri(endpoint), Timeout = Timeout }; }
public static IUnityContainer Build(ICommandLineOptions options, ProductInformation productInformation) { var container = new UnityContainer(); var targetMapper = new TargetMapper(); targetMapper.LoadFromConfig(options.TargetMapFile); container.RegisterInstance<ICommandLineOptions>(options); container.RegisterInstance<ITargetMapper>(targetMapper); // For debug purposes, the FileOutputApiPortService helps as it serializes the request to json and opens it with the // default json handler. To use this service, uncomment the the next line and comment the one after that. //container.RegisterType<IApiPortService, FileOutputApiPortService>(new ContainerControlledLifetimeManager()); container.RegisterInstance<IApiPortService>(new ApiPortService(options.ServiceEndpoint, productInformation)); container.RegisterType<IEnumerable<IgnoreAssemblyInfo>, FileIgnoreAssemblyInfoList>(new ContainerControlledLifetimeManager()); container.RegisterType<IDependencyFinder, ReflectionMetadataDependencyFinder>(new ContainerControlledLifetimeManager()); container.RegisterType<IDependencyFilter, DotNetFrameworkFilter>(new ContainerControlledLifetimeManager()); container.RegisterType<IReportGenerator, ReportGenerator>(new ContainerControlledLifetimeManager()); container.RegisterType<ApiPortService>(new ContainerControlledLifetimeManager()); container.RegisterType<IFileSystem, WindowsFileSystem>(new ContainerControlledLifetimeManager()); container.RegisterType<IFileWriter, ReportFileWriter>(new ContainerControlledLifetimeManager()); container.RegisterType<IRequestAnalyzer, RequestAnalyzer>(new ContainerControlledLifetimeManager()); container.RegisterType<IAnalysisEngine, AnalysisEngine>(new ContainerControlledLifetimeManager()); container.RegisterType<ConsoleApiPort>(new ContainerControlledLifetimeManager()); container.RegisterType<ICollection<IReportWriter>>(new ContainerControlledLifetimeManager(), new InjectionFactory(WriterCollection)); container.RegisterType<IApiPortOptions>(new ContainerControlledLifetimeManager(), new InjectionFactory(GetOptions)); container.RegisterType<DocIdSearchRepl>(new ContainerControlledLifetimeManager()); container.RegisterType<ISearcher<string>, ApiPortServiceSearcher>(new ContainerControlledLifetimeManager()); // Register the default output format name container.RegisterInstance(DefaultOutputFormatInstanceName, "Excel"); if (Console.IsOutputRedirected) { container.RegisterInstance<IProgressReporter>(new TextWriterProgressReporter(Console.Out)); } else { container.RegisterType<IProgressReporter, ConsoleProgressReporter>(new ContainerControlledLifetimeManager()); } #if FEATURE_DESKTOP_CONFIGURATION // Unity configuration is only available in its desktop package // Load any customizations via Unity var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = Path.Combine(GetApplicationDirectory(), "unity.config") }; var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var unitySection = (UnityConfigurationSection)configuration.GetSection("unity"); return unitySection == null ? container : container.LoadConfiguration(unitySection); #else // FEATURE_DESKTOP_CONFIGURATION // TODO : Allow runtime configuration through some non-.config means? return container; #endif // FEATURE_DESKTOP_CONFIGURATION }
public ApiPortService(string endpoint, ProductInformation info) { _endpoint = endpoint; _client = new CompressedHttpClient(info) { Timeout = TimeSpan.FromMinutes(10) }; }
public CompressedHttpClient(ProductInformation info, HttpMessageHandler handler) : base(handler) { DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); DefaultRequestHeaders.AcceptLanguage.TryParseAdd(CultureInfo.CurrentCulture.ToString()); DefaultRequestHeaders.Add("Client-Type", info.Name); DefaultRequestHeaders.Add("Client-Version", info.Version); }
/// <param name="productName">Product name that will be displayed in the User Agent string of requests</param> /// <param name="productVersion">Product version that will be displayed in the User Agent string of requests</param> public CompressedHttpClient(ProductInformation info) : this(info, new HttpClientHandler { #if !FEATURE_SERVICE_POINT_MANAGER SslProtocols = SupportedSSLProtocols, #endif AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }) { }
/// <param name="productName">Product name that will be displayed in the User Agent string of requests</param> /// <param name="productVersion">Product version that will be displayed in the User Agent string of requests</param> public CompressedHttpClient(ProductInformation info) : base(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }) { DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); DefaultRequestHeaders.AcceptLanguage.TryParseAdd(CultureInfo.CurrentCulture.ToString()); DefaultRequestHeaders.Add("Client-Type", info.Name); DefaultRequestHeaders.Add("Client-Version", info.Version); }
public ApiPortService(string endpoint, ProductInformation info) { if (string.IsNullOrWhiteSpace(endpoint)) { throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, "Must be a valid endpoint"); } _client = new CompressedHttpClient(info) { BaseAddress = new Uri(endpoint), Timeout = TimeSpan.FromMinutes(10) }; }
public CompressedHttpClient(ProductInformation info, HttpMessageHandler handler) : base(handler) { #if FEATURE_SERVICE_POINT_MANAGER ServicePointManager.SecurityProtocol = SupportedSecurityProtocols; #endif DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); DefaultRequestHeaders.AcceptLanguage.TryParseAdd(CultureInfo.CurrentCulture.ToString()); DefaultRequestHeaders.Add("Client-Type", info.Name); DefaultRequestHeaders.Add("Client-Version", info.Version); }
public ApiPortService(string endpoint, ProductInformation info) { if (string.IsNullOrWhiteSpace(endpoint)) { throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, LocalizedStrings.MustBeValidEndpoint); } _client = new CompressedHttpClient(info) { BaseAddress = new Uri(endpoint), Timeout = Timeout }; }
public static IUnityContainer Build(ICommandLineOptions options, ProductInformation productInformation) { var container = new UnityContainer(); var targetMapper = new TargetMapper(); targetMapper.LoadFromConfig(); var ignoreAssemblyList = new FileIgnoreAssemblyInfoList(options.RequestFlags.HasFlag(AnalyzeRequestFlags.NoDefaultIgnoreFile), options.IgnoredAssemblyFiles); container.RegisterInstance(options); container.RegisterInstance<ITargetMapper>(targetMapper); container.RegisterInstance<IEnumerable<IgnoreAssemblyInfo>>(ignoreAssemblyList); // For debug purposes, the FileOutputApiPortService helps as it serializes the request to json and opens it with the // default json handler. To use this service, uncomment the the next line and comment the one after that. //container.RegisterType<IApiPortService, FileOutputApiPortService>(new ContainerControlledLifetimeManager()); container.RegisterInstance<IApiPortService>(new ApiPortService(options.ServiceEndpoint, productInformation)); container.RegisterType<IDependencyFinder, ReflectionMetadataDependencyFinder>(new ContainerControlledLifetimeManager()); container.RegisterType<IReportGenerator, ReportGenerator>(new ContainerControlledLifetimeManager()); container.RegisterType<ApiPortService>(new ContainerControlledLifetimeManager()); container.RegisterType<IFileSystem, WindowsFileSystem>(new ContainerControlledLifetimeManager()); container.RegisterType<IFileWriter, ReportFileWriter>(new ContainerControlledLifetimeManager()); container.RegisterType<IRequestAnalyzer, RequestAnalyzer>(new ContainerControlledLifetimeManager()); container.RegisterType<IAnalysisEngine, AnalysisEngine>(new ContainerControlledLifetimeManager()); container.RegisterType<ICollection<IReportWriter>>(new ContainerControlledLifetimeManager(), new InjectionFactory(WriterCollection)); // Register the default output format name container.RegisterInstance("DefaultOutputFormat", "Excel"); if (Console.IsOutputRedirected) { container.RegisterInstance<IProgressReporter>(new TextWriterProgressReporter(Console.Out)); } else { container.RegisterType<IProgressReporter, ConsoleProgressReporter>(new ContainerControlledLifetimeManager()); } // Load any customizations via Unity var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = Path.Combine(GetApplicationDirectory(), "unity.config") }; var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var unitySection = (UnityConfigurationSection)configuration.GetSection("unity"); return unitySection == null ? container : container.LoadConfiguration(unitySection); }
public ApiPortService(string endpoint, ProductInformation info, IProxyProvider proxyProvider) { if (string.IsNullOrWhiteSpace(endpoint)) { throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, LocalizedStrings.MustBeValidEndpoint); } if (proxyProvider == null) { throw new ArgumentNullException(nameof(proxyProvider)); } // Create the URI directly from a string (rather than using a hard-coded scheme or port) because // even though production use of ApiPort should always use HTTPS, developers using a non-production // portability service URL (via the -e command line parameter) may need to specify a different // scheme or port. var uri = new Uri(endpoint); var proxy = proxyProvider.GetProxy(uri); // replace the handler with the proxy aware handler var clientHandler = new HttpClientHandler { #if !FEATURE_SERVICE_POINT_MANAGER SslProtocols = CompressedHttpClient.SupportedSSLProtocols, #endif Proxy = proxy, AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate) }; // HTTP handler pipeline can be injected here, around the client handler HttpMessageHandler messageHandler = clientHandler; if (proxy != null) { messageHandler = new ProxyAuthenticationHandler(clientHandler, proxyProvider); } _client = new CompressedHttpClient(info, messageHandler) { BaseAddress = new Uri(endpoint), Timeout = Timeout }; }
public ApiPortService(string endpoint, ProductInformation info, IProxyProvider proxyProvider = null) : this(endpoint, BuildMessageHandler(endpoint, proxyProvider), info) { }
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); } 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; } }
public PortabilityToolsStatusService(HttpClient client, ProductInformation productInfo) { _client = client; }
/// <param name="productName">Product name that will be displayed in the User Agent string of requests</param> /// <param name="productVersion">Product version that will be displayed in the User Agent string of requests</param> public CompressedHttpClient(ProductInformation info) : this(info, new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }) { }
public static IContainer Build(ICommandLineOptions options, ProductInformation productInformation) { var builder = new ContainerBuilder(); builder.RegisterType<TargetMapper>() .As<ITargetMapper>() .OnActivated(c => c.Instance.LoadFromConfig(options.TargetMapFile)) .SingleInstance(); builder.RegisterInstance<ICommandLineOptions>(options); #if DEBUG_SERVICE // For debug purposes, the FileOutputApiPortService helps as it serializes the request to json and opens it with the // default json handler. To use this service, uncomment the the next line and comment the one after that. container.RegisterType<FileOutputApiPortService>() .As<IApiPortService>() .SingleInstance(); #else builder.RegisterInstance<IApiPortService>(new ApiPortService(options.ServiceEndpoint, productInformation)); #endif builder.RegisterType<FileIgnoreAssemblyInfoList>() .As<IEnumerable<IgnoreAssemblyInfo>>() .SingleInstance(); builder.RegisterType<ReflectionMetadataDependencyFinder>() .As<IDependencyFinder>() .SingleInstance(); builder.RegisterType<DotNetFrameworkFilter>() .As<IDependencyFilter>() .SingleInstance(); builder.RegisterType<ReportGenerator>() .As<IReportGenerator>() .SingleInstance(); builder.RegisterType<ApiPortClient>() .SingleInstance(); builder.RegisterType<ApiPortService>() .SingleInstance(); builder.RegisterType<WindowsFileSystem>() .As<IFileSystem>() .SingleInstance(); builder.RegisterType<ReportFileWriter>() .As<IFileWriter>() .SingleInstance(); builder.RegisterType<RequestAnalyzer>() .As<IRequestAnalyzer>() .SingleInstance(); builder.RegisterType<AnalysisEngine>() .As<IAnalysisEngine>() .SingleInstance(); builder.RegisterType<ConsoleApiPort>() .SingleInstance(); builder.RegisterAdapter<ICommandLineOptions, IApiPortOptions>((ctx, opts) => { if (opts.OutputFormats?.Any() == true) { return opts; } return new ReadWriteApiPortOptions(opts) { OutputFormats = new[] { ctx.ResolveNamed<string>(DefaultOutputFormatInstanceName) } }; }) .SingleInstance(); builder.RegisterType<DocIdSearchRepl>(); builder.RegisterType<ApiPortServiceSearcher>() .As<ISearcher<string>>() .SingleInstance(); // Register the default output format name builder.RegisterInstance("Excel") .Named<string>(DefaultOutputFormatInstanceName); if (Console.IsOutputRedirected) { builder.RegisterInstance<IProgressReporter>(new TextWriterProgressReporter(Console.Out)); } else { builder.RegisterType<ConsoleProgressReporter>() .As<IProgressReporter>() .SingleInstance(); } TryLoadOffline(builder); return builder.Build(); }
public ApiPortService(string endpoint, HttpMessageHandler httpMessageHandler, ProductInformation info) { if (string.IsNullOrWhiteSpace(endpoint)) { throw new ArgumentOutOfRangeException(nameof(endpoint), endpoint, "Must be a valid endpoint"); } if (info == null) { throw new ArgumentNullException(nameof(info)); } _client = new CompressedHttpClient(info, httpMessageHandler) { BaseAddress = new Uri(endpoint), Timeout = Timeout }; }