public void SaveAddToSetStatus(AImg img)
        {
            if (img.IsAddToSetCompleted == false)
            {
                return;
            }

            string updateAddToSet = string.Format("update {0} " +
                                                  "set {1} = \"{2}\" ," +
                                                  " {3} = \"{4}\" ," +
                                                  " {5} = \"{6}\"" +
                                                  "where {7} = \"{8}\"",
                                                  tblImages,
                                                  colFlickrPhotoSetId, img.FlickrPhotoSetId,
                                                  colDateAddedToSet, img.DateAddedToSet.ToString("yyyy-MM-dd HH:mm:ss.000"),
                                                  colSecondsToAddToSet, img.SecondsToAddToSet,
                                                  colFullFilePath, img.FileFullPath);

            using (var dbConnection = GetConnection())
            {
                using (var command = new SQLiteCommand(updateAddToSet, dbConnection))
                {
                    int result = command.ExecuteNonQuery();
                    _log.InfoFormat("SaveAddToSetStatus {0}", result);

                }
            }
        }
        public void AddPhotoToSet(AImg img,Photoset set)
        {
            _log.InfoFormat("adding {0} to photoset : {1}",img.FileFullPath,set.PhotosetId);

            try
            {
                Stopwatch stopWatch = Stopwatch.StartNew();
                _flickr.PhotosetsAddPhoto(set.PhotosetId, img.FlickrPhotoId);
                stopWatch.Stop();
                _log.DebugFormat("Add to Set success. Took:{0}s.", stopWatch.Elapsed.TotalSeconds);
                img.UpdatePhotosetId(set.PhotosetId, DateTime.Now, stopWatch.Elapsed.TotalSeconds);
            }
            catch (FlickrApiException ex)
            {
                if (ex.Code == 3) //photo already exists.
                {
                    //DONT consider this as failure
                    img.UpdatePhotosetId(set.PhotosetId, DateTime.Now, 0);
                }
                else
                {
                    img.AddToSetEx = ex;
                    _log.Error(string.Format("Failed to add {0} to photoset : {1}", img.FileFullPath, set.Title), ex);
                }
            }
            catch (Exception ex)
            {
                img.AddToSetEx = ex;
                _log.Error(string.Format("Failed to add {0} to photoset : {1}", img.FileFullPath, set.Title), ex);
            }
        }
        /// <summary>
        /// This is called for each grouping.This can throw exception !!!
        /// </summary>
        /// <param name="photosetname"></param>
        /// <param name="photoid"></param>
        /// <returns></returns>
        public Photoset GetSet(string photosetname, AImg photoid)
        {
            Photoset existingset = null;

            if (Exists(photosetname, ref existingset))
            {
                return existingset;
            }

            Photoset newset = _flickr.PhotosetsCreate(photosetname, photoid.FlickrPhotoId);

            return newset;
        }
        public void Upload(AImg img)
        {
            try
            {
                Stopwatch stopWatch = Stopwatch.StartNew();

                string response = _flickr.UploadPicture(img.FileFullPath, img.FileName,
                                                        description: img.FolderName,
                                                        tags: img.FolderName,
                                                        isPublic: _config.IsPrivate,
                                                        isFamily: _config.IsPrivate,
                                                        isFriend: _config.IsPrivate);
                stopWatch.Stop();
                _log.DebugFormat("Upload success. Took:{0}s. Response :{1}", stopWatch.Elapsed.TotalSeconds, response);
                img.UpdateFlickrPhotoId(response, DateTime.Now, stopWatch.Elapsed.TotalSeconds);
            }
            catch (Exception ex)
            {
                img.UploadEx = ex;
                _log.Error(string.Format("error uploading " + img.FileFullPath), ex);
            }
        }
        private List<AImg> GetImgsInDb()
        {
            string sqlselect = string.Format("select {0},{1},{2} from {3}",
                                           colFullFilePath, colFlickrPhotoSetId, colFlickrImgId,
                                           tblImages);

            var imgsInDb = new List<AImg>();

            using (var conn = GetConnection())
            {
                using (var command = new SQLiteCommand(sqlselect, conn))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string fullfilepath = reader[colFullFilePath].ToString();
                            string flickrid = ConvertToString(reader[colFlickrImgId]);
                            string flickrphotosetid = ConvertToString(reader[colFlickrPhotoSetId]);
                            var imgdb = new AImg(fullfilepath);

                            if (string.IsNullOrEmpty(flickrphotosetid) == false)
                            {
                                imgdb.UpdatePhotosetId(flickrphotosetid);
                            }

                            if (string.IsNullOrEmpty(flickrid) == false)
                            {
                                imgdb.UpdateFlickrPhotoId(flickrid);
                            }
                            imgsInDb.Add(imgdb);
                        }
                    }
                }
            }
            return imgsInDb;
        }
        private void AddToDb(AImg imgToAdd)
        {
            string insertstatement = string.Format("insert into {0} ({1},{2}) values (\"{3}\",{4})",
                                                   tblImages,
                                                   colFullFilePath,colSize,
                                                   imgToAdd.FileFullPath,imgToAdd.Size);

            using (var dbConnection = GetConnection())
            {
                using (var command = new SQLiteCommand(insertstatement, dbConnection))
                {
                    int result = command.ExecuteNonQuery();
                    _log.InfoFormat("AddToDb {0}", result);
                }
            }
        }