示例#1
0
        public static void Execute(string md5, BooruImageType type)
        {
            byte[] md5blob    = MD5Helper.MD5ToBlob(md5);
            string typeString = "I";

            switch (type)
            {
            case BooruImageType.Animation:
                typeString = "A";
                break;

            case BooruImageType.Comix:
                typeString = "C";
                break;

            case BooruImageType.Video:
                typeString = "V";
                break;

            case BooruImageType.Image:
                typeString = "I";
                break;
            }

            new SetType(md5blob, typeString).ExecuteNonQuery();
        }
示例#2
0
        public bool AddImageIfNew(string path, string md5, string tags, BooruImageType fileType)
        {
            Logger.Log(BooruLog.Severity.Info, md5 + ": Adding/Updating: " + path);

            List <string> imageTagList = new List <string> (tags.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
            bool          result       = false;

            BooruApp.BooruApplication.Database.Mutex.ExecuteCriticalSection(() => {
                var transaction = BooruApp.BooruApplication.Database.Connection.BeginTransaction();
                try {
                    Queries.Images.Add.Execute(md5, fileType);
                    Queries.Files.Add.Execute(md5, path);

                    foreach (string tag in imageTagList)
                    {
                        this.AddImageTag(md5, tag);
                    }
                    transaction.Commit();
                    result = true;
                } catch (Exception ex) {
                    transaction.Rollback();
                    Logger.Log(ex, "Caught exception while updating image " + md5);
                }
            });
            return(result);
        }
示例#3
0
        public DatabaseCursor <ImageDetails> QueryRandomImagesForVoting(BooruImageType type)
        {
            DatabaseCursor <ImageDetails> result = null;

            BooruApp.BooruApplication.Database.Mutex.ExecuteCriticalSection(() => {
                result = Queries.Images.NextVoteImages.Execute(type);
            });
            return(result);
        }
示例#4
0
 public void SetImageType(string md5, BooruImageType type)
 {
     BooruApp.BooruApplication.TaskRunner.StartTaskAsync("Set image type", () => {
         BooruApp.BooruApplication.Database.Mutex.ExecuteCriticalSection(() => {
             Queries.Images.SetType.Execute(md5, type);
             Queries.Images.UpdateUpdated.Execute(md5);
         });
     });
 }
示例#5
0
        public static DatabaseCursor <ImageDetails> Execute(BooruImageType type)
        {
            string t = null;

            if (type != BooruImageType.Unknown)
            {
                t = type.ToString().Substring(0, 1);
            }

            var dbReader = new NextVoteImages(t).ExecuteReader();

            return(new DatabaseCursor <ImageDetails> (new DatabaseReader(dbReader)));
        }
示例#6
0
        public void SetFilter(BooruImageType type)
        {
            lock (this.taskQueue) {
                // clear out queue
                while (!this.taskQueue.IsEmpty)
                {
                    Task <Image> task;
                    this.taskQueue.TryDequeue(out task);
                }

                // replace reader with reader for new type
                this.reader.Close();
                this.reader = new ImageReader(type);

                // replace old queue with new one, add two tasks
                var queue = new ConcurrentQueue <Task <Image> >();
                queue.Enqueue(LoadImage());
                queue.Enqueue(LoadImage());
                this.taskQueue = queue;
            }
        }
示例#7
0
 public ImageReader(BooruImageType type)
 {
     this.type = type;
 }
示例#8
0
        public void ImportEntry(ImageEntry entry)
        {
            entry.Status = "Getting File Type";
            CallUpdate(entry);

            bool           callBooru = false;
            BooruImageType fileType  = BooruImageTypeHelper.IdentifyType(entry.path, out callBooru);

            switch (fileType)
            {
            case BooruImageType.Unknown:
                BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Warning, "Unsupported file type: " + entry.path);
                entry.Status = "Unsupported file type";
                CallUpdate(entry);
                return;

            case BooruImageType.Image:
                entry.IsImage = true;
                entry.IsAnim  = false;
                break;

            case BooruImageType.Animation:
                entry.IsImage = true;
                entry.IsAnim  = true;
                break;

            case BooruImageType.Video:
                entry.IsImage = false;
                entry.IsAnim  = true;
                break;
            }

            entry.Status = "Getting MD5";
            CallUpdate(entry);
            entry.MD5 = GetEntryMD5(entry);

            List <string> tags;
            bool          tagMeExpired = false;
            ImageDetails  details      = BooruApp.BooruApplication.Database.GetImageDetails(entry.MD5);

            if (details != null)
            {
                tags = BooruApp.BooruApplication.Database.GetImageTags(entry.MD5);
                tags.Sort();
                entry.TagString = string.Join(" ", tags);

                var    timeSinceUpdate = DateTime.Now.Subtract(details.Updated);
                double daysSinceUpdate = timeSinceUpdate.TotalDays;
                entry.LastUpdated = ReadableTimeSpan(details.Updated);
                // has image a tagme tag and last update was some time ago, ask servers again
                if (tags.Contains("tagme") && daysSinceUpdate > 30)
                {
                    tagMeExpired = true;
                }
            }
            else
            {
                entry.LastUpdated = "never";
                tags = new List <string>();
            }
            entry.Tags = tags;
            CallUpdate(entry);

            bool askedServer = false;

            entry.Status = "Asking plugins...";
            CallUpdate(entry);

            if (BooruApp.BooruApplication.PluginLoader.TagFinderPlugins.FindTagsForFile(entry.path, entry.MD5, tagMeExpired, tags))
            {
                askedServer = true;
            }
            CallUpdate(entry);

            if (details == null)
            {
                var tmpPixBuf = PixbufLoader.LoadPixbufAnimationForImage(entry.path, entry.MD5);
                if (tmpPixBuf != null)
                {
                    BooruApp.BooruApplication.Database.SetImageSize(entry.MD5, new Point2D(tmpPixBuf.Width, tmpPixBuf.Height));
                    tmpPixBuf.Dispose();
                }
            }

            entry.TagString = string.Join(" ", entry.Tags);

            if (askedServer || details == null || details.Updated.Ticks == 0)
            {
                entry.Status = (details == null)?"Adding to DB":"Updating";
                CallUpdate(entry);
                if (details == null || askedServer)
                {
                    int tries = 1;
                    while (!BooruApp.BooruApplication.Database.AddImageIfNew(entry.path, entry.MD5, entry.TagString, fileType))
                    {
                        BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Error, "Database error: " + entry.path);
                        entry.Status = string.Format("DB Error. Retrying... {0}", tries);
                        CallUpdate(entry);
                        tries++;
                        Thread.Sleep(1000);
                    }
                }
                Queries.Images.UpdateUpdated.Execute(entry.MD5);
                entry.Status = (details == null)?"Added":"Updated";
                CallUpdate(entry);
            }
            else
            {
                entry.Status = "No change";
                CallUpdate(entry);
            }
        }