Exemplo n.º 1
0
        /// <summary>
        /// Returns image content from clipboard as ImageContent object.
        /// </summary>
        private ImageContent getImageContentFromClipboard()
        {
            ImageContent contentToReturn = new ImageContent();

            contentToReturn.index = view.ImageRowCount + 1;
            contentToReturn.image = Clipboard.GetImage();
            contentToReturn.time  = System.DateTime.Now.ToShortTimeString();

            return(contentToReturn);
        }
Exemplo n.º 2
0
        public static EncryptedImageContent EncryptImageContent(ImageContent unencryptedContent, string password)
        {
            EncryptedImageContent contentToReturn = new EncryptedImageContent();

            contentToReturn.index          = unencryptedContent.index;
            contentToReturn.encryptedImage =
                StringCipher.Encrypt(ImageConversion.ImageToBase64(unencryptedContent.image, ImageFormat.Png), password);
            contentToReturn.time = StringCipher.Encrypt(unencryptedContent.time, password);
            return(contentToReturn);
        }
Exemplo n.º 3
0
        public static ImageContent DecryptImageContent(EncryptedImageContent encryptedContent, string password)
        {
            ImageContent contentToReturn = new ImageContent();

            contentToReturn.index = encryptedContent.index;
            contentToReturn.image =
                ImageConversion.Base64ToImage(StringCipher.Decrypt(encryptedContent.encryptedImage, password));
            contentToReturn.time = StringCipher.Decrypt(encryptedContent.time, password);
            return(contentToReturn);
        }
Exemplo n.º 4
0
        public void SetImageContentAt(ImageContent contentToAdd)
        {
            try {
                DataGridViewRow row = imageDataGrid.Rows[contentToAdd.index - 1];

                row.Cells[0].Value = contentToAdd.index;
                row.Cells[1].Value = contentToAdd.image;
                row.Cells[2].Value = contentToAdd.time;
            } catch (ArgumentOutOfRangeException) {
                MessageBox.Show("Error, unable to update content.",
                                "Clipboarder", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 5
0
        public List <ImageContent> GetAllImageContent()
        {
            List <ImageContent> returnValues = new List <ImageContent>();

            for (int i = 0; i < imageDataGrid.RowCount; i++)
            {
                ImageContent contentToAdd = new ImageContent();
                contentToAdd.index = (int)imageDataGrid.Rows[i].Cells[0].Value;
                contentToAdd.image = (Image)imageDataGrid.Rows[i].Cells[1].Value;
                contentToAdd.time  = (string)imageDataGrid.Rows[i].Cells[2].Value;

                returnValues.Add(contentToAdd);
            }

            return(returnValues);
        }
Exemplo n.º 6
0
        public void AddNewImageRow(ImageContent contentToAdd)
        {
            DataGridViewRow NewRow = new DataGridViewRow();

            NewRow.CreateCells(imageDataGrid);

            NewRow.Cells[0].Value = contentToAdd.index;
            NewRow.Cells[1].Value = contentToAdd.image;
            NewRow.Cells[2].Value = contentToAdd.time;

            //Adjusts height of a row
            NewRow.Height = contentToAdd.image.Height;

            imageDataGrid.Rows.Insert(imageDataGrid.RowCount, NewRow);
            MainTabControl.SelectedIndex = 1;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Import and populates CLipboarder grid with entries from database
        /// using DatabaseOperations, DatabaseReadWrite and User class
        /// </summary>
        private void ImportAndDisplayEntries()
        {
            if (!File.Exists(Path.Combine(Application.StartupPath, "contents.db")))
            {
                MessageBox.Show("No content to load." + "\n\n" + "Use Menu > Save Content to save entries.",
                                "Clipboarder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                // Creates DatabaseOperations object to perform operations on specified database
                DatabaseOperations dbOperations = new DatabaseOperations();

                // Connects to database and opens connection
                try {
                    dbOperations = new DatabaseOperations();
                    dbOperations.ConnectDatabase(databaseName);
                    dbOperations.OpenConnection();
                } catch (Exception ex) {
                    MessageBox.Show("Error connecting database, database does not exists or is unreachable."
                                    + ex.Message + "\n\nOperation aborted.\n", "Clipboarder Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    view.status = "Error";
                    dbOperations.CloseConnection();
                    return;
                }

                User user = new User(dbOperations);
                user.GetCurrentUserID();

                // Shows AskPasswordDecrypt form to ask user for password,
                // this call also passes hashed password from the database
                // to inform user for incorrect password.
                AskPasswordDecrypt askPassword = new AskPasswordDecrypt(this, user.GetUserPassword());
                DialogResult       result      = askPassword.ShowDialog();

                // If DialogResult.OK == true then AskPasswordDialog will provide password to
                // password field in MainFormPresenter instance earlier passed in constructor
                if (result != DialogResult.OK)
                {
                    dbOperations.CloseConnection();
                    return;
                }

                // Checks equality of password provided and stored
                if (!user.CurrentUserHasID())
                {
                    MessageBox.Show("Content for current user doesn't exists.\n\nOperation aborted.\n",
                                    "Clipboarder Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    dbOperations.CloseConnection();
                    return;
                }
                else
                {
                    view.ClearAll();
                    DatabaseReadWrite dbContent = new DatabaseReadWrite(dbOperations, user);
                    try {
                        view.status = "Reading text from database";
                        List <EncryptedTextContent> encryptedList = dbContent.GetTextData();
                        List <TextContent>          outputList    = new List <TextContent>();

                        // Resets progress
                        view.ProgressVisibility = true;
                        view.TaskProgress       = 0;

                        // Decrypts and adds text content to textDataGrid
                        encryptedList.ForEach((encryptedContent) => {
                            view.TaskProgress        = (100 / encryptedList.Count) * encryptedContent.index;
                            TextContent contentToAdd =
                                ContentEncryption.DecryptTextContent(encryptedContent, password);
                            view.AddNewTextRow(contentToAdd);
                        });
                        view.TaskProgress = 0;
                    } catch (Exception ex) {
                        MessageBox.Show("Error filling table with values.\n\n\nOperation aborted." + Environment.NewLine,
                                        "Clipboarder Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        view.status = "Error";
                        dbOperations.CloseConnection();
                        return;
                    }

                    try {
                        view.status = "Reading images from database.";

                        List <EncryptedImageContent> encryptedList = dbContent.GetImageData();
                        List <ImageContent>          outputList    = new List <ImageContent>();

                        //progress bar values
                        view.TaskProgress       = 0;
                        view.ProgressVisibility = true;

                        // Decrypts image content
                        encryptedList.ForEach(encryptedContent => {
                            view.TaskProgress         = (100 / encryptedList.Count) * encryptedContent.index;
                            ImageContent contentToAdd =
                                ContentEncryption.DecryptImageContent(encryptedContent, password);
                            view.AddNewImageRow(contentToAdd);
                        });
                        view.TaskProgress = 0;
                    } catch (Exception) {
                        MessageBox.Show("Error filling table with values.\n\n\nOperation aborted.\n",
                                        "Clipboarder Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        view.status = "Error";
                        dbOperations.CloseConnection();
                        return;
                    }
                }
                view.status             = "Imported successfully";
                view.ProgressVisibility = false;
                dbOperations.CloseConnection();
            } // Else statement for check on file existence
            password = "";
        }