internal static void LoginNow(User user) //works as expected { Console.WriteLine("LoginNow()"); DatabaseAccess.LocalDbPassword = BackendManager.GenerateLocalDbPassword(); DatabaseAccess.Instance.VerifyUserDataValidity(); if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(delegate { SplashScreen.Instance.Show(); })); } else { SplashScreen.Instance.Show(); } if (user.AccountType == "consumer") { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new MethodInvoker(LoadEssentialPanelsAfterLoginSuccess)); } else { LoadEssentialPanelsAfterLoginSuccess(); } BackendManager.SendPendingNuntii(); BackendManager.SyncWithTheServer(); ConversationListPanel.MyConversationListPanel.RefreshConversationList(); } }
private void SendTypedNuntias() { string rawText = this.nuntiasTextBox.Text; BackgroundWorker loaderWorker = new BackgroundWorker(); Nuntias newNuntias = null; loaderWorker.DoWork += (s, e) => { try { string processedText = Universal.ProcessValidMessageText(rawText); if (processedText == null) { return; } if (this.TheConversation == null) { long?conversationId = ServerRequest.GetDuetConversationId(User.LoggedIn, this.receiver); if (conversationId == null) { MessageBox.Show("Server connection failed!\r\nPlease retry."); return; } this.TheConversation = new DuetConversation(Consumer.LoggedIn, this.receiver); this.TheConversation.ConversationID = (long)conversationId; } newNuntias = new Nuntias(processedText, User.LoggedIn.Id, Time.CurrentTime, this.theConversation.ConversationID); long?nuntiasTmpID = NuntiasRepository.Instance.StoreTmpNuntias(newNuntias); if (nuntiasTmpID == null) { return; } newNuntias.Id = nuntiasTmpID ?? 0; SyncAssets.NuntiasSortedList[(long)nuntiasTmpID] = newNuntias; this.Invoke(new Action(() => { this.nuntiasTextBox.Clear(); })); this.ShowNuntias(newNuntias, true); BackendManager.SendPendingNuntii(); } catch (Exception ex) { Console.WriteLine("Exception in SendTypedNuntias() => " + ex.Message); } }; loaderWorker.RunWorkerAsync(); loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); }; if (ConversationListPanel.MyConversationListPanel != null) { ConversationListPanel.MyConversationListPanel.RefreshConversationList(); } }
private void SendChoosenFile(string choosenSafeFileName, string localPath, string extension) { if (File.ReadAllBytes(localPath).Length > 1024 * 1024 * 5) { Universal.ShowErrorMessage("Please choose a file below 5 MB."); return; } this.sendFileButton.Visible = false; this.cancelFileButton.Visible = false; int animationLeft = 0, animationPadding = 40; if (imgPreview != null) { animationLeft = imgPreview.Right + animationPadding; } else { animationLeft = Math.Max(animationLeft, fileNameLabel.Right + animationPadding); } VisualizingTools.ShowWaitingAnimation(new Point(animationLeft, (filePreviewPanel.Height - sendButton.Height / 2) / 2), new Size(this.filePreviewPanel.Right - animationLeft - animationPadding - 20, sendButton.Height / 2), filePreviewPanel); BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { try { using (FileStream gotFileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { string fileIdName = this.theConversation.ConversationID + "_" + Universal.SystemMACAddress + "_" + Time.CurrentTime.TimeStampString + "-" + choosenSafeFileName; MemoryStream gotFileMemoryStream = new MemoryStream(); gotFileStream.CopyTo(gotFileMemoryStream); bool storeToLocalSucceed = LocalDataFileAccess.SaveNuntiasContentToLocal(gotFileMemoryStream, fileIdName); if (storeToLocalSucceed) { if (this.theConversation == null) { long?conversationId = ServerRequest.GetDuetConversationId(User.LoggedIn, this.receiver); if (conversationId == null) { MessageBox.Show("Server connection failed!\r\nPlease retry."); return; } this.TheConversation = new DuetConversation(Consumer.LoggedIn, this.receiver); this.TheConversation.ConversationID = (long)conversationId; } Nuntias newNuntias = new Nuntias("File: " + choosenSafeFileName, Consumer.LoggedIn.Id, Time.CurrentTime, this.theConversation.ConversationID); newNuntias.ContentFileId = fileIdName; if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".gif" || extension == ".bmp") { newNuntias.Text = "Image : " + choosenSafeFileName; } long?nuntiasTmpID = NuntiasRepository.Instance.StoreTmpNuntias(newNuntias); if (nuntiasTmpID == null) { newNuntias = null; } else { newNuntias.Id = nuntiasTmpID ?? 0; } if (newNuntias == null) { return; } this.ShowNuntias(newNuntias, true); BackendManager.SendPendingNuntii(); string localStoredPath = LocalDataFileAccess.GetContentPathFromLocalData(fileIdName); Universal.ParentForm.Invoke(new Action(() => { VisualizingTools.HideWaitingAnimation(); if (localStoredPath != null) { this.FilePreviewPanelHeight(0); } else { Universal.ShowErrorMessage("Failed to send the file!"); } })); gotFileStream.Close(); gotFileMemoryStream.Dispose(); loaderWorker.Dispose(); this.DisposeUnmanaged(); } } } catch (Exception ex) { Console.WriteLine("Error occured while sending a file: " + ex.Message); }; }; loaderWorker.RunWorkerAsync(); loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); }; if (ConversationListPanel.MyConversationListPanel != null) { ConversationListPanel.MyConversationListPanel.RefreshConversationList(); } }