private async Task InsertTag(BooruTagData tag, BooruImageData image) { var cmd = Booru_Storage.CreateCommand("INSERT INTO Tag_Refs (Image, Tag) VALUES ($image, $tag)"); cmd.Parameters.AddWithValue("$image", image.ID); cmd.Parameters.AddWithValue("$tag", tag.Tag); await cmd.ExecuteNonQueryAsync(); }
private async Task RemoveTag(BooruTagData tag, BooruImageData image) { var cmd = Booru_Storage.CreateCommand("DELETE FROM Tag_Refs WHERE Tag = $tag AND Image = $image"); cmd.Parameters.AddWithValue("$image", image.ID); cmd.Parameters.AddWithValue("$tag", tag.Tag); await cmd.ExecuteNonQueryAsync(); }
protected void on_TagEntry_activate(object sender, EventArgs args) { if (this.findThread != null) { this.stopThread = true; this.findThread.Join(); this.findThread = null; } this.store.Clear(); this.stopThread = false; this.store = new ListStore(typeof(string), typeof(Gdk.Pixbuf), typeof(BooruImage), typeof(float)); //store.SetSortColumnId(3, SortType.Descending); this.ImageThumbView.Model = store; this.Spinner.Active = true; System.IO.Directory.CreateDirectory("/home/kolrabi/x/extract/" + TagEntry.Text); var start = new ThreadStart(() => { var reader = this.db.QueryImagesWithTags(TagEntry.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); var readerColumns = new Dictionary <string, int> (); for (int i = 0; i < reader.FieldCount; i++) { readerColumns [reader.GetName(i)] = i; } while (reader.Read() && !this.stopThread) { string path = reader.GetString(readerColumns ["path"]); object md5obj = reader.GetValue(readerColumns ["md5sum"]); float elo = reader.GetFloat(readerColumns ["elo"]); int votes = reader.GetInt32(readerColumns ["votes"]); byte[] md5blob = (byte[])md5obj; var data = new BooruImageData(MD5Helper.BlobToMD5(md5blob), path, elo, votes); var image = new BooruImage(data, this.db); try { var info = new Mono.Unix.UnixFileInfo(data.Path); info.CreateSymbolicLink("/home/kolrabi/x/extract/" + TagEntry.Text + "/" + data.MD5 + System.IO.Path.GetExtension(data.Path)); //System.IO.File.Copy(data.Path, "/home/kolrabi/x/extract/" + TagEntry.Text + "/"+data.MD5+System.IO.Path.GetExtension(data.Path)); } catch (Exception ex) { Console.WriteLine("Could not copy " + data.Path + ": " + ex.Message); } Gtk.Application.Invoke((s, a) => { this.store.AppendValues(data.Path + "\n" + string.Join(" ", image.Tags), null, image, data.ELO); }); } Gtk.Application.Invoke((s, a) => { this.Spinner.Active = false; }); }); this.findThread = new Thread(start); this.findThread.Start(); }
private async Task RemoveTags(IEnumerable <BooruTagData> tags, BooruImageData image) { var tasks = tags.Select(tag => RemoveTag(tag, image)); await Task.WhenAll(tasks); }