public void ShowWaitingAnimation()
        {
            Size  waitBarSize    = new Size(logoLabel.Width, logoLabel.Height / 28);
            Point waiBarLocation = new Point((this.Width - waitBarSize.Width) / 2, logoLabel.Bottom + logoLabel.Height);

            VisualizingTools.ShowWaitingAnimation(waiBarLocation, waitBarSize, this);
        }
 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); }
 }
Пример #3
0
        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 OnLoginButtonClick(Object sender, EventArgs e)
 {
     if (((Button)sender).Name == this.loginButton.Name)
     {
         VisualizingTools.ShowWaitingAnimation(new Point(loginButton.Right - loginButton.Width, loginButton.Bottom + 30), new Size(loginButton.Width, loginButton.Height / 2), this);
         Thread childThread = new Thread(TryToLogin);
         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();
            }
        }
Пример #6
0
        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);
            }
        }
        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();
        }
        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();
            }
        }
Пример #9
0
 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();
     }
 }