From eea84a79b4ee83138c8df0b83003d1d098998ad1 Mon Sep 17 00:00:00 2001 From: Jared Date: Wed, 23 Sep 2020 20:00:26 -0700 Subject: [PATCH] Code cleanup. --- Agent.Installer.Win/App.xaml.cs | 2 +- .../Services/InstallerService.cs | 11 ++- Agent.Installer.Win/Services/MessageBoxEx.cs | 2 +- .../ViewModels/MainWindowViewModel.cs | 8 +- Agent/Interfaces/IAppLauncher.cs | 2 - Agent/Program.cs | 14 ++-- Agent/Services/AgentSocket.cs | 38 ++++----- Agent/Services/AppLauncherLinux.cs | 1 - Agent/Services/AppLauncherWin.cs | 1 - Agent/Services/Bash.cs | 34 ++++---- Agent/Services/CMD.cs | 32 ++++---- Agent/Services/ChatClientService.cs | 32 ++++---- Agent/Services/PSCore.cs | 60 +++++++------- Agent/Services/ScriptRunner.cs | 12 +-- Agent/Services/Updater.cs | 12 +-- Agent/Services/WindowsPS.cs | 28 ++++--- Desktop.Core/Conductor.cs | 8 +- Desktop.Core/Interfaces/IChatHostService.cs | 5 +- Desktop.Core/Interfaces/ICursorIconWatcher.cs | 2 - .../Interfaces/IFileTransferService.cs | 2 - .../Interfaces/IKeyboardMouseInput.cs | 4 +- Desktop.Core/Interfaces/ISessionIndicator.cs | 6 +- Desktop.Core/Interfaces/IShutdownService.cs | 5 +- Desktop.Core/Services/CasterSocket.cs | 26 +++---- Desktop.Core/Services/DtoMessageHandler.cs | 8 -- Desktop.Core/Services/IdleTimer.cs | 3 +- Desktop.Core/Services/ScreenCaster.cs | 24 +++--- Desktop.Core/Services/Viewer.cs | 3 - Desktop.Core/Services/WebRtcSession.cs | 4 - Desktop.Core/Services/WebRtcSessionFactory.cs | 8 +- Desktop.Core/Utilities/ImageUtils.cs | 8 +- Desktop.Core/ViewModels/FileUpload.cs | 5 +- Desktop.Linux/App.xaml.cs | 7 +- .../Controls/HostNamePrompt.axaml.cs | 1 - Desktop.Linux/Controls/MessageBox.axaml.cs | 2 - Desktop.Linux/Program.cs | 3 +- .../Services/ChatHostServiceLinux.cs | 2 - .../Services/ClipboardServiceLinux.cs | 3 - .../Services/CursorIconWatcherLinux.cs | 2 - .../Services/FileTransferServiceLinux.cs | 23 +++--- .../Services/KeyboardMouseInputLinux.cs | 6 +- Desktop.Linux/Services/ScreenCapturerLinux.cs | 1 - .../Services/SessionIndicatorLinux.cs | 3 - .../Services/ShutdownServiceLinux.cs | 2 - Desktop.Linux/ViewLocator.cs | 2 +- .../ViewModels/ChatWindowViewModel.cs | 5 +- .../ViewModels/FileTransferWindowViewModel.cs | 2 - .../ViewModels/HostNamePromptViewModel.cs | 5 +- .../ViewModels/MainWindowViewModel.cs | 19 ++--- .../ViewModels/MessageBoxViewModel.cs | 1 - Desktop.Linux/ViewModels/ReactiveViewModel.cs | 3 - Desktop.Linux/Views/ChatWindow.axaml.cs | 4 - Desktop.Linux/X11Interop/LibX11.cs | 2 +- Desktop.Win.Wrapper/App.xaml.cs | 8 +- .../Properties/AssemblyInfo.cs | 2 - Desktop.Win/App.xaml.cs | 2 - Desktop.Win/Models/DirectXOutput.cs | 10 +-- Desktop.Win/Program.cs | 27 ++++--- Desktop.Win/Services/AudioCapturerWin.cs | 40 ++++------ Desktop.Win/Services/ChatHostServiceWin.cs | 2 - Desktop.Win/Services/ClipboardServiceWin.cs | 3 +- Desktop.Win/Services/CursorIconWatcherWin.cs | 44 ++++------- .../Services/FileTransferServiceWin.cs | 3 +- Desktop.Win/Services/KeyboardMouseInputWin.cs | 15 ++-- Desktop.Win/Services/ScreenCapturerWin.cs | 7 +- Desktop.Win/Services/SessionIndicatorWin.cs | 2 - Desktop.Win/Services/ShutdownServiceWin.cs | 4 +- Desktop.Win/ViewModels/ChatWindowViewModel.cs | 4 - .../ViewModels/FileTransferWindowViewModel.cs | 7 +- Desktop.Win/ViewModels/MainWindowViewModel.cs | 23 +++--- Desktop.Win/Views/ChatWindow.xaml.cs | 8 -- Desktop.Win/Views/FileTransferWindow.xaml.cs | 12 +-- Desktop.Win/Views/MainWindow.xaml.cs | 21 ++--- Server/API/AgentUpdateController.cs | 4 +- Server/API/AlertsController.cs | 4 +- Server/API/ClientDownloadsController.cs | 17 ++-- Server/API/CommandsController.cs | 57 +++++++------- Server/API/DevicesController.cs | 15 ++-- Server/API/FileSharingController.cs | 8 +- Server/API/LoginController.cs | 18 ++--- .../API/OrganizationManagementController.cs | 36 ++++----- Server/API/RemoteControlController.cs | 25 +++--- Server/API/ScriptingController.cs | 10 +-- Server/API/ServerLogsController.cs | 6 +- .../Areas/Identity/IdentityHostingStartup.cs | 3 +- .../Pages/Account/ConfirmEmail.cshtml.cs | 6 +- .../Account/ConfirmEmailChange.cshtml.cs | 6 +- .../Pages/Account/ForgotPassword.cshtml.cs | 14 ++-- .../Identity/Pages/Account/Login.cshtml.cs | 26 +++---- .../Identity/Pages/Account/Logout.cshtml.cs | 9 +-- .../Pages/Account/Manage/ApiTokens.cshtml.cs | 12 +-- .../Manage/EnableAuthenticator.cshtml.cs | 12 +-- .../Pages/Account/Manage/Index.cshtml.cs | 18 ++--- .../Pages/Account/Manage/ManageNavPages.cs | 4 +- .../Pages/Account/Manage/Options.cshtml.cs | 4 +- .../Account/Manage/Organization.cshtml.cs | 12 +-- .../Pages/Account/Manage/ServerLogs.cshtml.cs | 12 +-- .../Identity/Pages/Account/Register.cshtml.cs | 18 ++--- .../Attributes/ActionRateLimiterAttribute.cs | 3 - Server/Attributes/ApiAuthorizationFilter.cs | 4 +- .../RemoteControlFilterAttribute.cs | 7 +- Server/Data/ApplicationDbContext.cs | 16 ++-- Server/Hubs/AgentHub.cs | 78 +++++++++---------- Server/Hubs/BrowserHub.cs | 62 +++++++-------- Server/Hubs/CasterHub.cs | 7 +- Server/Hubs/ViewerHub.cs | 35 ++++----- Server/Models/RCSessionInfo.cs | 1 - Server/Models/RemoteControlFrame.cs | 6 +- Server/Pages/EditDevice.cshtml.cs | 6 +- Server/Pages/Error.cshtml.cs | 4 +- Server/Pages/GetSupport.cshtml.cs | 9 +-- Server/Pages/Index.cshtml.cs | 12 +-- Server/Pages/Invite.cshtml.cs | 4 +- Server/Pages/RemoteControl.cshtml.cs | 3 +- Server/Services/CleanupService.cs | 10 +-- Server/Services/DataService.cs | 35 ++++----- Server/Services/DbLogger.cs | 2 - Server/Services/DbLoggerProvider.cs | 3 - Server/Services/EmailSender.cs | 26 ++++--- Server/Services/PascalCasePolicy.cs | 2 +- Server/Startup.cs | 43 +++++----- Shared/Enums/EventType.cs | 6 +- Shared/Helpers/Disposer.cs | 2 - Shared/Models/ChatMessage.cs | 6 +- Shared/Models/IceServerModel.cs | 6 +- .../RemoteControlDtos/AudioSampleDto.cs | 3 - .../RemoteControlDtos/AutoQualityAdjustDto.cs | 3 - .../RemoteControlDtos/ClipboardTextDto.cs | 3 - .../RemoteControlDtos/ClipboardTransferDto.cs | 3 - .../RemoteControlDtos/CursorChangeDto.cs | 4 - Shared/Models/RemoteControlDtos/FileDto.cs | 3 - Shared/Models/RemoteControlDtos/KeyDownDto.cs | 3 - .../Models/RemoteControlDtos/KeyPressDto.cs | 3 - Shared/Models/RemoteControlDtos/KeyUpDto.cs | 3 - .../RemoteControlDtos/MachineNameDto.cs | 3 - .../Models/RemoteControlDtos/MouseDownDto.cs | 3 - .../Models/RemoteControlDtos/MouseMoveDto.cs | 3 - Shared/Models/RemoteControlDtos/MouseUpDto.cs | 3 - .../Models/RemoteControlDtos/MouseWheelDto.cs | 3 - .../RemoteControlDtos/QualityChangeDto.cs | 3 - .../Models/RemoteControlDtos/ScreenDataDto.cs | 3 - .../Models/RemoteControlDtos/ScreenSizeDto.cs | 3 - .../RemoteControlDtos/SelectScreenDto.cs | 3 - Shared/Models/RemoteControlDtos/TapDto.cs | 3 - .../RemoteControlDtos/ToggleAudioDto.cs | 3 - .../RemoteControlDtos/ToggleBlockInputDto.cs | 3 - .../RemoteControlDtos/ToggleWebRtcVideoDto.cs | 3 - .../RemoteControlDtos/WindowsSessionsDto.cs | 2 - Shared/Models/RemotelyUserOptions.cs | 4 +- Shared/Utilities/Logger.cs | 1 - Shared/Utilities/PasswordGenerator.cs | 6 +- Shared/Utilities/RandomGenerator.cs | 4 +- Shared/Win32/ADVAPI32.cs | 6 +- Shared/Win32/SECUR32.cs | 53 +++++++------ Shared/Win32/Shlwapi.cs | 5 +- Shared/Win32/User32.cs | 4 +- Shared/Win32/Win32Interop.cs | 4 +- Tests.LoadTester/CommandLineParser.cs | 3 +- Tests/IoCActivator.cs | 8 +- 159 files changed, 706 insertions(+), 967 deletions(-) diff --git a/Agent.Installer.Win/App.xaml.cs b/Agent.Installer.Win/App.xaml.cs index 716cf625..7a71daee 100644 --- a/Agent.Installer.Win/App.xaml.cs +++ b/Agent.Installer.Win/App.xaml.cs @@ -7,6 +7,6 @@ namespace Remotely.Agent.Installer.Win /// public partial class App : Application { - + } } diff --git a/Agent.Installer.Win/Services/InstallerService.cs b/Agent.Installer.Win/Services/InstallerService.cs index 22411982..51342943 100644 --- a/Agent.Installer.Win/Services/InstallerService.cs +++ b/Agent.Installer.Win/Services/InstallerService.cs @@ -3,7 +3,6 @@ using Microsoft.VisualBasic.FileIO; using Microsoft.Win32; using Remotely.Shared.Models; using System; -using System.Collections.Generic; using System.Configuration.Install; using System.Diagnostics; using System.IO; @@ -68,7 +67,7 @@ namespace Remotely.Agent.Installer.Win.Services CreateUninstallKey(); CreateSupportShortcut(serverUrl, connectionInfo.DeviceID, createSupportShortcut); - + return true; } catch (Exception ex) @@ -171,9 +170,9 @@ namespace Remotely.Agent.Installer.Win.Services } } - private async Task CreateDeviceOnServer(string deviceUuid, + private async Task CreateDeviceOnServer(string deviceUuid, string serverUrl, - string deviceGroup, + string deviceGroup, string deviceAlias, string organizationId) { @@ -210,7 +209,7 @@ namespace Remotely.Agent.Installer.Win.Services { Logger.Write(ex); } - + } private void CreateSupportShortcut(string serverUrl, string deviceUuid, bool createSupportShortcut) @@ -439,7 +438,7 @@ namespace Remotely.Agent.Installer.Win.Services remotelyService.WaitForStatus(ServiceControllerStatus.Stopped); } } - catch(Exception ex) + catch (Exception ex) { Logger.Write(ex); } diff --git a/Agent.Installer.Win/Services/MessageBoxEx.cs b/Agent.Installer.Win/Services/MessageBoxEx.cs index b390db29..9d23014f 100644 --- a/Agent.Installer.Win/Services/MessageBoxEx.cs +++ b/Agent.Installer.Win/Services/MessageBoxEx.cs @@ -11,6 +11,6 @@ namespace Remotely.Agent.Installer.Win.Services return MessageBox.Show(message, caption, messageBoxButton, messageBoxImage); } return MessageBoxResult.None; - } + } } } diff --git a/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs b/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs index 4d29c099..60d71a02 100644 --- a/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs +++ b/Agent.Installer.Win/ViewModels/MainWindowViewModel.cs @@ -108,13 +108,13 @@ namespace Remotely.Agent.Installer.Win.ViewModels Process.Start(logPath); } else - { + { MessageBoxEx.Show("Log file doesn't exist.", "No Logs", MessageBoxButton.OK, MessageBoxImage.Information); } }); } } - + public string OrganizationID { get @@ -213,7 +213,7 @@ namespace Remotely.Agent.Installer.Win.ViewModels } AddExistingConnectionInfo(); - + if (CommandLineParser.CommandLineArgs.ContainsKey("install")) { await Install(); @@ -333,7 +333,7 @@ namespace Remotely.Agent.Installer.Win.ViewModels } HeaderMessage = "Installing Remotely..."; - + if (await Installer.Install(ServerUrl, OrganizationID, DeviceGroup, DeviceAlias, DeviceUuid, CreateSupportShortcut)) { IsServiceInstalled = true; diff --git a/Agent/Interfaces/IAppLauncher.cs b/Agent/Interfaces/IAppLauncher.cs index d8ac03b0..3de643fe 100644 --- a/Agent/Interfaces/IAppLauncher.cs +++ b/Agent/Interfaces/IAppLauncher.cs @@ -1,7 +1,5 @@ using Microsoft.AspNetCore.SignalR.Client; -using System; using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace Remotely.Agent.Interfaces diff --git a/Agent/Program.cs b/Agent/Program.cs index 4da8c3de..16cf02c1 100644 --- a/Agent/Program.cs +++ b/Agent/Program.cs @@ -1,13 +1,13 @@ -using Remotely.Agent.Services; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Remotely.Agent.Interfaces; +using Remotely.Agent.Services; +using Remotely.Shared.Utilities; using System; using System.IO; using System.ServiceProcess; -using System.Threading.Tasks; using System.Threading; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Remotely.Shared.Utilities; -using Remotely.Agent.Interfaces; +using System.Threading.Tasks; namespace Remotely.Agent { @@ -22,7 +22,7 @@ namespace Remotely.Agent { BuildServices(); - Task.Run(() => {_ = Init(); }); + Task.Run(() => { _ = Init(); }); Thread.Sleep(Timeout.Infinite); diff --git a/Agent/Services/AgentSocket.cs b/Agent/Services/AgentSocket.cs index 6066c3bf..6906af48 100644 --- a/Agent/Services/AgentSocket.cs +++ b/Agent/Services/AgentSocket.cs @@ -1,28 +1,28 @@ -using Remotely.Shared.Models; +using Microsoft.AspNetCore.SignalR.Client; +using Microsoft.Extensions.DependencyInjection; +using Remotely.Agent.Interfaces; +using Remotely.Shared.Enums; +using Remotely.Shared.Models; using Remotely.Shared.Services; -using Microsoft.AspNetCore.SignalR.Client; +using Remotely.Shared.Utilities; +using Remotely.Shared.Win32; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; -using System.Threading.Tasks; -using System.Timers; -using Remotely.Shared.Win32; -using Microsoft.Extensions.DependencyInjection; using System.Text.Json; using System.Threading; -using Remotely.Shared.Utilities; -using Remotely.Shared.Enums; -using Remotely.Agent.Interfaces; +using System.Threading.Tasks; +using System.Timers; namespace Remotely.Agent.Services { public class AgentSocket { - public AgentSocket(ConfigService configService, - Uninstaller uninstaller, + public AgentSocket(ConfigService configService, + Uninstaller uninstaller, CommandExecutor commandExecutor, ScriptRunner scriptRunner, IAppLauncher appLauncher, @@ -145,7 +145,8 @@ namespace Remotely.Agent.Services // TODO: Remove possibility for circular dependencies in the future // by emitting these events so other services can listen for them. - HubConnection.On("Chat", async (string senderName, string message, string orgName, bool disconnected, string senderConnectionID) => { + HubConnection.On("Chat", async (string senderName, string message, string orgName, bool disconnected, string senderConnectionID) => + { if (!IsServerVerified) { Logger.Write("Chat attempted before server was verified.", EventType.Warning); @@ -231,8 +232,8 @@ namespace Remotely.Agent.Services } Logger.Write($"File upload started by {requesterID}."); - var sharedFilePath = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(),"RemotelySharedFiles")).FullName; - + var sharedFilePath = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "RemotelySharedFiles")).FullName; + foreach (var fileID in fileIDs) { var url = $"{ConnectionInfo.Host}/API/FileSharing/{fileID}"; @@ -255,7 +256,8 @@ namespace Remotely.Agent.Services } await HubConnection.SendAsync("TransferCompleted", transferID, requesterID); }); - HubConnection.On("DeployScript", async (string mode, string fileID, string commandResultID, string requesterID) => { + HubConnection.On("DeployScript", async (string mode, string fileID, string commandResultID, string requesterID) => + { if (!IsServerVerified) { Logger.Write($"Script deploy attempted before server was verified. Mode: {mode}. File ID: {fileID}. Sender: {requesterID}", EventType.Warning); @@ -269,7 +271,7 @@ namespace Remotely.Agent.Services { Uninstaller.UninstallAgent(); }); - + HubConnection.On("RemoteControl", async (string requesterID, string serviceID) => { if (!IsServerVerified) @@ -297,7 +299,7 @@ namespace Remotely.Agent.Services } User32.SendSAS(false); }); - + HubConnection.On("ServerVerificationToken", (string verificationToken) => { if (verificationToken == ConnectionInfo.ServerVerificationToken) @@ -309,7 +311,7 @@ namespace Remotely.Agent.Services Logger.Write($"Server sent an incorrect verification token. Token Sent: {verificationToken}.", EventType.Warning); return; } - }); + }); } } } diff --git a/Agent/Services/AppLauncherLinux.cs b/Agent/Services/AppLauncherLinux.cs index 34e6d29b..8635dfd0 100644 --- a/Agent/Services/AppLauncherLinux.cs +++ b/Agent/Services/AppLauncherLinux.cs @@ -2,7 +2,6 @@ using Remotely.Agent.Interfaces; using Remotely.Shared.Models; using Remotely.Shared.Utilities; -using Remotely.Shared.Win32; using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/Agent/Services/AppLauncherWin.cs b/Agent/Services/AppLauncherWin.cs index 9f338a0f..65916cb2 100644 --- a/Agent/Services/AppLauncherWin.cs +++ b/Agent/Services/AppLauncherWin.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Threading.Tasks; namespace Remotely.Agent.Services diff --git a/Agent/Services/Bash.cs b/Agent/Services/Bash.cs index 74d10ed8..ff2f03ce 100644 --- a/Agent/Services/Bash.cs +++ b/Agent/Services/Bash.cs @@ -1,9 +1,9 @@ -using Remotely.Shared.Models; +using Microsoft.Extensions.DependencyInjection; +using Remotely.Shared.Models; using System; +using System.Collections.Concurrent; using System.Diagnostics; using System.Threading; -using System.Collections.Concurrent; -using Microsoft.Extensions.DependencyInjection; namespace Remotely.Agent.Services { @@ -12,16 +12,20 @@ namespace Remotely.Agent.Services public Bash(ConfigService configService) { ConfigService = configService; - var psi = new ProcessStartInfo("bash"); - psi.WindowStyle = ProcessWindowStyle.Hidden; - psi.Verb = "RunAs"; - psi.UseShellExecute = false; - psi.RedirectStandardError = true; - psi.RedirectStandardInput = true; - psi.RedirectStandardOutput = true; + var psi = new ProcessStartInfo("bash") + { + WindowStyle = ProcessWindowStyle.Hidden, + Verb = "RunAs", + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardInput = true, + RedirectStandardOutput = true + }; - BashProc = new Process(); - BashProc.StartInfo = psi; + BashProc = new Process + { + StartInfo = psi + }; BashProc.ErrorDataReceived += CMDProc_ErrorDataReceived; BashProc.OutputDataReceived += CMDProc_OutputDataReceived; @@ -30,8 +34,10 @@ namespace Remotely.Agent.Services BashProc.BeginErrorReadLine(); BashProc.BeginOutputReadLine(); - ProcessIdleTimeout = new System.Timers.Timer(600_000); // 10 minutes. - ProcessIdleTimeout.AutoReset = false; + ProcessIdleTimeout = new System.Timers.Timer(600_000) + { + AutoReset = false + }; // 10 minutes. ProcessIdleTimeout.Elapsed += ProcessIdleTimeout_Elapsed; ProcessIdleTimeout.Start(); } diff --git a/Agent/Services/CMD.cs b/Agent/Services/CMD.cs index 086c0f36..9d8f31c8 100644 --- a/Agent/Services/CMD.cs +++ b/Agent/Services/CMD.cs @@ -1,9 +1,9 @@ -using Remotely.Shared.Models; +using Microsoft.Extensions.DependencyInjection; +using Remotely.Shared.Models; using System; using System.Collections.Concurrent; using System.Diagnostics; using System.Threading; -using Microsoft.Extensions.DependencyInjection; namespace Remotely.Agent.Services { @@ -12,16 +12,20 @@ namespace Remotely.Agent.Services public CMD(ConfigService configService) { ConfigService = configService; - var psi = new ProcessStartInfo("cmd.exe"); - psi.WindowStyle = ProcessWindowStyle.Hidden; - psi.Verb = "RunAs"; - psi.UseShellExecute = false; - psi.RedirectStandardError = true; - psi.RedirectStandardInput = true; - psi.RedirectStandardOutput = true; + var psi = new ProcessStartInfo("cmd.exe") + { + WindowStyle = ProcessWindowStyle.Hidden, + Verb = "RunAs", + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardInput = true, + RedirectStandardOutput = true + }; - CMDProc = new Process(); - CMDProc.StartInfo = psi; + CMDProc = new Process + { + StartInfo = psi + }; CMDProc.ErrorDataReceived += CMDProc_ErrorDataReceived; CMDProc.OutputDataReceived += CMDProc_OutputDataReceived; @@ -30,8 +34,10 @@ namespace Remotely.Agent.Services CMDProc.BeginErrorReadLine(); CMDProc.BeginOutputReadLine(); - ProcessIdleTimeout = new System.Timers.Timer(600_000); // 10 minutes. - ProcessIdleTimeout.AutoReset = false; + ProcessIdleTimeout = new System.Timers.Timer(600_000) + { + AutoReset = false + }; // 10 minutes. ProcessIdleTimeout.Elapsed += ProcessIdleTimeout_Elapsed; ProcessIdleTimeout.Start(); } diff --git a/Agent/Services/ChatClientService.cs b/Agent/Services/ChatClientService.cs index a9256eed..898bfe64 100644 --- a/Agent/Services/ChatClientService.cs +++ b/Agent/Services/ChatClientService.cs @@ -36,11 +36,11 @@ namespace Remotely.Agent.Services private MemoryCache ChatClients { get; } = new MemoryCache("ChatClients"); - public async Task SendMessage(string senderName, - string message, - string orgName, + public async Task SendMessage(string senderName, + string message, + string orgName, bool disconnected, - string senderConnectionID, + string senderConnectionID, HubConnection hubConnection) { if (!await MessageLock.WaitAsync(30000)) @@ -93,12 +93,10 @@ namespace Remotely.Agent.Services return; } - using (var sw = new StreamWriter(chatSession.PipeStream, leaveOpen: true)) - { - var chatMessage = new ChatMessage(senderName, message, disconnected); - await sw.WriteLineAsync(JsonSerializer.Serialize(chatMessage)); - await sw.FlushAsync(); - } + using var sw = new StreamWriter(chatSession.PipeStream, leaveOpen: true); + var chatMessage = new ChatMessage(senderName, message, disconnected); + await sw.WriteLineAsync(JsonSerializer.Serialize(chatMessage)); + await sw.FlushAsync(); } catch (Exception ex) { @@ -114,15 +112,13 @@ namespace Remotely.Agent.Services { while (clientPipe.IsConnected) { - using (var sr = new StreamReader(clientPipe, leaveOpen: true)) + using var sr = new StreamReader(clientPipe, leaveOpen: true); + var messageJson = await sr.ReadLineAsync(); + if (!string.IsNullOrWhiteSpace(messageJson)) { - var messageJson = await sr.ReadLineAsync(); - if (!string.IsNullOrWhiteSpace(messageJson)) - { - var chatMessage = JsonSerializer.Deserialize(messageJson); - await hubConnection.SendAsync("Chat", chatMessage.Message, false, senderConnectionID); - } - } + var chatMessage = JsonSerializer.Deserialize(messageJson); + await hubConnection.SendAsync("Chat", chatMessage.Message, false, senderConnectionID); + } } await hubConnection.SendAsync("Chat", string.Empty, true, senderConnectionID); ChatClients.Remove(senderConnectionID); diff --git a/Agent/Services/PSCore.cs b/Agent/Services/PSCore.cs index 96a13177..93565ce3 100644 --- a/Agent/Services/PSCore.cs +++ b/Agent/Services/PSCore.cs @@ -1,10 +1,10 @@ -using Remotely.Shared.Models; +using Microsoft.Extensions.DependencyInjection; +using Remotely.Shared.Models; using System; using System.Collections.Concurrent; using System.Linq; using System.Management.Automation; using System.Timers; -using Microsoft.Extensions.DependencyInjection; namespace Remotely.Agent.Services { @@ -20,8 +20,10 @@ namespace Remotely.Agent.Services $WarningPreference = ""Continue"";"); PS.Invoke(); - ProcessIdleTimeout = new Timer(600_000); // 10 minutes. - ProcessIdleTimeout.AutoReset = false; + ProcessIdleTimeout = new Timer(600_000) + { + AutoReset = false + }; // 10 minutes. ProcessIdleTimeout.Elapsed += ProcessIdleTimeout_Elapsed; ProcessIdleTimeout.Start(); } @@ -59,33 +61,31 @@ namespace Remotely.Agent.Services PS.AddScript(input); var results = PS.Invoke(); - using (var ps = PowerShell.Create()) + using var ps = PowerShell.Create(); + ps.AddScript("$args[0] | Out-String"); + ps.AddArgument(results); + var hostOutput = (ps.Invoke()[0].BaseObject as string); + + var verboseOut = PS.Streams.Verbose.ReadAll().Select(x => x.Message).ToList(); + var debugOut = PS.Streams.Debug.ReadAll().Select(x => x.Message).ToList(); + var errorOut = PS.Streams.Error.ReadAll().Select(x => x.Exception.ToString() + Environment.NewLine + x.ScriptStackTrace).ToList(); + var infoOut = PS.Streams.Information.Select(x => x.MessageData.ToString()).ToList(); + var warningOut = PS.Streams.Warning.Select(x => x.Message).ToList(); + + PS.Streams.ClearStreams(); + PS.Commands.Clear(); + + return new PSCoreCommandResult() { - ps.AddScript("$args[0] | Out-String"); - ps.AddArgument(results); - var hostOutput = (ps.Invoke()[0].BaseObject as string); - - var verboseOut = PS.Streams.Verbose.ReadAll().Select(x => x.Message).ToList(); - var debugOut = PS.Streams.Debug.ReadAll().Select(x => x.Message).ToList(); - var errorOut = PS.Streams.Error.ReadAll().Select(x => x.Exception.ToString() + Environment.NewLine + x.ScriptStackTrace).ToList(); - var infoOut = PS.Streams.Information.Select(x => x.MessageData.ToString()).ToList(); - var warningOut = PS.Streams.Warning.Select(x => x.Message).ToList(); - - PS.Streams.ClearStreams(); - PS.Commands.Clear(); - - return new PSCoreCommandResult() - { - CommandResultID = commandID, - DeviceID = ConfigService.GetConnectionInfo().DeviceID, - DebugOutput = debugOut, - ErrorOutput = errorOut, - VerboseOutput = verboseOut, - HostOutput = hostOutput, - InformationOutput = infoOut, - WarningOutput = warningOut - }; - } + CommandResultID = commandID, + DeviceID = ConfigService.GetConnectionInfo().DeviceID, + DebugOutput = debugOut, + ErrorOutput = errorOut, + VerboseOutput = verboseOut, + HostOutput = hostOutput, + InformationOutput = infoOut, + WarningOutput = warningOut + }; } private void ProcessIdleTimeout_Elapsed(object sender, ElapsedEventArgs e) diff --git a/Agent/Services/ScriptRunner.cs b/Agent/Services/ScriptRunner.cs index b9bdb7c0..980e7abd 100644 --- a/Agent/Services/ScriptRunner.cs +++ b/Agent/Services/ScriptRunner.cs @@ -33,14 +33,10 @@ namespace Remotely.Agent.Services var response = await wr.GetResponseAsync(); var cd = response.Headers["Content-Disposition"]; var filename = cd.Split(";").FirstOrDefault(x => x.Trim().StartsWith("filename")).Split("=")[1]; - using (var rs = response.GetResponseStream()) - { - using (var sr = new StreamReader(rs)) - { - var result = await sr.ReadToEndAsync(); - await CommandExecutor.ExecuteCommand(mode, result, commandResultID, requesterID, hubConnection); - } - } + using var rs = response.GetResponseStream(); + using var sr = new StreamReader(rs); + var result = await sr.ReadToEndAsync(); + await CommandExecutor.ExecuteCommand(mode, result, commandResultID, requesterID, hubConnection); } } } diff --git a/Agent/Services/Updater.cs b/Agent/Services/Updater.cs index 192d2fc6..438478c8 100644 --- a/Agent/Services/Updater.cs +++ b/Agent/Services/Updater.cs @@ -1,11 +1,10 @@ -using System; +using Remotely.Shared.Utilities; +using System; using System.Diagnostics; using System.IO; using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using System.Threading; -using Remotely.Shared.Utilities; +using System.Threading.Tasks; namespace Remotely.Agent.Services { @@ -69,7 +68,7 @@ namespace Remotely.Agent.Services } var lastEtag = string.Empty; - + if (File.Exists("etag.txt")) { lastEtag = await File.ReadAllTextAsync("etag.txt"); @@ -180,7 +179,8 @@ namespace Remotely.Agent.Services private class WebClientEx : WebClient - { private readonly int _requestTimeout; + { + private readonly int _requestTimeout; public WebClientEx(int requestTimeout) { diff --git a/Agent/Services/WindowsPS.cs b/Agent/Services/WindowsPS.cs index 32fc402f..089f351e 100644 --- a/Agent/Services/WindowsPS.cs +++ b/Agent/Services/WindowsPS.cs @@ -12,16 +12,20 @@ namespace Remotely.Agent.Services public WindowsPS(ConfigService configService) { ConfigService = configService; - var psi = new ProcessStartInfo("powershell.exe"); - psi.WindowStyle = ProcessWindowStyle.Hidden; - psi.Verb = "RunAs"; - psi.RedirectStandardError = true; - psi.RedirectStandardInput = true; - psi.RedirectStandardOutput = true; + var psi = new ProcessStartInfo("powershell.exe") + { + WindowStyle = ProcessWindowStyle.Hidden, + Verb = "RunAs", + RedirectStandardError = true, + RedirectStandardInput = true, + RedirectStandardOutput = true + }; - PSProc = new Process(); - PSProc.StartInfo = psi; - PSProc.EnableRaisingEvents = true; + PSProc = new Process + { + StartInfo = psi, + EnableRaisingEvents = true + }; PSProc.ErrorDataReceived += CMDProc_ErrorDataReceived; PSProc.OutputDataReceived += CMDProc_OutputDataReceived; @@ -30,8 +34,10 @@ namespace Remotely.Agent.Services PSProc.BeginErrorReadLine(); PSProc.BeginOutputReadLine(); - ProcessIdleTimeout = new System.Timers.Timer(600_000); // 10 minutes. - ProcessIdleTimeout.AutoReset = false; + ProcessIdleTimeout = new System.Timers.Timer(600_000) + { + AutoReset = false + }; // 10 minutes. ProcessIdleTimeout.Elapsed += ProcessIdleTimeout_Elapsed; ProcessIdleTimeout.Start(); } diff --git a/Desktop.Core/Conductor.cs b/Desktop.Core/Conductor.cs index 0bf71374..90ec83b2 100644 --- a/Desktop.Core/Conductor.cs +++ b/Desktop.Core/Conductor.cs @@ -1,11 +1,9 @@ -using Remotely.Shared.Models; -using Remotely.Desktop.Core.Enums; -using Remotely.Desktop.Core.Services; +using Remotely.Desktop.Core.Enums; +using Remotely.Shared.Models; +using Remotely.Shared.Utilities; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Threading.Tasks; -using Remotely.Shared.Utilities; namespace Remotely.Desktop.Core { diff --git a/Desktop.Core/Interfaces/IChatHostService.cs b/Desktop.Core/Interfaces/IChatHostService.cs index 81ab2434..9d0a2941 100644 --- a/Desktop.Core/Interfaces/IChatHostService.cs +++ b/Desktop.Core/Interfaces/IChatHostService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Remotely.Desktop.Core.Interfaces { diff --git a/Desktop.Core/Interfaces/ICursorIconWatcher.cs b/Desktop.Core/Interfaces/ICursorIconWatcher.cs index 12fe1905..d8ed8f51 100644 --- a/Desktop.Core/Interfaces/ICursorIconWatcher.cs +++ b/Desktop.Core/Interfaces/ICursorIconWatcher.cs @@ -1,7 +1,5 @@ using Remotely.Shared.Models; using System; -using System.Collections.Generic; -using System.Text; namespace Remotely.Desktop.Core.Interfaces { diff --git a/Desktop.Core/Interfaces/IFileTransferService.cs b/Desktop.Core/Interfaces/IFileTransferService.cs index 5f9574cf..05117af7 100644 --- a/Desktop.Core/Interfaces/IFileTransferService.cs +++ b/Desktop.Core/Interfaces/IFileTransferService.cs @@ -1,8 +1,6 @@ using Remotely.Desktop.Core.Services; using Remotely.Desktop.Core.ViewModels; using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace Remotely.Desktop.Core.Interfaces diff --git a/Desktop.Core/Interfaces/IKeyboardMouseInput.cs b/Desktop.Core/Interfaces/IKeyboardMouseInput.cs index 1cc4f862..845efac9 100644 --- a/Desktop.Core/Interfaces/IKeyboardMouseInput.cs +++ b/Desktop.Core/Interfaces/IKeyboardMouseInput.cs @@ -1,6 +1,4 @@ -using Remotely.Desktop.Core.Services; - -namespace Remotely.Desktop.Core.Interfaces +namespace Remotely.Desktop.Core.Interfaces { public interface IKeyboardMouseInput { diff --git a/Desktop.Core/Interfaces/ISessionIndicator.cs b/Desktop.Core/Interfaces/ISessionIndicator.cs index 228ceb67..78def2a3 100644 --- a/Desktop.Core/Interfaces/ISessionIndicator.cs +++ b/Desktop.Core/Interfaces/ISessionIndicator.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Remotely.Desktop.Core.Interfaces +namespace Remotely.Desktop.Core.Interfaces { public interface ISessionIndicator { diff --git a/Desktop.Core/Interfaces/IShutdownService.cs b/Desktop.Core/Interfaces/IShutdownService.cs index 150dfc1b..44b696f3 100644 --- a/Desktop.Core/Interfaces/IShutdownService.cs +++ b/Desktop.Core/Interfaces/IShutdownService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Remotely.Desktop.Core.Interfaces { diff --git a/Desktop.Core/Services/CasterSocket.cs b/Desktop.Core/Services/CasterSocket.cs index a557d816..441b7b3c 100644 --- a/Desktop.Core/Services/CasterSocket.cs +++ b/Desktop.Core/Services/CasterSocket.cs @@ -1,18 +1,12 @@ using Microsoft.AspNetCore.SignalR.Client; +using Microsoft.Extensions.DependencyInjection; +using Remotely.Desktop.Core.Interfaces; using Remotely.Shared.Models; +using Remotely.Shared.Utilities; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using System.Diagnostics; -using System.IO; -using System.Net; -using Remotely.Desktop.Core.Interfaces; -using Microsoft.Extensions.DependencyInjection; -using Remotely.Shared.Utilities; -using System.Threading; -using Remotely.Desktop.Core.Services; -using Remotely.Shared.Models.RemoteControlDtos; namespace Remotely.Desktop.Core.Services { @@ -159,10 +153,10 @@ namespace Remotely.Desktop.Core.Services try { ScreenCaster.BeginScreenCasting(new ScreenCastRequest() - { + { NotifyUser = notifyUser, - ViewerID = viewerID, - RequesterName = requesterName + ViewerID = viewerID, + RequesterName = requesterName }); } catch (Exception ex) @@ -205,11 +199,11 @@ namespace Remotely.Desktop.Core.Services Connection.On("RequestScreenCast", (string viewerID, string requesterName, bool notifyUser) => { - conductor.InvokeScreenCastRequested(new ScreenCastRequest() - { + conductor.InvokeScreenCastRequested(new ScreenCastRequest() + { NotifyUser = notifyUser, - ViewerID = viewerID, - RequesterName = requesterName + ViewerID = viewerID, + RequesterName = requesterName }); }); diff --git a/Desktop.Core/Services/DtoMessageHandler.cs b/Desktop.Core/Services/DtoMessageHandler.cs index 5a3dc322..25ce04c7 100644 --- a/Desktop.Core/Services/DtoMessageHandler.cs +++ b/Desktop.Core/Services/DtoMessageHandler.cs @@ -1,17 +1,9 @@ using MessagePack; -using Microsoft.Extensions.DependencyInjection; using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; using Remotely.Shared.Enums; using Remotely.Shared.Models.RemoteControlDtos; using Remotely.Shared.Utilities; -using Remotely.Shared.Win32; using System; -using System.Collections.Generic; -using System.Dynamic; -using System.Linq; -using System.Text; -using System.Threading; using System.Threading.Tasks; namespace Remotely.Desktop.Core.Services diff --git a/Desktop.Core/Services/IdleTimer.cs b/Desktop.Core/Services/IdleTimer.cs index 4905e285..229e35ae 100644 --- a/Desktop.Core/Services/IdleTimer.cs +++ b/Desktop.Core/Services/IdleTimer.cs @@ -1,5 +1,4 @@ -using Remotely.Desktop.Core.Services; -using Remotely.Shared.Utilities; +using Remotely.Shared.Utilities; using System; using System.Collections.Concurrent; using System.Timers; diff --git a/Desktop.Core/Services/ScreenCaster.cs b/Desktop.Core/Services/ScreenCaster.cs index 8897be46..c12f4b0a 100644 --- a/Desktop.Core/Services/ScreenCaster.cs +++ b/Desktop.Core/Services/ScreenCaster.cs @@ -1,25 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Remotely.Desktop.Core.Interfaces; -using System.Diagnostics; -using System.Drawing.Imaging; -using Microsoft.Extensions.DependencyInjection; -using Remotely.Desktop.Core.Utilities; -using Remotely.Shared.Utilities; -using System.Collections.Concurrent; +using Microsoft.Extensions.DependencyInjection; using Remotely.Desktop.Core.Enums; +using Remotely.Desktop.Core.Interfaces; +using Remotely.Desktop.Core.Utilities; using Remotely.Shared.Models; -using Remotely.Shared.Win32; +using Remotely.Shared.Utilities; +using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; using System.Threading; +using System.Threading.Tasks; namespace Remotely.Desktop.Core.Services { public class ScreenCaster : IScreenCaster { - public ScreenCaster(Conductor conductor, + public ScreenCaster(Conductor conductor, ICursorIconWatcher cursorIconWatcher, ISessionIndicator sessionIndicator, IShutdownService shutdownService) diff --git a/Desktop.Core/Services/Viewer.cs b/Desktop.Core/Services/Viewer.cs index 11d7111d..71f5ceaf 100644 --- a/Desktop.Core/Services/Viewer.cs +++ b/Desktop.Core/Services/Viewer.cs @@ -1,5 +1,4 @@ using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; using Remotely.Desktop.Core.ViewModels; using Remotely.Shared.Helpers; using Remotely.Shared.Models; @@ -8,8 +7,6 @@ using Remotely.Shared.Utilities; using Remotely.Shared.Win32; using System; using System.Collections.Concurrent; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Drawing.Imaging; using System.IO; using System.Linq; diff --git a/Desktop.Core/Services/WebRtcSession.cs b/Desktop.Core/Services/WebRtcSession.cs index c215c569..fee034fb 100644 --- a/Desktop.Core/Services/WebRtcSession.cs +++ b/Desktop.Core/Services/WebRtcSession.cs @@ -1,15 +1,11 @@ using MessagePack; using Microsoft.MixedReality.WebRTC; -using Remotely.Desktop.Core.Services; using Remotely.Shared.Helpers; using Remotely.Shared.Models; using Remotely.Shared.Models.RemoteControlDtos; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; -using System.Drawing; using System.Linq; -using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Remotely.Desktop.Core.Services diff --git a/Desktop.Core/Services/WebRtcSessionFactory.cs b/Desktop.Core/Services/WebRtcSessionFactory.cs index 1ac4b8e3..2acc2bc1 100644 --- a/Desktop.Core/Services/WebRtcSessionFactory.cs +++ b/Desktop.Core/Services/WebRtcSessionFactory.cs @@ -1,10 +1,4 @@ -using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Remotely.Desktop.Core.Services +namespace Remotely.Desktop.Core.Services { public interface IWebRtcSessionFactory { diff --git a/Desktop.Core/Utilities/ImageUtils.cs b/Desktop.Core/Utilities/ImageUtils.cs index cc5c7b36..32b876ff 100644 --- a/Desktop.Core/Utilities/ImageUtils.cs +++ b/Desktop.Core/Utilities/ImageUtils.cs @@ -12,11 +12,9 @@ namespace Remotely.Desktop.Core.Utilities public static ImageCodecInfo JpegEncoder { get; } = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == ImageFormat.Jpeg.Guid); public static byte[] EncodeBitmap(Bitmap bitmap, EncoderParameters encoderParams) { - using (var ms = new MemoryStream()) - { - bitmap.Save(ms, JpegEncoder, encoderParams); - return ms.ToArray(); - } + using var ms = new MemoryStream(); + bitmap.Save(ms, JpegEncoder, encoderParams); + return ms.ToArray(); } public static Rectangle GetDiffArea(Bitmap currentFrame, Bitmap previousFrame, bool captureFullscreen) diff --git a/Desktop.Core/ViewModels/FileUpload.cs b/Desktop.Core/ViewModels/FileUpload.cs index a6c337ef..42c07555 100644 --- a/Desktop.Core/ViewModels/FileUpload.cs +++ b/Desktop.Core/ViewModels/FileUpload.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; +using System.IO; namespace Remotely.Desktop.Core.ViewModels { diff --git a/Desktop.Linux/App.xaml.cs b/Desktop.Linux/App.xaml.cs index 69392829..ae9fa817 100644 --- a/Desktop.Linux/App.xaml.cs +++ b/Desktop.Linux/App.xaml.cs @@ -1,10 +1,5 @@ using Avalonia; -using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Microsoft.Extensions.DependencyInjection; -using Remotely.Desktop.Core; -using Remotely.Desktop.Linux.ViewModels; -using Remotely.Desktop.Linux.Views; namespace Remotely.Desktop.Linux { @@ -28,7 +23,7 @@ namespace Remotely.Desktop.Linux // }; // } //} - + base.OnFrameworkInitializationCompleted(); } } diff --git a/Desktop.Linux/Controls/HostNamePrompt.axaml.cs b/Desktop.Linux/Controls/HostNamePrompt.axaml.cs index a5dec959..ba4cb9bb 100644 --- a/Desktop.Linux/Controls/HostNamePrompt.axaml.cs +++ b/Desktop.Linux/Controls/HostNamePrompt.axaml.cs @@ -2,7 +2,6 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; using Remotely.Desktop.Linux.ViewModels; -using Remotely.Desktop.Linux.Views; namespace Remotely.Desktop.Linux.Controls { diff --git a/Desktop.Linux/Controls/MessageBox.axaml.cs b/Desktop.Linux/Controls/MessageBox.axaml.cs index ce4de2e0..0bae03c1 100644 --- a/Desktop.Linux/Controls/MessageBox.axaml.cs +++ b/Desktop.Linux/Controls/MessageBox.axaml.cs @@ -3,11 +3,9 @@ using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Remotely.Desktop.Linux.ViewModels; -using Remotely.Desktop.Linux.Views; using Remotely.Shared.Helpers; using System; using System.Linq; -using System.Threading; using System.Threading.Tasks; namespace Remotely.Desktop.Linux.Controls diff --git a/Desktop.Linux/Program.cs b/Desktop.Linux/Program.cs index 27ff913e..7839f5e3 100644 --- a/Desktop.Linux/Program.cs +++ b/Desktop.Linux/Program.cs @@ -12,7 +12,6 @@ using Remotely.Desktop.Linux.Services; using Remotely.Desktop.Linux.Views; using Remotely.Shared.Utilities; using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -20,7 +19,7 @@ namespace Remotely.Desktop.Linux { class Program { - + // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() diff --git a/Desktop.Linux/Services/ChatHostServiceLinux.cs b/Desktop.Linux/Services/ChatHostServiceLinux.cs index 65df2438..aba15b9e 100644 --- a/Desktop.Linux/Services/ChatHostServiceLinux.cs +++ b/Desktop.Linux/Services/ChatHostServiceLinux.cs @@ -7,10 +7,8 @@ using Remotely.Desktop.Linux.Views; using Remotely.Shared.Models; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; using System.IO; using System.IO.Pipes; -using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; diff --git a/Desktop.Linux/Services/ClipboardServiceLinux.cs b/Desktop.Linux/Services/ClipboardServiceLinux.cs index 03a204eb..d29a03bb 100644 --- a/Desktop.Linux/Services/ClipboardServiceLinux.cs +++ b/Desktop.Linux/Services/ClipboardServiceLinux.cs @@ -1,9 +1,6 @@ using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; using Remotely.Shared.Utilities; using System; -using System.Diagnostics; -using System.IO; using System.Threading; using System.Threading.Tasks; diff --git a/Desktop.Linux/Services/CursorIconWatcherLinux.cs b/Desktop.Linux/Services/CursorIconWatcherLinux.cs index f6b021bc..391d037f 100644 --- a/Desktop.Linux/Services/CursorIconWatcherLinux.cs +++ b/Desktop.Linux/Services/CursorIconWatcherLinux.cs @@ -1,9 +1,7 @@ using Remotely.Desktop.Core.Interfaces; using Remotely.Shared.Models; using System; -using System.Collections.Generic; using System.Drawing; -using System.Text; namespace Remotely.Desktop.Linux.Services { diff --git a/Desktop.Linux/Services/FileTransferServiceLinux.cs b/Desktop.Linux/Services/FileTransferServiceLinux.cs index fdafa90a..e388f39b 100644 --- a/Desktop.Linux/Services/FileTransferServiceLinux.cs +++ b/Desktop.Linux/Services/FileTransferServiceLinux.cs @@ -1,25 +1,24 @@ -using Remotely.Shared.Utilities; -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using System.Threading; -using System.Collections.Concurrent; -using Remotely.Desktop.Linux.Controls; +using Avalonia.Threading; using Remotely.Desktop.Core.Interfaces; -using Avalonia.Controls; using Remotely.Desktop.Core.Services; using Remotely.Desktop.Core.ViewModels; -using Avalonia.Threading; -using Remotely.Desktop.Linux.Views; +using Remotely.Desktop.Linux.Controls; using Remotely.Desktop.Linux.ViewModels; +using Remotely.Desktop.Linux.Views; +using Remotely.Shared.Utilities; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; namespace Remotely.Desktop.Linux.Services { public class FileTransferServiceLinux : IFileTransferService { private static readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1); - private static readonly ConcurrentDictionary _partialTransfers = + private static readonly ConcurrentDictionary _partialTransfers = new ConcurrentDictionary(); private static readonly ConcurrentDictionary _fileTransferWindows = new ConcurrentDictionary(); diff --git a/Desktop.Linux/Services/KeyboardMouseInputLinux.cs b/Desktop.Linux/Services/KeyboardMouseInputLinux.cs index 1a59bf2b..6afbc7f9 100644 --- a/Desktop.Linux/Services/KeyboardMouseInputLinux.cs +++ b/Desktop.Linux/Services/KeyboardMouseInputLinux.cs @@ -1,8 +1,8 @@ using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; using Remotely.Desktop.Linux.X11Interop; -using System; using Remotely.Shared.Utilities; +using System; namespace Remotely.Desktop.Linux.Services { @@ -92,9 +92,9 @@ namespace Remotely.Desktop.Linux.Services { try { - LibXtst.XTestFakeMotionEvent(Display, + LibXtst.XTestFakeMotionEvent(Display, viewer.Capturer.GetSelectedScreenIndex(), - (int)(viewer.Capturer.CurrentScreenBounds.Width * percentX), + (int)(viewer.Capturer.CurrentScreenBounds.Width * percentX), (int)(viewer.Capturer.CurrentScreenBounds.Height * percentY), 0); LibX11.XSync(Display, false); diff --git a/Desktop.Linux/Services/ScreenCapturerLinux.cs b/Desktop.Linux/Services/ScreenCapturerLinux.cs index 4ab08d05..56643707 100644 --- a/Desktop.Linux/Services/ScreenCapturerLinux.cs +++ b/Desktop.Linux/Services/ScreenCapturerLinux.cs @@ -1,5 +1,4 @@ using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; using Remotely.Desktop.Linux.X11Interop; using Remotely.Shared.Utilities; using System; diff --git a/Desktop.Linux/Services/SessionIndicatorLinux.cs b/Desktop.Linux/Services/SessionIndicatorLinux.cs index db5acc00..2b2c9c37 100644 --- a/Desktop.Linux/Services/SessionIndicatorLinux.cs +++ b/Desktop.Linux/Services/SessionIndicatorLinux.cs @@ -1,9 +1,6 @@ using Avalonia.Threading; using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Linux.Views; -using System; -using System.Collections.Generic; -using System.Text; namespace Remotely.Desktop.Linux.Services { diff --git a/Desktop.Linux/Services/ShutdownServiceLinux.cs b/Desktop.Linux/Services/ShutdownServiceLinux.cs index 483d9d6b..9c4847b1 100644 --- a/Desktop.Linux/Services/ShutdownServiceLinux.cs +++ b/Desktop.Linux/Services/ShutdownServiceLinux.cs @@ -4,9 +4,7 @@ using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Text; using System.Threading.Tasks; namespace Remotely.Desktop.Linux.Services diff --git a/Desktop.Linux/ViewLocator.cs b/Desktop.Linux/ViewLocator.cs index a0f78c4d..35764871 100644 --- a/Desktop.Linux/ViewLocator.cs +++ b/Desktop.Linux/ViewLocator.cs @@ -1,7 +1,7 @@ -using System; using Avalonia.Controls; using Avalonia.Controls.Templates; using Remotely.Desktop.Linux.ViewModels; +using System; namespace Remotely.Desktop.Linux { diff --git a/Desktop.Linux/ViewModels/ChatWindowViewModel.cs b/Desktop.Linux/ViewModels/ChatWindowViewModel.cs index f8299586..aacc098a 100644 --- a/Desktop.Linux/ViewModels/ChatWindowViewModel.cs +++ b/Desktop.Linux/ViewModels/ChatWindowViewModel.cs @@ -2,11 +2,8 @@ using ReactiveUI; using Remotely.Desktop.Linux.Services; using Remotely.Shared.Models; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; -using System.Text; using System.Text.Json; using System.Threading.Tasks; using System.Windows.Input; @@ -40,7 +37,7 @@ namespace Remotely.Desktop.Linux.ViewModels public string OrganizationName { get => organizationName; - set + set { this.RaiseAndSetIfChanged(ref organizationName, value); this.RaisePropertyChanged(nameof(ChatSessionHeader)); diff --git a/Desktop.Linux/ViewModels/FileTransferWindowViewModel.cs b/Desktop.Linux/ViewModels/FileTransferWindowViewModel.cs index a70d46a4..e094293f 100644 --- a/Desktop.Linux/ViewModels/FileTransferWindowViewModel.cs +++ b/Desktop.Linux/ViewModels/FileTransferWindowViewModel.cs @@ -7,11 +7,9 @@ using Remotely.Desktop.Core.ViewModels; using Remotely.Desktop.Linux.Services; using Remotely.Desktop.Linux.Views; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Windows.Input; diff --git a/Desktop.Linux/ViewModels/HostNamePromptViewModel.cs b/Desktop.Linux/ViewModels/HostNamePromptViewModel.cs index dd97a025..5f0e7145 100644 --- a/Desktop.Linux/ViewModels/HostNamePromptViewModel.cs +++ b/Desktop.Linux/ViewModels/HostNamePromptViewModel.cs @@ -1,8 +1,7 @@ -using System.Windows.Input; -using Avalonia.Controls; +using Avalonia.Controls; using ReactiveUI; -using Remotely.Desktop.Core.ViewModels; using Remotely.Desktop.Linux.Services; +using System.Windows.Input; namespace Remotely.Desktop.Linux.ViewModels { diff --git a/Desktop.Linux/ViewModels/MainWindowViewModel.cs b/Desktop.Linux/ViewModels/MainWindowViewModel.cs index 9ba73701..262d0f1f 100644 --- a/Desktop.Linux/ViewModels/MainWindowViewModel.cs +++ b/Desktop.Linux/ViewModels/MainWindowViewModel.cs @@ -1,25 +1,22 @@ using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Threading; +using Microsoft.Extensions.DependencyInjection; using ReactiveUI; -using Remotely.Desktop.Linux.Controls; -using Remotely.Desktop.Linux.Services; -using Remotely.Desktop.Linux.Views; using Remotely.Desktop.Core; using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; +using Remotely.Desktop.Linux.Controls; +using Remotely.Desktop.Linux.Services; +using Remotely.Desktop.Linux.Views; using Remotely.Shared.Models; +using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; -using System.Drawing; using System.Linq; using System.Threading.Tasks; using System.Windows.Input; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Remotely.Shared.Utilities; namespace Remotely.Desktop.Linux.ViewModels { @@ -249,8 +246,8 @@ namespace Remotely.Desktop.Linux.ViewModels Environment.NewLine + Environment.NewLine + "libx11-dev" + Environment.NewLine + "libc6-dev" + Environment.NewLine + - "libgdiplus" + Environment.NewLine + - "libxtst-dev" + Environment.NewLine + + "libgdiplus" + Environment.NewLine + + "libxtst-dev" + Environment.NewLine + "xclip"; await MessageBox.Show(message, "Dependencies Required", MessageBoxType.OK); @@ -268,7 +265,7 @@ namespace Remotely.Desktop.Linux.ViewModels { _ = Task.Run(() => { - Services.GetRequiredService().BeginScreenCasting(screenCastRequest); + Services.GetRequiredService().BeginScreenCasting(screenCastRequest); }); } }); diff --git a/Desktop.Linux/ViewModels/MessageBoxViewModel.cs b/Desktop.Linux/ViewModels/MessageBoxViewModel.cs index e24617f5..5952774c 100644 --- a/Desktop.Linux/ViewModels/MessageBoxViewModel.cs +++ b/Desktop.Linux/ViewModels/MessageBoxViewModel.cs @@ -1,6 +1,5 @@ using Avalonia.Controls; using ReactiveUI; -using Remotely.Desktop.Core.ViewModels; using Remotely.Desktop.Linux.Controls; using Remotely.Desktop.Linux.Services; using System.Windows.Input; diff --git a/Desktop.Linux/ViewModels/ReactiveViewModel.cs b/Desktop.Linux/ViewModels/ReactiveViewModel.cs index 806718b6..72886e72 100644 --- a/Desktop.Linux/ViewModels/ReactiveViewModel.cs +++ b/Desktop.Linux/ViewModels/ReactiveViewModel.cs @@ -1,7 +1,4 @@ using ReactiveUI; -using System; -using System.Collections.Generic; -using System.Text; namespace Remotely.Desktop.Linux.ViewModels { diff --git a/Desktop.Linux/Views/ChatWindow.axaml.cs b/Desktop.Linux/Views/ChatWindow.axaml.cs index 0e0f96a5..e1567b6a 100644 --- a/Desktop.Linux/Views/ChatWindow.axaml.cs +++ b/Desktop.Linux/Views/ChatWindow.axaml.cs @@ -1,12 +1,8 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.LogicalTree; using Avalonia.Markup.Xaml; -using Avalonia.VisualTree; -using ReactiveUI; using Remotely.Desktop.Linux.ViewModels; using System; -using System.Linq; using System.Threading.Tasks; namespace Remotely.Desktop.Linux.Views diff --git a/Desktop.Linux/X11Interop/LibX11.cs b/Desktop.Linux/X11Interop/LibX11.cs index 4197f8d2..6c457a9e 100644 --- a/Desktop.Linux/X11Interop/LibX11.cs +++ b/Desktop.Linux/X11Interop/LibX11.cs @@ -34,7 +34,7 @@ namespace Remotely.Desktop.Linux.X11Interop [DllImport("libX11")] public static extern IntPtr XGetImage(IntPtr display, IntPtr drawable, int x, int y, int width, int height, long plane_mask, int format); - + [DllImport("libX11")] public static extern IntPtr XDefaultVisual(IntPtr display, int screen_number); [DllImport("libX11")] diff --git a/Desktop.Win.Wrapper/App.xaml.cs b/Desktop.Win.Wrapper/App.xaml.cs index 9e537696..77e82de2 100644 --- a/Desktop.Win.Wrapper/App.xaml.cs +++ b/Desktop.Win.Wrapper/App.xaml.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace Desktop.Win.Wrapper { diff --git a/Desktop.Win.Wrapper/Properties/AssemblyInfo.cs b/Desktop.Win.Wrapper/Properties/AssemblyInfo.cs index 80336e4a..c13de173 100644 --- a/Desktop.Win.Wrapper/Properties/AssemblyInfo.cs +++ b/Desktop.Win.Wrapper/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows; diff --git a/Desktop.Win/App.xaml.cs b/Desktop.Win/App.xaml.cs index 5d534ddb..33c0bca1 100644 --- a/Desktop.Win/App.xaml.cs +++ b/Desktop.Win/App.xaml.cs @@ -1,11 +1,9 @@ using Microsoft.Extensions.DependencyInjection; using Remotely.Desktop.Core; -using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; using Remotely.Shared.Utilities; using Remotely.Shared.Win32; using System; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using System.Windows; diff --git a/Desktop.Win/Models/DirectXOutput.cs b/Desktop.Win/Models/DirectXOutput.cs index 90c0ad30..a7e8ef31 100644 --- a/Desktop.Win/Models/DirectXOutput.cs +++ b/Desktop.Win/Models/DirectXOutput.cs @@ -7,9 +7,9 @@ namespace Remotely.Desktop.Win.Models { public class DirectXOutput : IDisposable { - public DirectXOutput(Adapter1 adapter, - SharpDX.Direct3D11.Device device, - OutputDuplication outputDuplication, + public DirectXOutput(Adapter1 adapter, + SharpDX.Direct3D11.Device device, + OutputDuplication outputDuplication, Texture2D texture2D) { Adapter = adapter; @@ -25,8 +25,8 @@ namespace Remotely.Desktop.Win.Models public void Dispose() { - Disposer.TryDisposeAll(new IDisposable[] - { + Disposer.TryDisposeAll(new IDisposable[] + { Adapter, Device, OutputDuplication, diff --git a/Desktop.Win/Program.cs b/Desktop.Win/Program.cs index 0c22ab05..b55d8237 100644 --- a/Desktop.Win/Program.cs +++ b/Desktop.Win/Program.cs @@ -1,24 +1,23 @@ -using Remotely.Shared.Models; -using Remotely.Desktop.Core; -using Remotely.Desktop.Core.Services; -using System; -using System.Linq; -using System.Threading.Tasks; -using Remotely.Shared.Win32; -using System.Threading; -using Remotely.Desktop.Win.Services; -using Remotely.Desktop.Core.Interfaces; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Remotely.Shared.Utilities; -using System.Windows; +using Remotely.Desktop.Core; +using Remotely.Desktop.Core.Interfaces; +using Remotely.Desktop.Core.Services; +using Remotely.Desktop.Win.Services; using Remotely.Desktop.Win.Views; +using Remotely.Shared.Models; +using Remotely.Shared.Utilities; +using Remotely.Shared.Win32; +using System; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; using System.Windows.Forms; namespace Remotely.Desktop.Win { public class Program - { + { public static ManualResetEvent AppExitEvent { get; } = new ManualResetEvent(false); public static Form BackgroundForm { get; private set; } private static CasterSocket CasterSocket { get; set; } diff --git a/Desktop.Win/Services/AudioCapturerWin.cs b/Desktop.Win/Services/AudioCapturerWin.cs index 10727104..c1d53e66 100644 --- a/Desktop.Win/Services/AudioCapturerWin.cs +++ b/Desktop.Win/Services/AudioCapturerWin.cs @@ -1,12 +1,10 @@ -using System; +using NAudio.Wave; +using Remotely.Desktop.Core.Interfaces; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using NAudio.Wave; -using Remotely.Desktop.Core; -using Remotely.Desktop.Core.Interfaces; namespace Remotely.Desktop.Win.Services { @@ -36,26 +34,22 @@ namespace Remotely.Desktop.Win.Services return; } - using (var ms1 = new MemoryStream()) + using var ms1 = new MemoryStream(); + using (var wfw = new WaveFileWriter(ms1, Capturer.WaveFormat)) { - using (var wfw = new WaveFileWriter(ms1, Capturer.WaveFormat)) - { - wfw.Write(TempBuffer.ToArray(), 0, TempBuffer.Count); - } - TempBuffer.Clear(); - - // Resample to 16-bit so Firefox will play it. - using (var ms2 = new MemoryStream(ms1.ToArray())) - using (var wfr = new WaveFileReader(ms2)) - using (var ms3 = new MemoryStream()) - { - using (var resampler = new MediaFoundationResampler(wfr, TargetFormat)) - { - WaveFileWriter.WriteWavFileToStream(ms3, resampler); - } - AudioSampleReady?.Invoke(this, ms3.ToArray()); - } + wfw.Write(TempBuffer.ToArray(), 0, TempBuffer.Count); } + TempBuffer.Clear(); + + // Resample to 16-bit so Firefox will play it. + using var ms2 = new MemoryStream(ms1.ToArray()); + using var wfr = new WaveFileReader(ms2); + using var ms3 = new MemoryStream(); + using (var resampler = new MediaFoundationResampler(wfr, TargetFormat)) + { + WaveFileWriter.WriteWavFileToStream(ms3, resampler); + } + AudioSampleReady?.Invoke(this, ms3.ToArray()); } private void Start() diff --git a/Desktop.Win/Services/ChatHostServiceWin.cs b/Desktop.Win/Services/ChatHostServiceWin.cs index 6fa7b17b..21f67098 100644 --- a/Desktop.Win/Services/ChatHostServiceWin.cs +++ b/Desktop.Win/Services/ChatHostServiceWin.cs @@ -4,10 +4,8 @@ using Remotely.Desktop.Win.Views; using Remotely.Shared.Models; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; using System.IO; using System.IO.Pipes; -using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; diff --git a/Desktop.Win/Services/ClipboardServiceWin.cs b/Desktop.Win/Services/ClipboardServiceWin.cs index 47625461..12a7b20b 100644 --- a/Desktop.Win/Services/ClipboardServiceWin.cs +++ b/Desktop.Win/Services/ClipboardServiceWin.cs @@ -1,5 +1,4 @@ using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; using Remotely.Shared.Utilities; using Remotely.Shared.Win32; using System; @@ -53,7 +52,7 @@ namespace Remotely.Desktop.Win.Services }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); - + return Task.CompletedTask; } diff --git a/Desktop.Win/Services/CursorIconWatcherWin.cs b/Desktop.Win/Services/CursorIconWatcherWin.cs index 3256ad05..a2628e7a 100644 --- a/Desktop.Win/Services/CursorIconWatcherWin.cs +++ b/Desktop.Win/Services/CursorIconWatcherWin.cs @@ -1,13 +1,13 @@ -using System; +using Remotely.Desktop.Core.Interfaces; +using Remotely.Shared.Models; +using Remotely.Shared.Win32; +using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; using System.Timers; using System.Windows.Forms; -using Remotely.Shared.Win32; -using Remotely.Shared.Models; -using Remotely.Desktop.Core.Interfaces; namespace Remotely.Desktop.Win.Services { @@ -43,18 +43,12 @@ namespace Remotely.Desktop.Win.Services return new CursorInfo(new byte[0], Point.Empty, "text"); } - using (var icon = Icon.FromHandle(ci.hCursor)) - { - using (var ms = new MemoryStream()) - { - using (var cursor = new Cursor(ci.hCursor)) - { - var hotspot = cursor.HotSpot; - icon.ToBitmap().Save(ms, ImageFormat.Png); - return new CursorInfo(ms.ToArray(), hotspot); - } - } - } + using var icon = Icon.FromHandle(ci.hCursor); + using var ms = new MemoryStream(); + using var cursor = new Cursor(ci.hCursor); + var hotspot = cursor.HotSpot; + icon.ToBitmap().Save(ms, ImageFormat.Png); + return new CursorInfo(ms.ToArray(), hotspot); } else { @@ -89,18 +83,12 @@ namespace Remotely.Desktop.Win.Services } else { - using (var icon = Icon.FromHandle(cursorInfo.hCursor)) - { - using (var ms = new MemoryStream()) - { - using (var cursor = new Cursor(cursorInfo.hCursor)) - { - var hotspot = cursor.HotSpot; - icon.ToBitmap().Save(ms, ImageFormat.Png); - OnChange?.Invoke(this, new CursorInfo(ms.ToArray(), hotspot)); - } - } - } + using var icon = Icon.FromHandle(cursorInfo.hCursor); + using var ms = new MemoryStream(); + using var cursor = new Cursor(cursorInfo.hCursor); + var hotspot = cursor.HotSpot; + icon.ToBitmap().Save(ms, ImageFormat.Png); + OnChange?.Invoke(this, new CursorInfo(ms.ToArray(), hotspot)); } PreviousCursorHandle = currentCursor; } diff --git a/Desktop.Win/Services/FileTransferServiceWin.cs b/Desktop.Win/Services/FileTransferServiceWin.cs index 43841dcd..108f65b9 100644 --- a/Desktop.Win/Services/FileTransferServiceWin.cs +++ b/Desktop.Win/Services/FileTransferServiceWin.cs @@ -11,7 +11,6 @@ using System.Diagnostics; using System.IO; using System.Security.AccessControl; using System.Security.Principal; -using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -20,7 +19,7 @@ namespace Remotely.Desktop.Win.Services { public class FileTransferServiceWin : IFileTransferService { - private static readonly ConcurrentDictionary _partialTransfers = + private static readonly ConcurrentDictionary _partialTransfers = new ConcurrentDictionary(); private static readonly ConcurrentDictionary _fileTransferWindows = diff --git a/Desktop.Win/Services/KeyboardMouseInputWin.cs b/Desktop.Win/Services/KeyboardMouseInputWin.cs index 3f3719e2..0c39d775 100644 --- a/Desktop.Win/Services/KeyboardMouseInputWin.cs +++ b/Desktop.Win/Services/KeyboardMouseInputWin.cs @@ -1,15 +1,12 @@ using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; -using System; -using Remotely.Shared.Win32; -using static Remotely.Shared.Win32.User32; -using System.Windows.Forms; -using System.Threading; -using System.Collections.Concurrent; -using System.Threading.Tasks; -using Remotely.Desktop.Core; -using System.Runtime.InteropServices; using Remotely.Shared.Utilities; +using Remotely.Shared.Win32; +using System; +using System.Collections.Concurrent; +using System.Threading; +using System.Windows.Forms; +using static Remotely.Shared.Win32.User32; namespace Remotely.Desktop.Win.Services { diff --git a/Desktop.Win/Services/ScreenCapturerWin.cs b/Desktop.Win/Services/ScreenCapturerWin.cs index a8f5eb48..5d387bfc 100644 --- a/Desktop.Win/Services/ScreenCapturerWin.cs +++ b/Desktop.Win/Services/ScreenCapturerWin.cs @@ -23,7 +23,6 @@ using Microsoft.Win32; using Remotely.Desktop.Core.Interfaces; -using Remotely.Desktop.Core.Services; using Remotely.Desktop.Win.Models; using Remotely.Shared.Utilities; using Remotely.Shared.Win32; @@ -89,11 +88,11 @@ namespace Remotely.Desktop.Win.Services // have it fall back to BitBlt in those cases. if (directxScreens.ContainsKey(SelectedScreen)) { - var directXResult = GetDirectXFrame(); + var (result, frame) = GetDirectXFrame(); - if (directXResult.result == GetDirectXFrameResult.Success) + if (result == GetDirectXFrameResult.Success) { - return directXResult.frame; + return frame; } } diff --git a/Desktop.Win/Services/SessionIndicatorWin.cs b/Desktop.Win/Services/SessionIndicatorWin.cs index 719bb2a6..a76557a2 100644 --- a/Desktop.Win/Services/SessionIndicatorWin.cs +++ b/Desktop.Win/Services/SessionIndicatorWin.cs @@ -4,11 +4,9 @@ using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; -using System.Text; using System.Windows.Forms; namespace Remotely.Desktop.Win.Services diff --git a/Desktop.Win/Services/ShutdownServiceWin.cs b/Desktop.Win/Services/ShutdownServiceWin.cs index b01ea218..aad8c07f 100644 --- a/Desktop.Win/Services/ShutdownServiceWin.cs +++ b/Desktop.Win/Services/ShutdownServiceWin.cs @@ -4,9 +4,7 @@ using Remotely.Desktop.Core.Interfaces; using Remotely.Desktop.Core.Services; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Text; using System.Threading.Tasks; namespace Remotely.Desktop.Win.Services @@ -20,7 +18,7 @@ namespace Remotely.Desktop.Win.Services await casterSocket.DisconnectAllViewers(); System.Windows.Forms.Application.Exit(); App.Current.Shutdown(); - Environment.Exit(0); + //Environment.Exit(0); } } } diff --git a/Desktop.Win/ViewModels/ChatWindowViewModel.cs b/Desktop.Win/ViewModels/ChatWindowViewModel.cs index cc9966ed..d8baa3fb 100644 --- a/Desktop.Win/ViewModels/ChatWindowViewModel.cs +++ b/Desktop.Win/ViewModels/ChatWindowViewModel.cs @@ -1,11 +1,7 @@ using Remotely.Desktop.Core.ViewModels; using Remotely.Shared.Models; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; -using System.IO.Pipes; -using System.Text; using System.Text.Json; using System.Threading.Tasks; diff --git a/Desktop.Win/ViewModels/FileTransferWindowViewModel.cs b/Desktop.Win/ViewModels/FileTransferWindowViewModel.cs index 67887e2c..73ec895d 100644 --- a/Desktop.Win/ViewModels/FileTransferWindowViewModel.cs +++ b/Desktop.Win/ViewModels/FileTransferWindowViewModel.cs @@ -7,7 +7,6 @@ using System; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; -using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Input; @@ -40,10 +39,10 @@ namespace Remotely.Desktop.Win.ViewModels // Change initial directory so it doesn't open in %userprofile% path // for SYSTEM account. var rootDir = Path.GetPathRoot(Environment.SystemDirectory); - var userDir = Path.Combine(rootDir, - "Users", + var userDir = Path.Combine(rootDir, + "Users", Win32Interop.GetUsernameFromSessionId((uint)Process.GetCurrentProcess().SessionId)); - + var ofd = new OpenFileDialog() { Title = "Upload File via Remotely", diff --git a/Desktop.Win/ViewModels/MainWindowViewModel.cs b/Desktop.Win/ViewModels/MainWindowViewModel.cs index 6b79dbcf..5fbfde20 100644 --- a/Desktop.Win/ViewModels/MainWindowViewModel.cs +++ b/Desktop.Win/ViewModels/MainWindowViewModel.cs @@ -1,23 +1,22 @@ -using Remotely.Desktop.Win.Controls; +using Microsoft.Extensions.DependencyInjection; +using Remotely.Desktop.Core; +using Remotely.Desktop.Core.Interfaces; +using Remotely.Desktop.Core.Services; +using Remotely.Desktop.Core.ViewModels; +using Remotely.Desktop.Win.Controls; using Remotely.Desktop.Win.Services; using Remotely.Shared.Models; -using Remotely.Desktop.Core; -using Remotely.Desktop.Core.Services; +using Remotely.Shared.Utilities; +using Remotely.Shared.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using System.Security.Principal; using System.Threading.Tasks; using System.Windows; -using System.Security.Principal; using System.Windows.Input; -using Remotely.Desktop.Core.Interfaces; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Remotely.Shared.Win32; -using Remotely.Shared.Utilities; -using Remotely.Desktop.Core.ViewModels; namespace Remotely.Desktop.Win.ViewModels { @@ -25,7 +24,7 @@ namespace Remotely.Desktop.Win.ViewModels { private string host; private string sessionID; - + public static MainWindowViewModel Current { get; private set; } public MainWindowViewModel() @@ -186,7 +185,7 @@ namespace Remotely.Desktop.Win.ViewModels public async Task Init() { - + SessionID = "Retrieving..."; Host = Config.GetConfig().Host; diff --git a/Desktop.Win/Views/ChatWindow.xaml.cs b/Desktop.Win/Views/ChatWindow.xaml.cs index 41fcb8bf..ec18c469 100644 --- a/Desktop.Win/Views/ChatWindow.xaml.cs +++ b/Desktop.Win/Views/ChatWindow.xaml.cs @@ -1,15 +1,7 @@ using Remotely.Desktop.Win.ViewModels; using System; -using System.Collections.Generic; -using System.Text; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace Remotely.Desktop.Win.Views { diff --git a/Desktop.Win/Views/FileTransferWindow.xaml.cs b/Desktop.Win/Views/FileTransferWindow.xaml.cs index 60a4861b..1cc6f34a 100644 --- a/Desktop.Win/Views/FileTransferWindow.xaml.cs +++ b/Desktop.Win/Views/FileTransferWindow.xaml.cs @@ -1,16 +1,6 @@ -using Remotely.Desktop.Win.ViewModels; -using System; -using System.Collections.Generic; -using System.Text; +using System; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Forms; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace Remotely.Desktop.Win.Views { diff --git a/Desktop.Win/Views/MainWindow.xaml.cs b/Desktop.Win/Views/MainWindow.xaml.cs index b2f1fbad..8833a1d2 100644 --- a/Desktop.Win/Views/MainWindow.xaml.cs +++ b/Desktop.Win/Views/MainWindow.xaml.cs @@ -1,5 +1,4 @@ -using Remotely.Desktop.Win; -using Remotely.Desktop.Win.ViewModels; +using Remotely.Desktop.Win.ViewModels; using System; using System.Threading.Tasks; using System.Windows; @@ -29,14 +28,16 @@ namespace Remotely.Desktop.Win.Views private async void CopyLinkButton_Click(object sender, RoutedEventArgs e) { ViewModel.CopyLink(); - var tooltip = new ToolTip(); - tooltip.PlacementTarget = sender as Button; - tooltip.Placement = PlacementMode.Bottom; - tooltip.VerticalOffset = 5; - tooltip.Content = "Copied to clipboard!"; - tooltip.HasDropShadow = true; - tooltip.StaysOpen = false; - tooltip.IsOpen = true; + var tooltip = new ToolTip + { + PlacementTarget = sender as Button, + Placement = PlacementMode.Bottom, + VerticalOffset = 5, + Content = "Copied to clipboard!", + HasDropShadow = true, + StaysOpen = false, + IsOpen = true + }; await Task.Delay(750); var animation = new DoubleAnimation(0, TimeSpan.FromMilliseconds(750)); diff --git a/Server/API/AgentUpdateController.cs b/Server/API/AgentUpdateController.cs index ac50de45..76525d05 100644 --- a/Server/API/AgentUpdateController.cs +++ b/Server/API/AgentUpdateController.cs @@ -15,10 +15,10 @@ namespace Remotely.Server.API public class AgentUpdateController : ControllerBase { private static readonly MemoryCache downloadingAgents = new MemoryCache(new MemoryCacheOptions() - { ExpirationScanFrequency = TimeSpan.FromSeconds(10) }); + { ExpirationScanFrequency = TimeSpan.FromSeconds(10) }); - public AgentUpdateController(IWebHostEnvironment hostingEnv, + public AgentUpdateController(IWebHostEnvironment hostingEnv, DataService dataService, ApplicationConfig appConfig) { diff --git a/Server/API/AlertsController.cs b/Server/API/AlertsController.cs index b789e6fd..3e8590c6 100644 --- a/Server/API/AlertsController.cs +++ b/Server/API/AlertsController.cs @@ -56,7 +56,7 @@ namespace Remotely.Server.API { DataService.WriteEvent(ex, orgID); } - + } if (alertOptions.ShouldSendApiRequest) @@ -82,7 +82,7 @@ namespace Remotely.Server.API { DataService.WriteEvent(ex, orgID); } - + } return Ok(); diff --git a/Server/API/ClientDownloadsController.cs b/Server/API/ClientDownloadsController.cs index 387a69f0..277542f4 100644 --- a/Server/API/ClientDownloadsController.cs +++ b/Server/API/ClientDownloadsController.cs @@ -1,15 +1,14 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Hosting; -using Remotely.Server.Services; -using System.Text; -using Microsoft.Extensions.Configuration; -using System.Threading; using Remotely.Server.Attributes; +using Remotely.Server.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; namespace Remotely.Server.API { diff --git a/Server/API/CommandsController.cs b/Server/API/CommandsController.cs index 8a1dd9b4..3cc5fd19 100644 --- a/Server/API/CommandsController.cs +++ b/Server/API/CommandsController.cs @@ -1,13 +1,13 @@ -using System; +using Microsoft.AspNetCore.Mvc; +using Remotely.Server.Attributes; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using System; using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -using Remotely.Shared.Models; -using Remotely.Server.Services; -using Microsoft.AspNetCore.Mvc; -using Remotely.Server.Attributes; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -100,33 +100,30 @@ namespace Remotely.Server.API [HttpPost("{resultType}")] public async Task Post(string resultType) { - using (var sr = new StreamReader(Request.Body)) + using var sr = new StreamReader(Request.Body); + var content = await sr.ReadToEndAsync(); + switch (resultType) { - var content = await sr.ReadToEndAsync(); - switch (resultType) - { - case "PSCore": - { - var result = System.Text.Json.JsonSerializer.Deserialize(content); - var commandResult = DataService.GetCommandResult(result.CommandResultID); - commandResult.PSCoreResults.Add(result); - DataService.AddOrUpdateCommandResult(commandResult); - break; - } - case "WinPS": - case "CMD": - case "Bash": - { - var result = System.Text.Json.JsonSerializer.Deserialize(content); - var commandResult = DataService.GetCommandResult(result.CommandResultID); - commandResult.CommandResults.Add(result); - DataService.AddOrUpdateCommandResult(commandResult); - break; - } - default: + case "PSCore": + { + var result = System.Text.Json.JsonSerializer.Deserialize(content); + var commandResult = DataService.GetCommandResult(result.CommandResultID); + commandResult.PSCoreResults.Add(result); + DataService.AddOrUpdateCommandResult(commandResult); break; - } - + } + case "WinPS": + case "CMD": + case "Bash": + { + var result = System.Text.Json.JsonSerializer.Deserialize(content); + var commandResult = DataService.GetCommandResult(result.CommandResultID); + commandResult.CommandResults.Add(result); + DataService.AddOrUpdateCommandResult(commandResult); + break; + } + default: + break; } } } diff --git a/Server/API/DevicesController.cs b/Server/API/DevicesController.cs index 59aeec5b..b59ccca9 100644 --- a/Server/API/DevicesController.cs +++ b/Server/API/DevicesController.cs @@ -1,10 +1,9 @@ -using System.Collections.Generic; -using Remotely.Shared.Models; -using Remotely.Server.Services; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; using Remotely.Server.Attributes; -using Microsoft.AspNetCore.Http.Extensions; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using System.Collections.Generic; using System.Threading.Tasks; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -15,14 +14,14 @@ namespace Remotely.Server.API [Route("api/[controller]")] public class DevicesController : ControllerBase { - + public DevicesController(DataService dataService) { DataService = dataService; } private DataService DataService { get; set; } - + [HttpGet] [ServiceFilter(typeof(ApiAuthorizationFilter))] public IEnumerable Get() @@ -54,7 +53,7 @@ namespace Remotely.Server.API } [HttpPost] - public async Task Create([FromBody]DeviceSetupOptions deviceOptions) + public async Task Create([FromBody] DeviceSetupOptions deviceOptions) { var device = await DataService.CreateDevice(deviceOptions); if (device is null) diff --git a/Server/API/FileSharingController.cs b/Server/API/FileSharingController.cs index c505f06a..3f5acca2 100644 --- a/Server/API/FileSharingController.cs +++ b/Server/API/FileSharingController.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; using Remotely.Server.Services; -using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; using System.Threading.Tasks; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -17,7 +17,7 @@ namespace Remotely.Server.API DataService = dataService; } public DataService DataService { get; set; } - + [HttpGet("{id}")] public ActionResult Get(string id) { diff --git a/Server/API/LoginController.cs b/Server/API/LoginController.cs index 9d23c72a..0e2a6aec 100644 --- a/Server/API/LoginController.cs +++ b/Server/API/LoginController.cs @@ -1,12 +1,12 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Remotely.Shared.Models; -using Remotely.Server.Models; -using Remotely.Server.Services; using Microsoft.AspNetCore.SignalR; using Remotely.Server.Hubs; +using Remotely.Server.Models; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using System.Linq; +using System.Threading.Tasks; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -16,8 +16,8 @@ namespace Remotely.Server.API [ApiController] public class LoginController : ControllerBase { - public LoginController(SignInManager signInManager, - DataService dataService, + public LoginController(SignInManager signInManager, + DataService dataService, ApplicationConfig appConfig, IHubContext casterHubContext, IHubContext viewerHubContext) @@ -36,7 +36,7 @@ namespace Remotely.Server.API private IHubContext ViewerHubContext { get; } [HttpPost] - public async Task Post([FromBody]ApiLogin login) + public async Task Post([FromBody] ApiLogin login) { if (!AppConfig.AllowApiLogin) { diff --git a/Server/API/OrganizationManagementController.cs b/Server/API/OrganizationManagementController.cs index be6672b7..5d1ea3c8 100644 --- a/Server/API/OrganizationManagementController.cs +++ b/Server/API/OrganizationManagementController.cs @@ -1,13 +1,13 @@ -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Remotely.Shared.Models; -using Remotely.Server.Services; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Remotely.Shared.ViewModels.Organization; -using System.Text; using Microsoft.AspNetCore.WebUtilities; using Remotely.Server.Attributes; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using Remotely.Shared.ViewModels.Organization; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -31,15 +31,15 @@ namespace Remotely.Server.API [HttpPost("ChangeIsAdmin/{userID}")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public IActionResult ChangeIsAdmin(string userID, [FromBody]bool isAdmin) + public IActionResult ChangeIsAdmin(string userID, [FromBody] bool isAdmin) { - if (User.Identity.IsAuthenticated && + if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) { return Unauthorized(); } - if (User.Identity.IsAuthenticated && + if (User.Identity.IsAuthenticated && DataService.GetUserByName(User.Identity.Name).Id == userID) { return BadRequest("You can't remove administrator rights from yourself."); @@ -89,7 +89,7 @@ namespace Remotely.Server.API [HttpDelete("DeviceGroup")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public IActionResult DeviceGroup([FromBody]string deviceGroupID) + public IActionResult DeviceGroup([FromBody] string deviceGroupID) { if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) @@ -104,7 +104,7 @@ namespace Remotely.Server.API [HttpPost("DeviceGroup")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public IActionResult DeviceGroup([FromBody]DeviceGroup deviceGroup) + public IActionResult DeviceGroup([FromBody] DeviceGroup deviceGroup) { if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) @@ -128,7 +128,7 @@ namespace Remotely.Server.API [HttpDelete("DeviceGroup/{groupID}/Users/")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public async Task DeviceGroupRemoveUser([FromBody]string userID, string groupID) + public async Task DeviceGroupRemoveUser([FromBody] string userID, string groupID) { if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) @@ -151,7 +151,7 @@ namespace Remotely.Server.API [HttpPost("DeviceGroup/{groupID}/Users/")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public IActionResult DeviceGroupAddUser([FromBody]string userID, string groupID) + public IActionResult DeviceGroupAddUser([FromBody] string userID, string groupID) { if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) @@ -170,7 +170,7 @@ namespace Remotely.Server.API { return BadRequest(resultMessage); } - + return Ok(resultMessage); } @@ -207,7 +207,7 @@ namespace Remotely.Server.API [HttpPut("Name")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public IActionResult Name([FromBody]string organizationName) + public IActionResult Name([FromBody] string organizationName) { if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) @@ -225,7 +225,7 @@ namespace Remotely.Server.API } [HttpPost("SendInvite")] [ServiceFilter(typeof(ApiAuthorizationFilter))] - public async Task SendInvite([FromBody]Invite invite) + public async Task SendInvite([FromBody] Invite invite) { if (User.Identity.IsAuthenticated && !DataService.GetUserByName(User.Identity.Name).IsAdministrator) @@ -278,7 +278,7 @@ namespace Remotely.Server.API return Ok(); } - + } } } diff --git a/Server/API/RemoteControlController.cs b/Server/API/RemoteControlController.cs index 1209468a..f2b16094 100644 --- a/Server/API/RemoteControlController.cs +++ b/Server/API/RemoteControlController.cs @@ -1,16 +1,15 @@ -using System; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; -using Remotely.Shared.Models; +using Remotely.Server.Attributes; +using Remotely.Server.Hubs; using Remotely.Server.Models; using Remotely.Server.Services; -using Remotely.Server.Attributes; using Remotely.Shared.Helpers; -using Remotely.Server.Hubs; +using Remotely.Shared.Models; +using System; +using System.Linq; +using System.Threading.Tasks; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -20,9 +19,9 @@ namespace Remotely.Server.API [ApiController] public class RemoteControlController : ControllerBase { - public RemoteControlController(DataService dataService, - IHubContext agentHub, - ApplicationConfig appConfig, + public RemoteControlController(DataService dataService, + IHubContext agentHub, + ApplicationConfig appConfig, SignInManager signInManager) { DataService = dataService; @@ -45,7 +44,7 @@ namespace Remotely.Server.API } [HttpPost] - public async Task Post([FromBody]RemoteControlRequest rcRequest) + public async Task Post([FromBody] RemoteControlRequest rcRequest) { if (!AppConfig.AllowApiLogin) { @@ -77,7 +76,7 @@ namespace Remotely.Server.API private async Task InitiateRemoteControl(string deviceID, string orgID) { - var targetDevice = Hubs.AgentHub.ServiceConnections.FirstOrDefault(x => + var targetDevice = Hubs.AgentHub.ServiceConnections.FirstOrDefault(x => x.Value.OrganizationID == orgID && x.Value.ID.ToLower() == deviceID.ToLower()); diff --git a/Server/API/ScriptingController.cs b/Server/API/ScriptingController.cs index 506419d7..9b5bfaea 100644 --- a/Server/API/ScriptingController.cs +++ b/Server/API/ScriptingController.cs @@ -1,16 +1,16 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; +using Remotely.Server.Attributes; +using Remotely.Server.Hubs; using Remotely.Server.Services; +using Remotely.Shared.Helpers; using Remotely.Shared.Models; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; -using Remotely.Shared.Helpers; -using System.IO; -using Remotely.Server.Attributes; -using Remotely.Server.Hubs; namespace Remotely.Server.API { @@ -18,7 +18,7 @@ namespace Remotely.Server.API [Route("api/[controller]")] public class ScriptingController : ControllerBase { - public ScriptingController(DataService dataService, + public ScriptingController(DataService dataService, UserManager userManager, IHubContext agentHub) { diff --git a/Server/API/ServerLogsController.cs b/Server/API/ServerLogsController.cs index c92cbc09..970afea3 100644 --- a/Server/API/ServerLogsController.cs +++ b/Server/API/ServerLogsController.cs @@ -1,8 +1,8 @@ -using System.Text; -using System.Text.Json; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Remotely.Server.Attributes; using Remotely.Server.Services; +using System.Text; +using System.Text.Json; namespace Remotely.Server.API { diff --git a/Server/Areas/Identity/IdentityHostingStartup.cs b/Server/Areas/Identity/IdentityHostingStartup.cs index a38aadcc..6904abb8 100644 --- a/Server/Areas/Identity/IdentityHostingStartup.cs +++ b/Server/Areas/Identity/IdentityHostingStartup.cs @@ -7,7 +7,8 @@ namespace Remotely.Server.Areas.Identity { public void Configure(IWebHostBuilder builder) { - builder.ConfigureServices((context, services) => { + builder.ConfigureServices((context, services) => + { }); } } diff --git a/Server/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs b/Server/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs index 0295b96d..1eb9714a 100644 --- a/Server/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs @@ -1,11 +1,11 @@ -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.WebUtilities; using Remotely.Shared.Models; +using System.Text; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account { diff --git a/Server/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs b/Server/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs index bf9ad9b8..7c689df0 100644 --- a/Server/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.cs @@ -1,11 +1,11 @@ -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.WebUtilities; using Remotely.Shared.Models; +using System.Text; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account { diff --git a/Server/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs b/Server/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs index d7bdb0fb..7d0ad32f 100644 --- a/Server/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs @@ -1,14 +1,14 @@ -using System.ComponentModel.DataAnnotations; -using System.Text.Encodings.Web; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.WebUtilities; -using Remotely.Shared.Models; using Remotely.Server.Services; +using Remotely.Shared.Models; +using System.ComponentModel.DataAnnotations; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account { @@ -70,7 +70,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account ModelState.AddModelError("EmailError", "Error sending email."); return Page(); } - + return RedirectToPage("./ForgotPasswordConfirmation"); } diff --git a/Server/Areas/Identity/Pages/Account/Login.cshtml.cs b/Server/Areas/Identity/Pages/Account/Login.cshtml.cs index 43d3ce50..376d3910 100644 --- a/Server/Areas/Identity/Pages/Account/Login.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Login.cshtml.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Remotely.Shared.Models; -using Remotely.Server.Services; using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Extensions.Logging; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; using System.Text; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account { @@ -23,9 +23,9 @@ namespace Remotely.Server.Areas.Identity.Pages.Account private readonly UserManager _userManager; private readonly ILogger _logger; - public LoginModel(SignInManager signInManager, + public LoginModel(SignInManager signInManager, UserManager userManager, - DataService dataService, + DataService dataService, ILogger logger) { _dataService = dataService; @@ -65,7 +65,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account ModelState.AddModelError(string.Empty, ErrorMessage); } - returnUrl = returnUrl ?? Url.Content("~/"); + returnUrl ??= Url.Content("~/"); // Clear the existing external cookie to ensure a clean login process await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); @@ -77,7 +77,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account public async Task OnPostAsync(string returnUrl = null) { - returnUrl = returnUrl ?? Url.Content("~/"); + returnUrl ??= Url.Content("~/"); if (ModelState.IsValid) { @@ -91,7 +91,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account } if (result.RequiresTwoFactor) { - return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }); + return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, Input.RememberMe }); } if (result.IsLockedOut) { diff --git a/Server/Areas/Identity/Pages/Account/Logout.cshtml.cs b/Server/Areas/Identity/Pages/Account/Logout.cshtml.cs index 13da12e3..72bf50f2 100644 --- a/Server/Areas/Identity/Pages/Account/Logout.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Logout.cshtml.cs @@ -1,14 +1,13 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Remotely.Server.Hubs; -using Remotely.Server.Services; using Remotely.Shared.Models; +using System.Linq; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account { @@ -46,7 +45,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account await ViewerHubContext.Clients.Client(session.Value.RequesterSocketID).SendAsync("ConnectionFailed"); } } - + await _signInManager.SignOutAsync(); _logger.LogInformation("User logged out."); if (returnUrl != null) diff --git a/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml.cs index 7adb7344..97249f2f 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -9,6 +5,10 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Remotely.Server.Services; using Remotely.Shared.Models; using Remotely.Shared.Utilities; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { @@ -44,8 +44,8 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage public async Task OnPostRenameAsync() { - if (ModelState.IsValid && - !string.IsNullOrWhiteSpace(Input.TokenId) && + if (ModelState.IsValid && + !string.IsNullOrWhiteSpace(Input.TokenId) && !string.IsNullOrWhiteSpace(Input.TokenName)) { await DataService.RenameApiToken(User.Identity.Name, Input.TokenId, Input.TokenName); diff --git a/Server/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs index 8a19f8a4..3540d82d 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs @@ -1,13 +1,13 @@ -using System.ComponentModel.DataAnnotations; -using System.Text; -using System.Text.Encodings.Web; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; using Remotely.Shared.Models; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { diff --git a/Server/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs index 16e6cf40..3a390b90 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs @@ -1,14 +1,14 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Remotely.Shared.Models; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.WebUtilities; -using System.Text; using Remotely.Server.Services; +using Remotely.Shared.Models; +using System; +using System.ComponentModel.DataAnnotations; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { @@ -123,7 +123,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage } } - + if (Input.DisplayName != user.DisplayName) { @@ -155,7 +155,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, - values: new { area = "Identity", userId = user.Id, code = code }, + values: new { area = "Identity", userId = user.Id, code }, protocol: Request.Scheme); var emailResult = await _emailSender.SendEmailAsync( email, diff --git a/Server/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs b/Server/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs index 95c8835f..379bd30c 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; +using System; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { diff --git a/Server/Areas/Identity/Pages/Account/Manage/Options.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/Options.cshtml.cs index 6cf12df8..2319816b 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/Options.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/Options.cshtml.cs @@ -1,7 +1,7 @@ -using Remotely.Shared.Models; -using Remotely.Server.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Remotely.Server.Services; +using Remotely.Shared.Models; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { diff --git a/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs index 79bd1b33..240a1947 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs @@ -1,15 +1,15 @@ -using Remotely.Shared.Models; -using Remotely.Server.Services; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using Remotely.Shared.ViewModels.Organization; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Remotely.Shared.ViewModels.Organization; -using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; using System.Text.Encodings.Web; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { diff --git a/Server/Areas/Identity/Pages/Account/Manage/ServerLogs.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/ServerLogs.cshtml.cs index 3918d1a7..c48dc0bb 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/ServerLogs.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/ServerLogs.cshtml.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Remotely.Server.Services; using Remotely.Shared.Enums; using Remotely.Shared.Models; +using System; +using System.Collections.Generic; namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { @@ -37,17 +37,17 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage { var from = Input.FromDate ?? DateTimeOffset.MinValue; var to = Input.ToDate ?? DateTimeOffset.MaxValue; - EventLogs = DataService.GetEventLogs(User.Identity.Name, + EventLogs = DataService.GetEventLogs(User.Identity.Name, from, - to, + to, Input.Type, Input.Message); } else { - EventLogs = DataService.GetEventLogs(User.Identity.Name, + EventLogs = DataService.GetEventLogs(User.Identity.Name, DateTimeOffset.Now.AddDays(-10), - DateTimeOffset.Now, + DateTimeOffset.Now, Input.Type, Input.Message); } diff --git a/Server/Areas/Identity/Pages/Account/Register.cshtml.cs b/Server/Areas/Identity/Pages/Account/Register.cshtml.cs index 67102127..85fb532f 100644 --- a/Server/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -1,10 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -13,6 +7,12 @@ using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; using Remotely.Server.Services; using Remotely.Shared.Models; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; namespace Remotely.Server.Areas.Identity.Pages.Account { @@ -81,7 +81,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account { return NotFound(); } - returnUrl = returnUrl ?? Url.Content("~/"); + returnUrl ??= Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { @@ -102,7 +102,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, - values: new { area = "Identity", userId = user.Id, code = code }, + values: new { area = "Identity", userId = user.Id, code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", diff --git a/Server/Attributes/ActionRateLimiterAttribute.cs b/Server/Attributes/ActionRateLimiterAttribute.cs index 2c6fc873..09aca09e 100644 --- a/Server/Attributes/ActionRateLimiterAttribute.cs +++ b/Server/Attributes/ActionRateLimiterAttribute.cs @@ -1,10 +1,7 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Caching.Memory; using System; -using System.Collections.Generic; -using System.Linq; using System.Net; -using System.Threading.Tasks; namespace Remotely.Server.Attributes { diff --git a/Server/Attributes/ApiAuthorizationFilter.cs b/Server/Attributes/ApiAuthorizationFilter.cs index e99a4811..ebed44bc 100644 --- a/Server/Attributes/ApiAuthorizationFilter.cs +++ b/Server/Attributes/ApiAuthorizationFilter.cs @@ -15,7 +15,7 @@ namespace Remotely.Server.Attributes public void OnAuthorization(AuthorizationFilterContext context) { - + if (context.HttpContext.User.Identity.IsAuthenticated) { var orgID = DataService.GetUserByName(context.HttpContext.User.Identity.Name)?.OrganizationID; @@ -27,7 +27,7 @@ namespace Remotely.Server.Attributes { var apiToken = result.ToString().Split(":")[0]?.Trim(); var apiSecret = result.ToString().Split(":")[1]?.Trim(); - + if (DataService.ValidateApiToken(apiToken, apiSecret, context.HttpContext.Request.Path, context.HttpContext.Connection.RemoteIpAddress.ToString())) { var orgID = DataService.GetApiToken(apiToken)?.OrganizationID; diff --git a/Server/Attributes/RemoteControlFilterAttribute.cs b/Server/Attributes/RemoteControlFilterAttribute.cs index bbc7f60d..19129941 100644 --- a/Server/Attributes/RemoteControlFilterAttribute.cs +++ b/Server/Attributes/RemoteControlFilterAttribute.cs @@ -1,14 +1,9 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Caching.Memory; using Remotely.Server.Services; -using Remotely.Shared.Services; using Remotely.Shared.Utilities; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Remotely.Server.Attributes { diff --git a/Server/Data/ApplicationDbContext.cs b/Server/Data/ApplicationDbContext.cs index 3b65cc24..1d7728dd 100644 --- a/Server/Data/ApplicationDbContext.cs +++ b/Server/Data/ApplicationDbContext.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using Remotely.Shared.Models; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Remotely.Shared.Models; +using System; +using System.Collections.Generic; using System.Linq; using System.Text.Json; -using Microsoft.EntityFrameworkCore.ChangeTracking; namespace Remotely.Server.Data { @@ -49,10 +49,10 @@ namespace Remotely.Server.Data builder.Entity() .HasMany(x => x.Devices) - .WithOne(x=>x.Organization); + .WithOne(x => x.Organization); builder.Entity() .HasMany(x => x.RemotelyUsers) - .WithOne(x=> x.Organization); + .WithOne(x => x.Organization); builder.Entity() .HasMany(x => x.CommandResults) .WithOne(x => x.Organization); @@ -82,7 +82,7 @@ namespace Remotely.Server.Data builder.Entity() - .Property(x=>x.TargetDeviceIDs) + .Property(x => x.TargetDeviceIDs) .HasConversion( x => JsonSerializer.Serialize(x, null), x => JsonSerializer.Deserialize(x, null)); diff --git a/Server/Hubs/AgentHub.cs b/Server/Hubs/AgentHub.cs index 4508efb9..ac3d6e7c 100644 --- a/Server/Hubs/AgentHub.cs +++ b/Server/Hubs/AgentHub.cs @@ -1,13 +1,13 @@ -using Remotely.Shared.Models; -using Microsoft.AspNetCore.SignalR; +using Microsoft.AspNetCore.SignalR; +using Microsoft.Extensions.Caching.Memory; +using Remotely.Server.Services; +using Remotely.Shared.Enums; +using Remotely.Shared.Models; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.Extensions.Caching.Memory; -using Remotely.Shared.Enums; -using Remotely.Server.Services; namespace Remotely.Server.Hubs { @@ -27,23 +27,23 @@ namespace Remotely.Server.Hubs public IHubContext ViewerHubContext { get; } private IHubContext BrowserHubContext { get; } private DataService DataService { get; } - private Device Device - { - get - { - return this.Context.Items["Device"] as Device; - } - set - { - this.Context.Items["Device"] = value; - } - } + private Device Device + { + get + { + return this.Context.Items["Device"] as Device; + } + set + { + this.Context.Items["Device"] = value; + } + } - public Task BashResultViaAjax(string commandID) - { - var commandResult = DataService.GetCommandResult(commandID); - return BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("BashResultViaAjax", commandID, Device.ID); - } + public Task BashResultViaAjax(string commandID) + { + var commandResult = DataService.GetCommandResult(commandID); + return BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("BashResultViaAjax", commandID, Device.ID); + } public Task Chat(string message, bool disconnected, string senderConnectionID) { @@ -58,19 +58,19 @@ namespace Remotely.Server.Hubs } public Task CMDResultViaAjax(string commandID) - { - var commandResult = DataService.GetCommandResult(commandID); + { + var commandResult = DataService.GetCommandResult(commandID); return BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("CMDResultViaAjax", commandID, Device.ID); - } + } public Task CommandResult(GenericCommandResult result) - { - result.DeviceID = Device.ID; - var commandResult = DataService.GetCommandResult(result.CommandResultID); - commandResult.CommandResults.Add(result); - DataService.AddOrUpdateCommandResult(commandResult); + { + result.DeviceID = Device.ID; + var commandResult = DataService.GetCommandResult(result.CommandResultID); + commandResult.CommandResults.Add(result); + DataService.AddOrUpdateCommandResult(commandResult); return BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("CommandResult", result); - } + } public void CommandResultViaApi(string commandID, string requestID) { @@ -98,7 +98,7 @@ namespace Remotely.Server.Hubs { Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); - + var userIDs = BrowserHub.ConnectionIdToUserLookup.Values.Select(x => x.Id); var filteredUserIDs = DataService.FilterUsersByDevicePermission(userIDs, Device.ID); @@ -149,7 +149,7 @@ namespace Remotely.Server.Hubs public Task DisplayMessage(string consoleMessage, string popupMessage, string requesterID) { return BrowserHubContext.Clients.Client(requesterID).SendAsync("DisplayMessage", consoleMessage, popupMessage); - } + } public Task DownloadFile(string fileID, string requesterID) { return BrowserHubContext.Clients.Client(requesterID).SendAsync("DownloadFile", fileID); @@ -160,7 +160,7 @@ namespace Remotely.Server.Hubs } public override Task OnConnectedAsync() - { + { return base.OnConnectedAsync(); } public override async Task OnDisconnectedAsync(Exception exception) @@ -180,7 +180,7 @@ namespace Remotely.Server.Hubs ServiceConnections.Remove(Context.ConnectionId, out _); } - + await base.OnDisconnectedAsync(exception); } public Task PSCoreResult(PSCoreCommandResult result) @@ -191,11 +191,11 @@ namespace Remotely.Server.Hubs DataService.AddOrUpdateCommandResult(commandResult); return BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("PSCoreResult", result); } - public async void PSCoreResultViaAjax(string commandID) - { - var commandResult = DataService.GetCommandResult(commandID); - await BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("PSCoreResultViaAjax", commandID, Device.ID); - } + public async void PSCoreResultViaAjax(string commandID) + { + var commandResult = DataService.GetCommandResult(commandID); + await BrowserHubContext.Clients.Client(commandResult.SenderConnectionID).SendAsync("PSCoreResultViaAjax", commandID, Device.ID); + } public Task SendConnectionFailedToViewers(List viewerIDs) { diff --git a/Server/Hubs/BrowserHub.cs b/Server/Hubs/BrowserHub.cs index 4fc82c9c..e1f196b2 100644 --- a/Server/Hubs/BrowserHub.cs +++ b/Server/Hubs/BrowserHub.cs @@ -1,15 +1,15 @@ -using Remotely.Shared.Models; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.SignalR; +using Remotely.Server.Services; +using Remotely.Shared.Enums; +using Remotely.Shared.Models; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Remotely.Shared.Enums; -using Remotely.Server.Services; namespace Remotely.Server.Hubs { @@ -17,8 +17,8 @@ namespace Remotely.Server.Hubs public class BrowserHub : Hub { public BrowserHub( - DataService dataService, - SignInManager signInManager, + DataService dataService, + SignInManager signInManager, IHubContext agentHubContext, ApplicationConfig appConfig) { @@ -31,7 +31,7 @@ namespace Remotely.Server.Hubs public static ConcurrentDictionary ConnectionIdToUserLookup { get; } = new ConcurrentDictionary(); private ApplicationConfig AppConfig { get; } private DataService DataService { get; } - private IHubContext AgentHubContext { get; } + private IHubContext AgentHubContext { get; } private RemotelyUser RemotelyUser { get @@ -52,7 +52,7 @@ namespace Remotely.Server.Hubs var organizationName = DataService.GetOrganizationName(RemotelyUser.UserName); return AgentHubContext.Clients.Clients(connections.Select(x => x.Key).ToList()).SendAsync("Chat", RemotelyUser.DisplayName ?? RemotelyUser.UserName, - message, + message, organizationName, false, Context.ConnectionId); @@ -115,47 +115,47 @@ namespace Remotely.Server.Hubs } public override async Task OnConnectedAsync() - { - RemotelyUser = DataService.GetUserByID(Context.UserIdentifier); - if (await IsConnectionValid() == false) - { - return; - } + { + RemotelyUser = DataService.GetUserByID(Context.UserIdentifier); + if (await IsConnectionValid() == false) + { + return; + } ConnectionIdToUserLookup.AddOrUpdate(Context.ConnectionId, RemotelyUser, (id, ru) => RemotelyUser); await Clients.Caller.SendAsync("UserOptions", RemotelyUser.UserOptions); - await base.OnConnectedAsync(); - } + await base.OnConnectedAsync(); + } - public override async Task OnDisconnectedAsync(Exception exception) - { + public override async Task OnDisconnectedAsync(Exception exception) + { ConnectionIdToUserLookup.Remove(Context.ConnectionId, out _); await base.OnDisconnectedAsync(exception); - } + } - public Task RemoteControl(string deviceID) - { + public Task RemoteControl(string deviceID) + { var targetDevice = AgentHub.ServiceConnections.FirstOrDefault(x => x.Value.ID == deviceID); if (targetDevice.Value is null) { return Clients.Caller.SendAsync("DisplayMessage", $"The selected device is not online.", "Device is not online."); ; } if (DataService.DoesUserHaveAccessToDevice(deviceID, RemotelyUser)) - { - var currentUsers = CasterHub.SessionInfoList.Count(x => x.Value.OrganizationID == RemotelyUser.OrganizationID); - if (currentUsers >= AppConfig.RemoteControlSessionLimit) - { - return Clients.Caller.SendAsync("DisplayMessage", $"There are already the maximum amount of active remote control sessions for your organization.", "Max number of concurrent sessions reached."); - } - Clients.Caller.SendAsync("ServiceID", targetDevice.Key); + { + var currentUsers = CasterHub.SessionInfoList.Count(x => x.Value.OrganizationID == RemotelyUser.OrganizationID); + if (currentUsers >= AppConfig.RemoteControlSessionLimit) + { + return Clients.Caller.SendAsync("DisplayMessage", $"There are already the maximum amount of active remote control sessions for your organization.", "Max number of concurrent sessions reached."); + } + Clients.Caller.SendAsync("ServiceID", targetDevice.Key); return AgentHubContext.Clients.Client(targetDevice.Key).SendAsync("RemoteControl", Context.ConnectionId, targetDevice.Key); - } + } else { DataService.WriteEvent($"Remote control attempted by unauthorized user. Device ID: {deviceID}. User Name: {RemotelyUser.UserName}.", EventType.Warning, targetDevice.Value.OrganizationID); } return Task.CompletedTask; - } + } public Task RemoveDevices(string[] deviceIDs) { @@ -216,7 +216,7 @@ namespace Remotely.Server.Hubs } private async Task IsConnectionValid() { - if (Context?.User?.Identity?.IsAuthenticated != true || + if (Context?.User?.Identity?.IsAuthenticated != true || await SignInManager.UserManager.IsLockedOutAsync(RemotelyUser)) { _ = Clients.Caller.SendAsync("LockedOut"); diff --git a/Server/Hubs/CasterHub.cs b/Server/Hubs/CasterHub.cs index c9d1d5fe..f5389873 100644 --- a/Server/Hubs/CasterHub.cs +++ b/Server/Hubs/CasterHub.cs @@ -1,12 +1,11 @@ using Microsoft.AspNetCore.SignalR; +using Remotely.Server.Models; +using Remotely.Server.Services; +using Remotely.Shared.Models; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; -using System.Drawing; -using Remotely.Shared.Models; -using Remotely.Server.Models; -using Remotely.Server.Services; namespace Remotely.Server.Hubs { diff --git a/Server/Hubs/ViewerHub.cs b/Server/Hubs/ViewerHub.cs index b8025f15..fe1a1efe 100644 --- a/Server/Hubs/ViewerHub.cs +++ b/Server/Hubs/ViewerHub.cs @@ -1,16 +1,13 @@ -using Remotely.Shared.Models; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Remotely.Shared.Enums; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; using Remotely.Server.Attributes; using Remotely.Server.Models; using Remotely.Server.Services; -using Remotely.Shared.Models.RemoteControlDtos; +using Remotely.Shared.Enums; +using Remotely.Shared.Models; +using System; +using System.Linq; +using System.Threading.Tasks; namespace Remotely.Server.Hubs { @@ -85,15 +82,15 @@ namespace Remotely.Server.Hubs Context.Items["ScreenCasterID"] = value; } } - + public Task ChangeWindowsSession(int sessionID) { if (SessionInfo?.Mode == RemoteControlMode.Unattended) { return AgentHubContext.Clients .Client(SessionInfo.ServiceID) - .SendAsync("ChangeWindowsSession", - SessionInfo.ServiceID, + .SendAsync("ChangeWindowsSession", + SessionInfo.ServiceID, Context.ConnectionId, sessionID); } @@ -118,8 +115,8 @@ namespace Remotely.Server.Hubs } return base.OnDisconnectedAsync(exception); - } - + } + public Task SendIceCandidateToAgent(string candidate, int sdpMlineIndex, string sdpMid) { return CasterHubContext.Clients.Client(ScreenCasterID).SendAsync("ReceiveIceCandidate", candidate, sdpMlineIndex, sdpMid, Context.ConnectionId); @@ -159,7 +156,7 @@ namespace Remotely.Server.Hubs var user = DataService.GetUserByID(Context.UserIdentifier); RequesterName = user.DisplayName ?? user.UserName; orgId = user.OrganizationID; - var currentUsers = CasterHub.SessionInfoList.Count(x => + var currentUsers = CasterHub.SessionInfoList.Count(x => x.Key != screenCasterID && x.Value.OrganizationID == orgId); if (currentUsers >= AppConfig.RemoteControlSessionLimit) @@ -182,8 +179,8 @@ namespace Remotely.Server.Hubs $"Machine Name: {SessionInfo.MachineName}. " + $"Requester Name (if specified): {RequesterName}. " + $"Connection ID: {Context.ConnectionId}. User ID: {Context.UserIdentifier}. " + - $"Screen Caster ID: {screenCasterID}. " + - $"Mode: {(RemoteControlMode)remoteControlMode}. " + + $"Screen Caster ID: {screenCasterID}. " + + $"Mode: {(RemoteControlMode)remoteControlMode}. " + $"Requester IP Address: " + Context?.GetHttpContext()?.Connection?.RemoteIpAddress?.ToString(), OrganizationID = orgId }); @@ -194,7 +191,7 @@ namespace Remotely.Server.Hubs var deviceID = AgentHub.ServiceConnections[SessionInfo.ServiceID].ID; if ((!string.IsNullOrWhiteSpace(otp) && - RemoteControlFilterAttribute.OtpMatchesDevice(otp, deviceID)) + RemoteControlFilterAttribute.OtpMatchesDevice(otp, deviceID)) || (Context.User.Identity.IsAuthenticated && DataService.DoesUserHaveAccessToDevice(deviceID, Context.UserIdentifier))) @@ -213,6 +210,6 @@ namespace Remotely.Server.Hubs return CasterHubContext.Clients.Client(screenCasterID).SendAsync("RequestScreenCast", Context.ConnectionId, RequesterName, AppConfig.RemoteControlNotifyUser); } } - + } } diff --git a/Server/Models/RCSessionInfo.cs b/Server/Models/RCSessionInfo.cs index aa4b3bcb..bcfeb88f 100644 --- a/Server/Models/RCSessionInfo.cs +++ b/Server/Models/RCSessionInfo.cs @@ -1,6 +1,5 @@ using Remotely.Shared.Enums; using System; -using System.Collections.Concurrent; namespace Remotely.Server.Models { diff --git a/Server/Models/RemoteControlFrame.cs b/Server/Models/RemoteControlFrame.cs index 9ac7b222..23caa804 100644 --- a/Server/Models/RemoteControlFrame.cs +++ b/Server/Models/RemoteControlFrame.cs @@ -5,13 +5,13 @@ namespace Remotely.Server.Models public class RemoteControlFrame { - public RemoteControlFrame(byte[] frameBytes, + public RemoteControlFrame(byte[] frameBytes, int left, - int top, + int top, int screenWidth, int screenHeight, bool endOfFrame, - string viewerID, + string viewerID, string machineName, DateTimeOffset startTime) { diff --git a/Server/Pages/EditDevice.cshtml.cs b/Server/Pages/EditDevice.cshtml.cs index e85d385f..5c2cd22b 100644 --- a/Server/Pages/EditDevice.cshtml.cs +++ b/Server/Pages/EditDevice.cshtml.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Remotely.Server.Services; using Remotely.Shared.Enums; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; namespace Remotely.Server.Pages { diff --git a/Server/Pages/Error.cshtml.cs b/Server/Pages/Error.cshtml.cs index 31406484..64166c68 100644 --- a/Server/Pages/Error.cshtml.cs +++ b/Server/Pages/Error.cshtml.cs @@ -1,9 +1,9 @@ -using System.Diagnostics; -using Remotely.Server.Services; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Remotely.Server.Services; using Remotely.Shared.Enums; +using System.Diagnostics; namespace Remotely.Server.Pages { diff --git a/Server/Pages/GetSupport.cshtml.cs b/Server/Pages/GetSupport.cshtml.cs index 1fb84d52..41d2b341 100644 --- a/Server/Pages/GetSupport.cshtml.cs +++ b/Server/Pages/GetSupport.cshtml.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Remotely.Server.Services; +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; namespace Remotely.Server.Pages { diff --git a/Server/Pages/Index.cshtml.cs b/Server/Pages/Index.cshtml.cs index 7eb43615..9ddf0602 100644 --- a/Server/Pages/Index.cshtml.cs +++ b/Server/Pages/Index.cshtml.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Remotely.Shared.Models; using Microsoft.AspNetCore.Mvc.Rendering; using Remotely.Server.Services; +using Remotely.Shared.Models; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace Remotely.Server.Pages { public class IndexModel : PageModel { - public IndexModel(DataService dataService, + public IndexModel(DataService dataService, SignInManager signInManager, ApplicationConfig appConfig) { diff --git a/Server/Pages/Invite.cshtml.cs b/Server/Pages/Invite.cshtml.cs index a76b028a..b287fd4a 100644 --- a/Server/Pages/Invite.cshtml.cs +++ b/Server/Pages/Invite.cshtml.cs @@ -1,7 +1,7 @@ -using Remotely.Server.Services; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Remotely.Server.Services; namespace Remotely.Server.Pages { diff --git a/Server/Pages/RemoteControl.cshtml.cs b/Server/Pages/RemoteControl.cshtml.cs index 9bda6716..510d80f8 100644 --- a/Server/Pages/RemoteControl.cshtml.cs +++ b/Server/Pages/RemoteControl.cshtml.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Remotely.Server.Attributes; diff --git a/Server/Services/CleanupService.cs b/Server/Services/CleanupService.cs index d6598923..b4448060 100644 --- a/Server/Services/CleanupService.cs +++ b/Server/Services/CleanupService.cs @@ -1,8 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -40,12 +38,10 @@ namespace Remotely.Server.Services private void CleanupTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { - using (var scope = Services.CreateScope()) - { - var dataService = scope.ServiceProvider.GetRequiredService(); + using var scope = Services.CreateScope(); + var dataService = scope.ServiceProvider.GetRequiredService(); - dataService.CleanupOldRecords(); - } + dataService.CleanupOldRecords(); } } } diff --git a/Server/Services/DataService.cs b/Server/Services/DataService.cs index 644d99f2..3e8e92b9 100644 --- a/Server/Services/DataService.cs +++ b/Server/Services/DataService.cs @@ -1,26 +1,24 @@ -using Remotely.Shared.Models; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Remotely.Server.Data; +using Remotely.Shared.Enums; +using Remotely.Shared.Models; +using Remotely.Shared.ViewModels.Organization; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Remotely.Shared.ViewModels.Organization; -using Remotely.Server.Data; -using Microsoft.Extensions.Hosting; using System.Threading.Tasks; -using Remotely.Shared.Enums; -using Microsoft.Extensions.Logging; -using System.Threading; -using System.Security.Cryptography.X509Certificates; namespace Remotely.Server.Services { public class DataService { - public DataService(ApplicationDbContext context, - ApplicationConfig appConfig, + public DataService(ApplicationDbContext context, + ApplicationConfig appConfig, IHostEnvironment hostEnvironment, UserManager userManager) { @@ -47,7 +45,8 @@ namespace Remotely.Server.Services users = users.Where(x => filteredUserIDs.Contains(x.Id)); } - await users.ForEachAsync(x => { + await users.ForEachAsync(x => + { var alert = new Alert() { CreatedOn = DateTimeOffset.Now, @@ -57,7 +56,7 @@ namespace Remotely.Server.Services }; x.Alerts.Add(alert); }); - + await RemotelyContext.SaveChangesAsync(); } @@ -69,8 +68,8 @@ namespace Remotely.Server.Services var organization = RemotelyContext.Organizations .Include(x => x.DeviceGroups) .FirstOrDefault(x => x.ID == orgID); - - if (RemotelyContext.DeviceGroups.Any(x => + + if (RemotelyContext.DeviceGroups.Any(x => x.OrganizationID == orgID && x.Name.ToLower() == deviceGroup.Name.ToLower())) { @@ -379,7 +378,7 @@ namespace Remotely.Server.Services WriteEvent(ex, options.OrganizationID); return null; } - + } public async Task CreateUser(string userEmail, bool isAdmin, string organizationID) @@ -901,7 +900,7 @@ namespace Remotely.Server.Services .FirstOrDefault(x => x.ID == orgID) .RemotelyUsers.Remove(target); - + RemotelyContext.Users.Remove(target); await UserManager.DeleteAsync(target); @@ -1137,7 +1136,7 @@ namespace Remotely.Server.Services RemotelyContext.SaveChanges(); } catch { } - + } } } diff --git a/Server/Services/DbLogger.cs b/Server/Services/DbLogger.cs index 229980f9..ff5ebd95 100644 --- a/Server/Services/DbLogger.cs +++ b/Server/Services/DbLogger.cs @@ -4,10 +4,8 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Linq; using System.Threading; -using System.Threading.Tasks; namespace Remotely.Server.Services { diff --git a/Server/Services/DbLoggerProvider.cs b/Server/Services/DbLoggerProvider.cs index e39e9927..fca92c05 100644 --- a/Server/Services/DbLoggerProvider.cs +++ b/Server/Services/DbLoggerProvider.cs @@ -1,9 +1,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Logging; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Remotely.Server.Services { diff --git a/Server/Services/EmailSender.cs b/Server/Services/EmailSender.cs index a88402e2..c2e11bba 100644 --- a/Server/Services/EmailSender.cs +++ b/Server/Services/EmailSender.cs @@ -1,8 +1,8 @@ +using Microsoft.AspNetCore.Identity.UI.Services; using System; using System.Net; using System.Net.Mail; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity.UI.Services; namespace Remotely.Server.Services { @@ -27,20 +27,24 @@ namespace Remotely.Server.Services { try { - var mailClient = new SmtpClient(); - mailClient.Host = AppConfig.SmtpHost; - mailClient.Port = AppConfig.SmtpPort; - mailClient.EnableSsl = AppConfig.SmtpEnableSsl; - mailClient.Credentials = new NetworkCredential(AppConfig.SmtpUserName, AppConfig.SmtpPassword); - mailClient.DeliveryMethod = SmtpDeliveryMethod.Network; + var mailClient = new SmtpClient + { + Host = AppConfig.SmtpHost, + Port = AppConfig.SmtpPort, + EnableSsl = AppConfig.SmtpEnableSsl, + Credentials = new NetworkCredential(AppConfig.SmtpUserName, AppConfig.SmtpPassword), + DeliveryMethod = SmtpDeliveryMethod.Network + }; var from = new MailAddress(AppConfig.SmtpEmail, AppConfig.SmtpDisplayName, System.Text.Encoding.UTF8); var to = new MailAddress(email); - var mailMessage = new MailMessage(from, to); - mailMessage.IsBodyHtml = true; - mailMessage.Subject = subject; - mailMessage.Body = htmlMessage; + var mailMessage = new MailMessage(from, to) + { + IsBodyHtml = true, + Subject = subject, + Body = htmlMessage + }; mailMessage.ReplyToList.Add(new MailAddress(replyTo)); mailClient.Send(mailMessage); DataService.WriteEvent($"Email successfully sent to {email}. Subject: \"{subject}\".", organizationID); diff --git a/Server/Services/PascalCasePolicy.cs b/Server/Services/PascalCasePolicy.cs index 9a91c5d4..79083e00 100644 --- a/Server/Services/PascalCasePolicy.cs +++ b/Server/Services/PascalCasePolicy.cs @@ -13,7 +13,7 @@ namespace Remotely.Server.Services } var first = name.First().ToString().ToUpper(); - + return first + new string(name.Skip(1).ToArray()); } } diff --git a/Server/Startup.cs b/Server/Startup.cs index 98ba43f9..f0ab49f2 100644 --- a/Server/Startup.cs +++ b/Server/Startup.cs @@ -1,28 +1,27 @@ -using System; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.HttpOverrides; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.StaticFiles; using Microsoft.EntityFrameworkCore; -using Remotely.Server.Data; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Identity.UI.Services; -using System.IO; -using Remotely.Server.Services; using Microsoft.Extensions.FileProviders; -using Microsoft.AspNetCore.StaticFiles; -using Remotely.Shared.Models; -using Remotely.Shared.Services; -using Microsoft.AspNetCore.HttpOverrides; -using System.Net; using Microsoft.Extensions.Hosting; -using Microsoft.OpenApi.Models; -using Remotely.Server.Attributes; -using Npgsql; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using Npgsql; +using Remotely.Server.Attributes; +using Remotely.Server.Data; using Remotely.Server.Hubs; +using Remotely.Server.Services; +using Remotely.Shared.Models; +using System; +using System.IO; +using System.Net; namespace Remotely.Server { @@ -59,8 +58,10 @@ namespace Remotely.Server // See https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1 if (!string.IsNullOrWhiteSpace(Configuration.GetValue("PostgresPassword"))) { - var connectionBuilder = new NpgsqlConnectionStringBuilder(Configuration.GetConnectionString("PostgreSQL")); - connectionBuilder.Password = Configuration["PostgresPassword"]; + var connectionBuilder = new NpgsqlConnectionStringBuilder(Configuration.GetConnectionString("PostgreSQL")) + { + Password = Configuration["PostgresPassword"] + }; services.AddDbContext(options => options.UseNpgsql(connectionBuilder.ConnectionString)); } @@ -77,7 +78,7 @@ namespace Remotely.Server .AddDefaultTokenProviders(); var trustedOrigins = Configuration.GetSection("ApplicationOptions:TrustedCorsOrigins").Get(); - + if (trustedOrigins != null) { services.AddCors(options => @@ -137,9 +138,9 @@ namespace Remotely.Server } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, - IWebHostEnvironment env, - ApplicationDbContext context, + public void Configure(IApplicationBuilder app, + IWebHostEnvironment env, + ApplicationDbContext context, DataService dataService, ILoggerFactory loggerFactory) { @@ -208,7 +209,7 @@ namespace Remotely.Server routeBuilder.MapRazorPages(); routeBuilder.MapControllers(); - + }); try diff --git a/Shared/Enums/EventType.cs b/Shared/Enums/EventType.cs index 3d2d5daf..1b6dc945 100644 --- a/Shared/Enums/EventType.cs +++ b/Shared/Enums/EventType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Remotely.Shared.Enums +namespace Remotely.Shared.Enums { public enum EventType { diff --git a/Shared/Helpers/Disposer.cs b/Shared/Helpers/Disposer.cs index 28a081e0..33797058 100644 --- a/Shared/Helpers/Disposer.cs +++ b/Shared/Helpers/Disposer.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Remotely.Shared.Helpers { diff --git a/Shared/Models/ChatMessage.cs b/Shared/Models/ChatMessage.cs index 7011074a..9e45e75f 100644 --- a/Shared/Models/ChatMessage.cs +++ b/Shared/Models/ChatMessage.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Remotely.Shared.Models +namespace Remotely.Shared.Models { public class ChatMessage { diff --git a/Shared/Models/IceServerModel.cs b/Shared/Models/IceServerModel.cs index 6c4e9feb..e6afaa33 100644 --- a/Shared/Models/IceServerModel.cs +++ b/Shared/Models/IceServerModel.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Remotely.Shared.Models +namespace Remotely.Shared.Models { public class IceServerModel { diff --git a/Shared/Models/RemoteControlDtos/AudioSampleDto.cs b/Shared/Models/RemoteControlDtos/AudioSampleDto.cs index 23080ae2..02d4935e 100644 --- a/Shared/Models/RemoteControlDtos/AudioSampleDto.cs +++ b/Shared/Models/RemoteControlDtos/AudioSampleDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/AutoQualityAdjustDto.cs b/Shared/Models/RemoteControlDtos/AutoQualityAdjustDto.cs index 41e596b0..0c8043d8 100644 --- a/Shared/Models/RemoteControlDtos/AutoQualityAdjustDto.cs +++ b/Shared/Models/RemoteControlDtos/AutoQualityAdjustDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ClipboardTextDto.cs b/Shared/Models/RemoteControlDtos/ClipboardTextDto.cs index 3a382eb1..1b18363c 100644 --- a/Shared/Models/RemoteControlDtos/ClipboardTextDto.cs +++ b/Shared/Models/RemoteControlDtos/ClipboardTextDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ClipboardTransferDto.cs b/Shared/Models/RemoteControlDtos/ClipboardTransferDto.cs index e111b411..820f8a15 100644 --- a/Shared/Models/RemoteControlDtos/ClipboardTransferDto.cs +++ b/Shared/Models/RemoteControlDtos/ClipboardTransferDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/CursorChangeDto.cs b/Shared/Models/RemoteControlDtos/CursorChangeDto.cs index b5315002..e635060f 100644 --- a/Shared/Models/RemoteControlDtos/CursorChangeDto.cs +++ b/Shared/Models/RemoteControlDtos/CursorChangeDto.cs @@ -1,9 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; -using System.Drawing; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/FileDto.cs b/Shared/Models/RemoteControlDtos/FileDto.cs index 61e5ac92..e813ba3f 100644 --- a/Shared/Models/RemoteControlDtos/FileDto.cs +++ b/Shared/Models/RemoteControlDtos/FileDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/KeyDownDto.cs b/Shared/Models/RemoteControlDtos/KeyDownDto.cs index 2ee9bd96..6cdcbd79 100644 --- a/Shared/Models/RemoteControlDtos/KeyDownDto.cs +++ b/Shared/Models/RemoteControlDtos/KeyDownDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/KeyPressDto.cs b/Shared/Models/RemoteControlDtos/KeyPressDto.cs index e3773055..99d4125d 100644 --- a/Shared/Models/RemoteControlDtos/KeyPressDto.cs +++ b/Shared/Models/RemoteControlDtos/KeyPressDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/KeyUpDto.cs b/Shared/Models/RemoteControlDtos/KeyUpDto.cs index 5f7ec848..29278abc 100644 --- a/Shared/Models/RemoteControlDtos/KeyUpDto.cs +++ b/Shared/Models/RemoteControlDtos/KeyUpDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/MachineNameDto.cs b/Shared/Models/RemoteControlDtos/MachineNameDto.cs index b135bf5c..0670d60e 100644 --- a/Shared/Models/RemoteControlDtos/MachineNameDto.cs +++ b/Shared/Models/RemoteControlDtos/MachineNameDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/MouseDownDto.cs b/Shared/Models/RemoteControlDtos/MouseDownDto.cs index ed9781eb..2b3f4f80 100644 --- a/Shared/Models/RemoteControlDtos/MouseDownDto.cs +++ b/Shared/Models/RemoteControlDtos/MouseDownDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/MouseMoveDto.cs b/Shared/Models/RemoteControlDtos/MouseMoveDto.cs index e29c5c91..ddd3a117 100644 --- a/Shared/Models/RemoteControlDtos/MouseMoveDto.cs +++ b/Shared/Models/RemoteControlDtos/MouseMoveDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/MouseUpDto.cs b/Shared/Models/RemoteControlDtos/MouseUpDto.cs index 872150c5..2e6a557a 100644 --- a/Shared/Models/RemoteControlDtos/MouseUpDto.cs +++ b/Shared/Models/RemoteControlDtos/MouseUpDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/MouseWheelDto.cs b/Shared/Models/RemoteControlDtos/MouseWheelDto.cs index 8a9f41ce..d37b02b8 100644 --- a/Shared/Models/RemoteControlDtos/MouseWheelDto.cs +++ b/Shared/Models/RemoteControlDtos/MouseWheelDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/QualityChangeDto.cs b/Shared/Models/RemoteControlDtos/QualityChangeDto.cs index 8506cb81..9100e442 100644 --- a/Shared/Models/RemoteControlDtos/QualityChangeDto.cs +++ b/Shared/Models/RemoteControlDtos/QualityChangeDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ScreenDataDto.cs b/Shared/Models/RemoteControlDtos/ScreenDataDto.cs index 27b2c83f..8a00a04b 100644 --- a/Shared/Models/RemoteControlDtos/ScreenDataDto.cs +++ b/Shared/Models/RemoteControlDtos/ScreenDataDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ScreenSizeDto.cs b/Shared/Models/RemoteControlDtos/ScreenSizeDto.cs index 5b17902d..f7b6c038 100644 --- a/Shared/Models/RemoteControlDtos/ScreenSizeDto.cs +++ b/Shared/Models/RemoteControlDtos/ScreenSizeDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/SelectScreenDto.cs b/Shared/Models/RemoteControlDtos/SelectScreenDto.cs index b13e7df9..1475b0ce 100644 --- a/Shared/Models/RemoteControlDtos/SelectScreenDto.cs +++ b/Shared/Models/RemoteControlDtos/SelectScreenDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/TapDto.cs b/Shared/Models/RemoteControlDtos/TapDto.cs index 27f27983..93f2c9d3 100644 --- a/Shared/Models/RemoteControlDtos/TapDto.cs +++ b/Shared/Models/RemoteControlDtos/TapDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ToggleAudioDto.cs b/Shared/Models/RemoteControlDtos/ToggleAudioDto.cs index 0451132f..68665383 100644 --- a/Shared/Models/RemoteControlDtos/ToggleAudioDto.cs +++ b/Shared/Models/RemoteControlDtos/ToggleAudioDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ToggleBlockInputDto.cs b/Shared/Models/RemoteControlDtos/ToggleBlockInputDto.cs index b3d23d76..0853499d 100644 --- a/Shared/Models/RemoteControlDtos/ToggleBlockInputDto.cs +++ b/Shared/Models/RemoteControlDtos/ToggleBlockInputDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/ToggleWebRtcVideoDto.cs b/Shared/Models/RemoteControlDtos/ToggleWebRtcVideoDto.cs index 8f167fe4..8ab705cf 100644 --- a/Shared/Models/RemoteControlDtos/ToggleWebRtcVideoDto.cs +++ b/Shared/Models/RemoteControlDtos/ToggleWebRtcVideoDto.cs @@ -1,8 +1,5 @@ using Remotely.Shared.Enums; -using System; -using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemoteControlDtos/WindowsSessionsDto.cs b/Shared/Models/RemoteControlDtos/WindowsSessionsDto.cs index df3dac9d..eee26e43 100644 --- a/Shared/Models/RemoteControlDtos/WindowsSessionsDto.cs +++ b/Shared/Models/RemoteControlDtos/WindowsSessionsDto.cs @@ -1,8 +1,6 @@ using Remotely.Shared.Enums; -using System; using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace Remotely.Shared.Models.RemoteControlDtos { diff --git a/Shared/Models/RemotelyUserOptions.cs b/Shared/Models/RemotelyUserOptions.cs index a28be225..a339a213 100644 --- a/Shared/Models/RemotelyUserOptions.cs +++ b/Shared/Models/RemotelyUserOptions.cs @@ -5,10 +5,10 @@ namespace Remotely.Shared.Models { public class RemotelyUserOptions { - [Display(Name ="Console Prompt")] + [Display(Name = "Console Prompt")] [StringLength(5)] public string ConsolePrompt { get; set; } = "~>"; - + [Display(Name = "Web Shortcut")] [StringLength(10)] public string CommandModeShortcutWeb { get; set; } = "/web"; diff --git a/Shared/Utilities/Logger.cs b/Shared/Utilities/Logger.cs index 63187098..688ea0d2 100644 --- a/Shared/Utilities/Logger.cs +++ b/Shared/Utilities/Logger.cs @@ -1,5 +1,4 @@ using Remotely.Shared.Enums; -using Remotely.Shared.Utilities; using System; using System.Diagnostics; using System.IO; diff --git a/Shared/Utilities/PasswordGenerator.cs b/Shared/Utilities/PasswordGenerator.cs index b3249645..ceac9fda 100644 --- a/Shared/Utilities/PasswordGenerator.cs +++ b/Shared/Utilities/PasswordGenerator.cs @@ -1,5 +1,5 @@ -using System.Security.Cryptography; -using System; +using System; +using System.Security.Cryptography; namespace Remotely.Shared.Utilities { @@ -7,7 +7,7 @@ namespace Remotely.Shared.Utilities { public static string GeneratePassword(int size) { - var buffer = new byte[size]; + var buffer = new byte[size]; var rng = RandomNumberGenerator.Create(); rng.GetNonZeroBytes(buffer); return Convert.ToBase64String(buffer).Replace("=", ""); diff --git a/Shared/Utilities/RandomGenerator.cs b/Shared/Utilities/RandomGenerator.cs index 7d195a36..b34e78fd 100644 --- a/Shared/Utilities/RandomGenerator.cs +++ b/Shared/Utilities/RandomGenerator.cs @@ -1,5 +1,5 @@ -using System.Security.Cryptography; -using System.Linq; +using System.Linq; +using System.Security.Cryptography; namespace Remotely.Shared.Utilities { diff --git a/Shared/Win32/ADVAPI32.cs b/Shared/Win32/ADVAPI32.cs index 8650d86b..77d6b526 100644 --- a/Shared/Win32/ADVAPI32.cs +++ b/Shared/Win32/ADVAPI32.cs @@ -305,7 +305,7 @@ namespace Remotely.Shared.Win32 [DllImport("advapi32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool AdjustTokenPrivileges(IntPtr tokenHandle, - [MarshalAs(UnmanagedType.Bool)]bool disableAllPrivileges, + [MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges, ref TOKEN_PRIVILEGES newState, UInt32 bufferLengthInBytes, ref TOKEN_PRIVILEGES previousState, @@ -351,7 +351,7 @@ namespace Remotely.Shared.Win32 [DllImport("advapi32", SetLastError = true), SuppressUnmanagedCodeSecurityAttribute] public static extern bool OpenProcessToken(IntPtr ProcessHandle, int DesiredAccess, ref IntPtr TokenHandle); [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public extern static bool DuplicateTokenEx( + public static extern bool DuplicateTokenEx( IntPtr hExistingToken, uint dwDesiredAccess, ref SECURITY_ATTRIBUTES lpTokenAttributes, @@ -367,6 +367,6 @@ namespace Remotely.Shared.Win32 [Out] byte[] pvInfo, uint nLength, out uint lpnLengthNeeded); #endregion - + } } diff --git a/Shared/Win32/SECUR32.cs b/Shared/Win32/SECUR32.cs index 334bd0d6..bd8e50cd 100644 --- a/Shared/Win32/SECUR32.cs +++ b/Shared/Win32/SECUR32.cs @@ -1,9 +1,9 @@ -using System; +using Microsoft.Win32.SafeHandles; +using Remotely.Shared.Win32; +using System; +using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Runtime.Versioning; -using Microsoft.Win32.SafeHandles; -using System.Runtime.ConstrainedExecution; -using Remotely.Shared.Win32; public static class SECUR32 { @@ -238,12 +238,12 @@ public static class SECUR32 [StructLayout(LayoutKind.Sequential)] public struct QUOTA_LIMITS { - UInt32 PagedPoolLimit; - UInt32 NonPagedPoolLimit; - UInt32 MinimumWorkingSetSize; - UInt32 MaximumWorkingSetSize; - UInt32 PagefileLimit; - Int64 TimeLimit; + readonly UInt32 PagedPoolLimit; + readonly UInt32 NonPagedPoolLimit; + readonly UInt32 MinimumWorkingSetSize; + readonly UInt32 MaximumWorkingSetSize; + readonly UInt32 PagefileLimit; + readonly Int64 TimeLimit; } [StructLayout(LayoutKind.Sequential)] @@ -308,7 +308,7 @@ public static class SECUR32 } [System.Security.SecurityCritical] - override protected bool ReleaseHandle() + protected override bool ReleaseHandle() { // LsaDeregisterLogonProcess returns an NTSTATUS return LsaDeregisterLogonProcess(handle) >= 0; @@ -329,9 +329,6 @@ public static class SECUR32 UserName = "", Password = "" }; - IntPtr pluid; - IntPtr lsaHan; - uint authPackID; IntPtr kerbLogInfo; SECUR32.LSA_STRING logonProc = new SECUR32.LSA_STRING() { @@ -353,21 +350,29 @@ public static class SECUR32 }; IntPtr hLogonProc = Marshal.AllocHGlobal(Marshal.SizeOf(logonProc)); Marshal.StructureToPtr(logonProc, hLogonProc, false); - ADVAPI32.AllocateLocallyUniqueId(out pluid); - LsaConnectUntrusted(out lsaHan); + ADVAPI32.AllocateLocallyUniqueId(out IntPtr pluid); + LsaConnectUntrusted(out IntPtr lsaHan); //SECUR32.LsaRegisterLogonProcess(hLogonProc, out lsaHan, out secMode); - SECUR32.LsaLookupAuthenticationPackage(lsaHan, ref authPackage, out authPackID); + SECUR32.LsaLookupAuthenticationPackage(lsaHan, ref authPackage, out uint authPackID); kerbLogInfo = Marshal.AllocHGlobal(Marshal.SizeOf(kli)); Marshal.StructureToPtr(kli, kerbLogInfo, false); var ts = new SECUR32.TOKEN_SOURCE("Insta"); - IntPtr profBuf; - uint profBufLen; - long logonID; - IntPtr logonToken; - SECUR32.QUOTA_LIMITS quotas; - SECUR32.WinStatusCodes subStatus; - SECUR32.LsaLogonUser(lsaHan, ref originName, SECUR32.SecurityLogonType.Interactive, authPackID, kerbLogInfo, (uint)Marshal.SizeOf(kerbLogInfo), IntPtr.Zero, ref ts, out profBuf, out profBufLen, out logonID, out logonToken, out quotas, out subStatus); + SECUR32.LsaLogonUser( + lsaHan, + ref originName, + SECUR32.SecurityLogonType.Interactive, + authPackID, + kerbLogInfo, + (uint)Marshal.SizeOf(kerbLogInfo), + IntPtr.Zero, + ref ts, + out IntPtr profBuf, + out uint profBufLen, + out long logonID, + out IntPtr logonToken, + out QUOTA_LIMITS quotas, + out WinStatusCodes subStatus); } } \ No newline at end of file diff --git a/Shared/Win32/Shlwapi.cs b/Shared/Win32/Shlwapi.cs index 1e4c5275..716c8e0c 100644 --- a/Shared/Win32/Shlwapi.cs +++ b/Shared/Win32/Shlwapi.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +using System.Runtime.InteropServices; namespace Remotely.Shared.Win32 { diff --git a/Shared/Win32/User32.cs b/Shared/Win32/User32.cs index fac17918..2011d0a1 100644 --- a/Shared/Win32/User32.cs +++ b/Shared/Win32/User32.cs @@ -1150,10 +1150,10 @@ namespace Remotely.Shared.Win32 public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] - public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, UIntPtr dwExtraInfo); + public static extern void Mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, UIntPtr dwExtraInfo); [DllImport("user32.dll")] - public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); + public static extern void Keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] diff --git a/Shared/Win32/Win32Interop.cs b/Shared/Win32/Win32Interop.cs index eb087f5e..4da11680 100644 --- a/Shared/Win32/Win32Interop.cs +++ b/Shared/Win32/Win32Interop.cs @@ -194,8 +194,8 @@ namespace Remotely.Shared.Win32 SendMessage(0xFFFF, 0x112, 0xF170, (int)state); } - public static MessageBoxResult ShowMessageBox(IntPtr owner, - string message, + public static MessageBoxResult ShowMessageBox(IntPtr owner, + string message, string caption, MessageBoxType messageBoxType) { diff --git a/Tests.LoadTester/CommandLineParser.cs b/Tests.LoadTester/CommandLineParser.cs index 3deed50e..8623c67c 100644 --- a/Tests.LoadTester/CommandLineParser.cs +++ b/Tests.LoadTester/CommandLineParser.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Windows; namespace Remotely.Tests.LoadTester { @@ -29,7 +28,7 @@ namespace Remotely.Tests.LoadTester } key = key.Trim().Replace("-", "").ToLower(); - + commandLineArgs.Add(key, args[i + 1]); } } diff --git a/Tests/IoCActivator.cs b/Tests/IoCActivator.cs index d7071a39..d9ed661a 100644 --- a/Tests/IoCActivator.cs +++ b/Tests/IoCActivator.cs @@ -1,14 +1,14 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Remotely.Server.Data; using Remotely.Server.Services; -using System; -using Microsoft.EntityFrameworkCore; using Remotely.Shared.Models; -using Microsoft.AspNetCore.Identity; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; namespace Remotely.Tests {