Esempio n. 1
0
        public void TestText()
        {
            DataObject d = new DataObject();

            d.SetText("yo");

            Assert.AreEqual(false, d.ContainsAudio(), "A1");
            Assert.AreEqual(false, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(false, d.ContainsImage(), "A3");
            Assert.AreEqual(true, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreEqual("yo", d.GetText(), "A6");
            Assert.AreEqual("yo", d.GetData(DataFormats.StringFormat), "A6-1");

            d.SetText("<html></html>", TextDataFormat.Html);
            Assert.AreEqual(true, d.ContainsText(), "A7");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A8");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.Html), "A9");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.Rtf), "A10");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.Text), "A11");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.UnicodeText), "A12");

            // directly put a string
            d.SetData("yo");

            Assert.AreEqual(true, d.ContainsText(TextDataFormat.Text), "A13");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.UnicodeText), "A14");

            Assert.AreEqual("yo", d.GetData(DataFormats.StringFormat), "A15");
            Assert.AreEqual("yo", d.GetData(DataFormats.Text), "A16");
            Assert.AreEqual("yo", d.GetData(DataFormats.UnicodeText), "A17");
        }
        bool ValidaTipo(DragEventArgs e)
        {
            bool bandera = false;

            RutaArchivo = null;
            DataObject data = (DataObject)e.Data;

            if (data.ContainsFileDropList())
            {
                string[] rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);

                foreach (var item in rawFiles)
                {
                    string TipoArchv  = item.ToString();
                    int    Total      = TipoArchv.Length;
                    string tipoArchvi = TipoArchv.Substring(Total - 3, 3);

                    if (tipoArchvi.Equals("txt"))
                    {
                        bandera = true;
                    }
                    else
                    {
                        bandera = false;
                        break;
                    }
                }
            }

            return(bandera);
        }
Esempio n. 3
0
 public override bool ContainsFileDropList()
 {
     if (FData != null)
     {
         return(FData.ContainsFileDropList());
     }
     return(base.ContainsFileDropList());
 }
        void DragDrop_Input(DragEventArgs e)
        {
            try
            {
                if (ValidaTipo(e))
                {
                    RutaArchivo = null;
                    String     Nombre = null;
                    DataObject data   = (DataObject)e.Data;
                    if (data.ContainsFileDropList())
                    {
                        string[] rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                        if (rawFiles != null)
                        {
                            List <string> lines = new List <string>();
                            foreach (string path in rawFiles)
                            {
                                Nombre = path;
                                lines.AddRange(File.ReadAllLines(path));
                            }
                            RutaArchivo         = Nombre;
                            BarraName.Text      = Nombre;
                            txtEditexRT_Ul.Text = "";
                            var ListaArchivos = lines.ToArray();
                            if (ListaArchivos.Count() > 1)
                            {
                                String Lines = null;
                                foreach (string paths in ListaArchivos)
                                {
                                    Lines = paths + "\r\n";
                                    txtEditexRT_Ul.Text += Lines;
                                }
                            }
                            else
                            {
                                foreach (string paths in ListaArchivos)
                                {
                                    txtEditexRT_Ul.Text = paths;
                                }
                            }
                            TotalText = txtEditexRT_Ul.TextLength;
                        }
                    }
                }

                else
                {
                    if (MessageBox.Show("Archivo No tiene Extenxion .TXT", "Editor De Texto",
                                        MessageBoxButtons.OK, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
        private string GetFirstFile(DataObject data)
        {
            if (data.ContainsFileDropList())
            {
                return(data.GetFileDropList()[0]);
            }

            return(string.Empty);
        }
Esempio n. 6
0
        public void OnPreviewDragOver(object sender, DataObject dataObject, ref DragDropEffects effects)
        {
            if (dataObject == null)
            {
                Debug.WriteLine("DragObject was null for Viewport drag");
                return;
            }

            if (dataObject.ContainsFileDropList() || dataObject.GetDataPresent("GongSolutions.Wpf.DragDrop"))
            {
                effects = DragDropEffects.Copy;
            }
        }
Esempio n. 7
0
        private void textBox1_DragDrop(object sender, DragEventArgs e)
        {
            DataObject data = (DataObject)e.Data;

            if (data.ContainsFileDropList())
            {
                string[] rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                if ((rawFiles != null) && (rawFiles.Length == 1))
                {
                    textBox1.Text = rawFiles[0];
                    button2.PerformClick();
                }
            }
        }
Esempio n. 8
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            DataObject o = new DataObject(e.Data);

            if (o.ContainsFileDropList())
            {
                FileTreeNode node = (FileTreeNode)treeView.GetNodeAt(treeView.PointToClient(new Point(e.X, e.Y)));
                if (node != null && node.File.Type == FileSystemObjectType.Directory)
                {
                    StringCollection files = o.GetFileDropList();

                    Paste(node, files, e.Effect == DragDropEffects.Move ? false : true);
                }
            }
        }
 private void DropFiles(Action <ISound, int> insertSoundAction, int insertIndex, DataObject dataObject)
 {
     if (dataObject != null && dataObject.ContainsFileDropList())
     {
         foreach (string fileName in dataObject.GetFileDropList())
         {
             if (_soundFactory.SupportedExtensions.Contains("*" + Path.GetExtension(fileName), StringComparer.OrdinalIgnoreCase))
             {
                 ISound sound = _soundFactory.Create();
                 sound.FileName = fileName;
                 insertSoundAction(sound, insertIndex++);
             }
         }
     }
 }
        private void userControl_DragLeave(object sender, DragEventArgs e)
        {
            DataObject dataObject = (DataObject)e.Data;

            if (dataObject.ContainsFileDropList())
            {
                e.Handled = true;
                e.Effects = DragDropEffects.Copy;
            }
            else
            {
                e.Handled = false;
                e.Effects = DragDropEffects.None;
            }
        }
Esempio n. 11
0
        public void TestImage()
        {
            DataObject d = new DataObject();
            Image      i = new Bitmap(16, 16);

            d.SetImage(i);

            Assert.AreEqual(false, d.ContainsAudio(), "A1");
            Assert.AreEqual(false, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(true, d.ContainsImage(), "A3");
            Assert.AreEqual(false, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreSame(i, d.GetImage(), "A6");
        }
Esempio n. 12
0
        public void TestAudio()
        {
            DataObject d = new DataObject();

            byte[] b = new byte[] { 1, 2, 3 };

            d.SetAudio(b);

            Assert.AreEqual(true, d.ContainsAudio(), "A1");
            Assert.AreEqual(false, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(false, d.ContainsImage(), "A3");
            Assert.AreEqual(false, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreEqual(b.Length, d.GetAudioStream().Length, "A6");
        }
Esempio n. 13
0
        private void txtEditex_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                RutaArchivo = null;

                String     Nombre = null;
                DataObject data   = (DataObject)e.Data;
                if (data.ContainsFileDropList())
                {
                    string[] rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                    if (rawFiles != null)
                    {
                        List <string> lines = new List <string>();
                        foreach (string path in rawFiles)
                        {
                            Nombre = path;
                            lines.AddRange(File.ReadAllLines(path));
                        }
                        RutaArchivo    = Nombre;
                        BarraName.Text = Nombre;
                        txtEditex.Text = "";
                        var ListaArchivos = lines.ToArray();
                        if (ListaArchivos.Count() > 1)
                        {
                            String Lines = null;
                            foreach (string paths in ListaArchivos)
                            {
                                Lines           = paths + "\r\n";
                                txtEditex.Text += Lines;
                            }
                        }
                        else
                        {
                            foreach (string paths in ListaArchivos)
                            {
                                txtEditex.Text = paths;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 14
0
        public void TestFileDrop()
        {
            DataObject       d  = new DataObject();
            StringCollection sc = new StringCollection();

            sc.AddRange(new string[] { "A", "B", "C" });

            d.SetFileDropList(sc);

            Assert.AreEqual(false, d.ContainsAudio(), "A1");
            Assert.AreEqual(true, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(false, d.ContainsImage(), "A3");
            Assert.AreEqual(false, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreEqual(sc.Count, d.GetFileDropList().Count, "A6");
        }
Esempio n. 15
0
        public void Drop(IDropInfo dropInfo)
        {
            if (dropInfo.Data is NoteFile)
            {
                TextBox box = dropInfo.VisualTarget as TextBox;
                if (box != null)
                {
                    AddFilesToTextBox(box, dropInfo, new List <NoteFile> {
                        (NoteFile)dropInfo.Data
                    });
                }
            }
            else if (dropInfo.Data is DataObject)
            {
                DataObject dataObject = (DataObject)dropInfo.Data;
                if (dataObject.ContainsFileDropList())
                {
                    var             fileList     = dataObject.GetFileDropList();
                    List <NoteFile> createdFiles = new List <NoteFile>();
                    foreach (string filePath in fileList)
                    {
                        if (File.Exists(filePath))
                        {
                            FileInfo fi   = new FileInfo(filePath);
                            var      file = File.ReadAllBytes(filePath);

                            string ext = Path.GetExtension(filePath);
                            if (!string.IsNullOrWhiteSpace(ext))
                            {
                                ext = ext.ToLower();
                            }

                            string noteFileName = NoteFile.ProposeNoteFileName(fi.Name, Note);

                            string mime = MimeTypes.MimeTypeMap.GetMimeType(ext);
                            var    nf   = NoteFile.Create(noteFileName, mime, file, Note, ext);
                            createdFiles.Add(nf);
                        }
                    }
                    if (dropInfo.VisualTarget is TextBox)
                    {
                        AddFilesToTextBox((TextBox)dropInfo.VisualTarget, dropInfo, createdFiles);
                    }
                }
            }
        }
    void MyTextBox_DragDrop(object sender, DragEventArgs e)
    {
        DataObject data = (DataObject)e.Data;

        if (data.ContainsFileDropList())
        {
            string[] rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (rawFiles != null)
            {
                List <string> lines = new List <string>();
                foreach (string path in rawFiles)
                {
                    lines.AddRange(File.ReadAllLines(path));
                }
                Lines = lines.ToArray();
            }
        }
    }
Esempio n. 17
0
        private void _DragDrop(DragEventArgs e, TextBox tb, string langKey)
        {
            DataObject data = (DataObject)e.Data;

            if (data.ContainsFileDropList())
            {
                string[] rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (rawFiles != null)
                {
                    List <string> lines = new List <string>();
                    foreach (string path in rawFiles)
                    {
                        tb.Text = path;
                        _LoadXmlFileToList(path, langKey, tb);
                        return;
                    }
                }
            }
        }
Esempio n. 18
0
        private void AddNewFlower_DragDrop(object sender, DragEventArgs e)
        {
            DataObject data = (DataObject)e.Data;

            if (data.ContainsFileDropList())
            {
                string[] flowersFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (flowersFiles != null)
                {
                    List <string> lines = new List <string>();
                    foreach (string flowers in flowersFiles)
                    {
                        lines.AddRange(File.ReadAllLines(flowers));
                        int counter = 0;
                        foreach (string flower in lines)
                        {
                            try
                            {
                                string[] flowerComponents = flower.Split(',');
                                tryAdd(flowerComponents);
                                Flower flowerToAdd = new Flower(flowerComponents[0], double.Parse(flowerComponents[1]));
                                flowerToAdd.checkForCollision(_flowers);
                                _flowers.Add(flowerToAdd);
                            }
                            catch (InvalidFlowerException ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                            }
                            catch (FlowerCollisionException ex)
                            {
                                counter++;
                            }
                        }
                        if (counter > 0)
                        {
                            MessageBox.Show(counter + " collisions were found while importing");
                        }
                        serializeFlowers();
                    }
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Only applies to external files and other wierd types that are not Models in our tree views but that we might still want to allow drag and drop interactions for
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="dropTargetModel"></param>
        /// <returns></returns>
        private ICommandExecution GetExecutionCommandIfAnyForNonModelObjects(DataObject dataObject, object dropTargetModel)
        {
            //if user is dragging in files
            if (dataObject.ContainsFileDropList())
            {
                //get file list
                var files = dataObject.GetFileDropList().Cast <string>().Select(s => new FileInfo(s)).ToArray();
                ICombineToMakeCommand fileCommand = _commandFactory.Create(files);

                //if command factory supports generating file based commands
                if (fileCommand != null)
                {
                    //does the execution factory permit the combination of a file command with the drop target
                    ICommandExecution execution = _commandExecutionFactory.Create(fileCommand, dropTargetModel);
                    return(execution);
                }
            }

            return(null);
        }
Esempio n. 20
0
        private void txtApkPath_DragDrop(object sender, DragEventArgs e)
        {
            DataObject data = (DataObject)e.Data;

            if (data.ContainsFileDropList())
            {
                string[]      rawFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                List <string> paths    = new List <string>(rawFiles.Length);
                if (rawFiles != null)
                {
                    foreach (string path in rawFiles)
                    {
                        if (path.EndsWith(".apk", true, null))
                        {
                            paths.Add(path);
                        }
                    }
                }

                txtApkPath.Text = paths[0];
            }
        }
        private void userControl_Drop(object sender, DragEventArgs e)
        {
            DataObject dataObject = (DataObject)e.Data;

            if (dataObject.ContainsFileDropList())
            {
                e.Handled = true;
                e.Effects = DragDropEffects.Copy;

                StringCollection fileDropList = dataObject.GetFileDropList();
                if (DropFileList != null)
                {
                    string[] list = new string[fileDropList.Count];
                    fileDropList.CopyTo(list, 0);
                    DropFileList(this, list);
                }
            }
            else
            {
                e.Handled = false;
                e.Effects = DragDropEffects.None;
            }
        }
Esempio n. 22
0
        private void mdFileDropped(object sender, DragEventArgs e)
        {
            DataObject data = e.Data as DataObject;

            if (!data.ContainsFileDropList())
            {
                return;
            }
            StringCollection fileDropList  = data.GetFileDropList();
            StringBuilder    stringBuilder = new StringBuilder();

            foreach (string str in fileDropList)
            {
                stringBuilder.Append(str + "\n");
            }
            string str1 = stringBuilder.ToString();

            if (str1.Substring(0, str1.Length - 1).Split('\n').Length > 1)
            {
                if (MessageBox.Show("Please select a single file.", "error", MessageBoxButton.OK, MessageBoxImage.Hand) == MessageBoxResult.Yes)
                {
                    Application.Current.Shutdown();
                }
            }
            else if (!str1.Substring(0, str1.Length - 1).EndsWith(".md"))
            {
                if (MessageBox.Show("Please select a Markdown file.", "error", MessageBoxButton.OK, MessageBoxImage.Hand) == MessageBoxResult.Yes)
                {
                    Application.Current.Shutdown();
                }
            }
            else
            {
                this.openMDFile(str1.Substring(0, str1.Length - 1));
            }
        }
Esempio n. 23
0
        private void treeView_DragOver(object sender, DragEventArgs e)
        {
            DataObject o = new DataObject(e.Data);

            if (o.ContainsFileDropList())
            {
                FileTreeNode node = (FileTreeNode)treeView.GetNodeAt(treeView.PointToClient(new Point(e.X, e.Y)));
                if (node != null && node.File.Type == FileSystemObjectType.Directory)
                {
                    if ((e.AllowedEffect & DragDropEffects.Move) != 0 && (e.KeyState & 8) == 0) // Ctrl is pressed
                    {
                        e.Effect = DragDropEffects.Move;
                        return;
                    }
                    else if ((e.AllowedEffect & DragDropEffects.Copy) != 0)
                    {
                        e.Effect = DragDropEffects.Copy;
                        return;
                    }
                }
            }

            e.Effect = DragDropEffects.None;
        }
Esempio n. 24
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            DataObject dataObject = dropInfo.Data as DataObject;

            if (dataObject != null && dataObject.ContainsFileDropList())
            {
                IEnumerable <string> dropList = dataObject.GetFileDropList().Cast <string>();
                List <TrackInfo>     tlist    = new List <TrackInfo>();

                foreach (string filePath in dropList)
                {
                    if (!MPLiteConstant.validFileType.Contains(Path.GetExtension(filePath)))
                    {
                        continue;
                    }
                    try
                    {
                        TrackInfo track = TrackInfo.ParseSource(filePath);
                        tlist.Add(track);
                        Soundtracks.Add(track);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                if (tlist.Count != 0)
                {
                    Playlist pl = PlaylistCollection.UpdatePlaylist(tlist, TracklistName);
                    UpdatePlaylistEventArgs e = new UpdatePlaylistEventArgs(pl, PlayingTrack);
                    PlaylistIsUpdatedEvent?.Invoke(e);
                }
            }
            else
            {
                // workaround: There is a bug that user can drag item from the gap between two items.
                //    It triggers DragEvent without SelectionChangeEvent. So that `selectedIndices` will be empty.
                if (selectedIndices.Count == 0)
                {
                    return;
                }

                // Reorder tracks
                List <TrackInfo> tracks;

                if ((dropInfo.Data as List <TrackInfo>) == null)
                {
                    // Single file is dropped
                    tracks = new List <TrackInfo>();
                    tracks.Add(dropInfo.Data as TrackInfo);
                }
                else
                {
                    // Multiple files is dropped
                    tracks = dropInfo.Data as List <TrackInfo>;
                }

                Playlist pl = PlaylistCollection.ReorderTracks(TracklistGUID, SelectedIndices, dropInfo.InsertIndex);
                if (pl == null)
                {
                    return;
                }
                UpdateSoundtracks(pl.Soundtracks);

                UpdatePlaylistEventArgs e = new UpdatePlaylistEventArgs(pl, PlayingTrack);
                PlaylistIsUpdatedEvent?.Invoke(e);

                // reset PlayStatus
                if (PlayingTrack != null)
                {
                    TrackInfo track = soundtracks.FirstOrDefault(x => x.GUID == PlayingTrack.GUID);
                    if (track != null)
                    {
                        track.TrackStatus = PlayingTrack.TrackStatus;
                    }
                }
            }
        }
Esempio n. 25
0
        public void Drop(IDropInfo dropInfo)
        {
            // There is nothing we can do here.
            if (dropInfo == null)
            {
                return;
            }
            // Data is populated from external and internal drag & drop. If it is null there is nothing we can do here.
            if (dropInfo.Data == null)
            {
                return;
            }
            // Check if target is not group, if yes, then there is nothing we can do here.
            bool targetIsTreeViewItem = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;

            if (targetIsTreeViewItem)
            {
                TreeViewItem treeViewItem = (TreeViewItem)dropInfo.VisualTargetItem;
                ItemVM       itemVM       = (ItemVM)treeViewItem.DataContext;
                if (!itemVM.IsGroup)
                {
                    return;
                }
            }

            // Target is group proced with the other checks...

            var insertIndex  = dropInfo.InsertIndex != dropInfo.UnfilteredInsertIndex ? dropInfo.UnfilteredInsertIndex : dropInfo.InsertIndex;
            var itemsControl = dropInfo.VisualTarget as ItemsControl;

            if (itemsControl != null)
            {
                var editableItems = itemsControl.Items as IEditableCollectionView;
                if (editableItems != null)
                {
                    var newItemPlaceholderPosition = editableItems.NewItemPlaceholderPosition;
                    if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning && insertIndex == 0)
                    {
                        ++insertIndex;
                    }
                    else if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd && insertIndex == itemsControl.Items.Count)
                    {
                        --insertIndex;
                    }
                }
            }

            var destinationList = dropInfo.TargetCollection.TryGetList();
            var data            = ExtractData(dropInfo.Data).OfType <object>().ToList();

            // If this is a move for sure it is from the internal Drag & Drop, so delete the source item.
            DragDropEffects dragDropEffects = GetDragDropEffects(dropInfo);

            if (dragDropEffects == DragDropEffects.Move)
            {
                if (dropInfo.DragInfo != null)
                {
                    // This is a drag & drop item from treeview its self
                    var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();
                    if (sourceList != null)
                    {
                        foreach (var o in data)
                        {
                            var index = sourceList.IndexOf(o);
                            if (index != -1)
                            {
                                sourceList.RemoveAt(index);
                                // so, is the source list the destination list too ?
                                if (destinationList != null && Equals(sourceList, destinationList) && index < insertIndex)
                                {
                                    --insertIndex;
                                }
                            }
                        }
                    }
                }
            }

            // Add item
            if (destinationList != null)
            {
                // check for cloning
                var cloneData = dropInfo.Effects.HasFlag(DragDropEffects.Copy) || dropInfo.Effects.HasFlag(DragDropEffects.Link);
                foreach (var o in data)
                {
                    // ----------------------------------------------
                    // This is a Drag & Drop from the external source
                    // ----------------------------------------------
                    if (dropInfo.Data is DataObject)
                    {
                        DataObject dataObject = o as DataObject;
                        if (dataObject != null)
                        {
                            // ******************************************************************************************************************************************
                            // FileDrop. Queries a data object for the presence of data in the System.Windows.DataFormats.FileDrop data format.
                            // ******************************************************************************************************************************************
                            if (dataObject.ContainsFileDropList() && dataObject.GetDataPresent(DataFormats.FileDrop, true))
                            {
                                // We can have more than one file dropped.
                                var droppedFilePaths = dataObject.GetFileDropList();
                                foreach (string droppedFilePath in droppedFilePaths)
                                {
                                    string        shortcutsDirectoryPath = Helper.GetShortcutsPath();
                                    string        guid          = NewData.NewGuid();
                                    string        name          = Path.GetFileName(droppedFilePath);
                                    DirectoryInfo directoryInfo = new DirectoryInfo(droppedFilePath);
                                    if (directoryInfo.Parent == null)
                                    {
                                        // This is the root. In that case name is empty so we need to set the name differently.
                                        DriveInfo driveInfo = new DriveInfo(droppedFilePath);
                                        // Something like this: Local Disk (C:)
                                        string volumeLabel = driveInfo.VolumeLabel;
                                        if (string.IsNullOrEmpty(volumeLabel))
                                        {
                                            volumeLabel = "Drive";
                                        }
                                        name = $"{volumeLabel} ({driveInfo.Name.Replace(@"\", "")})";
                                    }

                                    ItemVM obj2Insert = null;

                                    // Check if the dropped file is a .lnk file. We just copy the .lnk files to the sortcuts folder and use them from there.
                                    if (Path.GetExtension(droppedFilePath).Equals(Constants.EXT_LNK, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        // This is a .lnk file. In this case we copy this file to our shortcuts
                                        string shortcutLnkFilePath = Path.Combine(shortcutsDirectoryPath, guid + Constants.EXT_LNK);
                                        File.Copy(droppedFilePath, shortcutLnkFilePath);
                                        obj2Insert = new ItemVM(guid, false, false, name, shortcutLnkFilePath, Constants.EXT_LNK);
                                    }
                                    // Check if the dropped file is a .url file. We just copy the .url files to the sortcuts folder and use them from there.
                                    else if (Path.GetExtension(droppedFilePath).Equals(Constants.EXT_URL, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        // This is a .url file. In this case we copy this file to our shortcuts
                                        string shortcutUrlFilePath = Path.Combine(shortcutsDirectoryPath, guid + Constants.EXT_URL);
                                        File.Copy(droppedFilePath, shortcutUrlFilePath);
                                        obj2Insert = new ItemVM(guid, false, false, name, shortcutUrlFilePath, Constants.EXT_URL);
                                    }
                                    else
                                    {
                                        obj2Insert = new ItemVM(guid, false, false, name, droppedFilePath, Constants.EXT_LNK);
                                    }

                                    destinationList.Insert(insertIndex++, obj2Insert);
                                    SaveShortcutSettings();
                                }
                            }
                            // ******************************************************************************************************************************************
                            // AbsoluteUri. Queries a data object for the presence of data in the System.Windows.DataFormats.UnicodeText format.
                            // ******************************************************************************************************************************************
                            else if (dataObject.ContainsText() && dataObject.GetDataPresent(DataFormats.Text, true))
                            {
                                string dataText = (string)dataObject.GetData(DataFormats.Text, true);
                                Uri    uri;
                                bool   isAbsoluteUri = Uri.TryCreate(dataText, UriKind.Absolute, out uri);
                                if (isAbsoluteUri)
                                {
                                    ItemVM obj2Insert = new ItemVM(NewData.NewGuid(), false, false, uri.AbsoluteUri, uri.AbsoluteUri, Constants.EXT_URL);
                                    destinationList.Insert(insertIndex++, obj2Insert);
                                    // Save shortcut settings.
                                    SaveShortcutSettings();
                                }
                            }
                            else
                            {
                                // ******************************************************************************************************************************************
                                // ShellIDListArray. Perhaps data contain virtual files
                                // ******************************************************************************************************************************************
                                // Returns a list of formats in which the data in this data object is stored, or can be converted to.
                                string[] formats = dataObject.GetFormats();
                                foreach (string format in formats)
                                {
                                    if (format == "Shell IDList Array")
                                    {
                                        // Virtual file/s been draged.
                                        string message = "To create this kind of shortcut please do:\n";
                                        message += "1. Drag to create a desktop shortcut first,\n";
                                        message += "2. Drag the shortcut from desktop to MDSHO,\n";
                                        message += "3. Delete the shortcut from desktop if you want.";
                                        Window parent = Helper.GetWindowFromWindowItemVM(this);
                                        MessageBox.Show(parent, message, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                                    }
                                }
                            }
                        }
                    }
                    // ---------------------------------------------------------------------------
                    // This is a Drag & Drop from the internal source. Item from treeview its self
                    // ---------------------------------------------------------------------------
                    else
                    {
                        var obj2Insert = o;
                        if (cloneData)
                        {
                            var cloneable = o as ICloneable;
                            if (cloneable != null)
                            {
                                obj2Insert = cloneable.Clone();
                            }
                        }
                        destinationList.Insert(insertIndex++, obj2Insert);
                        // Save shortcut settings.
                        SaveShortcutSettings();
                    }
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Drop event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            // Find RadTreeViewItem
            var item = e.OriginalSource as RadTreeViewItem;

            if (e.OriginalSource != null && e.OriginalSource is DependencyObject)
            {
                var dependencySource = (DependencyObject)e.OriginalSource;
                item = Framework.UI.WPFVisualTreeHelper.FindParent <RadTreeViewItem>(dependencySource);
            }

            var targetDirectory = item?.DataContext as DirectoryViewModel;

            // Save target filestructure before drop action
            if (targetDirectory.StructureViewModel.IsDirty)
            {
                targetDirectory.StructureViewModel.Save();
            }
            //Check if the the folder is a workflow folder and has a workflow assigned
            if (IsWorkflowDirectory(targetDirectory))
            {
                return;
            }
            // File drag & drop
            DataObject dataObject           = (e.Data as DataObject);
            var        refreshDirectoryPath = true;

            if (dataObject != null && dataObject.ContainsFileDropList())
            {
                foreach (var file in dataObject.GetFileDropList())
                {
                    Helper.ArchiveHelper.ArchiveFile(targetDirectory.StructureViewModel.Model, targetDirectory.Model, file);
                }

                refreshDirectoryPath = false;
            }
            else if (dataObject != null && dataObject.GetData("FileGroupDescriptorW") != null)
            {
                var outlookDataObject = new OutlookDataObject(dataObject);

                string[] filenames   = (string[])outlookDataObject.GetData("FileGroupDescriptorW");
                var      fileStreams = (MemoryStream[])outlookDataObject.GetData("FileContents");

                string directory = GlobalSettings.AppDataPath + "\\Temp\\Blobs\\";
                if (!System.IO.Directory.Exists(directory))
                {
                    System.IO.Directory.CreateDirectory(directory);
                }

                for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
                {
                    //use the fileindex to get the name and data stream
                    string       filename   = filenames[fileIndex];
                    MemoryStream filestream = fileStreams[fileIndex];

                    //save the file stream using its name to the application path
                    FileStream outputStream = File.Create(directory + filename);
                    filestream.WriteTo(outputStream);
                    outputStream.Close();

                    if (filename.ToLower().EndsWith(".msg"))
                    {
                        try
                        {
                            OutlookStorage.Message msg = new OutlookStorage.Message(directory + filename);
                            DateTime receiveDateTime   = msg.ReceivedDate;
                            msg.Dispose();

                            File.SetLastWriteTime(directory + filename, receiveDateTime);
                        }
                        catch (Exception ex)
                        {
                            Log.LogManagerInstance.Instance.Error(string.Format(@"Invalid mail format: {0}", filename), ex);
                        }
                    }
                    else
                    {
                        File.SetLastWriteTime(directory + filename, DateTime.Now);
                    }

                    Helper.ArchiveHelper.ArchiveFile(targetDirectory.StructureViewModel.Model, targetDirectory.Model, directory + filename);
                }

                refreshDirectoryPath = false;
            }
            else if (dataObject != null && dataObject.GetData(typeof(GridViewPayload)) != null)
            {
                var service             = CommonServiceLocator.ServiceLocator.Current.GetInstance <IFileStructureDocumentPathService>();
                var localizationService = CommonServiceLocator.ServiceLocator.Current.GetInstance <ILocalizationService>();
                var payload             = dataObject.GetData(typeof(GridViewPayload)) as GridViewPayload;

                foreach (var path in payload.DataObjects.OfType <FileStructureDocumenPath>())
                {
                    var copyMode = Keyboard.Modifiers == ModifierKeys.Shift;

                    if (copyMode)
                    {
                        var newPath = new FileStructureDocumenPath
                        {
                            DirectoryGuid     = targetDirectory.Model.Id,
                            FileStructureGuid = targetDirectory.StructureViewModel.Model.Id,
                            DocumentGuid      = path.DocumentGuid,
                            WorkflowId        = targetDirectory.Model.WorkflowId
                        };

                        service.Save(newPath);
                    }
                    else
                    {
                        if (path.IsProtectedPath)
                        {
                            MessageBox.Show(localizationService.Translate("filestructure_path_protected"), localizationService.Translate("filestructure_path_protected_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                            continue;
                        }

                        path.DirectoryGuid     = targetDirectory.Model.Id;
                        path.WorkflowId        = targetDirectory.Model.WorkflowId;
                        path.FileStructureGuid = targetDirectory.StructureViewModel.Model.Id;

                        service.Save(path);
                    }

                    if (targetDirectory.Model.WorkflowId != null)
                    {
                        var configurationService = CommonServiceLocator.ServiceLocator.Current.GetInstance <Workflow.IDocumentWorkflowConfigurationService>();
                        var workflow             = configurationService.Get(targetDirectory.Model.WorkflowId.Value);
                        if (!string.IsNullOrWhiteSpace(workflow.AccessProviderName))
                        {
                            var accessProvider = CommonServiceLocator.ServiceLocator.Current.GetInstance <Workflow.IDocumentWorkflowAccessProvider>(workflow.AccessProviderName);
                            accessProvider.SetUserAccess(GlobalSettings.UserId, path.DocumentGuid, path.Id, path.FileStructureGuid, workflow);
                        }
                    }
                }

                refreshDirectoryPath = false;

                // Refresh grid
                if (payload.Grid is CursorGridViewControl)
                {
                    (payload.Grid as CursorGridViewControl).RefreshData();
                }
            }

            // Save target filestructure before drop action
            if (refreshDirectoryPath)
            {
                targetDirectory.StructureViewModel.Save();
                var directoriesToCheck = new List <DirectoryViewModel>();
                directoriesToCheck.Add(targetDirectory);
                //Recalculating the path through the save method
                while (directoriesToCheck.Any())
                {
                    var innerDirectories = new List <DirectoryViewModel>();

                    foreach (var subDirectory in directoriesToCheck)
                    {
                        var guid = subDirectory.Model.Id;
                        var list = fileStructureDocumentPathService.GetByDirectoryId(guid);
                        foreach (FileStructureDocumenPath fileStructureDocumenPath in list)
                        {
                            fileStructureDocumentPathService.Save(fileStructureDocumenPath);
                        }

                        innerDirectories.AddRange(subDirectory.Directories);
                    }

                    directoriesToCheck.Clear();
                    directoriesToCheck.AddRange(innerDirectories);
                }
            }
        }