From 83eed067bd0d8a5b77276a6a7a1ebe8eb89c2baa Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Sun, 16 Feb 2020 22:22:17 -0800 Subject: [PATCH] Added debugging params to config service. --- Agent/Program.cs | 25 +----------- Agent/Services/ConfigService.cs | 51 +++++++++++++++++++++++-- Server/API/ClientDownloadsController.cs | 10 +++-- Server/Services/DeviceSocketHub.cs | 10 ++--- 4 files changed, 61 insertions(+), 35 deletions(-) diff --git a/Agent/Program.cs b/Agent/Program.cs index b03d5681..cf5ab0a2 100644 --- a/Agent/Program.cs +++ b/Agent/Program.cs @@ -27,7 +27,7 @@ namespace Remotely.Agent { BuildServices(); - Task.Run(() => { Init(args); }); + Task.Run(() => { Init(); }); Thread.Sleep(Timeout.Infinite); @@ -98,7 +98,7 @@ namespace Remotely.Agent } } - private static async void Init(string[] args) + private static async void Init() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; @@ -107,7 +107,6 @@ namespace Remotely.Agent #endif SetWorkingDirectory(); - var argDict = ProcessArgs(args); if (!IsDebug && OSUtils.IsWindows) { @@ -126,26 +125,6 @@ namespace Remotely.Agent await HandleConnection(); } } - private static Dictionary ProcessArgs(string[] args) - { - var argDict = new Dictionary(); - - for (var i = 0; i < args.Length; i += 2) - { - var key = args?[i]; - if (key != null) - { - key = key.Trim().Replace("-", "").ToLower(); - var value = args?[i + 1]; - if (value != null) - { - argDict[key] = args[i + 1].Trim(); - } - } - - } - return argDict; - } private static void SetWorkingDirectory() { diff --git a/Agent/Services/ConfigService.cs b/Agent/Services/ConfigService.cs index c101d7ce..95bccab2 100644 --- a/Agent/Services/ConfigService.cs +++ b/Agent/Services/ConfigService.cs @@ -1,10 +1,10 @@ using Remotely.Shared.Models; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Text.Json; namespace Remotely.Agent.Services { @@ -14,8 +14,37 @@ namespace Remotely.Agent.Services private ConnectionInfo connectionInfo; private string debugGuid = "f2b0a595-5ea8-471b-975f-12e70e0f3497"; + private Dictionary commandLineArgs; + private Dictionary CommandLineArgs + { + get + { + if (commandLineArgs is null) + { + commandLineArgs = new Dictionary(); + var args = Environment.GetCommandLineArgs(); + for (var i = 1; i < args.Length; i += 2) + { + var key = args?[i]; + if (key != null) + { + key = key.Trim().Replace("-", "").ToLower(); + var value = args?[i + 1]; + if (value != null) + { + commandLineArgs[key] = args[i + 1].Trim(); + } + } + + } + } + return commandLineArgs; + } + } + public ConnectionInfo GetConnectionInfo() { + if (Program.IsDebug && Debugger.IsAttached) { return new ConnectionInfo() @@ -25,6 +54,19 @@ namespace Remotely.Agent.Services }; } + // For debugging purposes (i.e. launch of a bunch of instances). + if (CommandLineArgs.TryGetValue("host", out var hostName) && + CommandLineArgs.TryGetValue("organization", out var orgID) && + CommandLineArgs.TryGetValue("device", out var deviceID)) + { + return new ConnectionInfo() + { + DeviceID = deviceID, + Host = hostName, + OrganizationID = orgID + }; + } + if (connectionInfo == null) { lock (fileLock) @@ -34,7 +76,7 @@ namespace Remotely.Agent.Services Logger.Write(new Exception("No connection info available. Please create ConnectionInfo.json file with appropriate values.")); return null; } - connectionInfo = JsonConvert.DeserializeObject(File.ReadAllText("ConnectionInfo.json")); + connectionInfo = JsonSerializer.Deserialize(File.ReadAllText("ConnectionInfo.json")); } } @@ -46,7 +88,7 @@ namespace Remotely.Agent.Services { lock (fileLock) { - File.WriteAllText("ConnectionInfo.json", JsonConvert.SerializeObject(connectionInfo)); + File.WriteAllText("ConnectionInfo.json", JsonSerializer.Serialize(connectionInfo)); } } @@ -54,7 +96,7 @@ namespace Remotely.Agent.Services { if (File.Exists("DeviceSetupOptions.json")) { - options = JsonConvert.DeserializeObject(File.ReadAllText("DeviceSetupOptions.json")); + options = JsonSerializer.Deserialize(File.ReadAllText("DeviceSetupOptions.json")); File.Delete("DeviceSetupOptions.json"); return true; } @@ -62,5 +104,6 @@ namespace Remotely.Agent.Services options = null; return false; } + } } diff --git a/Server/API/ClientDownloadsController.cs b/Server/API/ClientDownloadsController.cs index 5177c913..24274449 100644 --- a/Server/API/ClientDownloadsController.cs +++ b/Server/API/ClientDownloadsController.cs @@ -19,15 +19,13 @@ namespace Remotely.Server.API [ApiController] public class ClientDownloadsController : ControllerBase { - public ClientDownloadsController(IWebHostEnvironment hostEnv, DataService dataService, ApplicationConfig appConfig) + public ClientDownloadsController(IWebHostEnvironment hostEnv, ApplicationConfig appConfig) { HostEnv = hostEnv; - DataService = dataService; AppConfig = appConfig; } private ApplicationConfig AppConfig { get; } - private DataService DataService { get; set; } private IWebHostEnvironment HostEnv { get; set; } [ServiceFilter(typeof(ApiAuthorizationFilter))] @@ -38,6 +36,12 @@ namespace Remotely.Server.API return await GetInstallFile(orgID, platformID); } + [HttpGet("{organizationID}/{platformID}")] + public async Task Get(string organizationID, string platformID) + { + return await GetInstallFile(organizationID, platformID); + } + private async Task GetInstallFile(string organizationID, string platformID) { var scheme = AppConfig.RedirectToHttps ? "https" : Request.Scheme; diff --git a/Server/Services/DeviceSocketHub.cs b/Server/Services/DeviceSocketHub.cs index 5bb98609..3fff288e 100644 --- a/Server/Services/DeviceSocketHub.cs +++ b/Server/Services/DeviceSocketHub.cs @@ -101,11 +101,11 @@ namespace Remotely.Server.Services return BrowserHub.Clients.Clients(connectionIds).SendAsync("DeviceCameOnline", Device); } - else - { - // Organization wasn't found. - return Clients.Caller.SendAsync("UninstallClient"); - } + //else + //{ + // // Organization wasn't found. + // return Clients.Caller.SendAsync("UninstallClient"); + //} } catch (Exception ex) {