private void OnLocalClipboardChange(object sender, ClipboardDataBase data) { if (!GlobalClipboardEnabled) { return; } //Create a new dataoperation, a guid will be created generated automatically ServerDataOperation operation = new ServerDataOperation(data, ISServerSocket.Localhost); SetOperation(operation); }
private async void Client_RequestedFileToken(object sender, NetworkSocket.FileTokenRequestArgs args) { ISServerSocket client = sender as ISServerSocket; Guid token; //We need to find the dataoperation that the client requested access too (if it exists) ServerDataOperation op = null; //Check if the specified operation is the active clipboard or dragdrop operation if (cbController.CurrentOperation != null && cbController.CurrentOperation.OperationGuid == args.DataOperationId) { op = cbController.CurrentOperation; } else if (ddController.CurrentOperation != null && ddController.CurrentOperation.OperationGuid == args.DataOperationId) { op = ddController.CurrentOperation; } //If we can't find the operation, let the client know if (op == null || op.Data.DataType != Clipboard.DataTypes.ClipboardDataType.File) { client.SendFileErrorResponse(args.NetworkMessageId, "Data operation not found"); return; } //If localhost is the host of the operation, we can just create an access token using FileAccessController //otherwise, we need to get a token from the host client if (op.Host == ISServerSocket.Localhost) { //We want the token to timeout if it is not access for 10 seconds. The token is only generated for a client //when it pastes the files, so having a timeout will ensure that all filestreams are closed when the client //has finished pasting all files token = fileController.CreateTokenForOperation(op, 10000); } else { try { token = await op.Host.RequestFileTokenAsync(op.OperationGuid); fileController.AddRemoteAccessToken(op.Host, token); } catch (Exception ex) { client.SendFileErrorResponse(args.NetworkMessageId, "Failed to get access token from remote client: " + ex.Message); return; } } client.SendTokenRequestReponse(args.NetworkMessageId, token); }
private void SetOperation(ServerDataOperation operation) { try { CurrentOperation = operation; BroadcastOperation(); ClipboardDataChanged?.Invoke(this, CurrentOperation); ISLogger.Write("Clipboard operation set! type = {0} host = {1}", CurrentOperation.Data.DataType, CurrentOperation.Host); }catch (Exception ex) { ISLogger.Write("GlobalClipboardController: Error setting global clipboard operation: " + ex.Message); ISLogger.Write(ex.StackTrace); } }