private void AssignClientEvents(ISServerSocket client) { //client.ClientDisplayConfigUpdated client.ConnectionError += (object o, string e) => HandleClientDisconnect(client); client.ClipboardDataReceived += cbController.OnClientClipboardChange; client.EdgeHit += (object o, Edge edge) => inputController.HandleEdgeHit(client, edge); client.RequestedStreamRead += fileController.Client_RequestedStreamRead; client.RequestedFileToken += Client_RequestedFileToken; client.DragDropDataReceived += ddController.OnClientDataDropped; client.DragDropSuccess += ddController.OnClientDropCancelled; client.DragDropCancelled += ddController.OnClientDropSuccess; client.HotkeyChanged += (object o, EventArgs e) => Client_HotkeyChanged(client, client.CurrentHotkey); client.ClientEdgeUpdated += (object o, Edge e) => OnClientEdgeChanged(client, e); }
public void OnClientClipboardChange(object sender, NetworkSocket.ClipboardDataReceivedArgs args) { if (!GlobalClipboardEnabled) { return; } ISServerSocket client = sender as ISServerSocket; ClipboardDataBase cbData = ClipboardDataBase.FromBytes(args.RawData); //Create the operation with the GUID that the client sent. We can use this GUID to request an access //token if the data contains files SetOperation(new ServerDataOperation(cbData, client, args.OperationId)); }
private void SetGlobalClipboard(ClipboardDataBase data, ISServerSocket host, Guid operationId) { ISLogger.Write("New clipboard operation. Type {0}, Host {1}, ID {2}", data.DataType, host.ClientName, operationId); if (data.DataType == ClipboardDataType.File) { ISLogger.Write("Clipboard file copy/paste not yet implemented!"); //SetClipboardFiles((data as ClipboardVirtualFileData), host, operationId); } else { SetClipboardTextOrImage(data, host, operationId); } }
/// <summary> /// Begins a file dragdrop operation, and assigns an access token to the operation /// </summary> /// <param name="cbFiles"></param> /// <param name="host"></param> /// <param name="operationId"></param> private async Task BeginFileOperationAsync(ClipboardVirtualFileData cbFiles, ISServerSocket host, Guid operationId) { Guid fileAccesstoken = Guid.Empty; DragDropOperation newOperation = new DragDropOperation(cbFiles, host, operationId); try { fileAccesstoken = await CreateAccessTokenForOperation(newOperation); } catch (Exception ex) { ISLogger.Write("DragDropController: Cancelling operation, could not generate file access token: " + ex.Message); return; } newOperation.RemoteFileAccessToken = fileAccesstoken; //Create events, incase the files are dropped on localhost if (!newOperation.Host.IsLocalhost) { for (int i = 0; i < cbFiles.AllFiles.Count; i++) { cbFiles.AllFiles[i].RemoteAccessToken = fileAccesstoken; cbFiles.AllFiles[i].ReadDelegate = File_RequestDataAsync; cbFiles.AllFiles[i].ReadComplete += VirtualFile_ReadComplete; cbFiles.AllFiles[i].FileOperationId = newOperation.OperationId; } } //If the previous dragdrop operation is still transfering files, store it so that the files can keep being transfered if (CurrentOperation != null && CurrentOperation.State == DragDropState.TransferingFiles) { previousOperationIds.Add(CurrentOperation.OperationId, CurrentOperation); } //Sets the new operation, which is automatically set to dragging state CurrentOperation = newOperation; if (currentInputClient.IsLocalhost) { ddManager.DoDragDrop(CurrentOperation.OperationData, newOperation.OperationId); } else { currentInputClient.SendDragDropData(CurrentOperation.OperationData.ToBytes(), CurrentOperation.OperationId); } }
private void OnDropSuccess(ISServerSocket sender, Guid operationId) { if (sender != currentInputClient) { ISLogger.Write("DragDropController: {0} attempted to send drop success when they are not input client!", sender.ClientName); return; } //If the specified operation is the current operation, mark it as success only if it is in the dragging state if (CurrentOperation?.OperationId == operationId && CurrentOperation?.State == DragDropState.Dragging) { ISLogger.Write("DragDropController: {0} marked current dragdrop operation success... {1}", sender.ClientName, CurrentOperation.OperationId); CurrentOperation.State = DragDropState.TransferingFiles; CurrentOperation.ReceiverClient = sender; OnOperationChanged(); } else if (CurrentOperation.OperationId == operationId && CurrentOperation.State != DragDropState.Dragging) { //TODO - WindowsDragDropManager reports filedrop success twice ISLogger.Write("DragDropController: {0} attempted to send drop success when specified operationstate is {1}!", sender.ClientName, CurrentOperation.State); return; } //If it is not the current operation, check if it a previous operation, if so mark as transferingfiles if (CurrentOperation?.OperationId != operationId) { if (previousOperationIds.TryGetValue(operationId, out DragDropOperation operation)) { if (operation.State == DragDropState.Dragging) { ISLogger.Write("DragDropController: {0} marked previous dragdrop operation success {1}", sender.ClientName, operation.OperationId); operation.State = DragDropState.TransferingFiles; operation.ReceiverClient = sender; OnOperationChanged(); return; } } else { ISLogger.Write("DragDropController: {0} attempted to mark unknown dragdrop operation as success", sender.ClientName); return; } } CurrentOperation.State = DragDropState.TransferingFiles; }
public void HandleClientSwitch(ISServerSocket newClient, ISServerSocket oldClient) { currentInputClient = newClient; //if moving from localhost to client, check for drop if not in operation, Only do this if the left mouse button is down if (oldClient.IsLocalhost && CurrentOperation?.State != DragDropState.Dragging && ddManager.LeftMouseState) { ddManager.CheckForDrop(); } ddManager.CancelDrop(); if (CurrentOperation == null) { return; } //If we are dragging a file, make sure that we don't send the dragdrop back to the host //as this causes issues if (CurrentOperation.DataType == ClipboardDataType.File && CurrentOperation.State == DragDropState.Dragging) { if (newClient == CurrentOperation.Host) { ISLogger.Write("Dragdrop returned to sender... cancelling"); OnDropCancel(newClient, CurrentOperation.OperationId); return; } } if (CurrentOperation.State == DragDropState.Dragging) { if (newClient.IsLocalhost) { ddManager.DoDragDrop(CurrentOperation.OperationData, CurrentOperation.OperationId); } } //if we are dragging a file, send the dragdrop data to the client if (CurrentOperation.State == DragDropState.Dragging) { if (!newClient.IsLocalhost) { newClient.SendDragDropData(CurrentOperation.OperationData.ToBytes(), CurrentOperation.OperationId); } } }
private void OnDropCancel(ISServerSocket sender, Guid operationId) { if (sender != currentInputClient) { ISLogger.Write("DragDropController: {0} attempted to cancel dragdrop operation when they are not input client!", sender.ClientName); return; } DragDropOperation operation; if (operationId == CurrentOperation?.OperationId) { operation = CurrentOperation; } else if (!previousOperationIds.TryGetValue(operationId, out operation)) { ISLogger.Write("DragDropController: Error cancelling operation: operation not found"); return; } if (operation.State != DragDropState.Dragging) { ISLogger.Write("DragDropController: {0} attempted to cancel dragdrop operation when state is {1}", sender.ClientName, operation.State); return; } ISLogger.Write("DragDropController: {0} cancelled current operation {1}", sender.ClientName, operation.OperationId); operation.State = DragDropState.Cancelled; if (operation.DataType == ClipboardDataType.File) { if (operation.Host != null && operation.Host.IsLocalhost) { fileController.DeleteToken(operation.RemoteFileAccessToken); } else if (operation.Host != null && !operation.Host.IsLocalhost) { CurrentOperation.Host.SendDragDropComplete(operationId); } } CancelAllDragDrops(); OnOperationChanged(); }
public void SetInputClient(ISServerSocket client) { if (client == null) { SetInputLocal(); return; } if (client.IsLocalhost) { SetInputLocal(); } else { SetInputExternal(client); } }
private void HandleClientDisconnect(ISServerSocket client) { if (inputController.CurrentInputClient == client) { inputController.SetInputClient(ISServerSocket.Localhost); } clientMan.RemoveClient(client); ISLogger.Write("Client {0} lost connection", client.ClientName); //Remove the clients hotkey if it exists if (inputMan.GetClientHotkey(client.ClientId) != null) { inputMan.RemoveClientHotkey(client.ClientId); } ClientDisconnected?.Invoke(this, new ISClientInfoModel(client, clientMan)); client.Dispose(); }
internal static void SaveClientEdge(ISServerSocket client, Edge edge) { if (edge == Edge.Bottom) { ConfigFile.TryWrite(client.ClientName + "-bottom", client.BottomClient == null ? "None" : client.BottomClient.ClientName); } else if (edge == Edge.Top) { ConfigFile.TryWrite(client.ClientName + "-top", client.TopClient == null ? "None" : client.TopClient.ClientName); } else if (edge == Edge.Right) { ConfigFile.TryWrite(client.ClientName + "-right", client.RightClient == null ? "None" : client.RightClient.ClientName); } else if (edge == Edge.Left) { ConfigFile.TryWrite(client.ClientName + "-left", client.LeftClient == null ? "None" : client.LeftClient.ClientName); } }
private void HandleEdgeHitLocal(Edge edge) { if (!LocalInput) { return; } ISServerSocket target = ISServerSocket.Localhost.GetClientAtEdge(edge); if (target == null) { return; } else if (!target.IsConnected && !target.IsLocalhost) { return; } SetInputExternal(target); }
private void HandleEdgeHitExternal(ISServerSocket client, Edge edge) { //Ignore if not input client if (client != CurrentInputClient) { return; } ISServerSocket target = client.GetClientAtEdge(edge); if (target == null) { return; } if (!target.IsConnected && !target.IsLocalhost) { return; } SetInputClient(target); }
private async void SetClipboardFiles(ClipboardVirtualFileData cbFiles, ISServerSocket host, Guid operationId) { if (currentOperation != null && currentOperation.DataType == ClipboardDataType.File) { previousOperationDictionary.Add(currentOperation.OperationId, currentOperation); } currentOperation = new ClipboardOperation(operationId, cbFiles.DataType, cbFiles, host); if (host == ISServerSocket.Localhost) { //TODO - We can't use the same access token for clipboard operations, as more than one client can //be reading from the stream at the same time which will cause corruption. //We need to create a new access token for each client that pastes the files to create multiple stream instances } else { //Assign virtual file events, so if localhosts pastes the files then the shell can read data from the host. foreach (var file in cbFiles.AllFiles) { file.ReadComplete += File_ReadComplete; file.ReadDelegate = File_RequestDataAsync; } //Create a token so that localhost can access files try { currentOperation.LocalhostAccessToken = await currentOperation.Host.RequestFileTokenAsync(operationId); }catch (Exception ex) { ISLogger.Write("GlobalClipboardController: Failed to get access token for clipboard content: " + ex.Message); return; } } BroadcastCurrentOperation(); }
private void OnClientEdgeChanged(ISServerSocket client, Edge e) { ClientConfig.SaveClientEdge(client, e); OnClientSettingChanged(); client.SendClientEdgesUpdate(); }
internal static void SaveClientHotkey(ISServerSocket client, Hotkey hk) { ConfigFile.TryWrite(client.ClientName + "-hotkey", hk == null ? "None" : hk.ToSettingsString()); }
public void Client_DragDropCancelled(object sender, Guid operationId) { ISServerSocket client = sender as ISServerSocket; OnDropCancel(client, operationId); }
private void HandleClientOK(ISServerSocket sender) { ISLogger.Write("ISUdpServer: {0} UDP connected", sender); sender.UdpConnected = true; sender.SetUdpEnabled(true); }
public void Client_DataDropped(object sender, NetworkSocket.DragDropDataReceivedArgs args) { ISServerSocket client = sender as ISServerSocket; BeginOperation(client, ClipboardDataBase.FromBytes(args.RawData), args.OperationId); }
public ClipboardOperation(Guid operationId, ClipboardDataType dataType, ClipboardDataBase data, ISServerSocket host) { OperationId = operationId; DataType = dataType; Data = data; Host = host; }
public void Client_DragDropSuccess(object sender, Guid operationId) { ISServerSocket client = sender as ISServerSocket; OnDropSuccess(client, operationId); }
public void InitClient(ISServerSocket client) { SendMessage(UdpMessageType.HostOK, client); }