Skip to content

Commit

Permalink
InvokeAsync to SendAsync.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 8, 2020
1 parent b8b706e commit df80db9
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 57 deletions.
22 changes: 11 additions & 11 deletions Agent/Services/AppLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public async Task<int> LaunchChatService(string orgName, string requesterID, Hub
var rcBinaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScreenCast", OSUtils.ScreenCastExecutableFileName);
if (!File.Exists(rcBinaryPath))
{
await hubConnection.InvokeAsync("DisplayMessage", "Chat executable not found on target device.", "Executable not found on device.", requesterID);
await hubConnection.SendAsync("DisplayMessage", "Chat executable not found on target device.", "Executable not found on device.", requesterID);
}


// Start ScreenCast.
await hubConnection.InvokeAsync("DisplayMessage", $"Starting chat service...", "Starting chat service.", requesterID);
await hubConnection.SendAsync("DisplayMessage", $"Starting chat service...", "Starting chat service.", requesterID);
if (OSUtils.IsWindows)
{

Expand All @@ -46,7 +46,7 @@ public async Task<int> LaunchChatService(string orgName, string requesterID, Hub
var result = Win32Interop.OpenInteractiveProcess($"{rcBinaryPath} -mode Chat -requester {requesterID} -organization \"{orgName}\"", "default", false, out var procInfo);
if (!result)
{
await hubConnection.InvokeAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
else
{
Expand All @@ -63,7 +63,7 @@ public async Task<int> LaunchChatService(string orgName, string requesterID, Hub
catch (Exception ex)
{
Logger.Write(ex);
await hubConnection.InvokeAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
return -1;
}
Expand All @@ -75,13 +75,13 @@ public async Task LaunchRemoteControl(string requesterID, string serviceID, HubC
var rcBinaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScreenCast", OSUtils.ScreenCastExecutableFileName);
if (!File.Exists(rcBinaryPath))
{
await hubConnection.InvokeAsync("DisplayMessage", "Remote control executable not found on target device.", "Executable not found on device.", requesterID);
await hubConnection.SendAsync("DisplayMessage", "Remote control executable not found on target device.", "Executable not found on device.", requesterID);
return;
}


// Start ScreenCast.
await hubConnection.InvokeAsync("DisplayMessage", $"Starting remote control...", "Starting remote control.", requesterID);
await hubConnection.SendAsync("DisplayMessage", $"Starting remote control...", "Starting remote control.", requesterID);
if (OSUtils.IsWindows)
{

Expand All @@ -94,7 +94,7 @@ public async Task LaunchRemoteControl(string requesterID, string serviceID, HubC
var result = Win32Interop.OpenInteractiveProcess(rcBinaryPath + $" -mode Unattended -requester {requesterID} -serviceid {serviceID} -deviceid {ConnectionInfo.DeviceID} -host {ConnectionInfo.Host}", "default", true, out _);
if (!result)
{
await hubConnection.InvokeAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
}
}
Expand All @@ -107,7 +107,7 @@ public async Task LaunchRemoteControl(string requesterID, string serviceID, HubC
catch (Exception ex)
{
Logger.Write(ex);
await hubConnection.InvokeAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
}
public async Task RestartScreenCaster(List<string> viewerIDs, string serviceID, string requesterID, HubConnection hubConnection)
Expand Down Expand Up @@ -140,8 +140,8 @@ public async Task RestartScreenCaster(List<string> viewerIDs, string serviceID,
if (!result)
{
Logger.Write("Failed to relaunch screen caster.");
await hubConnection.InvokeAsync("SendConnectionFailedToViewers", viewerIDs);
await hubConnection.InvokeAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
await hubConnection.SendAsync("SendConnectionFailedToViewers", viewerIDs);
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
}
}
Expand All @@ -154,7 +154,7 @@ public async Task RestartScreenCaster(List<string> viewerIDs, string serviceID,
}
catch (Exception ex)
{
await hubConnection.InvokeAsync("SendConnectionFailedToViewers", viewerIDs);
await hubConnection.SendAsync("SendConnectionFailedToViewers", viewerIDs);
Logger.Write(ex);
throw;
}
Expand Down
20 changes: 10 additions & 10 deletions Agent/Services/CommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public async Task ExecuteCommand(string mode, string command, string commandID,
if (Encoding.UTF8.GetBytes(serializedResult).Length > 400000)
{
await SendResultsViaAjax("PSCore", psCoreResult);
await hubConnection.InvokeAsync("PSCoreResultViaAjax", commandID);
await hubConnection.SendAsync("PSCoreResultViaAjax", commandID);
}
else
{
await hubConnection.InvokeAsync("PSCoreResult", psCoreResult);
await hubConnection.SendAsync("PSCoreResult", psCoreResult);
}
break;
}
Expand All @@ -48,11 +48,11 @@ public async Task ExecuteCommand(string mode, string command, string commandID,
if (Encoding.UTF8.GetBytes(serializedResult).Length > 400000)
{
await SendResultsViaAjax("WinPS", result);
await hubConnection.InvokeAsync("WinPSResultViaAjax", commandID);
await hubConnection.SendAsync("WinPSResultViaAjax", commandID);
}
else
{
await hubConnection.InvokeAsync("CommandResult", result);
await hubConnection.SendAsync("CommandResult", result);
}
}
break;
Expand All @@ -64,11 +64,11 @@ public async Task ExecuteCommand(string mode, string command, string commandID,
if (Encoding.UTF8.GetBytes(serializedResult).Length > 400000)
{
await SendResultsViaAjax("CMD", result);
await hubConnection.InvokeAsync("CMDResultViaAjax", commandID);
await hubConnection.SendAsync("CMDResultViaAjax", commandID);
}
else
{
await hubConnection.InvokeAsync("CommandResult", result);
await hubConnection.SendAsync("CommandResult", result);
}
}
break;
Expand All @@ -80,11 +80,11 @@ public async Task ExecuteCommand(string mode, string command, string commandID,
if (Encoding.UTF8.GetBytes(serializedResult).Length > 400000)
{
await SendResultsViaAjax("Bash", result);
await hubConnection.InvokeAsync("BashResultViaAjax", commandID);
await hubConnection.SendAsync("BashResultViaAjax", commandID);
}
else
{
await hubConnection.InvokeAsync("CommandResult", result);
await hubConnection.SendAsync("CommandResult", result);
}
}
break;
Expand All @@ -95,7 +95,7 @@ public async Task ExecuteCommand(string mode, string command, string commandID,
catch (Exception ex)
{
Logger.Write(ex);
await hubConnection.InvokeAsync("DisplayMessage", "There was an error executing the command. It has been logged on the client device.", "Error executing command.", senderConnectionID);
await hubConnection.SendAsync("DisplayMessage", "There was an error executing the command. It has been logged on the client device.", "Error executing command.", senderConnectionID);
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task ExecuteCommandFromApi(string mode, string requestID, string co
break;
}

await hubConnection.InvokeAsync("CommandResultViaApi", commandID, requestID);
await hubConnection.SendAsync("CommandResultViaApi", commandID, requestID);
}
catch (Exception ex)
{
Expand Down
12 changes: 6 additions & 6 deletions Agent/Services/DeviceSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task Connect()

var device = await DeviceInformation.Create(ConnectionInfo.DeviceID, ConnectionInfo.OrganizationID);

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

if (!result)
{
Expand All @@ -75,17 +75,17 @@ public async Task Connect()
{
IsServerVerified = true;
ConnectionInfo.ServerVerificationToken = Guid.NewGuid().ToString();
await HubConnection.InvokeAsync("SetServerVerificationToken", ConnectionInfo.ServerVerificationToken);
await HubConnection.SendAsync("SetServerVerificationToken", ConnectionInfo.ServerVerificationToken);
ConfigService.SaveConnectionInfo(ConnectionInfo);
}
else
{
await HubConnection.InvokeAsync("SendServerVerificationToken");
await HubConnection.SendAsync("SendServerVerificationToken");
}

if (ConfigService.TryGetDeviceSetupOptions(out DeviceSetupOptions options))
{
await HubConnection.InvokeAsync("DeviceSetupOptions", options, ConnectionInfo.DeviceID);
await HubConnection.SendAsync("DeviceSetupOptions", options, ConnectionInfo.DeviceID);
}

HeartbeatTimer?.Dispose();
Expand All @@ -97,7 +97,7 @@ public async Task Connect()
public async Task SendHeartbeat()
{
var currentInfo = await DeviceInformation.Create(ConnectionInfo.DeviceID, ConnectionInfo.OrganizationID);
await HubConnection.InvokeAsync("DeviceHeartbeat", currentInfo);
await HubConnection.SendAsync("DeviceHeartbeat", currentInfo);
}

private async void HeartbeatTimer_Elapsed(object sender, ElapsedEventArgs e)
Expand Down Expand Up @@ -176,7 +176,7 @@ private void RegisterMessageHandlers()
}
}
}
await this.HubConnection.InvokeAsync("TransferCompleted", transferID, requesterID);
await this.HubConnection.SendAsync("TransferCompleted", transferID, requesterID);
});
HubConnection.On("DeployScript", async (string mode, string fileID, string commandResultID, string requesterID) => {
if (!IsServerVerified)
Expand Down
2 changes: 0 additions & 2 deletions Desktop.Win/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Security.Principal;
Expand All @@ -20,7 +19,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Remotely.Shared.Win32;
using Screen = System.Windows.Forms.Screen;

namespace Remotely.Desktop.Win.ViewModels
{
Expand Down
6 changes: 3 additions & 3 deletions ScreenCast.Core/Communication/CasterSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void ApplyConnectionHandlers()
{
if (conductor.Viewers.TryGetValue(viewerID, out var viewer) && viewer.HasControl)
{
await Connection.InvokeAsync("CtrlAltDel");
await Connection.SendAsync("CtrlAltDel");
}
});

Expand All @@ -217,7 +217,7 @@ private void ApplyConnectionHandlers()
Logger.Write($"Disconnecting caster socket. Reason: {reason}");
foreach (var viewer in conductor.Viewers.Values.ToList())
{
await Connection.InvokeAsync("ViewerDisconnected", viewer.ViewerConnectionID);
await Connection.SendAsync("ViewerDisconnected", viewer.ViewerConnectionID);
viewer.DisconnectRequested = true;
}
});
Expand Down Expand Up @@ -313,7 +313,7 @@ private void ApplyConnectionHandlers()

Connection.On("ViewerDisconnected", async (string viewerID) =>
{
await Connection.InvokeAsync("ViewerDisconnected", viewerID);
await Connection.SendAsync("ViewerDisconnected", viewerID);
if (conductor.Viewers.TryGetValue(viewerID, out var viewer))
{
viewer.DisconnectRequested = true;
Expand Down
5 changes: 4 additions & 1 deletion Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
{
if (OSUtils.IsWindows && enableEventLog)
{
logging.AddEventLog();
logging.AddEventLog(settings => {
settings.LogName = "Remotely_Server";
settings.SourceName = "Remotely_Server";
});
}
}
});
Expand Down
4 changes: 3 additions & 1 deletion Server/Services/RCBrowserSocketHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public async Task<Task> SendScreenCastRequestToDevice(string screenCasterID, str
if (Context?.User?.Identity?.IsAuthenticated == true)
{
orgId = DataService.GetUserByID(Context.UserIdentifier).OrganizationID;
var currentUsers = RCDeviceSocketHub.SessionInfoList.Count(x => x.Value.OrganizationID == orgId);
var currentUsers = RCDeviceSocketHub.SessionInfoList.Count(x =>
x.Key != screenCasterID &&
x.Value.OrganizationID == orgId);
if (currentUsers >= AppConfig.RemoteControlSessionLimit)
{
await Clients.Caller.SendAsync("ShowMessage", "Max number of concurrent sessions reached.");
Expand Down
3 changes: 2 additions & 1 deletion Server/wwwroot/css/remote-control-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ button:active {
}

button.toggled {
background-color: rgb(120,120,120);
background-color: rgb(220, 220, 220);
color: black;
}

button[disabled] {
Expand Down
3 changes: 2 additions & 1 deletion Server/wwwroot/css/remote-control-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ button:active {
}

button.toggled {
background-color: #60d8ff;
background-color: #afecff;
color: black;
}

button[disabled] {
Expand Down
Loading

0 comments on commit df80db9

Please sign in to comment.