public static bool DeleteNuntias(long ownerId, long nuntiasId, bool forBoth)
        {
            if (nuntiasId <= 0)
            {
                NuntiasRepository.Instance.DeleteTmpNuntias(nuntiasId);
                return(true);
            }
            JObject nuntiasDeleteRequestJson = new JObject();

            nuntiasDeleteRequestJson["owner_id"]   = ownerId;
            nuntiasDeleteRequestJson["nuntias_id"] = nuntiasId;
            nuntiasDeleteRequestJson["for_both"]   = forBoth;

            bool?success = null;

            ServerHub.WorkingInstance.ServerHubProxy.Invoke <bool>("DeleteNuntias", nuntiasDeleteRequestJson).ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    success = task.Result;
                }
            }).Wait();

            if (success == null)
            {
                Universal.ShowErrorMessage("Server connection failed", "Message deletion failed");
                return(false);
            }

            if (!forBoth)
            {
                NuntiasRepository.Instance.Delete(nuntiasId);
            }
            return(true);
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        private void othersInfoEditBoxInitialize()
        {
            this.othersInfoEditPanel        = new Panel();
            this.othersInfoEditPanel.Width  = this.Width;
            this.othersInfoEditPanel.Height = this.Height;

            Label settingsLabel = new Label();

            settingsLabel.Text      = "Account Settings";
            settingsLabel.Font      = CustomFonts.RegularBold;
            settingsLabel.Size      = settingsLabel.PreferredSize;
            settingsLabel.ForeColor = Color.FromArgb(77, 77, 77);
            this.othersInfoEditPanel.Controls.Add(settingsLabel);

            Label macAddressLabel = new Label();

            macAddressLabel.Text      = "Device MAC :";
            macAddressLabel.Font      = CustomFonts.Smaller;
            macAddressLabel.Size      = macAddressLabel.PreferredSize;
            macAddressLabel.ForeColor = Color.FromArgb(77, 77, 77);
            this.othersInfoEditPanel.Controls.Add(macAddressLabel);

            this.macAddressTextbox             = new TextBox();
            this.macAddressTextbox.Text        = Universal.SystemMACAddress;
            this.macAddressTextbox.ReadOnly    = true;
            this.macAddressTextbox.BorderStyle = BorderStyle.None;
            this.macAddressTextbox.Font        = CustomFonts.Small;
            this.macAddressTextbox.Width       = this.Width * 4 / 5;
            this.macAddressTextbox.ForeColor   = Color.FromArgb(77, 77, 77);
            this.macAddressTextbox.BackColor   = this.BackColor;
            this.othersInfoEditPanel.Controls.Add(macAddressTextbox);

            Label usernameLabel = new Label();

            usernameLabel.Text      = "Username :"******"@" + this.usernameTextbox.Text; };
            this.othersInfoEditPanel.Controls.Add(usernameTextbox);

            Label phoneLabel = new Label();

            phoneLabel.Text      = "Phone :";
            phoneLabel.Font      = CustomFonts.Smaller;
            phoneLabel.Size      = phoneLabel.PreferredSize;
            phoneLabel.ForeColor = Color.FromArgb(77, 77, 77);
            this.othersInfoEditPanel.Controls.Add(phoneLabel);

            this.phoneTextBox             = new TextBox();
            this.phoneTextBox.Text        = Consumer.LoggedIn.Phone;
            this.phoneTextBox.Font        = CustomFonts.Small;
            this.phoneTextBox.BorderStyle = BorderStyle.None;
            this.phoneTextBox.Width       = (this.Width * 5 / 6) - phoneLabel.Width;
            this.phoneTextBox.ForeColor   = Color.FromArgb(77, 77, 77);
            //this.phoneTextBox.KeyPress += (s, e) => { if(e.KeyChar >= '0' && e.KeyChar <= '9') };
            this.othersInfoEditPanel.Controls.Add(phoneTextBox);

            Label emailLabel = new Label();

            emailLabel.Text      = "Email";
            emailLabel.Font      = CustomFonts.Smaller;
            emailLabel.Size      = emailLabel.PreferredSize;
            emailLabel.ForeColor = Color.FromArgb(77, 77, 77);
            this.othersInfoEditPanel.Controls.Add(emailLabel);

            this.emailTextBox             = new TextBox();
            this.emailTextBox.Text        = Consumer.LoggedIn.Email;
            this.emailTextBox.ReadOnly    = true;               //changing email address is temporarily disabled
            this.emailTextBox.Font        = CustomFonts.Small;
            this.emailTextBox.BorderStyle = BorderStyle.None;
            this.emailTextBox.Width       = this.Width * 5 / 6;
            this.emailTextBox.ForeColor   = Color.FromArgb(77, 77, 77);
            this.othersInfoEditPanel.Controls.Add(emailTextBox);

            Label genderLabel = new Label();

            genderLabel.Text      = "Gender";
            genderLabel.Font      = CustomFonts.Smaller;
            genderLabel.ForeColor = Color.FromArgb(77, 77, 77);
            genderLabel.Size      = genderLabel.PreferredSize;
            this.othersInfoEditPanel.Controls.Add(genderLabel);

            genderChooser      = new ComboBox();
            genderChooser.Font = CustomFonts.Smallest;
            string[] itemList = new string[] { "", "Male", "Female", "Others" };
            foreach (string str in itemList)
            {
                genderChooser.Items.Add(str);
            }
            if (Consumer.LoggedIn.GenderIndex > 0)
            {
                genderChooser.SelectedIndex = (int)Consumer.LoggedIn.GenderIndex;
            }
            genderChooser.DropDownStyle = ComboBoxStyle.DropDownList;
            this.othersInfoEditPanel.Controls.Add(genderChooser);

            Label birthdateLabel = new Label();

            birthdateLabel.Text      = "Birth Date";
            birthdateLabel.Font      = CustomFonts.Smaller;
            birthdateLabel.Size      = birthdateLabel.PreferredSize;
            birthdateLabel.ForeColor = Color.FromArgb(77, 77, 77);
            this.othersInfoEditPanel.Controls.Add(birthdateLabel);

            birthdatePicker = new DateTimePicker();
            if (Consumer.LoggedIn.Birthdate != null)
            {
                birthdatePicker.Value = Convert.ToDateTime(Consumer.LoggedIn.Birthdate.DbFormat);
                birthdateLabel.Text   = "Birth Date";
            }
            else
            {
                birthdateLabel.Text = "Birth Date (not set)";
            }
            birthdateLabel.Size  = birthdateLabel.PreferredSize;
            birthdatePicker.Font = CustomFonts.Smaller;
            this.othersInfoEditPanel.Controls.Add(birthdatePicker);

            Label oldPasswordLabel = new Label();

            oldPasswordLabel.Text      = "Current Password";
            oldPasswordLabel.Font      = CustomFonts.Smaller;
            oldPasswordLabel.ForeColor = Color.FromArgb(77, 77, 77);
            oldPasswordLabel.Size      = oldPasswordLabel.PreferredSize;
            this.othersInfoEditPanel.Controls.Add(oldPasswordLabel);

            currentPasswordTextBox = new TextBox();
            currentPasswordTextBox.PasswordChar = '•';
            currentPasswordTextBox.ForeColor    = Color.FromArgb(77, 77, 77);
            currentPasswordTextBox.Font         = CustomFonts.Smallest;
            currentPasswordTextBox.Size         = currentPasswordTextBox.PreferredSize;
            this.othersInfoEditPanel.Controls.Add(currentPasswordTextBox);

            this.Controls.Add(othersInfoEditPanel);
            this.othersInfoEditPanel.Location = new Point(0, userViewPanel.Bottom + 4);

            //initializing sizes
            settingsLabel.Location = new Point((this.Width - settingsLabel.Width) / 2, settingsLabel.Height / 2);

            emailTextBox.Left           = (this.Width - emailTextBox.Width) / 2;
            usernameLabel.Left          = emailTextBox.Left - 3;
            usernameTextbox.Left        = usernameLabel.Right + 10;
            macAddressLabel.Left        = emailTextBox.Left - 3;
            macAddressTextbox.Left      = macAddressLabel.Right + 10;
            phoneLabel.Left             = emailTextBox.Left - 3;
            phoneTextBox.Left           = phoneLabel.Right + 10;
            emailLabel.Left             = emailTextBox.Left - 3;
            genderLabel.Left            = emailTextBox.Left - 3;
            genderChooser.Left          = genderLabel.Right + 10;
            birthdateLabel.Left         = emailTextBox.Left - 3;
            birthdatePicker.Left        = birthdateLabel.Right + 5;
            oldPasswordLabel.Left       = emailTextBox.Left - 3;
            currentPasswordTextBox.Left = oldPasswordLabel.Right + 5;

            macAddressLabel.Top   = settingsLabel.Bottom + 20;
            macAddressTextbox.Top = macAddressLabel.Top;

            usernameLabel.Top   = macAddressTextbox.Bottom + 15;
            usernameTextbox.Top = usernameLabel.Top;

            phoneLabel.Top   = usernameTextbox.Bottom + 15;
            phoneTextBox.Top = phoneLabel.Top;

            emailLabel.Top   = phoneTextBox.Bottom + 15;
            emailTextBox.Top = emailLabel.Bottom + 5;

            genderLabel.Top   = emailTextBox.Bottom + 15;
            genderChooser.Top = genderLabel.Top;

            birthdateLabel.Top  = genderChooser.Bottom + 15;
            birthdatePicker.Top = birthdateLabel.Top;

            oldPasswordLabel.Top         = birthdatePicker.Bottom + 15;
            currentPasswordTextBox.Top   = oldPasswordLabel.Top;
            currentPasswordTextBox.Width = emailTextBox.Right - oldPasswordLabel.Right;

            //buttons initialize

            saveButton             = new Button();
            saveButton.Text        = "Save";
            saveButton.BackColor   = Color.FromArgb(0, 0, 102);
            saveButton.ForeColor   = Color.FromArgb(234, 234, 234);
            saveButton.Font        = CustomFonts.SmallerBold;
            saveButton.Size        = saveButton.PreferredSize;
            saveButton.FlatStyle   = FlatStyle.Flat;
            saveButton.Left        = this.currentPasswordTextBox.Right - saveButton.Width;
            saveButton.MouseEnter += (s, e) => { saveButton.BackColor = Color.FromArgb(saveButton.BackColor.R + 50, saveButton.BackColor.G + 50, saveButton.BackColor.B + 50); };
            saveButton.MouseLeave += (s, e) => { saveButton.BackColor = Color.FromArgb(saveButton.BackColor.R - 50, saveButton.BackColor.G - 50, saveButton.BackColor.B - 50); };
            saveButton.Click      += (sender, eargs) =>
            {
                try
                {
                    string name = this.fullnameTextBox.Text, phone = phoneTextBox.Text, username = usernameTextbox.Text, email = emailTextBox.Text, inputPassword = currentPasswordTextBox.Text;
                    Time   birthdate = new Time(birthdatePicker.Value);
                    string nameError = null, usernameError = null, emailError = null, genderError = null, birthdateError = null, passwordError = null;
                    nameError = StandardAssuranceLibrary.Checker.CheckNameValidity(name);
                    if (username != Consumer.LoggedIn.Username)
                    {
                        usernameError = StandardAssuranceLibrary.Checker.CheckUsernameValidity(ref username);
                    }
                    if (email != Consumer.LoggedIn.Email)
                    {
                        emailError = StandardAssuranceLibrary.Checker.CheckEmailValidity(ref email);
                    }
                    if (genderChooser.SelectedIndex == -1 || genderChooser.SelectedIndex == 0)
                    {
                        genderError = "No gender is choosen.";
                    }
                    if (Time.TimeDistanceInMinute(birthdate, Time.CurrentTime) < 6837340)
                    {
                        birthdateError = "Less than 13 years old are not allowed.";
                    }

                    JObject consumerJson = new JObject();
                    consumerJson["id"]           = Consumer.LoggedIn.Id;
                    consumerJson["name"]         = name;
                    consumerJson["username"]     = username;
                    consumerJson["email"]        = email;
                    consumerJson["phone"]        = phone;
                    consumerJson["birthdate"]    = birthdate.TimeStampString;
                    consumerJson["gender_index"] = genderChooser.SelectedIndex;
                    if (Consumer.LoggedIn.ProfileImageId.Length > 5)
                    {
                        consumerJson["profile_img_id"] = Consumer.LoggedIn.ProfileImageId;
                    }

                    BackgroundWorker loaderWorker = new BackgroundWorker();
                    loaderWorker.DoWork += (s, e) =>
                    {
                        passwordError = StandardAssuranceLibrary.Checker.CheckOldPasswordMatch(inputPassword);
                        string errorMessage = passwordError + "\r\n" + nameError + "\r\n" + usernameError + "\r\n" + emailError + "\r\n" + genderError + "\r\n" + birthdateError + "\r\n";
                        string errorSum     = passwordError + usernameError + nameError + emailError + genderError + birthdateError;
                        if (errorSum.Length < 4)
                        {
                            Consumer consumer = new Consumer(consumerJson);
                            bool?    success  = ServerRequest.UpdateUserInfo(consumer);
                            if (success == true)
                            {
                                Consumer.LoggedIn = consumer;
                                Universal.ShowInfoMessage("The informations have been updated successful!", "Updated successfully!");
                                Universal.ParentForm.Invoke(new Action(() =>
                                {
                                    currentPasswordTextBox.Text = "";
                                }));
                            }
                            else
                            {
                                Universal.ShowErrorMessage("Error encountered while updating the informations.", "Update unsuccessful!");
                                Universal.ParentForm.Invoke(new Action(() =>
                                {
                                    currentPasswordTextBox.Text = "";
                                }));
                            }
                        }
                        else
                        {
                            Universal.ShowErrorMessage(errorMessage);
                        }
                    };
                    loaderWorker.RunWorkerAsync();
                    loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); };
                }
                catch (Exception ex) { Console.WriteLine("Exception in UpdateUser() => " + ex.Message); }
            };
            this.othersInfoEditPanel.Controls.Add(saveButton);

            deleteAccountButton             = new Button();
            deleteAccountButton.Text        = "Delete Account";
            deleteAccountButton.BackColor   = Color.FromArgb(153, 0, 0);
            deleteAccountButton.ForeColor   = Color.FromArgb(234, 234, 234);
            deleteAccountButton.Font        = CustomFonts.SmallerBold;
            deleteAccountButton.Size        = deleteAccountButton.PreferredSize;
            deleteAccountButton.FlatStyle   = FlatStyle.Flat;
            deleteAccountButton.Left        = oldPasswordLabel.Left;
            deleteAccountButton.MouseEnter += (s, e) => { deleteAccountButton.BackColor = Color.FromArgb(deleteAccountButton.BackColor.R + 50, deleteAccountButton.BackColor.G + 50, deleteAccountButton.BackColor.B + 50); };
            deleteAccountButton.MouseLeave += (s, e) => { deleteAccountButton.BackColor = Color.FromArgb(deleteAccountButton.BackColor.R - 50, deleteAccountButton.BackColor.G - 50, deleteAccountButton.BackColor.B - 50); };
            deleteAccountButton.Click      += (sender, eargs) =>
            {
                DialogResult result = MessageBox.Show("Are you sure to delete your account?\r\nAll your messages, conversations, friendlist and everything belongs to you will be deleted.\r\nAnd this can't be undone!", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly);
                if (result == DialogResult.Yes)
                {
                    if (this.currentPasswordTextBox.Text == null || this.currentPasswordTextBox.Text.Length <= 6)
                    {
                        Universal.ShowErrorMessage("Please enter your valid current password.", "Deletion unsuccessful!");
                        return;
                    }
                    BackgroundWorker loaderWorker = new BackgroundWorker();
                    loaderWorker.DoWork += (s, e) =>
                    {
                        try
                        {
                            string operationMessage = ServerRequest.DeleteConsumerAccount(Universal.SystemMACAddress, this.currentPasswordTextBox.Text);
                            if (operationMessage == null || operationMessage.Length == 0)
                            {
                                Universal.ShowErrorMessage("Connection to the server failed!", "Deletion unsuccessful!");
                            }
                            if (operationMessage == "success")
                            {
                                Universal.ShowInfoMessage("Your account has been deleted!", "Deletion successful!");
                                BackendManager.Logout();
                            }
                            else
                            {
                                Universal.ShowErrorMessage(operationMessage, "Deletion unsuccessful!");
                            }
                        }
                        catch { }
                    };
                    loaderWorker.RunWorkerAsync();
                    loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); };
                }
            };
            this.othersInfoEditPanel.Controls.Add(deleteAccountButton);

            Label cancelButtonLabel = new Label();

            cancelButtonLabel.Text        = "Cancel && Back";
            cancelButtonLabel.BackColor   = Color.FromArgb(this.BackColor.R - 20, this.BackColor.G - 20, this.BackColor.B - 20);
            cancelButtonLabel.TextAlign   = ContentAlignment.MiddleCenter;
            cancelButtonLabel.Font        = CustomFonts.SmallerBold;
            cancelButtonLabel.Width       = this.Width;
            cancelButtonLabel.Height      = cancelButtonLabel.PreferredHeight * 5 / 2;
            cancelButtonLabel.Top         = this.Bottom - this.userViewPanel.Height - cancelButtonLabel.Height;
            cancelButtonLabel.MouseEnter += (s, e) => { cancelButtonLabel.BackColor = Color.FromArgb(cancelButtonLabel.BackColor.R - 30, cancelButtonLabel.BackColor.G - 30, cancelButtonLabel.BackColor.B - 30); };
            cancelButtonLabel.MouseLeave += (s, e) => { cancelButtonLabel.BackColor = Color.FromArgb(cancelButtonLabel.BackColor.R + 30, cancelButtonLabel.BackColor.G + 30, cancelButtonLabel.BackColor.B + 30); };
            cancelButtonLabel.Click      += (s, e) =>
            {
                SlidebarPanel.MySidebarPanel.Controls.Remove(this);
                this.Dispose();
                SlidebarPanel.MySidebarPanel.Controls.Add(SlidebarPanel.MySidebarPanel.MainPanelInSidebar);
            };

            deleteAccountButton.Top = cancelButtonLabel.Top - deleteAccountButton.Height - 10;
            saveButton.Top          = deleteAccountButton.Top;

            LinkLabel changePasswordLink = new LinkLabel();

            changePasswordLink.Text         = "or, Change Password";
            changePasswordLink.Font         = CustomFonts.Smaller;
            changePasswordLink.LinkArea     = new LinkArea(4, changePasswordLink.Text.Length - 4);
            changePasswordLink.Size         = changePasswordLink.PreferredSize;
            changePasswordLink.Left         = oldPasswordLabel.Left;
            changePasswordLink.Top          = deleteAccountButton.Top - changePasswordLink.Height - 10;
            changePasswordLink.LinkClicked += (s, e) =>
            {
                if (ConversationPanel.CurrentDisplayedConversationPanel != null)
                {
                    ConversationPanel.CurrentDisplayedConversationPanel.Visible = false; SlidebarPanel.MySidebarPanel.Visible = false;
                }
                (new LoginPanel(Universal.ParentForm, true, true)).ShowPasswordSetupPanel();
            };
            this.othersInfoEditPanel.Controls.Add(changePasswordLink);

            LinkLabel UnbindDeviceLink = new LinkLabel();

            UnbindDeviceLink.Text         = "&Unbind Device";
            UnbindDeviceLink.Font         = CustomFonts.Smaller;
            UnbindDeviceLink.LinkArea     = new LinkArea(0, UnbindDeviceLink.Text.Length);
            UnbindDeviceLink.Size         = UnbindDeviceLink.PreferredSize;
            UnbindDeviceLink.Left         = this.othersInfoEditPanel.Right - UnbindDeviceLink.Width - (changePasswordLink.Left - this.othersInfoEditPanel.Left);
            UnbindDeviceLink.Top          = changePasswordLink.Top;
            UnbindDeviceLink.LinkClicked += (sender, eargs) =>
            {
                string passwordError = StandardAssuranceLibrary.Checker.CheckOldPasswordMatch(this.currentPasswordTextBox.Text);
                if (passwordError != null && passwordError.Length > 0)
                {
                    Universal.ShowErrorMessage(passwordError, "Error!");
                    return;
                }

                DialogResult result = MessageBox.Show("Are you sure to unbind this device from this account?", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly);
                if (result == DialogResult.Yes)
                {
                    BackgroundWorker loaderWorker = new BackgroundWorker();
                    loaderWorker.DoWork += (s, e) =>
                    {
                        bool?success = ServerRequest.UnbindDeviceFromAccount();
                        if (success == true)
                        {
                            Universal.ShowInfoMessage("This device has been unbound\r\nsuccessfullly from user account '" + User.LoggedIn.Username + "'!", "Unbound successfull!");
                            BackendManager.Logout();
                        }
                        else
                        {
                            string operationMessage = "Sorry! The device unbound process has been failed!";
                            if (success == null)
                            {
                                operationMessage = "Server Connection Failed!";
                            }
                            Universal.ShowErrorMessage(operationMessage, "Unbound unsuccessful!");
                        }
                    };
                    loaderWorker.RunWorkerAsync();
                    loaderWorker.RunWorkerCompleted += (s, e) => { loaderWorker.Dispose(); };
                }
            };
            this.othersInfoEditPanel.Controls.Add(UnbindDeviceLink);

            this.othersInfoEditPanel.Controls.Add(cancelButtonLabel);
        }
Exemplo n.º 4
0
        public static void LoginProcessRun()                                                    //works as expected
        {
            bool?macExists = ServerRequest.MacAddressExists(Universal.SystemMACAddress);

            if (macExists == false)
            {
                if (Universal.ParentForm.InvokeRequired)
                {
                    Universal.ParentForm.Invoke(new MethodInvoker(delegate
                    {
                        Universal.ParentForm.Controls.Add(new SignupPanel(Universal.ParentForm));
                        SplashScreen.Instance.Hide();
                    }));
                }
                else
                {
                    Universal.ParentForm.Controls.Add(new SignupPanel(Universal.ParentForm));
                    SplashScreen.Instance.Hide();
                }
                return;
            }
            else if (macExists == null)
            {
                if (Universal.ParentForm.InvokeRequired)
                {
                    Universal.ParentForm.Invoke(new MethodInvoker(delegate
                    {
                        MessageBox.Show(Universal.ParentForm, "Server connection failed", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }));
                }
                else
                {
                    MessageBox.Show(Universal.ParentForm, "Server connection failed", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }

            JObject localCookieJson = Checker.ValidLoginCookieData(Universal.SystemMACAddress);

            if (localCookieJson != null && (Time.TimeDistanceInMinute(new Time(localCookieJson["last_login_time"].ToString()), Time.CurrentTime) > 4320 || localCookieJson["mac_address"].ToString() != Universal.SystemMACAddress))
            {
                LocalDataFileAccess.EraseCurrentLoginCookie();
                localCookieJson = null;
            }

            if (localCookieJson == null)
            {
                int?userVerifiedOrPasswordIsSet = ServerRequest.UserVerifiedOrPasswordIsSet(Universal.SystemMACAddress);
                if (userVerifiedOrPasswordIsSet == 0)            //0 means user is not verified
                {
                    if (Universal.ParentForm.InvokeRequired)
                    {
                        Universal.ParentForm.Invoke(new MethodInvoker(ShowEmailVerificationInputPanel));
                    }
                    else
                    {
                        ShowEmailVerificationInputPanel();
                    }
                }
                else if (userVerifiedOrPasswordIsSet == 1)          //1 means user verified but password is not set
                {
                    if (Universal.ParentForm.InvokeRequired)
                    {
                        Universal.ParentForm.Invoke(new MethodInvoker(ShowPasswordSetupPanel));
                    }
                    else
                    {
                        ShowPasswordSetupPanel();
                    }
                }
                else if (userVerifiedOrPasswordIsSet == 2)           //2 means user is verified and password is set
                {
                    if (Universal.ParentForm.InvokeRequired)
                    {
                        Universal.ParentForm.Invoke(new MethodInvoker(ShowPasswordEnterPanel));
                    }
                    else
                    {
                        ShowPasswordEnterPanel();
                    }
                }
                else if (userVerifiedOrPasswordIsSet == null)
                {
                    Universal.ShowErrorMessage("Server connection failed!");
                }
            }
            else
            {
                bool?loginSuccess = ServerRequest.LoginWithCookie(localCookieJson);
                if (loginSuccess == true)
                {
                    BackendManager.Password = localCookieJson["password"].ToString();
                    BackendManager.SaveLoginCookie();
                    BackendManager.LoginNow(User.LoggedIn);
                    SplashScreen.Instance.Hide();
                }
                else if (loginSuccess == false)
                {
                    LocalDataFileAccess.EraseCurrentLoginCookie();
                    LoginProcessRun();
                }
                else
                {
                    MessageBox.Show("Server connection failed!");
                }
            }
        }
        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();
            }
        }
Exemplo n.º 6
0
        private void ShowNuntiasTasks(Nuntias nuntias, bool playConversationInnerSound, string processesedText)
        {
            bool nuntiasIsImage = (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0 && nuntias.Text.Length >= 5 && nuntias.Text.Substring(0, 5) == "Image");     //Nuntias.Text format for image file is 'Image: image_file_name'

            SyncAssets.NuntiasSortedList[nuntias.Id] = nuntias;
            if (playConversationInnerSound)
            {
                ConversationPanel.newMessageSound.Play();
            }
            bool      newTimeStampShowed = this.ShowTimeStampIfNecessary(nuntias);
            bool      profileImageShowed = this.ShowProfileImageIfNecessary(nuntias, newTimeStampShowed);
            LinkLabel nuntiasLabel       = SyncAssets.ShowedNuntiasLabelSortedList[nuntias.Id] = new LinkLabel();

            nuntiasLabel.Name     = nuntias.Id.ToString();
            nuntiasLabel.LinkArea = new LinkArea(0, 0);
            if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0)
            {
                try
                {
                    if (nuntias.ContentFileId == "deleted")
                    {
                        nuntiasLabel.Text      = processesedText;
                        nuntiasLabel.ForeColor = Color.FromArgb(95, 95, 95);
                        nuntiasLabel.Padding   = new Padding(7, 7, 7, 7);
                        nuntiasLabel.Font      = CustomFonts.New(CustomFonts.SmallerSize, 'i');
                        nuntiasLabel.Size      = nuntiasLabel.PreferredSize;
                    }
                    else
                    {
                        string contentFilePath = LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId);
                        if (nuntiasIsImage)
                        {
                            if (contentFilePath != null)
                            {
                                using (FileStream imgStream = new FileStream(contentFilePath, FileMode.Open))
                                {
                                    Image img = Image.FromStream(imgStream);
                                    nuntiasLabel.Image = new Bitmap(img, new Size((int)((150.0 / img.Height) * img.Width), 150));
                                    img.Dispose();
                                    imgStream.Close();
                                    nuntiasLabel.Size = nuntiasLabel.Image.Size;
                                }
                            }
                            nuntiasLabel.Padding = new Padding(7, 7, 7, 7);
                        }
                        else
                        {
                            nuntiasLabel.Text         = processesedText;
                            nuntiasLabel.LinkArea     = new LinkArea(6, nuntiasLabel.Text.Length - 6);
                            nuntiasLabel.LinkColor    = Color.FromArgb(94, 92, 0);
                            nuntiasLabel.LinkClicked += delegate(Object sender, LinkLabelLinkClickedEventArgs e)
                            {
                                try
                                {
                                    Process.Start(contentFilePath);
                                    nuntiasLabel.LinkVisited = true;
                                }
                                catch
                                {
                                    Universal.ShowErrorMessage("Failed to open the file!");
                                }
                            };
                            nuntiasLabel.ForeColor = Color.FromArgb(95, 95, 95);
                            nuntiasLabel.Padding   = new Padding(7, 7, 7, 7);
                            nuntiasLabel.Font      = CustomFonts.New(CustomFonts.SmallerSize, 'i');
                            nuntiasLabel.Size      = nuntiasLabel.PreferredSize;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception occured in conversation panel ShowNuntias() method due to: " + e.Message + " exception type " + e.GetType());
                }
            }
            else
            {
                nuntiasLabel.Text = processesedText;
                Universal.SetLinkAreaIfLinkFound(nuntiasLabel);
                nuntiasLabel.LinkClicked += delegate(Object sender, LinkLabelLinkClickedEventArgs e)
                {
                    try
                    {
                        Process.Start(e.Link.LinkData.ToString());; e.Link.Visited = true;
                    }
                    catch
                    {
                        Universal.ShowErrorMessage("Failed to open the link!");
                    }
                };
                nuntiasLabel.Font    = CustomFonts.Smaller;
                nuntiasLabel.Padding = new Padding(7, 7, 7, 7);
                nuntiasLabel.Size    = nuntiasLabel.PreferredSize;
            }

            if (!nuntiasIsImage && nuntias.ContentFileId != "deleted")
            {
                if (nuntias.SenderId == Consumer.LoggedIn.Id)
                {
                    nuntiasLabel.BackColor = Color.FromArgb(231, 255, 234);
                }
                else
                {
                    nuntiasLabel.BackColor = Color.FromArgb(229, 231, 255);
                }
            }
            if (profileImageShowed)
            {
                nuntiasLabel.Top = this.lastShowedLabel.Bottom - this.profileImageSize.Height + 5;
            }
            else if (this.lastShowedNuntias == null || this.lastShowedNuntias.SenderId != nuntias.SenderId)
            {
                nuntiasLabel.Top = this.lastShowedLabel.Bottom + 25;
            }
            else
            {
                nuntiasLabel.Top = this.lastShowedLabel.Bottom + 5;
            }
            if (nuntias.SenderId == Consumer.LoggedIn.Id)
            {
                nuntiasLabel.Left = this.selfProfileImageLocation.X - nuntiasLabel.Width - this.profileImageSize.Width / 4;
            }
            else
            {
                nuntiasLabel.Left = this.othersProfileImageLocation.X + this.profileImageSize.Width + this.profileImageSize.Width / 4;
            }
            this.nuntiasBossPanel.Controls.Add(nuntiasLabel);
            this.lastShowedNuntias = nuntias;
            this.lastShowedLabel   = nuntiasLabel;

            int   x = 0;
            Timer makeXzeroTimer = new Timer()
            {
                Interval = 500
            };

            makeXzeroTimer.Tick += delegate(Object sender, EventArgs e) { x = 0; };

            NuntiasInfoPanel    respectiveInfoPanel   = null;
            NuntiasOptionsPanel respectiveOptionPanel = null;

            if (nuntias.ContentFileId != "deleted")
            {
                respectiveInfoPanel = SyncAssets.NuntiasInfoPanelSortedList[nuntias.Id] = new NuntiasInfoPanel(nuntias.Id);
                this.nuntiasBossPanel.Controls.Add(respectiveInfoPanel);

                respectiveOptionPanel = SyncAssets.NuntiasOptionPanelSortedList[nuntias.Id] = new NuntiasOptionsPanel(nuntias.Id);
                this.nuntiasBossPanel.Controls.Add(respectiveOptionPanel);
            }

            nuntiasLabel.MouseEnter += (s, me) =>
            {
                if (nuntiasIsImage)
                {
                    return;
                }
                Color current = ((Label)s).BackColor;
                if (current == Color.Transparent)
                {
                    return;
                }
                ((Label)s).BackColor = Color.FromArgb(current.R - 25, current.G - 25, current.B - 25);
            };
            nuntiasLabel.MouseLeave += (s, me) =>
            {
                if (nuntiasIsImage)
                {
                    return;
                }
                Color current = ((Label)s).BackColor;
                if (current == Color.Transparent)
                {
                    return;
                }
                ((Label)s).BackColor = Color.FromArgb(current.R + 25, current.G + 25, current.B + 25);
            };
            nuntiasLabel.MouseClick += delegate(Object sender, MouseEventArgs e)
            {
                if (respectiveOptionPanel == null)
                {
                    return;
                }
                if (respectiveInfoPanel == null)
                {
                    return;
                }
                if (e.Button == MouseButtons.Left)
                {
                    if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0)
                    {
                        makeXzeroTimer.Start();
                        x++;
                    }
                    if (x == 2)
                    {
                        if (nuntias.ContentFileId != null && nuntias.ContentFileId.Length > 0)
                        {
                            try
                            {
                                Process.Start(LocalDataFileAccess.GetFilePathInLocalData(nuntias.ContentFileId));
                            }
                            catch
                            {
                                Universal.ShowErrorMessage("Failed to open the file!");
                            }
                        }
                        makeXzeroTimer.Stop();
                        x = 0;
                    }
                    if (respectiveOptionPanel.Visible)
                    {
                        respectiveOptionPanel.ChangeNuntiasOptionPanelState();
                    }
                    respectiveInfoPanel.ChangeNuntiasInfoPanelState();
                    this.OnClick(sender, e);
                }
                else
                {
                    if (respectiveInfoPanel.Visible)
                    {
                        respectiveInfoPanel.ChangeNuntiasInfoPanelState();
                    }
                    respectiveOptionPanel.ChangeNuntiasOptionPanelState();
                    this.OnClick(sender, e);
                }
            };

            Label keepSpaceAtBottom = new Label();

            keepSpaceAtBottom.Location = new Point(0, this.lastShowedLabel.Bottom + 25);
            keepSpaceAtBottom.Size     = new Size(0, 0);
            this.nuntiasBossPanel.Controls.Add(keepSpaceAtBottom);
            FilePreviewPanelHeight(0);
            this.nuntiasBossPanel.VerticalScroll.Value = this.nuntiasBossPanel.VerticalScroll.Maximum;
        }