private async Task <Guid> CreateAccessTokenForOperation(DragDropOperation operation) { if (operation.Host.IsLocalhost) { return(GenerateLocalAccessTokenForOperation(operation)); } else { return(await operation.Host.RequestFileTokenAsync(operation.OperationId)); } }
//**************************************************************************************************** // //**************************************************************************************************** public void Update() { if (ScrFade.finished) { UpdateTransition(); UpdateNavigationMode(); DragDropOperation.Update(); } }
/// <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 UpdateDragDropInputs() { if (DragDropOperation.pending == false) { return; } if (Input.GetKeyDown(KeyCode.Escape)) { DragDropOperation.Cancel(); } else if (Input.GetMouseButtonDown(0)) { DragDropOperation.Drop(this); } }
private async void BeginReceivedOperation(NetworkSocket.DragDropDataReceivedArgs args) { //Check if the received operation has previously been received if (CurrentOperation?.OperationId == args.OperationId) { ddManager.DoDragDrop(CurrentOperation.Data, args.OperationId); return; } if (CurrentOperation != null && !previousOperations.ContainsKey(CurrentOperation.OperationId)) { previousOperations.Add(CurrentOperation.OperationId, CurrentOperation); } ClipboardDataBase cbData = ClipboardDataBase.FromBytes(args.RawData); //We need to setup the virtual files if this is a file drop if (cbData is ClipboardVirtualFileData cbFiles) { //Get an access token for the files from the server Guid token; try { token = await Server.RequestFileTokenAsync(args.OperationId); } catch (Exception ex) { ISLogger.Write("LocalDragDropController: Failed to get access token for dragdrop operation: " + ex.Message); return; } for (int i = 0; i < cbFiles.AllFiles.Count; i++) { cbFiles.AllFiles[i].RemoteAccessToken = token; cbFiles.AllFiles[i].ReadComplete += VirtualFile_ReadComplete; cbFiles.AllFiles[i].ReadDelegate = VirtualFile_RequestDataAsync; cbFiles.AllFiles[i].FileOperationId = args.OperationId; } } CurrentOperation = new DragDropOperation(args.OperationId, cbData); ddManager.DoDragDrop(cbData, args.OperationId); }
//**************************************************************************************************** // //**************************************************************************************************** public WebMapObjectBase CreateMapObject(OBJECT_TYPE type, CREATE_MODE mode, Localizable localizable) { GameObject mdl = Resources.Load <GameObject>(m_mapObjectModel[( int )type]); Quaternion q = Quaternion.AngleAxis(-90.0f, Vector3.right); GameObject Obj = (mdl != null) ? GameObject.Instantiate(mdl, Vector3.up * 32.0f, q, m_deposit.transform) as GameObject : null; if (Obj != null) { WebMapObjectBase mapObj = Obj.GetComponent <WebMapObjectBase>(); if (mapObj != null) { mapObj.localizable = localizable; if (mode == CREATE_MODE.CREATE_DRAG) { if (DragDropOperation.Begin(this, mapObj) == false) { DragDropOperation.Cancel(); } else { UpdateDrag(mapObj); return(mapObj); } } else { List <WebMapObjectBase> list = (type == OBJECT_TYPE.FLAG) ? m_flags : m_pins; list.Add(mapObj); return(mapObj); } } } return(null); }
private Guid GenerateLocalAccessTokenForOperation(DragDropOperation operation) { if (operation.DataType != ClipboardDataType.File) { throw new ArgumentException("DateType must be file"); } ClipboardVirtualFileData file = operation.OperationData as ClipboardVirtualFileData; Guid[] fIds = new Guid[file.AllFiles.Count]; string[] fSources = new string[file.AllFiles.Count]; for (int i = 0; i < file.AllFiles.Count; i++) { fIds[i] = file.AllFiles[i].FileRequestId; fSources[i] = file.AllFiles[i].FullPath; } return(fileController.CreateFileReadTokenForGroup(new FileAccessController.FileAccessInfo(fIds, fSources), 10000)); }
internal void Local_DataDropped(object sender, ClipboardDataBase cbData) { if (!Server.IsConnected) { return; } if (CurrentOperation != null && !previousOperations.ContainsKey(CurrentOperation.OperationId)) { previousOperations.Add(CurrentOperation.OperationId, CurrentOperation); } if (Server.IsConnected) { Guid opId = Guid.NewGuid(); CurrentOperation = new DragDropOperation(opId, cbData); ISLogger.Write("LocalDragDropController: Started dragdrop operation " + opId); Server.SendDragDropData(cbData.ToBytes(), opId); } }
private void BeginTextOrImageOperation(ClipboardDataBase cbData, Guid 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); } //Create a new operation with the text/image data, we don't care about the ID or host //as text and image data is not streamed the same way as file data. Text/Image data are sent as a single block CurrentOperation = new DragDropOperation(cbData, null, operationId); if (currentInputClient.IsLocalhost) { ddManager.DoDragDrop(cbData, operationId); } else { ISLogger.Write("SDragDropController: Sending dragdrop type {0} to {1}", cbData.DataType, currentInputClient.ClientName); currentInputClient.SendDragDropData(cbData.ToBytes(), CurrentOperation.OperationId); } }