Added debugging params to config service.

This commit is contained in:
Jared Goodwin 2020-02-16 22:22:17 -08:00
parent 6fc0b84ab1
commit 83eed067bd
4 changed files with 61 additions and 35 deletions

View File

@ -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<string,string> ProcessArgs(string[] args)
{
var argDict = new Dictionary<string, string>();
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()
{

View File

@ -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<string, string> commandLineArgs;
private Dictionary<string, string> CommandLineArgs
{
get
{
if (commandLineArgs is null)
{
commandLineArgs = new Dictionary<string, string>();
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<ConnectionInfo>(File.ReadAllText("ConnectionInfo.json"));
connectionInfo = JsonSerializer.Deserialize<ConnectionInfo>(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<DeviceSetupOptions>(File.ReadAllText("DeviceSetupOptions.json"));
options = JsonSerializer.Deserialize<DeviceSetupOptions>(File.ReadAllText("DeviceSetupOptions.json"));
File.Delete("DeviceSetupOptions.json");
return true;
}
@ -62,5 +104,6 @@ namespace Remotely.Agent.Services
options = null;
return false;
}
}
}

View File

@ -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<ActionResult> Get(string organizationID, string platformID)
{
return await GetInstallFile(organizationID, platformID);
}
private async Task<ActionResult> GetInstallFile(string organizationID, string platformID)
{
var scheme = AppConfig.RedirectToHttps ? "https" : Request.Scheme;

View File

@ -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)
{