Esempio n. 1
0
        /// <summary>
        /// Searches the database for the row that matches the specified ID.
        /// </summary>
        /// <param name="ID">The ID of the row that you want to retrieve.</param>
        /// <returns>A PasteDBRow object containing all the data for the specified row.</returns>
        public PasteDBRow getPasteByID(int ID)
        {
            PasteDBRow result = new PasteDBRow();

            string whereCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, pictures.pictures_uploadAddress, pictures.pictures_lastPaste FROM Pictures WHERE ((pictures.pictures_ID)=" + ID + @")";
            //Debug.WriteLine(whereCommand);
            OleDbCommand command = new OleDbCommand(whereCommand, connection);

            // Retrieve the result from the database
            try
            {
                OleDbDataReader reader = command.ExecuteReader();

                // While there is still unread results
                while (reader.Read())
                {
                    result.id            = (int)reader.GetValue(0);
                    result.location      = reader.GetString(1);
                    result.uploadAddress = reader.GetString(2);
                    result.lastPasteDate = reader.GetValue(3).ToString();
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get paste address from ID:");
                Debug.WriteLine(ex.ToString());

                return(null);
            }

            return(result);
        }
Esempio n. 2
0
        // Repopulate the data grid with the new search results
        public void FillDataGrid(List <String> tags)
        {
            dgd_Results.Rows.Clear();

            List <PasteDBRow> results;

            if (tags == null || tags.Count == 0 || tags[0] == "")
            {
                results = db.returnAll();
            }
            else
            {
                results = new List <PasteDBRow>();

                //List<PasteDBRow> dbResults = db.getTopPastesByTags(tags);
                PasteDBRow dbResults = db.getTopPasteByTags(tags);
                if (dbResults != null)
                {
                    results.Add(dbResults);
                }
            }

            if (results.Count > 0)
            {
                // Add rows to datagrid
                object[] tempobj = new object[4];
                foreach (PasteDBRow resultRow in results)
                {
                    // Set image preview
                    Image preview   = Image.FromFile(resultRow.location);
                    int   newHeight = preview.Height;
                    int   newWidth  = preview.Width;
                    if (preview.Width > preview.Height)
                    {
                        newWidth  = dgd_ROWHEIGHT;
                        newHeight = (int)(((double)dgd_ROWHEIGHT / preview.Width) * preview.Height);
                    }
                    else
                    {
                        newHeight = dgd_ROWHEIGHT;
                        newWidth  = (int)(((double)dgd_ROWHEIGHT / preview.Height) * preview.Width);
                    }
                    tempobj[0] = new Bitmap(preview, newWidth, newHeight);

                    // Add in the upload address, and tag list
                    tempobj[1] = resultRow.uploadAddress;
                    tempobj[2] = resultRow.TagsAsString;
                    tempobj[3] = resultRow.id;

                    dgd_Results.Rows.Add(tempobj);
                }

                // Size all the rows to be the proper height
                for (int rowCount = 0; rowCount < dgd_Results.Rows.Count; rowCount++)
                {
                    dgd_Results.Rows[rowCount].Height = dgd_ROWHEIGHT;
                }
            }
        }
Esempio n. 3
0
        static private Boolean scanLibrary()
        {
            string[]      fileTypes = { "*.jpg", "*.jpeg", "*.gif", "*.png" };
            List <string> fileList  = new List <string>();

            Boolean success = true;

            // Populate fileList with a list of all picture files in DefaultDir
            // Useful for getting a total count of the files that are being scanned
            foreach (String fileType in fileTypes)
            {
                String[] filenames = Directory.GetFiles(Properties.Settings.Default.homeDirectory, fileType);
                foreach (String filename in filenames)
                {
                    fileList.Add(filename);
                }
            }

            // Proceed through the file list, adding any pictures that aren't already in the database
            for (int count = 0; count < fileList.Count; count++)
            {
                // If file doesn't exist in database, attempt to upload the picture and store it in the database
                //Console.WriteLine(db.getPasteByFilename(fileList[count]).TagsAsString);
                if (db.getPasteByFilename(fileList[count]) == null)
                {
                    try
                    {
                        CmdUtil.colorWriteLine("Image " + (count + 1) + "/" + fileList.Count + " : Uploading to Imgur...");

                        ImageUploadAPI imgur = new ImgurUpload();

                        String uploadAddress = imgur.UploadPicture(fileList[count]);

                        if (uploadAddress != null || uploadAddress != "")
                        {
                            PasteDBRow newRow = new PasteDBRow(0, fileList[count], imgur.UploadPicture(fileList[count]), "");
                            db.addRow(newRow);
                        }
                        else
                        {
                            throw new Exception("An error occured trying to upload the file.");
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMsg(ex.ToString());
                        CmdUtil.colorWriteLine("Error uploading image " + (count + 1) + " to Imgur", ConsoleColor.Red);

                        success = false;
                    }
                }
                else
                {
                    CmdUtil.colorWriteLine("Image " + (count + 1) + "/" + fileList.Count + " : Already in database!");
                }
            }

            return(success);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns all the rows in the database.
        /// </summary>
        /// <returns>Returns the rows in the database as a list of PasteDBRows.</returns>
        public List <PasteDBRow> returnAll()
        {
            string getPicturesCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, Pictures.pictures_UploadAddress, Pictures.pictures_lastPaste FROM Pictures";

            //Debug.WriteLine(getPicturesCommand);
            OleDbCommand command = new OleDbCommand(getPicturesCommand, connection);

            // Build the set of results
            List <PasteDBRow> resultSet = new List <PasteDBRow>();

            try
            {
                OleDbDataReader picturesReader = command.ExecuteReader();

                // While there is still unread results
                while (picturesReader.Read())
                {
                    // Read each result into a PasteDBRow object
                    PasteDBRow newRow = new PasteDBRow(
                        Int32.Parse(picturesReader.GetValue(0).ToString()),
                        picturesReader.GetValue(1).ToString(),
                        picturesReader.GetValue(2).ToString(),
                        picturesReader.GetValue(3).ToString()
                        );

                    // Search for all tags belonging to the current picture, and add them
                    string          getTagsCommand = @"SELECT Tags.tags_tag FROM Tags WHERE Tags.pictures_ID=" + newRow.id;
                    OleDbCommand    tagsCommand    = new OleDbCommand(getTagsCommand, connection);
                    OleDbDataReader tagsReader     = tagsCommand.ExecuteReader();
                    //Debug.WriteLine(getTagsCommand);
                    while (tagsReader.Read())
                    {
                        newRow.tags.Add(tagsReader.GetString(0));
                    }

                    // Add the newly-built row to the results
                    resultSet.Add(newRow);
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get all rows from database:");
                Debug.WriteLine(ex.ToString());
                return(null);
            }
            finally
            {
                Debug.WriteLine("Results for 'return db': " + resultSet.Count);
            }

            return(resultSet);
        }
Esempio n. 5
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //////////////////////////////// UPDATE ////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Updates the row in the database.
        /// </summary>
        /// <param name="updatedRow">The row to be updated. The ID number in this row is which record to update.</param>
        /// <returns>True on success, false on failure. A failure includes an ID in $updatedRow that doesn't exist.</returns>
        public Boolean updateRow(PasteDBRow updatedRow)
        {
            string updateCommand = "UPDATE Pictures SET " +
                                   "Location='" + updatedRow.location + "', " +
                                   "Upload_Address='" + updatedRow.uploadAddress + "', " +
                                   "Last_Paste='" + updatedRow.lastPasteDate + "' " +
                                   "WHERE ID=" + updatedRow.id;

            //Debug.WriteLine(updateCommand);
            OleDbCommand command = new OleDbCommand(updateCommand, connection);

            command.ExecuteNonQuery();

            return(true);
        }
Esempio n. 6
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ///////////////////////////////// READ /////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Searches the database for the row that best matches the supplied tags.
        /// </summary>
        /// <param name="tags">A list of tags that will be searched for.</param>
        /// <returns>A List of PasteDBRows corresponding to the results from the query. </returns>
        public List <PasteDBRow> getPastesByTag(String tag)
        {
            List <PasteDBRow> resultSet = new List <PasteDBRow>();

            string whereCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, pictures.pictures_uploadAddress, pictures.pictures_lastPaste FROM Pictures LEFT JOIN Tags ON Pictures.pictures_ID = Tags.pictures_ID WHERE ((Tags.tags_tag)='" + tag + @"')";
            //Debug.WriteLine(whereCommand);
            OleDbCommand command = new OleDbCommand(whereCommand, connection);

            // Add this to the set of results
            try
            {
                OleDbDataReader reader = command.ExecuteReader();

                // While there is still unread results
                while (reader.Read())
                {
                    // Read each result into a PasteDBRow object
                    PasteDBRow newRow = new PasteDBRow(
                        Int32.Parse(reader.GetValue(0).ToString()),
                        reader.GetValue(1).ToString(),
                        reader.GetValue(2).ToString(),
                        reader.GetValue(3).ToString()
                        );

                    // Add the newly-built row to the results
                    resultSet.Add(newRow);
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get paste address from tag:");
                Debug.WriteLine(ex.ToString());
                return(null);
            }
            finally
            {
                Debug.WriteLine("Results for tag '" + tag + "': " + resultSet.Count);
            }

            if (resultSet.Count > 0)
            {
                return(resultSet);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Searches the database for the row that matches the supplied filename.
        /// </summary>
        /// <param name="tags">The filename to search for.</param>
        /// <returns>A PasteDBRow that corresponds to the supplied filename. </returns>
        public PasteDBRow getPasteByFilename(String filename)
        {
            //TODO: Would be totally cool if this function would detect if filename was relative or absolute, and acted accordingly
            //Path.Combine(dbLocation, filename);
            if (File.Exists(Path.Combine(Path.GetDirectoryName(dbLocation), filename)))
            {
                filename = Path.Combine(Path.GetDirectoryName(dbLocation), filename);
            }

            PasteDBRow result = new PasteDBRow();

            string whereCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, pictures.pictures_uploadAddress, pictures.pictures_lastPaste FROM Pictures WHERE ((pictures.pictures_location)='" + filename + @"')";
            //Debug.WriteLine(whereCommand);
            OleDbCommand command = new OleDbCommand(whereCommand, connection);

            // Retrieve the result from the database
            try
            {
                OleDbDataReader reader = command.ExecuteReader();

                if (!reader.HasRows)
                {
                    return(null);
                }

                // While there is still unread results
                while (reader.Read())
                {
                    result.id            = int.Parse(reader.GetValue(0).ToString());
                    result.location      = reader.GetValue(1).ToString();
                    result.uploadAddress = reader.GetValue(2).ToString();
                    result.lastPasteDate = reader.GetValue(3).ToString();
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get paste address from filename:");
                Debug.WriteLine(ex.ToString());
                return(null);
            }

            return(result);
        }
Esempio n. 8
0
        public Boolean addTagsToPictureByID(int pictureID, List <String> tags)
        {
            Boolean success = true;

            PasteDBRow pictureToTag = getPasteByID(pictureID);

            foreach (String tag in tags)
            {
                //TODO: remove all punctuation marks from the tag, make lowercase

                String addTagCommand = "INSERT INTO Tags (tags_tag, pictures_ID) VALUES ('" + tag + "', " + pictureToTag.id + ")";
                //Debug.WriteLine(addTagCommand);
                OleDbCommand command = new OleDbCommand(addTagCommand, connection);
                if (command.ExecuteNonQuery() == 0)
                {
                    success = false;
                }
            }

            return(success);
        }
Esempio n. 9
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //////////////////////////////// CREATE ////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds a row to the database.
        /// </summary>
        /// <param name="newRow">The row to be added to the database. The ID number in $newRow isn't used, as the database generates its own ID.</param>
        /// <returns>True on success, false on failure.</returns>
        public Boolean addRow(PasteDBRow newRow)
        {
            try
            {
                string now = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

                string insertCommand = @"INSERT INTO Pictures (pictures_location, pictures_uploadAddress, pictures_lastPaste) VALUES ('" +
                                       newRow.location + @"', '" +
                                       newRow.uploadAddress + @"', '" +
                                       DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + @"');";

                OleDbCommand command = new OleDbCommand(insertCommand, connection);
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to insert new row:");
                Debug.WriteLine(ex.ToString());
                return(false);
            }

            return(true);
        }
Esempio n. 10
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //////////////////////////////// CREATE ////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Adds a row to the database.
        /// </summary>
        /// <param name="newRow">The row to be added to the database. The ID number in $newRow isn't used, as the database generates its own ID.</param>
        /// <returns>True on success, false on failure.</returns>
        public Boolean addRow(PasteDBRow newRow)
        {
            try
            {
                string now = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

                string insertCommand = @"INSERT INTO Pictures (pictures_location, pictures_uploadAddress, pictures_lastPaste) VALUES ('" +
                    newRow.location + @"', '" +
                    newRow.uploadAddress + @"', '" +
                    DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + @"');";

                OleDbCommand command = new OleDbCommand(insertCommand, connection);
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to insert new row:");
                Debug.WriteLine(ex.ToString());
                return false;
            }

            return true;
        }
Esempio n. 11
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //////////////////////////////// UPDATE ////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Updates the row in the database.
        /// </summary>
        /// <param name="updatedRow">The row to be updated. The ID number in this row is which record to update.</param>
        /// <returns>True on success, false on failure. A failure includes an ID in $updatedRow that doesn't exist.</returns>
        public Boolean updateRow(PasteDBRow updatedRow)
        {
            string updateCommand = "UPDATE Pictures SET " +
                "Location='" + updatedRow.location + "', " +
                "Upload_Address='" + updatedRow.uploadAddress + "', " +
                "Last_Paste='" + updatedRow.lastPasteDate + "' " +
                "WHERE ID=" + updatedRow.id;

            //Debug.WriteLine(updateCommand);
            OleDbCommand command = new OleDbCommand(updateCommand, connection);
            command.ExecuteNonQuery();

            return true;
        }
Esempio n. 12
0
        /// <summary>
        /// Returns all the rows in the database.
        /// </summary>
        /// <returns>Returns the rows in the database as a list of PasteDBRows.</returns>
        public List<PasteDBRow> returnAll()
        {
            string getPicturesCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, Pictures.pictures_UploadAddress, Pictures.pictures_lastPaste FROM Pictures";

            //Debug.WriteLine(getPicturesCommand);
            OleDbCommand command = new OleDbCommand(getPicturesCommand, connection);

            // Build the set of results
            List<PasteDBRow> resultSet = new List<PasteDBRow>();
            try
            {
                OleDbDataReader picturesReader = command.ExecuteReader();

                // While there is still unread results
                while (picturesReader.Read())
                {
                    // Read each result into a PasteDBRow object
                    PasteDBRow newRow = new PasteDBRow(
                        Int32.Parse(picturesReader.GetValue(0).ToString()),
                        picturesReader.GetValue(1).ToString(),
                        picturesReader.GetValue(2).ToString(),
                        picturesReader.GetValue(3).ToString()
                    );

                    // Search for all tags belonging to the current picture, and add them
                    string getTagsCommand = @"SELECT Tags.tags_tag FROM Tags WHERE Tags.pictures_ID=" + newRow.id;
                    OleDbCommand tagsCommand = new OleDbCommand(getTagsCommand, connection);
                    OleDbDataReader tagsReader = tagsCommand.ExecuteReader();
                    //Debug.WriteLine(getTagsCommand);
                    while (tagsReader.Read())
                    {
                        newRow.tags.Add(tagsReader.GetString(0));
                    }

                    // Add the newly-built row to the results
                    resultSet.Add(newRow);
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get all rows from database:");
                Debug.WriteLine(ex.ToString());
                return null;
            }
            finally
            {
                Debug.WriteLine("Results for 'return db': " + resultSet.Count);
            }

            return resultSet;
        }
Esempio n. 13
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ///////////////////////////////// READ /////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Searches the database for the row that best matches the supplied tags.
        /// </summary>
        /// <param name="tags">A list of tags that will be searched for.</param>
        /// <returns>A List of PasteDBRows corresponding to the results from the query. </returns>
        public List<PasteDBRow> getPastesByTag(String tag)
        {
            List<PasteDBRow> resultSet = new List<PasteDBRow>();

            string whereCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, pictures.pictures_uploadAddress, pictures.pictures_lastPaste FROM Pictures LEFT JOIN Tags ON Pictures.pictures_ID = Tags.pictures_ID WHERE ((Tags.tags_tag)='" + tag + @"')";
            //Debug.WriteLine(whereCommand);
            OleDbCommand command = new OleDbCommand(whereCommand, connection);

            // Add this to the set of results
            try
            {
                OleDbDataReader reader = command.ExecuteReader();

                // While there is still unread results
                while (reader.Read())
                {
                    // Read each result into a PasteDBRow object
                    PasteDBRow newRow = new PasteDBRow(
                        Int32.Parse(reader.GetValue(0).ToString()),
                        reader.GetValue(1).ToString(),
                        reader.GetValue(2).ToString(),
                        reader.GetValue(3).ToString()
                    );

                    // Add the newly-built row to the results
                    resultSet.Add(newRow);
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get paste address from tag:");
                Debug.WriteLine(ex.ToString());
                return null;
            }
            finally
            {
                Debug.WriteLine("Results for tag '" + tag + "': " + resultSet.Count);
            }

            if (resultSet.Count > 0)
                return resultSet;
            else
                return null;
        }
Esempio n. 14
0
        /// <summary>
        /// Searches the database for the row that matches the specified ID.
        /// </summary>
        /// <param name="ID">The ID of the row that you want to retrieve.</param>
        /// <returns>A PasteDBRow object containing all the data for the specified row.</returns>
        public PasteDBRow getPasteByID(int ID)
        {
            PasteDBRow result = new PasteDBRow();

            string whereCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, pictures.pictures_uploadAddress, pictures.pictures_lastPaste FROM Pictures WHERE ((pictures.pictures_ID)=" + ID + @")";
            //Debug.WriteLine(whereCommand);
            OleDbCommand command = new OleDbCommand(whereCommand, connection);

            // Retrieve the result from the database
            try
            {
                OleDbDataReader reader = command.ExecuteReader();

                // While there is still unread results
                while (reader.Read())
                {
                    result.id = (int)reader.GetValue(0);
                    result.location = reader.GetString(1);
                    result.uploadAddress = reader.GetString(2);
                    result.lastPasteDate = reader.GetValue(3).ToString();
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get paste address from ID:");
                Debug.WriteLine(ex.ToString());

                return null;
            }

            return result;
        }
Esempio n. 15
0
        /// <summary>
        /// Searches the database for the row that matches the supplied filename.
        /// </summary>
        /// <param name="tags">The filename to search for.</param>
        /// <returns>A PasteDBRow that corresponds to the supplied filename. </returns>
        public PasteDBRow getPasteByFilename(String filename)
        {
            //TODO: Would be totally cool if this function would detect if filename was relative or absolute, and acted accordingly
            //Path.Combine(dbLocation, filename);
            if (File.Exists(Path.Combine(Path.GetDirectoryName(dbLocation), filename)))
            {
                filename = Path.Combine(Path.GetDirectoryName(dbLocation), filename);
            }

            PasteDBRow result = new PasteDBRow();

            string whereCommand = @"SELECT Pictures.pictures_ID, Pictures.pictures_location, pictures.pictures_uploadAddress, pictures.pictures_lastPaste FROM Pictures WHERE ((pictures.pictures_location)='" + filename + @"')";
            //Debug.WriteLine(whereCommand);
            OleDbCommand command = new OleDbCommand(whereCommand, connection);

            // Retrieve the result from the database
            try
            {
                OleDbDataReader reader = command.ExecuteReader();

                if (!reader.HasRows) return null;

                // While there is still unread results
                while (reader.Read())
                {
                    result.id = int.Parse(reader.GetValue(0).ToString());
                    result.location = reader.GetValue(1).ToString();
                    result.uploadAddress = reader.GetValue(2).ToString();
                    result.lastPasteDate = reader.GetValue(3).ToString();
                }
            }
            catch (OleDbException ex)
            {
                Debug.WriteLine("Failed to get paste address from filename:");
                Debug.WriteLine(ex.ToString());
                return null;
            }

            return result;
        }
Esempio n. 16
0
        [STAThread]                                                                                                                                     // Single-threaded for use of the clipboard
        static void Main(string[] args)
        {
            // On first startup, set the homeDirectory (default to @"%userprofile%\Poof\")
            if (Properties.Settings.Default.homeDirectory == "")
            {
                Program_cli.debugMsg("No home directory found. First start?");

                string homeDir = System.Environment.GetEnvironmentVariable("userprofile") + @"\Poof\";

                CmdUtil.colorWriteLine("Poof wants to set your paste directory to \"" + homeDir + "\"" + Environment.NewLine + ". If this is okay, press enter. Else, enter a new directory.", ConsoleColor.Green);
                string input = System.Console.ReadLine();

                if (input.Length > 0)
                {
                    homeDir = input;
                }

                setHomeDirectory(homeDir);
                Properties.Settings.Default.Save();
            }

            // On debug, set up my test directory
            useTestDirectory();

            try
            {
                // Initialize the database
                db = new PasteDB(Path.Combine(Properties.Settings.Default.homeDirectory, "poof.accdb"));
                if (!db.Connect())
                {
                    db.makeDB();
                    db.Connect();
                }

                if (args.Length == 0)
                {
                    // No arguments given. User doesn't know what they're doing; Display help text
                    displayHelp();
                }
                else if (
                    args[0].Length >= (commandPrefix.Length + 1) &&
                    args[0].Substring(0, commandPrefix.Length).Equals(commandPrefix)
                    )
                {
                    // First argument is a command. Perform the command using all the remaining arguments
                    performCommand(args);
                }
                else
                {
                    // search the arguments as a list of tags for the best match
                    List <String> tags = new List <string>();
                    foreach (String arg in args)
                    {
                        tags.Add(arg);
                    }

                    PasteDBRow pasteResult = db.getTopPasteByTags(tags);
                    if (pasteResult != null)
                    {
                        displayPaste(pasteResult.uploadAddress);
                    }
                    else
                    {
                        // no results
                        CmdUtil.colorWriteLine("Alas, no results were found.", ConsoleColor.DarkRed);
                    }
                }

                db.Close();
            }
            catch (Exception ex)
            {
                Program_cli.errorMsg(ex.ToString());
                CmdUtil.displayFatalError();
            }

            CmdUtil.colorWriteLine("\n«poof!»", ConsoleColor.DarkMagenta);
        }
Esempio n. 17
0
        private static Boolean scanLibrary()
        {
            string[] fileTypes = {"*.jpg", "*.jpeg", "*.gif", "*.png"};
            List<string> fileList = new List<string>();

            Boolean success = true;

            // Populate fileList with a list of all picture files in DefaultDir
            // Useful for getting a total count of the files that are being scanned
            foreach(String fileType in fileTypes)
            {
                String[] filenames = Directory.GetFiles(Properties.Settings.Default.homeDirectory, fileType);
                foreach(String filename in filenames)
                {
                    fileList.Add(filename);
                }
            }

            // Proceed through the file list, adding any pictures that aren't already in the database
            for (int count = 0; count < fileList.Count; count++)
            {
                // If file doesn't exist in database, attempt to upload the picture and store it in the database
                //Console.WriteLine(db.getPasteByFilename(fileList[count]).TagsAsString);
                if(db.getPasteByFilename(fileList[count]) == null)
                {
                    try
                    {
                        CmdUtil.colorWriteLine("Image " + (count + 1) + "/" + fileList.Count + " : Uploading to Imgur...");

                        ImageUploadAPI imgur = new ImgurUpload();

                        String uploadAddress = imgur.UploadPicture(fileList[count]);

                        if (uploadAddress != null || uploadAddress != "")
                        {
                            PasteDBRow newRow = new PasteDBRow(0, fileList[count], imgur.UploadPicture(fileList[count]), "");
                            db.addRow(newRow);
                        }
                        else
                        {
                            throw new Exception("An error occured trying to upload the file.");
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMsg(ex.ToString());
                        CmdUtil.colorWriteLine("Error uploading image " + (count+1) + " to Imgur", ConsoleColor.Red);

                        success = false;
                    }
                }
                else
                {
                    CmdUtil.colorWriteLine("Image " + (count + 1) + "/" + fileList.Count + " : Already in database!");
                }
            }

            return success;
        }
Esempio n. 18
0
        // Handler for doing background work
        private void uploadNewPictures(object sender, DoWorkEventArgs e)
        {
            string[] fileTypes = { "*.jpg", "*.jpeg", "*.gif", "*.png" };
            List<string> fileList = new List<string>();

            // Populate fileList with a list of all picture files in DefaultDir
            // Useful for getting a total count of the files that are being scanned
            foreach (String fileType in fileTypes)
            {
                String[] filenames = Directory.GetFiles(Properties.Settings.Default.homeDirectory, fileType);
                foreach (String filename in filenames)
                {
                    fileList.Add(filename);
                }
            }

            //setUploadProgressMax(fileList.Count);
            pgb_UploadProgress.Invoke(
                (MethodInvoker)delegate()
                {
                    pgb_UploadProgress.Maximum = fileList.Count;
                }
            );

            // Proceed through the file list, adding any pictures that aren't already in the database
            for (int count = 0; count < fileList.Count; count++)
            {
                // If file doesn't exist in database, attempt to upload the picture and store it in the database
                //Console.WriteLine(db.getPasteByFilename(fileList[count]).TagsAsString);
                if (db.getPasteByFilename(fileList[count]) == null)
                {
                    try
                    {
                        Debug.WriteLine("Image " + (count + 1) + "/" + fileList.Count + " (" + fileList[count] + ") : Uploading to Imgur...");

                        //setUploadProgressCurrent(count);
                        pgb_UploadProgress.Invoke(
                            (MethodInvoker)delegate()
                            {
                                pgb_UploadProgress.Value = count;
                            }
                        );

                        ImageUploadAPI imgur = new ImgurUpload();

                        String uploadAddress = imgur.UploadPicture(fileList[count]);

                        if (uploadAddress != null || uploadAddress != "")
                        {
                            PasteDBRow newRow = new PasteDBRow(0, fileList[count], imgur.UploadPicture(fileList[count]), "");
                            db.addRow(newRow);
                        }
                        else
                        {
                            throw new Exception("An error occured trying to upload the file.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error uploading file");
                        Debug.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Debug.WriteLine("Image " + (count + 1) + "/" + fileList.Count + " (" + fileList[count] + ") : Already in database!");
                }
            }
        }
Esempio n. 19
0
        // Handler for doing background work
        private void uploadNewPictures(object sender, DoWorkEventArgs e)
        {
            string[]      fileTypes = { "*.jpg", "*.jpeg", "*.gif", "*.png" };
            List <string> fileList  = new List <string>();

            // Populate fileList with a list of all picture files in DefaultDir
            // Useful for getting a total count of the files that are being scanned
            foreach (String fileType in fileTypes)
            {
                String[] filenames = Directory.GetFiles(Properties.Settings.Default.homeDirectory, fileType);
                foreach (String filename in filenames)
                {
                    fileList.Add(filename);
                }
            }

            //setUploadProgressMax(fileList.Count);
            pgb_UploadProgress.Invoke(
                (MethodInvoker) delegate()
            {
                pgb_UploadProgress.Maximum = fileList.Count;
            }
                );

            // Proceed through the file list, adding any pictures that aren't already in the database
            for (int count = 0; count < fileList.Count; count++)
            {
                // If file doesn't exist in database, attempt to upload the picture and store it in the database
                //Console.WriteLine(db.getPasteByFilename(fileList[count]).TagsAsString);
                if (db.getPasteByFilename(fileList[count]) == null)
                {
                    try
                    {
                        Debug.WriteLine("Image " + (count + 1) + "/" + fileList.Count + " (" + fileList[count] + ") : Uploading to Imgur...");

                        //setUploadProgressCurrent(count);
                        pgb_UploadProgress.Invoke(
                            (MethodInvoker) delegate()
                        {
                            pgb_UploadProgress.Value = count;
                        }
                            );

                        ImageUploadAPI imgur = new ImgurUpload();

                        String uploadAddress = imgur.UploadPicture(fileList[count]);

                        if (uploadAddress != null || uploadAddress != "")
                        {
                            PasteDBRow newRow = new PasteDBRow(0, fileList[count], imgur.UploadPicture(fileList[count]), "");
                            db.addRow(newRow);
                        }
                        else
                        {
                            throw new Exception("An error occured trying to upload the file.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error uploading file");
                        Debug.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Debug.WriteLine("Image " + (count + 1) + "/" + fileList.Count + " (" + fileList[count] + ") : Already in database!");
                }
            }
        }