private void InnerChatContainer_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = e.Data.GetData(DataFormats.FileDrop) as string[]; bool supported = true; foreach (string file in files) { if (!SupportedExtensions.Contains(Path.GetExtension(file))) { supported = false; break; } } if (supported) { e.Effect = DragDropEffects.Copy; UploadDropHere.BackColor = Color.FromArgb(200, 0, 100, 0); UploadDropHere.Text = "DROP FILES HERE"; } else { UploadDropHere.BackColor = Color.FromArgb(200, 100, 0, 0); UploadDropHere.Text = "UNSUPPORTED FILE TYPE"; } } else { e.Effect = DragDropEffects.None; UploadDropHere.BackColor = Color.FromArgb(200, 100, 0, 0); UploadDropHere.Text = "UNSUPPORTED FILE TYPE"; } UploadDropHere.Show(); UploadDropHere.BringToFront(); }
private void InnerChatContainer_DragDrop(object sender, DragEventArgs e) { UploadDropHere.Hide(); string[] files = e.Data.GetData(DataFormats.FileDrop) as string[]; if (files == null) { return; } if (files.Length <= 0) { return; } string[] serverNames = new string[files.Length]; foreach (var upPic in UploadContainer.Controls.OfType <UploadPictureBox>()) { upPic?.Dispose(); } UploadTotalProgressBar.Size = new Size(0, UploadTotalProgressBar.Height); ChatType = Reply.ContentType.Picture; Uploading = true; uploadTotalSize = uploadProgressSize = 0; UploadContainer.Show(); int x, y; int h = UploadContainer.Height - 10; int cc = 1; x = y = 10; if (files.Length > 5) { UploadHiddenItems.Text = "+" + (files.Length - 5).ToString(); } UploadHiddenItems.Visible = files.Length > 5; foreach (string file in files) { uploadTotalSize += new FileInfo(file).Length; if (cc > 5) { continue; } UploadPictureBox upPicture = new UploadPictureBox(file, new Size(h, h)); upPicture.Location = new Point(x, y); UploadContainer.Controls.Add(upPicture); x += upPicture.Width + 5; cc++; } Task.Run(async() => { UploadPictureBox[] upBoxes = UploadContainer.Controls.OfType <UploadPictureBox>().ToArray(); for (int c = 0; c < upBoxes.Length; c++) { await upBoxes[c].LoadImage(upBoxes[c].Name); } for (int c = 0; c < upBoxes.Length; c++) { string dest = REMOTE_IMAGE_LOCATION + Guid.NewGuid() + Path.GetExtension(upBoxes[c].Name); serverNames[c] = dest; await upBoxes[c].Upload(upBoxes[c].Name, dest, new NetworkCredential("2159860_user", "Qub1cR3dSt0rag3"), UploadProgress); } if (files.Length > 5) // Upload all the files that aren't actually shown in the preview bar { for (int i = 5; i < files.Length; i++) { const int CHUNK_SIZE = (1024 * 1024) / 2; string source = files[i]; string destination = REMOTE_IMAGE_LOCATION + Guid.NewGuid() + Path.GetExtension(source); int chunk = CHUNK_SIZE; serverNames[i] = destination; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(destination); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("2159860_user", "Qub1cR3dSt0rag3"); using (Stream inputStream = File.Open(source, FileMode.Open, FileAccess.Read)) using (Stream stream = request.GetRequestStream()) { request.ContentLength = inputStream.Length; if (request.ContentLength <= chunk) { byte[] buffer = new byte[inputStream.Length]; inputStream.Read(buffer, 0, buffer.Length); await stream.WriteAsync(buffer, 0, buffer.Length); UploadProgress(buffer.Length); } else { chunk = Math.Min((int)inputStream.Length / 100, CHUNK_SIZE); byte[] buffer = new byte[chunk]; int totalReadBytesCount = 0; int readBytesCount; while ((readBytesCount = inputStream.Read(buffer, 0, buffer.Length)) > 0) { await stream.WriteAsync(buffer, 0, readBytesCount); totalReadBytesCount += readBytesCount; UploadProgress(readBytesCount); } } } } } SendIcon.Image = Properties.Resources.send; pictureURLs = serverNames; Uploading = false; }); }
private void InnerChatContainer_DragLeave(object sender, EventArgs e) { UploadDropHere.Hide(); }