/// <summary> /// Configure Dependency injection /// </summary> /// <returns></returns> private static IContainer ConfigureContainer() { var builder = new ContainerBuilder(); // Register logger builder.RegisterLogger(LogEx.ConsoleOut()); // Register infrastructure code builder.RegisterType <ResourceGroupFactory>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <AzureSubscription>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <ConsoleSelector>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <VisualStudioCredentials>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <IoTHubFactory>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <VirtualMachineFactory>() .AsImplementedInterfaces().SingleInstance(); return(builder.Build()); }
/// <summary> /// Create hub container /// </summary> /// <returns></returns> private IContainer CreateHubContainer() { var builder = new ContainerBuilder(); builder.RegisterInstance(this).AsImplementedInterfaces(); builder.RegisterLogger(LogEx.ConsoleOut()); builder.RegisterModule <IoTHubMockService>(); builder.RegisterType <TestIoTHubConfig>() .AsImplementedInterfaces(); // Twin and history clients builder.RegisterModule <TwinModuleClients>(); builder.RegisterType <HistoryRawSupervisorAdapter>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <TwinSupervisorAdapter>() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <TwinModuleClient>() .AsImplementedInterfaces(); builder.RegisterType <HistoryModuleClient>() .AsImplementedInterfaces(); // Adapts to expanded hda builder.RegisterType <HistoricAccessAdapter <string> >() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <HistoricAccessAdapter <EndpointRegistrationModel> >() .AsImplementedInterfaces().SingleInstance(); builder.RegisterType <HistoricAccessAdapter <EndpointApiModel> >() .AsImplementedInterfaces().SingleInstance(); // Supervisor clients builder.RegisterType <ActivationClient>() .AsImplementedInterfaces(); builder.RegisterType <DiagnosticsClient>() .AsImplementedInterfaces(); builder.RegisterType <DiscoveryClient>() .AsImplementedInterfaces(); builder.RegisterType <JsonVariantEncoder>() .AsImplementedInterfaces(); builder.RegisterType <JsonVariantEncoder>() .AsImplementedInterfaces(); // Add services builder.RegisterModule <RegistryServices>(); builder.RegisterType <ApplicationTwins>() .AsImplementedInterfaces(); builder.RegisterType <EndpointEventBrokerStub>() .AsImplementedInterfaces(); builder.RegisterType <ApplicationEventBrokerStub>() .AsImplementedInterfaces(); // Register http client module builder.RegisterModule <HttpClientModule>(); return(builder.Build()); }
/// <summary> /// Test network scanning /// </summary> /// <returns></returns> private static async Task TestNetworkScanner() { var logger = LogEx.ConsoleOut(); var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10)); var watch = Stopwatch.StartNew(); var scanning = new ScanServices(logger); DumpMemory(); var results = await scanning.ScanAsync(NetworkClass.Wired, cts.Token); foreach (var result in results) { Console.WriteLine($"Found {result.Address}..."); } Console.WriteLine($"Scan took: {watch.Elapsed}"); DumpMemory(); }
/// <summary> /// Test port scanning /// </summary> /// <param name="host"></param> /// <returns></returns> private static async Task TestPortScanner(string host) { var logger = LogEx.ConsoleOut(); var addresses = await Dns.GetHostAddressesAsync(host); using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10))) { var watch = Stopwatch.StartNew(); var scanning = new ScanServices(logger); DumpMemory(); var results = await scanning.ScanAsync( PortRange.All.SelectMany(r => r.GetEndpoints(addresses.First())), cts.Token); foreach (var result in results) { Console.WriteLine($"Found {result} open."); } Console.WriteLine($"Scan took: {watch.Elapsed}"); DumpMemory(); } }
/// <summary> /// Run client /// </summary> /// <param name="args">command-line arguments</param> public static async Task RunAsync(string[] args) { var sshFactory = new SshShellFactory(LogEx.ConsoleOut()); ISecureShell shell = null; try { var run = true; do { if (run) { Console.Write("> "); args = CliOptions.ParseAsCommandLine(Console.ReadLine()); } try { if (args.Length < 1) { throw new ArgumentException("Need a command!"); } var command = args[0].ToLowerInvariant(); var options = new CliOptions(args); switch (command) { case "exit": run = false; break; case "logout": shell = Logout(shell); break; case "login": if (shell != null) { throw new ArgumentException("Already logged in."); } shell = await LoginAsync(sshFactory, options); break; case "terminal": await RunTerminalAsync(shell, options); break; case "exec": await ExecuteCommandAsync(shell, options); break; case "download": await DownloadAsync(shell, options); break; case "upload": await UploadAsync(shell, options); break; case "folderup": await UploadFolderAsync(shell, options); break; case "folderdown": await DownloadFolderAsync(shell, options); break; case "-?": case "-h": case "--help": case "help": PrintHelp(); break; default: throw new ArgumentException($"Unknown command {command}."); } } catch (ArgumentException e) { Console.WriteLine(e.Message); if (!run) { PrintHelp(); return; } } catch (Exception e) { Console.WriteLine("=================="); Console.WriteLine(e); Console.WriteLine("=================="); } }while (run); } finally { shell?.Dispose(); } }