public MainWindowViewModel(ILogger <MainWindowViewModel> logger, IWDClientServices wdClientServices, string[] streamingTypes, UInt16 preferredServerPort = 80, UInt16 preferredStreamingPort = 5500, int preferredLocalScreenWidth = 1024, int preferredRemoteScreenWidth = 1024) { _logger = logger; _wdClientServices = wdClientServices; _preferredServerPort = preferredServerPort; _preferredStreamingPort = preferredStreamingPort; _preferredLocalScreenWidth = preferredLocalScreenWidth; _preferredRemoteScreenWidth = preferredRemoteScreenWidth; // Initialize bound properties ServerPort = _preferredServerPort; InitialLocalScreenResolution = _wdClientServices.GetInitalLocalScreenResolution(); CurrentLocalScreenResolution = _wdClientServices.GetCurrentLocalScreenResolution(); //InitialRemoteScreenResolution = _wdClientServices.GetInitalRemoteScreenResolution(); //CurrentRemoteScreenResolution = await _wdClientServices.GetCurrentRemoteScreenResolution(); AvailableLocalScreenResolutions = new ObservableCollection <string>(); SelectedLocalScreenResolutionIndex = -1; AvailableRemoteScreenResolutions = new ObservableCollection <string>(); SelectedRemoteScreenResolutionIndex = -1; StreamingTypes = new ObservableCollection <string>(streamingTypes); // pre-select first of the provided straming-types SelectedStreamingTypeIndex = 0; StreamingPort = _preferredStreamingPort; }
private void createWdClientServices() { var loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddFilter("Default", LogLevel.Information) .AddConsole(); }); // Create LocalScriptRunner. var loggerForLocalScriptRunner = loggerFactory.CreateLogger <LocalScriptRunner>(); var scriptDir = new DirectoryInfo(SCRIPT_DIR_LINUX); var localScriptRunner = new LocalScriptRunner( loggerForLocalScriptRunner, SHELL_LINUX, SHELL_ARGS_LINUX, scriptDir, SCRIPT_FILE_EXTENSION_LINUX ); // Create RemoteScriptRunner. var loggerForRemoteScriptRunner = loggerFactory.CreateLogger <RemoteScriptRunner>(); var remoteScriptRunner = new RemoteScriptRunner(loggerForRemoteScriptRunner); // Create WDClientServices, passing it the LocalScriptRunner and // the RemoteScriptRunner. var loggerForWdClientServices = loggerFactory.CreateLogger <WDClientServices>(); _wdClientServices = new WDClientServices( logger: loggerForWdClientServices, localScriptRunner: localScriptRunner, remoteScriptRunner: remoteScriptRunner, localIpAddress: LOCAL_IP, scriptNameManageScreenResolutions: SCRIPT_NAME_MANAGE_SCREEN_RESOLUTIONS, scriptArgsManageScreenResolutions: SCRIPT_ARGS_MANAGE_SCREEN_RESOLUTIONS, scriptNameStartStreamingSink: SCRIPT_NAME_START_STREAMING_SINK, scriptArgsStartStreamingSink: SCRIPT_ARGS_START_STREAMING_SINK, scriptNameStartStreamingSource: SCRIPT_NAME_START_STREAMING_SOURCE, scriptArgsStartStreamingSource: SCRIPT_ARGS_START_STREAMING_SOURCE, scriptNamePreventDisplayBlanking: SCRIPT_NAME_PREVENT_DISPLAY_BLANKING, scriptArgsPreventDisplayBlanking: SCRIPT_ARGS_PREVENT_DISPLAY_BLANKING ); }
//############ Original code from template - end ############################ /// <summary> /// Creates all objects that need to be injected into the constructor /// of MainViewModel (prepare Dependency-injection). These created /// object themselves need other things injected in their constructors. /// This funciton glues all the needed objects together using /// dependecy-injection. /// </summary> private void realizeDependencyInjection( out ILogger <MainWindowViewModel> loggerforMainWindowModel, out IWDClientServices wdClientServices, out string[] streamingTypes, out UInt16 preferredServerPort, out UInt16 preferredStreamingPort, out int preferredLocalScreenWidth, out int preferredRemoteScreenWidth) { // Create typed loggers. // See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#non-host-console-app var loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddFilter("Default", LogLevel.Information) .AddConsole(); }); // Assign out-object logger loggerforMainWindowModel = loggerFactory.CreateLogger <MainWindowViewModel>(); // Create reader for config.json var customConfigProviderLogger = loggerFactory.CreateLogger <CustomConfigProvider>(); var customConfigProvider = new CustomConfigProvider(customConfigProviderLogger, MagicStrings.CONFIG_FILE); // Assign out-objects read from config.json string streamtypeList = customConfigProvider[MagicStrings.STREAMING_TYPES]; streamingTypes = streamtypeList.Split(',', StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < streamingTypes.Length; i++) { streamingTypes[i] = streamingTypes[i].Trim(); } preferredServerPort = Convert.ToUInt16( customConfigProvider[MagicStrings.PREFERRED_SERVER_PORT]); preferredStreamingPort = Convert.ToUInt16( customConfigProvider[MagicStrings.PREFERRED_STREAMING_PORT]); preferredLocalScreenWidth = Convert.ToInt32( customConfigProvider[MagicStrings.PREFERRED_LOCAL_SCREEN_WIDTH]); preferredRemoteScreenWidth = Convert.ToInt32( customConfigProvider[MagicStrings.PREFERRED_REMOTE_SCREEN_WIDTH]); bool letShellWindowsPopUpWhenStartScript; bool success = bool.TryParse(customConfigProvider[MagicStrings.LET_SHELL_WINDOW_POP_UP_WHEN_START_SCRIPT], out letShellWindowsPopUpWhenStartScript); if (!success) { throw new WDFatalException($"Value '{customConfigProvider[MagicStrings.LET_SHELL_WINDOW_POP_UP_WHEN_START_SCRIPT]}' for key '{MagicStrings.LET_SHELL_WINDOW_POP_UP_WHEN_START_SCRIPT}' in configuration-file '{MagicStrings.CONFIG_FILE}' is not 'true' or 'false'."); } var loggerForLocalScriptRunner = loggerFactory.CreateLogger <LocalScriptRunner>(); var scriptDir = new DirectoryInfo( customConfigProvider[MagicStrings.SCRIPT_DIRECTORY]); var localScriptRunner = new LocalScriptRunner( logger: loggerForLocalScriptRunner, shell: customConfigProvider[MagicStrings.SHELL], shellArgsTemplate: customConfigProvider[MagicStrings.SHELL_ARGS_TEMPLATE], scriptDirectory: scriptDir, scriptExtension: customConfigProvider[MagicStrings.SCRIPT_FILE_EXTENSION], letShellWindowsPopUpWhenStartScript: letShellWindowsPopUpWhenStartScript ); var loggerForRemoteScriptRunner = loggerFactory.CreateLogger <RemoteScriptRunner>(); var remoteScriptRunner = new RemoteScriptRunner(loggerForRemoteScriptRunner); string localIpAddress = HostAddressProvider.IPv4Address; var loggerForWdClientServices = loggerFactory.CreateLogger <WDClientServices>(); wdClientServices = new WDClientServices( logger: loggerForWdClientServices, localScriptRunner: localScriptRunner, localIpAddress: localIpAddress, remoteScriptRunner: remoteScriptRunner, scriptNameManageScreenResolutions: customConfigProvider[MagicStrings.SCRIPTNAME_MANAGE_SCREEN_RESOLUTION], scriptArgsManageScreenResolutions: customConfigProvider[MagicStrings.SCRIPTARGS_MANAGE_SCREEN_RESOLUTION], scriptNameStartStreamingSink: customConfigProvider[MagicStrings.SCRIPTNAME_START_STREAMING_SINK], scriptArgsStartStreamingSink: customConfigProvider[MagicStrings.SCRIPTARGS_START_STREAMING_SINK], scriptNameStartStreamingSource: customConfigProvider[MagicStrings.SCRIPTNAME_START_STREAMING_SOURCE], scriptArgsStartStreamingSource: customConfigProvider[MagicStrings.SCRIPTARGS_START_STREAMING_SOURCE], scriptNamePreventDisplayBlanking: customConfigProvider[MagicStrings.SCRIPTNAME_PREVENT_DISPLAY_BLANKING], scriptArgsPreventDisplayBlanking: customConfigProvider[MagicStrings.SCRIPTARGS_PREVENT_DISPLAY_BLANKING] ); }