Exemplo n.º 1
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);
                    }
                }
            }
        }