/// <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); } }
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); } } }