private void OnDragDrop(DragDropMessage message) { if (!IsBusy) { // ReSharper disable once StyleCop.SA1305 var jwLibraryFiles = _dragDropService.GetDroppedFiles(message.DragEventArgs); var tmpFilesCollection = new ConcurrentBag <JwLibraryFile>(); // ReSharper disable once StyleCop.SA1116 // ReSharper disable once StyleCop.SA1115 Parallel.ForEach(jwLibraryFiles, file => { var backupFile = _backupFileService.Load(file); tmpFilesCollection.Add(new JwLibraryFile { BackupFile = backupFile, FilePath = file }); }); foreach (var file in tmpFilesCollection) { if (Files.FirstOrDefault(x => IsSameFile(file.FilePath, x.FilePath)) == null) { file.PropertyChanged += FilePropertyChanged; Files.Add(file); } } } message.DragEventArgs.Handled = true; }
private void OnDragDrop(DragDropMessage message) { var epubFolder = FileUtils.GetEpubFolder(); if (!FileUtils.DirectoryIsWritable(epubFolder)) { message.DragEventArgs.Handled = true; _snackbarService.EnqueueWithOk(string.Format(Properties.Resources.NO_WRITE_ACCESS, epubFolder)); return; } var busyCursor = _userInterfaceService.GetBusy(); var origEpubPath = _bibleVersesService.EpubPath; Task.Run(() => { var files = GetDroppedFiles(message.DragEventArgs); var validFileCount = 0; // close reader so that we can overwrite the current epub (if necessary) _bibleVersesService.CloseReader(); Parallel.ForEach(files, file => { try { if (_bibleVersesService.IsValidBibleEpub(file)) { File.Copy(file, GetDestinationFileName(file), overwrite: true); Interlocked.Increment(ref validFileCount); } } catch (Exception ex) { Log.Logger.Error(ex, $@"Could not copy epub file {file}"); } }); _snackbarService.EnqueueWithOk(GetDoneMessage(files.Count, validFileCount)); message.DragEventArgs.Handled = true; }).ContinueWith(t => { _bibleVersesService.EpubPath = origEpubPath; DispatcherHelper.CheckBeginInvokeOnUI(() => { EpubFileListChanged?.Invoke(this, EventArgs.Empty); busyCursor.Dispose(); }); }); }
private void HandleDragDropMessage(DragDropMessage msg, EntitySessionEventArgs args) { var performer = args.SenderSession.AttachedEntity; if (performer == null) { return; } if (!EntityManager.TryGetEntity(msg.Dropped, out var dropped)) { return; } if (!EntityManager.TryGetEntity(msg.Target, out var target)) { return; } var interactionArgs = new DragDropEventArgs(performer, msg.DropLocation, dropped, target); // must be in range of both the target and the object they are drag / dropping // Client also does this check but ya know we gotta validate it. if (!interactionArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) { return; } // trigger dragdrops on the dropped entity RaiseLocalEvent(dropped.Uid, interactionArgs); foreach (var dragDrop in dropped.GetAllComponents <IDraggable>()) { if (dragDrop.CanDrop(interactionArgs) && dragDrop.Drop(interactionArgs)) { return; } } // trigger dragdropons on the targeted entity RaiseLocalEvent(target.Uid, interactionArgs, false); foreach (var dragDropOn in target.GetAllComponents <IDragDropOn>()) { if (dragDropOn.CanDragDropOn(interactionArgs) && dragDropOn.DragDropOn(interactionArgs)) { return; } } }
private void HandleDragDropMessage(DragDropMessage msg, EntitySessionEventArgs args) { var performer = args.SenderSession.AttachedEntity; if (!EntityManager.TryGetEntity(msg.Dropped, out var dropped)) { return; } if (!EntityManager.TryGetEntity(msg.Target, out var target)) { return; } var interactionArgs = new DragDropEventArgs(performer, msg.DropLocation, dropped, target); // must be in range of both the target and the object they are drag / dropping if (!interactionArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) { return; } // trigger dragdrops on the dropped entity foreach (var dragDrop in dropped.GetAllComponents <IDragDrop>()) { if (dragDrop.CanDragDrop(interactionArgs) && dragDrop.DragDrop(interactionArgs)) { return; } } // trigger dragdropons on the targeted entity foreach (var dragDropOn in target.GetAllComponents <IDragDropOn>()) { if (dragDropOn.CanDragDropOn(interactionArgs) && dragDropOn.DragDropOn(interactionArgs)) { return; } } }