public static void SendPendingNuntii() { while (SendPendingNuntiiTaskGoing) { Thread.Sleep(500); continue; } SendPendingNuntiiTaskGoing = true; List <Nuntias> pendingNuntiiList = NuntiasRepository.Instance.GetAllPendingPendingNuntiiList(); if (pendingNuntiiList == null) { Universal.ShowErrorMessage("Error in accessing user data!"); return; } Dictionary <long, long?> universalIdMapAgainstTmpId = new Dictionary <long, long?>(); List <long> toBeDeleted = new List <long>(); foreach (Nuntias tmpNuntias in pendingNuntiiList) { if (tmpNuntias.Id == 0) { continue; } long localNuntiasId = (long)tmpNuntias.Id; long?universalNuntiasId = null; if (tmpNuntias.ContentFileId == null || tmpNuntias.ContentFileId.Length == 0) { universalNuntiasId = ServerRequest.SendNewNuntias(tmpNuntias); } else { universalNuntiasId = ServerFileRequest.SendContentedNuntias(tmpNuntias); } if (universalNuntiasId == null || universalNuntiasId == 0) { continue; } tmpNuntias.Id = (long)universalNuntiasId; NuntiasRepository.Instance.Insert(tmpNuntias); SyncAssets.ConvertLocalNuntiasToGlobal(tmpNuntias, localNuntiasId); toBeDeleted.Add(localNuntiasId); } NuntiasRepository.Instance.DeleteTmpNuntii(toBeDeleted); SendPendingNuntiiTaskGoing = false; }
public NuntiasOptionsPanel(long nuntiasId) { this.nuntiasId = nuntiasId; Nuntias nuntias = SyncAssets.NuntiasSortedList[this.nuntiasId]; this.parentNuntiasLabel = SyncAssets.ShowedNuntiasLabelSortedList[nuntias.Id]; this.BackColor = Color.FromArgb(51, 51, 51); this.ForeColor = Color.FromArgb(220, 220, 220); if (nuntias.SenderId == Consumer.LoggedIn.Id) { this.Name = "own"; } else { this.Name = "other"; } copyNuntiasTextLabel = new Label(); deleteNuntiasLabel = new Label(); this.Controls.Add(copyNuntiasTextLabel); this.Controls.Add(deleteNuntiasLabel); copyNuntiasTextLabel.Text = ""; copyNuntiasTextLabel.Image = copyIcon; copyNuntiasTextLabel.ImageAlign = ContentAlignment.MiddleLeft; copyNuntiasTextLabel.TextAlign = ContentAlignment.MiddleRight; copyNuntiasTextLabel.Font = CustomFonts.Smallest; copyNuntiasTextLabel.Size = labelSize; copyNuntiasTextLabel.MouseEnter += (s, e) => { copyNuntiasTextLabel.BackColor = Color.FromArgb(128, 128, 128); }; copyNuntiasTextLabel.MouseLeave += (s, e) => { copyNuntiasTextLabel.BackColor = Color.Transparent; }; copyNuntiasTextLabel.Click += (s, e) => { if (nuntias.ContentFileId == null || nuntias.ContentFileId.Length == 0) { Clipboard.SetText(nuntias.Text); } else if (nuntias.Text.Length >= 5 && nuntias.Text.Substring(0, 5) == "Image") { Clipboard.SetImage(Image.FromFile(LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId))); } else if (nuntias.Text.Length >= 4 && nuntias.Text.Substring(0, 4) == "File") { StringCollection paths = new StringCollection(); paths.Add(LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId)); Clipboard.SetFileDropList(paths); } this.ChangeNuntiasOptionPanelState(); }; copyNuntiasTextLabel.Visible = false; deleteNuntiasLabel.Text = ""; deleteNuntiasLabel.Image = deleteIcon; deleteNuntiasLabel.ImageAlign = ContentAlignment.MiddleLeft; deleteNuntiasLabel.TextAlign = ContentAlignment.MiddleRight; deleteNuntiasLabel.Font = CustomFonts.Smallest; deleteNuntiasLabel.Size = labelSize; deleteNuntiasLabel.MouseEnter += (s, e) => { deleteNuntiasLabel.BackColor = Color.FromArgb(128, 128, 128); }; deleteNuntiasLabel.MouseLeave += (s, e) => { deleteNuntiasLabel.BackColor = Color.Transparent; }; deleteNuntiasLabel.Click += (s, e) => { if (nuntias.SenderId == Consumer.LoggedIn.Id && Time.TimeDistanceInSecond(Time.CurrentTime, nuntias.SentTime) <= 300) { //server allows deletion of a message that was sent 5 minutes ago or later. DialogResult result = MessageBox.Show("Delete the message from both side?\r\nClick Yes. Else click No.", "Message Deletion", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes || result == DialogResult.No) { BackgroundWorker bworker = new BackgroundWorker(); bworker.DoWork += (ss, ee) => { bool success = ServerRequest.DeleteNuntias(Consumer.LoggedIn.Id, this.NuntiasId, result == DialogResult.Yes); if (success && result == DialogResult.No) { SyncAssets.DeleteNuntiasAssets(this.NuntiasId); } }; bworker.RunWorkerAsync(); bworker.RunWorkerCompleted += (ss, ee) => { bworker.Dispose(); }; } else { return; } } else { DialogResult result = MessageBox.Show("Delete the message for you?", "Message Deletion", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { BackgroundWorker bworker = new BackgroundWorker(); bworker.DoWork += (ss, ee) => { bool success = ServerRequest.DeleteNuntias(Consumer.LoggedIn.Id, this.NuntiasId, false); if (success) { SyncAssets.DeleteNuntiasAssets(this.NuntiasId); } }; bworker.RunWorkerAsync(); bworker.RunWorkerCompleted += (ss, ee) => { bworker.Dispose(); }; } else { return; } } this.ChangeNuntiasOptionPanelState(); }; deleteNuntiasLabel.Visible = false; this.UpdateOptionPanel(); }