public String GeneratePage(String colorCode, Post post) { String fileUrl = post.HasLarge ? Constants.SiteUrl + "/data/sample/sample-" + post.MD5 + "." + post.FileExtension : Constants.SiteUrl + "/data/" + post.MD5 + "." + post.FileExtension; return String.Format(template, colorCode, fileUrl); }
/// <summary> /// Loads the post on a background thread, /// but does not change the UI state. /// </summary> /// <param name="p"></param> private void LoadPost(Post p) { // Reset all parameters PivotRoot.SelectedIndex = 0; animation.IsEnabled = true; PivotRoot.IsLocked = true; viewModel.Comments.Clear(); #region loadTags Lambda Action<String[], TextBlock, WrapPanel, Color> loadTags = (@tags, header, panel, color) => { panel.Children.Clear(); if (tags.Length == 0) { header.Visibility = Visibility.Collapsed; panel.Visibility = Visibility.Collapsed; } else { SolidColorBrush brush = new SolidColorBrush(color); foreach (string t in tags) { TextBlock block = new TextBlock {FontSize = TagFontSize, Tag = t}; block.Tap += (@s, e) => { Object tag = ((TextBlock) s).Tag; viewModel.SearchTagCommand.Execute(tag); }; block.Inlines.Add(new Run { Text = t, Foreground = brush }); block.Margin = new Thickness(4, 2, 4, 2); panel.Children.Add(block); } header.Visibility = Visibility.Visible; panel.Visibility = Visibility.Visible; } }; #endregion // Load up tags String[] cpTags = p.CopyrightTagsString.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); loadTags(cpTags, CopyrightTagHeader, CopyrightTagPanel, Color.FromArgb(0xFF, 0xEE, 0x66, 0xEE)); String[] chTags = p.CharacterTagsString.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); loadTags(chTags, CharacterTagHeader, CharacterTagPanel, Color.FromArgb(0xFF, 0x44, 0xEE, 0x44)); String[] arTags = p.ArtistTagsString.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); loadTags(arTags, ArtistTagHeader, ArtistTagPanel, Color.FromArgb(0xFF, 0xEE, 0x66, 0x66)); String[] gTags = p.GeneralTagsString.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); loadTags(gTags, GeneralTagHeader, GeneralTagPanel, Color.FromArgb(0xFF, 0x44, 0x77, 0xFF)); // Load Post Info PostIdTextBlock.Text = p.ID.ToString(CultureInfo.InvariantCulture); UploaderTextBlock.Text = p.Author; // Convert Byte size to something more readable SizeTextBlock.Text = viewModel.Post.FileSizeString; RatingTextBlock.Text = p.Rating.ToString(); }
public void AddFavorite(User user, Post post) { if (dbConnection == null) throw new InvalidOperationException("Database Connection is null!"); using (var cmd = dbConnection.CreateCommand()) { cmd.CommandText = "INSERT OR IGNORE INTO favorites(id, userid, parent_id, has_children, rating, uploader, uploader_id, md5, image_height, image_width, file_size, file_ext, tag_string_artist, tag_string_character, tag_string_copyright, tag_string_general, has_large, add_time) " + "VALUES(@id, @userid, @parent_id, @has_children, @rating, @uploader, @uploader_id, @md5, @image_height, @image_width, @file_size, @file_ext, @tag_string_artist, @tag_string_character, @tag_string_copyright, @tag_string_general, @has_large, @add_time);SELECT last_insert_rowid();"; cmd.Parameters.Add("@id", post.ID); cmd.Parameters.Add("@userid", user.ID); cmd.Parameters.Add("@parent_id", post.ParentIdString); cmd.Parameters.Add("@has_children", post.HasChildren ? 1 : 0); cmd.Parameters.Add("@rating", post.RatingString); cmd.Parameters.Add("@uploader", post.Author); cmd.Parameters.Add("@uploader_id", post.AuthorID); cmd.Parameters.Add("@md5", post.MD5); cmd.Parameters.Add("@image_height", post.Height); cmd.Parameters.Add("@image_width", post.Width); cmd.Parameters.Add("@file_size", post.FileSize); cmd.Parameters.Add("@file_ext", post.FileExtension); cmd.Parameters.Add("@tag_string_artist", post.ArtistTagsString); cmd.Parameters.Add("@tag_string_character", post.CharacterTagsString); cmd.Parameters.Add("@tag_string_copyright", post.CopyrightTagsString); cmd.Parameters.Add("@tag_string_general", post.GeneralTagsString); cmd.Parameters.Add("@has_large", post.HasLarge ? 1 : 0); cmd.Parameters.Add("@add_time", DateTime.Now.Ticks / 10000); cmd.ExecuteScalar(); } }
public void RemoveFavorite(User user, Post post) { if (dbConnection == null) throw new InvalidOperationException("Database Connection is null!"); using (var cmd = dbConnection.CreateCommand()) { cmd.CommandText = "DELETE FROM favorites WHERE userid = @userid AND id = @id"; cmd.Parameters.Add("@id", post.ID); cmd.Parameters.Add("@userid", user.ID); cmd.ExecuteScalar(); } }
public Boolean HasFavorite(User user, Post post) { if (dbConnection == null) throw new InvalidOperationException("Database Connection is null!"); Int32 result; using (var cmd = dbConnection.CreateCommand()) { cmd.CommandText = "SELECT COUNT(id) FROM favorites WHERE id = @id AND userid = @userid"; cmd.Parameters.Add("@id", post.ID); cmd.Parameters.Add("@userid", user.ID); using (var reader = cmd.ExecuteReader()) { reader.Read(); result = reader.GetInt32(0); } } return result > 0; }
public Post[] GetFavorites(User user, Int64 lastAddTime) { if (dbConnection == null) throw new InvalidOperationException("Database Connection is null!"); List<Post> result = new List<Post>(); using (var cmd = dbConnection.CreateCommand()) { cmd.CommandText = "SELECT * FROM favorites WHERE userid = @userid AND add_time < @last_time ORDER BY add_time DESC LIMIT @page_size"; cmd.Parameters.Add("@userid", user.ID); cmd.Parameters.Add("@last_time", lastAddTime); cmd.Parameters.Add("@page_size", PostPageSize); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Post p = new Post(); p.ID = reader.GetInt32(0); if (reader.IsDBNull(2)) p.ParentIdString = null; else p.ParentIdString = reader.GetString(2); p.HasChildren = ReadNullableInt32(reader, 3, 0) != 0; p.RatingString = ReadNullableString(reader, 4, "s"); p.Author = ReadNullableString(reader, 5, "Anonymous"); p.AuthorID = ReadNullableInt32(reader, 6, 0); p.MD5 = ReadNullableString(reader, 7, ""); p.Height = ReadNullableInt32(reader, 8, 0); p.Width = ReadNullableInt32(reader, 9, 0); p.FileSize = ReadNullableInt32(reader, 10, 0); p.FileExtension = ReadNullableString(reader, 11, ".jpg"); p.ArtistTagsString = ReadNullableString(reader, 12, ""); p.CharacterTagsString = ReadNullableString(reader, 13, ""); p.CopyrightTagsString = ReadNullableString(reader, 14, ""); p.GeneralTagsString = ReadNullableString(reader, 15, ""); p.HasLarge = ReadNullableInt32(reader, 16, 0) != 0; p.LastAddTime = reader.GetInt64(17); result.Add(p); } } } return result.ToArray(); }