private async void uploadImage_Click(object sender, EventArgs e) { try { int size = GetSplitSize(); if (size == -1) return; if (lbFriendID.Text != "...") { string messagePath = GetMessageInput(cmbSelectTextType, tbMessagePath, tbInputMessage); string bkMessagePath= messagePath; string encodeFile = tbImagePath.Text; List<string> tagList = new List<string>(); tagList.Add(lbFriendID.Text); if (sentPass == null) return; SimplerAES aes = new SimplerAES(sentPass); messagePath = aes.EncryptFile(messagePath); List<string> a = SplitFileIntoPart(messagePath, size); List<string> coverFile = new List<string>(); coverFile.Add(encodeFile); bool retry = false; while (true) { if (!GetMoreImage(a, coverFile, retry)) return; List<string> FailFile = new List<string>(); string albumId = cmbInputAlbum.SelectedValue.ToString(); var progress = new Progress<string>(s => { MyHelper.ShowProgressBar(s, pbStatus, lbStatusBar, lbDoing); }); int count = 0; for (int i = 0; i < a.Count; i++) { //string newFile = Common.AppendFileName(encodeFile, i.ToString()); //File.Copy(encodeFile, newFile, true); string flag = ""; if (Path.GetDirectoryName(coverFile[i]).Equals(Path.Combine(FB_Image.RelativeDirectory, "SuccessImage"))) await Task.Factory.StartNew(() => flag = SendImageWithTag(progress, coverFile[i], a[i], tagList, albumId), TaskCreationOptions.LongRunning); else await Task.Factory.StartNew(() => flag = SendNoTestImageWithTag(progress, coverFile[i], a[i], albumId, tagList), TaskCreationOptions.LongRunning); if (flag != null) { count++; } else { FailFile.Add(a[i]); } } if (FailFile.Count > 0) { if (DialogResult.Retry == MessageBox.Show("There are " + FailFile.Count.ToString() + " fail images. Do you want to retry ?", "Sent Fail", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question)) { coverFile.Clear(); a.Clear(); a.AddRange(FailFile); retry = true; } else { break; } } else { MessageBox.Show("The message has been sent"); InboxUser currentSentInbox = MyHelper.GetInboxByUserID(lbFriendID.Text, ListInboxUser); FB_Message sentMes = new FB_Message(File.ReadAllText(bkMessagePath), new FB_Image("0", encodeFile), MyHelper.GetUnixTimesStamp(DateTime.Now), true); currentSentInbox.Messages.Add(sentMes); break; } } MyHelper.ResetStatusTrip(pbStatus, lbStatusBar, lbDoing); // Common.DeleteFile(Common.listFileDelete); } else { MessageBox.Show("Please choose a Friend", "Choose A Friend", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Log(ex); MyHelper.ResetStatusTrip(pbStatus, lbStatusBar, lbDoing); MessageBox.Show("There are some error with these images","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); } }
public bool AddMessageToInbox(string content, string imageId, string imagePath, long createdTime, bool isSent = false) { try { if (content.Length >= Form1.HEADER_LEN) { string header = content.Substring(0, Form1.HEADER_LEN); string[] headerComponent = header.Split('|'); if (headerComponent.Length == 3) { string id = headerComponent[0]; int offset = Int16.Parse(headerComponent[1]); int flag = Int16.Parse( headerComponent[2]); string subContent = content.Substring(Form1.HEADER_LEN, content.Length - Form1.HEADER_LEN); FB_Message m = GetMessageByID(messages, id); if (m != null) { m.Part.Add(new MessagePart(subContent, offset, flag,imagePath)); return false; } else { MessagePart part = new MessagePart(subContent, offset, flag,imagePath); FB_Message mes = new FB_Message(content, new FB_Image(imageId, imagePath), id,createdTime); mes.Part.Add(part); messages.Add(mes); return true; } } } return false; } catch (Exception e) { MessageBox.Show(e.Message); return false; } }