示例#1
0
        private string uploadPicture(string authenticationID, string sfAppID, DateTime dateTaken, string newPath, string fileName, string ext)
        {
            System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
            string monthName = mfi.GetMonthName(dateTaken.Month).ToString();

            return(Shutterfly.uploadToShutterfly(authenticationID, sfAppID, monthName, dateTaken.Year.ToString(), newPath, fileName + ext));
        }
示例#2
0
        internal void RunImport()
        {
            SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=PhotoSorter.db;Version=3;");

            try
            {
                //Get Data
                m_dbConnection.Open();
                string           sql           = "SELECT * FROM tbl_configs";
                SQLiteCommand    command       = new SQLiteCommand(sql, m_dbConnection);
                SQLiteDataReader reader        = command.ExecuteReader();
                string           prefix        = "";
                string           suffix        = "";
                bool             useCameraMake = false;
                string           sfUserID      = "";
                string           sfPasswd      = "";
                string           sfAppID       = "";
                string           sfSS          = "";
                string           sfAuthID      = "";
                while (reader.Read())
                {
                    this.importDir = Environment.ExpandEnvironmentVariables(reader["importDirectory"].ToString());
                    this.picDir    = Environment.ExpandEnvironmentVariables(reader["pictureDirectory"].ToString());
                    this.videoDir  = Environment.ExpandEnvironmentVariables(reader["videoDirectory"].ToString());
                    prefix         = reader["prefix"].ToString();
                    suffix         = reader["suffix"].ToString();
                    if (reader["includeCameraMake"] != DBNull.Value)
                    {
                        useCameraMake = Convert.ToBoolean(reader["includeCameraMake"]);
                    }
                    sfUserID = reader["sfUserID"].ToString();
                    if (reader["sfPasswd"] != DBNull.Value)
                    {
                        sfPasswd = Encrypting.ToInsecureString(Encrypting.DecryptString(reader["sfPasswd"].ToString()));
                    }
                    sfAppID = reader["sfAppID"].ToString();
                    if (reader["sfSS"] != DBNull.Value)
                    {
                        sfSS = Encrypting.ToInsecureString(Encrypting.DecryptString(reader["sfSS"].ToString()));
                    }
                    sfAuthID = reader["sfAuthID"].ToString();
                }
                reader.Close();

                //Initialize Shutterfly
                if (sfUserID != "" && sfPasswd != "" && sfAppID != "" && sfSS != "")
                {
                    string authenticationID = Shutterfly.getAuthenticationID(sfUserID, sfPasswd, sfAppID, sfSS, sfAuthID);
                    if (!authenticationID.StartsWith("Failed:") && authenticationID != sfAuthID)
                    {
                        string        sfsql  = String.Format("UPDATE tbl_configs SET sfAuthID = '{0}' WHERE user_pk = 1", authenticationID);
                        SQLiteCommand sqlcmd = new SQLiteCommand(sql, m_dbConnection);
                        sqlcmd.ExecuteNonQuery();
                        sfAuthID = authenticationID;
                    }
                }

                //Get video extensions
                List <string>    videoEXT = new List <string>();
                string           query    = "SELECT * FROM tbl_videos ORDER BY extension";
                SQLiteCommand    cmd      = new SQLiteCommand(query, m_dbConnection);
                SQLiteDataReader rdr      = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    videoEXT.Add(rdr["extension"].ToString());
                }
                rdr.Close();

                if (Directory.Exists(importDir))
                {
                    if (!Directory.Exists(picDir))
                    {
                        Directory.CreateDirectory(picDir);
                    }

                    if (!Directory.Exists(videoDir))
                    {
                        Directory.CreateDirectory(videoDir);
                    }

                    FileInfo[] Pictures = (from fi in new DirectoryInfo(importDir).GetFiles("*.*", SearchOption.AllDirectories)
                                           where !videoEXT.Contains(fi.Extension.ToLower())
                                           select fi)
                                          .ToArray();

                    FileInfo[] Videos = (from fi in new DirectoryInfo(importDir).GetFiles("*.*", SearchOption.AllDirectories)
                                         where videoEXT.Contains(fi.Extension.ToLower())
                                         select fi)
                                        .ToArray();

                    List <string> moveErrors   = new List <string>();
                    List <string> uploadErrors = new List <string>();

                    foreach (FileInfo pictureFile in Pictures)
                    {
                        processPicture(pictureFile, sfAuthID, sfAppID, prefix, suffix, useCameraMake, ref moveErrors, ref uploadErrors);
                    }

                    foreach (FileInfo videoFile in Videos)
                    {
                        processVideo(videoFile, prefix, suffix, useCameraMake, ref moveErrors);
                    }

                    if (moveErrors.Count > 0 || uploadErrors.Count > 0)
                    {
                        //sendEmail(moveErrors, uploadErrors);
                    }

                    cleanUp();
                }
                else
                {
                    string error = "Import directory does not exist. Check your settings.";
                }
            }
            catch (Exception ex) { }
            finally
            {
                m_dbConnection.Close();
            }
        }