Пример #1
0
        /// <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);
            }
        }