Пример #1
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);
        }
Пример #2
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!");
                }
            }
        }