public void ChangeProfilePicture() { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "Image Files (JPG, JPEG, PNG)|*.jpg;*.jpeg;*.png"; fileDialog.InitialDirectory = FileResources.WindowsPicturePath; fileDialog.ShowDialog(); if (fileDialog.FileName.Length == 0) { return; } BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { Image gotImg = Image.FromFile(fileDialog.FileName); string profileImgId = ServerFileRequest.ChangeProfileImage(gotImg); if (profileImgId != null) { Universal.ParentForm.Invoke(new Action(() => { Consumer.LoggedIn.ProfileImage = LocalDataFileAccess.GetProfileImgFromLocalData(profileImgId); userProfilePictureLabel.Image = this.ResizedProfileImage; })); } gotImg.Dispose(); }; loaderWorker.RunWorkerCompleted += (s, e) => { VisualizingTools.HideWaitingAnimation(); loaderWorker.Dispose(); }; loaderWorker.RunWorkerAsync(); }
private void OnTextChanged(object sender, EventArgs me) { try { string keyword = ((TextBox)sender).Text; if (keyword.Length >= 2) { VisualizingTools.ShowWaitingAnimation(new Point(this.searchIcon.Left, this.searchBox.Bottom + 5), new Size(this.searchIcon.Width + this.searchBox.Width, this.searchBox.Height / 2), this); BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (s, e) => { List <Consumer> matchList = ServerRequest.SearchFriendsByKeyword(Consumer.LoggedIn.Id, keyword); if (matchList.Count > 0) { this.Invoke(new Action(() => { ShowFriendsInPanel(matchList); })); } }; backgroundWorker.RunWorkerCompleted += (s, e) => { backgroundWorker.Dispose(); VisualizingTools.HideWaitingAnimation(); }; backgroundWorker.RunWorkerAsync(); } else { RefreshFriendlist(); } } catch (Exception ex) { Console.WriteLine("Error in firendlist search box : " + ex.Message); } }
private void OnSetupButtonClick(Object sender, EventArgs e) { VisualizingTools.ShowWaitingAnimation(new Point(this.passwordSetupButton.Left, this.passwordSetupButton.Bottom + 30), new Size(this.passwordSetupButton.Width, this.passwordSetupButton.Height / 2), this); Thread childThread = new Thread(delegate() { if (this.AllKeySetupConstraintsOk()) { TryToSetupLoginKey(); } else { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate { VisualizingTools.HideWaitingAnimation(); })); } else { VisualizingTools.HideWaitingAnimation(); } } }); childThread.Start(); }
private void SetUserNameValidity(Object sender, EventArgs e) { if (this.usernameBox.TextLength > 0 && usernameBoxSign.Visible == false && WaitingUsernameAnimationShowing == false) { VisualizingTools.ShowWaitingAnimation(usernameBoxSign.Location, usernameBoxSign.Size, this); WaitingUsernameAnimationShowing = true; } this.UserNameValid = false; if (Time.TimeDistanceInSecond(this.lastUsernameTextChangeTime, Time.CurrentTime) < 3) { return; } this.userNameValidateTimer.Stop(); if (this.usernameBox.TextLength > 0) { int selectionStartPrev = this.usernameBox.SelectionStart; string input = this.usernameBox.Text; string errorMessage = Checker.CheckUsernameValidity(ref input); this.usernameBox.Text = input; this.usernameBox.SelectionStart = selectionStartPrev; if (errorMessage == null) { UserNameValid = true; } if (UserNameValid) { this.usernameBoxSign.Image = new Bitmap(FileResources.Icon("ok.png"), usernameBoxSign.Size); this.usernameBoxErrorMessage.Visible = false; } else { this.usernameBoxErrorMessage.Text = errorMessage; this.usernameBoxErrorMessage.Size = this.usernameBoxErrorMessage.PreferredSize; this.usernameBoxErrorMessage.Left = this.usernameBox.Right - this.usernameBoxErrorMessage.Width + 5; this.usernameBoxSign.Image = new Bitmap(FileResources.Icon("redwarning.png"), usernameBoxSign.Size); this.usernameBoxErrorMessage.Visible = true; } VisualizingTools.HideWaitingAnimation(); this.WaitingUsernameAnimationShowing = false; this.usernameBoxSign.Visible = true; } else { usernameBoxSign.Visible = false; usernameBoxErrorMessage.Visible = false; } if (this.signUpButtonMessage.Visible) { this.AllSignupConstraintsOk(); } }
private void TryToSetupLoginKey() { string errorMessage = ServerRequest.SetPassword(Universal.SystemMACAddress, this.newPassword); if (errorMessage != null) { VisualizingTools.HideWaitingAnimation(); MessageBox.Show(errorMessage); } else { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate { this.parent.Controls.Remove(this); VisualizingTools.HideWaitingAnimation(); })); } else { this.parent.Controls.Remove(this); VisualizingTools.HideWaitingAnimation(); } if (!this.passwordIsSet) { BackendManager.LoginProcessRun(); } else { BackendManager.SetChangedPassword(this.newPassword); if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new Action(() => { Universal.ParentForm.Controls.Remove(this); ConversationPanel.CurrentDisplayedConversationPanel.Visible = true; SlidebarPanel.MySidebarPanel.Visible = true; MessageBox.Show(Universal.ParentForm, "Password has been sucessfully changed!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } else { Universal.ParentForm.Controls.Remove(this); ConversationPanel.CurrentDisplayedConversationPanel.Visible = true; SlidebarPanel.MySidebarPanel.Visible = true; MessageBox.Show(Universal.ParentForm, "Password has been sucessfully changed!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void ShowErrorMessage(string errorMessage) { if (errorMessage.Length > 0) { VisualizingTools.HideWaitingAnimation(); this.errorLabel.Text = errorMessage; this.errorLabel.Font = CustomFonts.New(CustomFonts.SmallerSize, 'i'); this.errorLabel.TextAlign = ContentAlignment.MiddleCenter; this.errorLabel.ForeColor = Color.Red; this.errorLabel.Size = this.errorLabel.PreferredSize; this.errorLabel.Location = new Point((this.Width - this.errorLabel.PreferredWidth) / 2, this.backButton.Bottom + 15); this.Controls.Add(this.errorLabel); } }
private void EventListener(Object sender, EventArgs e) { if (sender == this.signUpButton) { if (this.AllSignupConstraintsOk()) { VisualizingTools.ShowWaitingAnimation(new Point(this.signUpButton.Left, this.signUpButton.Bottom + 20), new Size(this.signUpButton.Width, this.signUpButton.Height / 2), this); childThreadDB = new System.Threading.Thread(delegate() { JObject signupData = new JObject(); signupData["type"] = "consumer"; signupData["username"] = this.usernameBox.Text; signupData["email"] = this.emailBox.Text; signupData["name"] = Universal.NameValidator(this.nameBox.Text); signupData["mac_address"] = Universal.SystemMACAddress; long?userId = ServerRequest.SignupUser(signupData); if (this.InvokeRequired) { this.Invoke(new Action(() => { if (userId != null) { Universal.ParentForm.Controls.Remove(this); this.Dispose(); VisualizingTools.HideWaitingAnimation(); } else { this.signUpButtonMessage.Text = "Error in connection!"; VisualizingTools.HideWaitingAnimation(); } })); } if (userId != null) { BackendManager.LoginProcessRun(); } }); childThreadDB.Start(); } } else if (sender == this.policiesLinkLabel) { this.policiesLinkLabel.ForeColor = Color.FromArgb(106, 0, 154); } }
new public void Hide() { if (Universal.ParentForm.InvokeRequired) { Universal.ParentForm.Invoke(new Action(() => { this.Hide(); })); return; } if (this.Hidden) { return; } Universal.ParentForm.Controls.Remove(this); VisualizingTools.HideWaitingAnimation(); this.Hidden = true; }
private void TryToLogin() { BackendManager.Password = passwordBox.Text; this.RememberLogin = this.rememberCheck.Checked; bool?loginSuccess = ServerConnections.ServerRequest.LoginWithCredentials(Universal.SystemMACAddress, BackendManager.Password); if (loginSuccess == true) { if (this.RememberLogin) { BackendManager.SaveLoginCookie(); } this.Invoke(new MethodInvoker(delegate { this.parent.Controls.Remove(this); })); BackendManager.LoginNow(User.LoggedIn); } else { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate { VisualizingTools.HideWaitingAnimation(); Label errorLabel = new Label(); if (loginSuccess == false) { errorLabel.Text = "Incorrect password!"; } else { errorLabel.Text = "Communication with database failed!"; } errorLabel.ForeColor = Colors.ErrorTextColor; errorLabel.Font = CustomFonts.Smallest; errorLabel.Size = errorLabel.PreferredSize; errorLabel.Location = new Point(this.loginButton.Right - errorLabel.Width + 5, this.loginButton.Bottom + 3); this.Controls.Add(errorLabel); })); } } }
private void LoadPerviousNuntiasList() { VisualizingTools.ShowWaitingAnimation(new Point(this.Width / 4, this.conversationTitleBar.Bottom + 30), new Size(this.Width / 2, 10), this); BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { 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; } List <Nuntias> previousNuntii = ConversationRepository.Instance.GetLastNuntias(this.theConversation); List <Nuntias> previousPendingNuntii = ConversationRepository.Instance.GetPendingNuntii(this.theConversation); previousNuntii.AddRange(previousPendingNuntii); if (previousNuntii != null && previousNuntii.Count > 0) { foreach (Nuntias item in previousNuntii) { SyncAssets.NuntiasSortedList[item.Id] = item; if (item.Id > 0) { ServerFileRequest.DownloadAndStoreContentFile(item); } this.ShowNuntias(item, false); } } this.ConversationPanelLoadingOk = true; }; loaderWorker.RunWorkerCompleted += (s, e) => { VisualizingTools.HideWaitingAnimation(); loaderWorker.Dispose(); }; loaderWorker.RunWorkerAsync(); }
public bool AllKeySetupConstraintsOk() { if (this.InvokeRequired) { this.Invoke(new MethodInvoker( delegate { this.passwordSetupButtonMessage.Visible = false; })); } else { this.passwordSetupButtonMessage.Visible = false; } this.SetOldPasswordValidity(); string errorMessage = null; if (!this.OldPasswordValid) { errorMessage = "Current Password is Incorrect"; } if (!this.NewPasswordValid) { if (errorMessage != null) { errorMessage += "\r\n"; } errorMessage += "Invalid Password format"; } else if (!this.ConfirmPasswordValid) { if (errorMessage != null) { errorMessage += "\r\n"; } errorMessage += "Confirmed Password not matches"; } if (errorMessage == null) { return(true); } if (this.InvokeRequired) { this.Invoke(new MethodInvoker( delegate { this.passwordSetupButtonMessage.Text = errorMessage; this.passwordSetupButtonMessage.Size = this.passwordSetupButtonMessage.PreferredSize; this.passwordSetupButtonMessage.Left = this.passwordSetupButton.Right - this.passwordSetupButtonMessage.Width + 5; this.passwordSetupButtonMessage.Visible = true; VisualizingTools.HideWaitingAnimation(); })); } else { this.passwordSetupButtonMessage.Text = errorMessage; this.passwordSetupButtonMessage.Size = this.passwordSetupButtonMessage.PreferredSize; this.passwordSetupButtonMessage.Left = this.passwordSetupButton.Right - this.passwordSetupButtonMessage.Width + 5; this.passwordSetupButtonMessage.Visible = true; VisualizingTools.HideWaitingAnimation(); } return(false); }
public void UpdateUserActivity(string userActivity) { BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { if (userActivity == null) { userActivity = ServerRequest.ReceiverLastActiveTime(this.receiver.Id); } ConsumerRepository.Instance.UpdateUserActivity(this.receiver.Id, userActivity); if (userActivity == null || this.theConversation.Type != "duet") { return; } this.receiver.LastActive = ConsumerRepository.Instance.ReceiverLastActiveTime(receiver.Id); Universal.ParentForm.Invoke(new MethodInvoker(delegate { if (this.receiver.LastActive == null) { this.currentStatusLabel.Visible = false; this.currentStatusIcon.Visible = false; return; } if (Time.TimeDistanceInSecond(Time.CurrentTime, this.receiver.LastActive) > 5) { long timeDistanceInMinute = Time.TimeDistanceInMinute(Time.CurrentTime, this.receiver.LastActive); if (timeDistanceInMinute < 60) { this.currentStatusLabel.Text = "Active " + timeDistanceInMinute + " minutes ago"; } else if (timeDistanceInMinute < 1440) { this.currentStatusLabel.Text = "Active about " + timeDistanceInMinute / 60 + " hours ago"; } else if (timeDistanceInMinute < 10080) { this.currentStatusLabel.Text = "Active about " + timeDistanceInMinute / 1440 + " days ago"; } else if (timeDistanceInMinute < 40320) { this.currentStatusLabel.Text = "Active about " + timeDistanceInMinute / 10080 + " weeks ago"; } else { this.currentStatusLabel.Text = "Active about " + timeDistanceInMinute / 40320 + " months ago"; } this.currentStatusIcon.Visible = false; } else { this.currentStatusLabel.Text = "Active Now"; this.currentStatusIcon.Visible = true; } this.currentStatusLabel.Visible = true; this.currentStatusLabel.Size = this.currentStatusLabel.PreferredSize; this.currentStatusLabel.Left = this.conversationNameLabel.Right - currentStatusLabel.PreferredWidth; this.currentStatusIcon.Left = this.currentStatusLabel.Left - 15; })); }; loaderWorker.RunWorkerCompleted += (s, e) => { VisualizingTools.HideWaitingAnimation(); loaderWorker.Dispose(); }; loaderWorker.RunWorkerAsync(); }
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(); } }
private void EventListener(object sender, EventArgs ee) { if (sender == this.bindButton) { string errorMessage = ""; bool allOk = true; if (macAddressBox.Text == null || macAddressBox.Text.Length == 0) { errorMessage += "Invalid MAC Address Input!"; allOk = false; } if (usernameTextBox.Text == null || usernameTextBox.Text.Length == 0) { if (errorMessage.Length > 0) { errorMessage += "\r\n"; } errorMessage += "Username is empty!"; allOk = false; } if (passwordTextBox.Text == null || passwordTextBox.Text.Length == 0) { if (errorMessage.Length > 0) { errorMessage += "\r\n"; } errorMessage += "Password is empty!"; allOk = false; } if (allOk) { VisualizingTools.ShowWaitingAnimation(new Point(this.bindButton.Left, this.bindButton.Bottom + 20), new Size(this.bindButton.Width, this.bindButton.Height / 2), this); BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { try { bool?success = ServerRequest.BindDeviceAndLogin(macAddressBox.Text, usernameTextBox.Text, passwordTextBox.Text); if (success == true) { if (this.loginCheckbox.Checked) { BackendManager.SaveLoginCookie(); } BackendManager.LoginNow(User.LoggedIn); this.Invoke(new Action(() => { VisualizingTools.HideWaitingAnimation(); this.Visible = false; this.parent.Visible = false; this.parent.Dispose(); this.Dispose(); } )); } else if (success == false) { errorMessage = "Invalid username or password!"; this.Invoke(new Action(() => { ShowErrorMessage(errorMessage); } )); } else { errorMessage = "Server connection failed!"; this.Invoke(new Action(() => { ShowErrorMessage(errorMessage); } )); } } catch { } }; loaderWorker.RunWorkerAsync(); loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); }; } else { ShowErrorMessage(errorMessage); } } else if (sender == this.backButton) { this.parent.Visible = true; this.Dispose(); } }
private void EventListener(object sender, EventArgs ee) { if (sender == this.verifyButton) { string errorMessage = ""; if (verificationCodeTextBox.Text == null || verificationCodeTextBox.Text.Length == 0) { errorMessage += "Verification Code Field Empty!"; ShowErrorMessage(errorMessage); return; } VisualizingTools.ShowWaitingAnimation(new Point(this.verifyButton.Left, this.verifyButton.Bottom + 20), new Size(this.verifyButton.Width, this.verifyButton.Height / 2), this); BackgroundWorker loaderWorker = new BackgroundWorker(); loaderWorker.DoWork += (s, e) => { try { int?status = null; status = ServerRequest.VerifyVerificationCode(verificationCodeTextBox.Text, this.purpose); if (status == 1) //1 means verification code is verified successfully { this.Invoke(new Action(() => { VisualizingTools.HideWaitingAnimation(); this.Visible = false; this.Dispose(); if (this.parent != null) { this.parent.Hide(); this.parent.Dispose(); } } )); if (this.purpose == "email_verify") { BackendManager.LoginProcessRun(); } else if (this.purpose == "password_reset") { Universal.ParentForm.Invoke(new MethodInvoker(BackendManager.ShowPasswordSetupPanel)); } } else { if (status == 2) //2 means verification code is not valid { errorMessage = "Verification Code is invalid!"; } else if (status == 3) //3 means verification code is expried { errorMessage = "Verification Code is expired!\r\nA new verification code is sent."; } else if (status == 4) //4 means too many wrong (more than 5) attempts { errorMessage = "Too many unsuccessful attempts!\r\nA new verification code is sent."; } else { errorMessage = "Server connection failed!"; } this.Invoke(new Action(() => { ShowErrorMessage(errorMessage); } )); } } catch (Exception ex) { Console.WriteLine("Exception in UserVerificationPanel.cs = > " + ex.Message); } }; loaderWorker.RunWorkerAsync(); loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); }; } else if (sender == this.backButton) { if (this.parent != null) { this.parent.Visible = true; } else { ServerRequest.DeleteConsumerAccount(Universal.SystemMACAddress, ""); BackendManager.Logout(); } this.Dispose(); } }