Skip to content

Commit

Permalink
Search fixes.
Browse files Browse the repository at this point in the history
Add load-testing project.

Add using around webclient.
  • Loading branch information
bitbound committed Apr 27, 2020
1 parent 7328aee commit 1aa2bda
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Agent/Services/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task InstallLatestVersion()

Logger.Write("Service Updater: Downloading install package.");

var wc = new WebClientEx((int)UpdateTimer.Interval);
using var wc = new WebClientEx((int)UpdateTimer.Interval);
var downloadId = Guid.NewGuid().ToString();
var zipPath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.zip");

Expand Down
14 changes: 14 additions & 0 deletions Remotely.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Desktop.Win.Wrapper", "Desktop.Win.Wrapper\Desktop.Win.Wrapper.csproj", "{A9967E61-B1BE-4AA5-A33A-99B0B8B5FC2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.LoadTester", "Tests.LoadTester\Tests.LoadTester.csproj", "{6C25240C-613D-4A86-A04E-784BA6726094}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -193,6 +195,18 @@ Global
{A9967E61-B1BE-4AA5-A33A-99B0B8B5FC2A}.Release|x64.Build.0 = Release|Any CPU
{A9967E61-B1BE-4AA5-A33A-99B0B8B5FC2A}.Release|x86.ActiveCfg = Release|Any CPU
{A9967E61-B1BE-4AA5-A33A-99B0B8B5FC2A}.Release|x86.Build.0 = Release|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Debug|x64.Build.0 = Debug|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Debug|x86.Build.0 = Debug|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Release|Any CPU.Build.0 = Release|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Release|x64.ActiveCfg = Release|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Release|x64.Build.0 = Release|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Release|x86.ActiveCfg = Release|Any CPU
{6C25240C-613D-4A86-A04E-784BA6726094}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 6 additions & 4 deletions Server/wwwroot/scripts/Commands/WebCommands.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/scripts/Commands/WebCommands.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Server/wwwroot/scripts/Commands/WebCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ var commands: Array<ConsoleCommand> = [
var key = filter.slice(0, operatorIndex).trim().toLowerCase();
var operator = filter.slice(operatorIndex, valueIndex).trim().toLowerCase();
var value = filter.slice(valueIndex).trim().toLowerCase();

console.log(`Searching by key ${key}, operator ${operator}, value ${value}`);
if (key == "lastonline") {
var parsedDate = Date.parse(value);
switch (operator) {
Expand All @@ -374,16 +374,16 @@ var commands: Array<ConsoleCommand> = [
else {
switch (operator) {
case "=":
lambda += `(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)] || "").toString().toLowerCase() === "${value}".toString().toLowerCase() && `;
lambda += `(String(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)])).toLowerCase() === "${value}".toString().toLowerCase() && `;
break;
case "*":
lambda += `(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)] || "").toString().toLowerCase().search("${value}".toString().toLowerCase()) > -1 && `;
lambda += `(String(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)])).toLowerCase().search("${value}".toString().toLowerCase()) > -1 && `;
break;
case "!=":
lambda += `(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)] || "").toString().toLowerCase() !== "${value}".toString().toLowerCase() && `;
lambda += `(String(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)])).toLowerCase() !== "${value}".toString().toLowerCase() && `;
break;
case "!*":
lambda += `(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)] || "").toString().toLowerCase().search("${value}".toString().toLowerCase()) === -1 && `;
lambda += `(String(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)])).toLowerCase().search("${value}".toString().toLowerCase()) === -1 && `;
break;
case ">":
lambda += `parseFloat(x[Object.keys(x).find(y=>y.toString().toLowerCase().indexOf("${key}") > -1)]) > parseFloat("${value}") && `;
Expand All @@ -400,6 +400,7 @@ var commands: Array<ConsoleCommand> = [
}
catch (ex) {
AddConsoleOutput("Unable to parse filter. Please check your syntax.");
console.error(ex);
return;
}
lambda = lambda.slice(0, lambda.lastIndexOf(" &&"));
Expand Down
59 changes: 59 additions & 0 deletions Shared/Utilities/CommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Windows;

namespace Remotely.Shared.Utilities
{
public class CommandLineParser
{
private static Dictionary<string, string> commandLineArgs;
public static 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)
{
try
{
var key = args?[i];
if (key != null)
{
if (!key.Contains("-"))
{
i -= 1;
continue;
}
key = key.Trim().Replace("-", "").ToLower();
if (i + 1 == args.Length)
{
commandLineArgs.Add(key, "true");
continue;
}
var value = args[i + 1];
if (value != null)
{
if (value.StartsWith("-"))
{
commandLineArgs.Add(key, "true");
i -= 1;
}
else
{
commandLineArgs.Add(key, args[i + 1].Trim());
}
}
}
}
catch { }

}
}
return commandLineArgs;
}
}
}
}
93 changes: 93 additions & 0 deletions Tests.LoadTester/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Microsoft.AspNetCore.SignalR.Client;
using Remotely.Shared.Services;
using Remotely.Shared.Utilities;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Remotely.Tests.LoadTester
{
internal class Program
{
private static void Main(string[] args)
{
Task.Run(ConnectAgents).Wait();

Console.Write("Press Enter to exit...");
Console.ReadLine();
}

private static async Task ConnectAgents()
{
try
{
if (!CommandLineParser.CommandLineArgs.ContainsKey("serverurl") ||
!CommandLineParser.CommandLineArgs.ContainsKey("organizationid") ||
!CommandLineParser.CommandLineArgs.ContainsKey("agentcount"))
{
Console.WriteLine("Command line arguments must include all of the following: ");
Console.WriteLine();
Console.WriteLine("-serverurl [full URL of the Remotely server]");
Console.WriteLine();
Console.WriteLine("-organizationid [organization ID that the device will belong to]");
Console.WriteLine();
Console.WriteLine("-agentcount [the number of agent connections to simulate]");
Console.WriteLine();
Console.WriteLine("Press Enter to exit...");
Environment.Exit(0);
}

var agentCount = int.Parse(CommandLineParser.CommandLineArgs["agentcount"]);
var organizationId = CommandLineParser.CommandLineArgs["organizationid"];
var serverurl = CommandLineParser.CommandLineArgs["serverurl"];
var connections = new Dictionary<string, HubConnection>();

for (var i = 0; i < agentCount; i++)
{
try
{
var deviceId = Guid.NewGuid().ToString();

var hubConnection = new HubConnectionBuilder()
.WithUrl(serverurl + "/DeviceHub")
.Build();

Console.WriteLine("Connecting device number " + i.ToString());
await hubConnection.StartAsync();

var device = await DeviceInformation.Create(deviceId, organizationId);
device.DeviceName = "TestDevice-" + Guid.NewGuid();

var result = await hubConnection.InvokeAsync<bool>("DeviceCameOnline", device);

if (!result)
{
Console.WriteLine($"Device {i} failed to come online.");
return;
}

var heartbeatTimer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds);
heartbeatTimer.Elapsed += async (sender, args) =>
{
var currentInfo = await DeviceInformation.Create(device.ID, organizationId);
currentInfo.DeviceName = device.DeviceName;
await hubConnection.SendAsync("DeviceHeartbeat", currentInfo);
};
heartbeatTimer.Start();
}
catch (Exception ex)
{
Console.WriteLine($"Device {i} failed to connect.");
Console.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred. Check your syntex. Error: ");
Console.WriteLine();
Console.WriteLine(ex.Message);
}
}
}
}
8 changes: 8 additions & 0 deletions Tests.LoadTester/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Tests.LoadTester": {
"commandName": "Project",
"commandLineArgs": "-serverurl https://localhost:5001 -organizationid 6b8ff6b6-a5ac-4e38-a022-3b64f2e6b486 -agentcount 1000"
}
}
}
14 changes: 14 additions & 0 deletions Tests.LoadTester/Tests.LoadTester.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Remotely.Tests.LoadTester</AssemblyName>
<RootNamespace>Remotely.Tests.LoadTester</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ScreenCast.Core\ScreenCast.Core.csproj" />
</ItemGroup>

</Project>

0 comments on commit 1aa2bda

Please sign in to comment.