From 704086cfcd6a070aec682bd7cb0a0b40b79d2cd7 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sat, 2 Nov 2024 12:41:46 +0800 Subject: [PATCH] fix: upstream changes --- ExClient/Galleries/Gallery.cs | 241 ++++++++-------------- ExClient/Galleries/Rating/RatingStatus.cs | 2 +- ExClient/Internal/ThumbClient.cs | 57 +++-- ExClient/Status/UserStatus.cs | 92 +++------ ExClient/Tagging/GalleryTag.cs | 21 +- 5 files changed, 152 insertions(+), 261 deletions(-) diff --git a/ExClient/Galleries/Gallery.cs b/ExClient/Galleries/Gallery.cs index d6a5c476..6350b47f 100644 --- a/ExClient/Galleries/Gallery.cs +++ b/ExClient/Galleries/Gallery.cs @@ -20,6 +20,7 @@ using System.Diagnostics; using System.Globalization; using System.Linq; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -29,23 +30,17 @@ using static System.Runtime.InteropServices.WindowsRuntime.AsyncInfo; -namespace ExClient.Galleries -{ +namespace ExClient.Galleries { [JsonObject] [System.Diagnostics.DebuggerDisplay(@"\{Id = {Id} Count = {Count}\}")] - public class Gallery : FixedLoadingList - { - public static IAsyncOperation TryLoadGalleryAsync(long galleryId) - { - return Task.Run(async () => - { - using (var db = new GalleryDb()) - { + public class Gallery : FixedLoadingList { + public static IAsyncOperation TryLoadGalleryAsync(long galleryId) { + return Task.Run(async () => { + using (var db = new GalleryDb()) { db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; var cm = db.SavedSet.SingleOrDefault(c => c.GalleryId == galleryId); var gm = db.GallerySet.SingleOrDefault(g => g.GalleryModelId == galleryId); - if (gm is null) - { + if (gm is null) { return null; } @@ -58,31 +53,24 @@ public static IAsyncOperation TryLoadGalleryAsync(long galleryId) }).AsAsyncOperation(); } - public static IAsyncOperation> FetchGalleriesAsync(IReadOnlyList galleryInfo) - { + public static IAsyncOperation> FetchGalleriesAsync(IReadOnlyList galleryInfo) { if (galleryInfo is null) throw new ArgumentNullException(nameof(galleryInfo)); if (galleryInfo.Count <= 0) return AsyncOperation>.CreateCompleted(Array.Empty()); - if (galleryInfo.Count <= 25) - { - return Run>(async token => - { + if (galleryInfo.Count <= 25) { + return Run>(async token => { var re = await new GalleryDataRequest(galleryInfo, 0, galleryInfo.Count).GetResponseAsync(token); var data = re.GalleryMetaData; data.ForEach(async g => await g.InitAsync()); return data; }); - } - else - { - return Run>(async token => - { + } else { + return Run>(async token => { var result = new List(galleryInfo.Count); var pageCount = MathHelper.GetPageCount(galleryInfo.Count, 25); - for (var i = 0; i < pageCount; i++) - { + for (var i = 0; i < pageCount; i++) { var pageSize = MathHelper.GetSizeOfPage(galleryInfo.Count, 25, i); var startIndex = MathHelper.GetStartIndexOfPage(25, i); var re = await new GalleryDataRequest(galleryInfo, startIndex, pageSize).GetResponseAsync(token); @@ -95,8 +83,7 @@ public static IAsyncOperation> FetchGalleriesAsync(IReadOnlyList< } } - private static readonly IReadOnlyDictionary _CategoriesForRestApi = new Dictionary(StringComparer.OrdinalIgnoreCase) - { + private static readonly IReadOnlyDictionary _CategoriesForRestApi = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["Doujinshi"] = Category.Doujinshi, ["Manga"] = Category.Manga, ["Artist CG"] = Category.ArtistCG, @@ -109,10 +96,8 @@ public static IAsyncOperation> FetchGalleriesAsync(IReadOnlyList< ["Misc"] = Category.Misc }; - public virtual IAsyncActionWithProgress SaveAsync(ConnectionStrategy strategy) - { - return Run((token, progress) => Task.Run(async () => - { + public virtual IAsyncActionWithProgress SaveAsync(ConnectionStrategy strategy) { + return Run((token, progress) => Task.Run(async () => { await Task.Yield(); progress.Report(new SaveGalleryProgress(-1, Count)); var loadOP = LoadItemsAsync(0, Count); @@ -122,53 +107,41 @@ public virtual IAsyncActionWithProgress SaveAsync(Connectio var loadedCount = 0; progress.Report(new SaveGalleryProgress(loadedCount, Count)); - using (var semaphore = new SemaphoreSlim(10, 10)) - { - async Task loadSingleImage(GalleryImage i) - { - try - { + using (var semaphore = new SemaphoreSlim(10, 10)) { + async Task loadSingleImage(GalleryImage i) { + try { Debug.WriteLine($"Start {i.PageId}"); token.ThrowIfCancellationRequested(); var firstFailed = false; - try - { + try { var firstChance = i.LoadImageAsync(false, strategy, true); var firstTask = firstChance.AsTask(token); var c = await Task.WhenAny(Task.Delay(30_000), firstTask); - if (c != firstTask) - { + if (c != firstTask) { Debug.WriteLine($"Timeout 1st {i.PageId}"); firstFailed = true; firstChance.Cancel(); } - } - catch (Exception) - { + } catch (Exception) { Debug.WriteLine($"Fail 1st {i.PageId}"); firstFailed = true; } - if (firstFailed) - { + if (firstFailed) { Debug.WriteLine($"Retry {i.PageId}"); token.ThrowIfCancellationRequested(); await i.LoadImageAsync(true, strategy, true).AsTask(token); } progress.Report(new SaveGalleryProgress(Interlocked.Increment(ref loadedCount), Count)); Debug.WriteLine($"Success {i.PageId}"); - } - finally - { + } finally { semaphore.Release(); Debug.WriteLine($"End {i.PageId}"); } } var pendingTasks = new List(Count); - await Task.Run(async () => - { - foreach (var item in this) - { + await Task.Run(async () => { + foreach (var item in this) { await semaphore.WaitAsync().ConfigureAwait(false); pendingTasks.Add(loadSingleImage(item)); } @@ -177,16 +150,12 @@ await Task.Run(async () => await Task.WhenAll(pendingTasks).ConfigureAwait(false); } - using (var db = new GalleryDb()) - { + using (var db = new GalleryDb()) { var gid = Id; var myModel = db.SavedSet.SingleOrDefault(model => model.GalleryId == gid); - if (myModel is null) - { + if (myModel is null) { db.SavedSet.Add(new SavedGalleryModel().Update(this)); - } - else - { + } else { myModel.Update(this); } await db.SaveChangesAsync(); @@ -195,27 +164,23 @@ await Task.Run(async () => } private Gallery(long id, EToken token, int recordCount) - : base(recordCount) - { + : base(recordCount) { Id = id; Token = token; Rating = new RatingStatus(this); GalleryUri = new GalleryInfo(id, token).Uri; - if (Client.Current.Settings.RawSettings.TryGetValue("tr", out var trv)) - { - switch (trv) - { - case "1": _PageSize = 50; break; - case "2": _PageSize = 100; break; - case "3": _PageSize = 200; break; - default: _PageSize = 20; break; + if (Client.Current.Settings.RawSettings.TryGetValue("tr", out var trv)) { + switch (trv) { + case "1": _PageSize = 50; break; + case "2": _PageSize = 100; break; + case "3": _PageSize = 200; break; + default: _PageSize = 20; break; } } } internal Gallery(GalleryModel model) - : this(model.GalleryModelId, new EToken(model.Token), model.RecordCount) - { + : this(model.GalleryModelId, new EToken(model.Token), model.RecordCount) { Available = model.Available; Title = model.Title; TitleJpn = model.TitleJpn; @@ -246,10 +211,8 @@ internal Gallery( string rating = null, string torrentcount = null, string[] tags = null) - : this(gid, EToken.Parse(token.CoalesceNullOrWhiteSpace("0")), int.Parse(filecount, NumberStyles.Integer, CultureInfo.InvariantCulture)) - { - if (error != null) - { + : this(gid, EToken.Parse(token.CoalesceNullOrWhiteSpace("0")), int.Parse(filecount, NumberStyles.Integer, CultureInfo.InvariantCulture)) { + if (error != null) { throw new Exception(error); } Available = !expunged; @@ -269,17 +232,13 @@ internal Gallery( ThumbUri = ThumbClient.FormatThumbUri(thumb); } - protected IAsyncAction InitAsync() - { + protected IAsyncAction InitAsync() { return InitOverrideAsync(); } - protected virtual IAsyncAction InitOverrideAsync() - { - return Task.Run(() => - { - using (var db = new GalleryDb()) - { + protected virtual IAsyncAction InitOverrideAsync() { + return Task.Run(() => { + using (var db = new GalleryDb()) { var gid = Id; var myModel = db.GallerySet.SingleOrDefault(model => model.GalleryModelId == gid); if (myModel is null) @@ -313,14 +272,11 @@ protected override GalleryImage CreatePlaceholder(int index) internal string ShowKey { get; set; } private readonly WeakReference _ThumbImage = new WeakReference(null); - public ImageSource Thumb - { - get - { + public ImageSource Thumb { + get { if (_ThumbImage.TryGetTarget(out var img)) return img; - this.GetThumbAsync().ContinueWith(t => - { + this.GetThumbAsync().ContinueWith(t => { var r = t.Result; if (r is null) return; @@ -351,22 +307,19 @@ public ImageSource Thumb public TagCollection Tags { get; } private FavoriteCategory _FavoriteCategory; - public FavoriteCategory FavoriteCategory - { + public FavoriteCategory FavoriteCategory { get => _FavoriteCategory; protected internal set => Set(ref _FavoriteCategory, value); } private string _FavoriteNote; - public string FavoriteNote - { + public string FavoriteNote { get => _FavoriteNote; protected internal set => Set(ref _FavoriteNote, value); } private RevisionCollection _Revisions; - public RevisionCollection Revisions - { + public RevisionCollection Revisions { get => _Revisions; private set => Set(ref _Revisions, value); } @@ -376,11 +329,9 @@ public RevisionCollection Revisions public CommentCollection Comments => LazyInitializer.EnsureInitialized(ref _Comments, () => new CommentCollection(this)); #endregion - internal void RefreshMetaData(HtmlDocument doc) - { + internal void RefreshMetaData(HtmlDocument doc) { var favNode = doc.GetElementbyId("fav"); - if (favNode != null) - { + if (favNode != null) { var favContentNode = favNode.Element("div"); FavoriteCategory = Client.Current.Favorites.GetCategory(favContentNode); } @@ -392,29 +343,26 @@ internal void RefreshMetaData(HtmlDocument doc) public Task RefreshMetaDataAsync() => Comments.FetchAsync(false); - protected override IAsyncOperation> LoadItemAsync(int index) - { - return Run(token => Task.Run(async () => - { + protected override IAsyncOperation> LoadItemAsync(int index) { + return Run(token => Task.Run(async () => { var html = await getDoc(index, token); token.ThrowIfCancellationRequested(); var picRoot = html.GetElementbyId("gdt"); var start = int.MaxValue; var end = 0; - using (var db = new GalleryDb()) - { + using (var db = new GalleryDb()) { db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; - foreach (var page in picRoot.Elements("div", "gdtl")) - { - var nodeA = page.Element("a"); - var thumb = ThumbClient.FormatThumbUri(nodeA.Element("img").GetAttribute("src", "")); + foreach (var page in picRoot.Elements("a")) { + var nodeDiv = page.SelectSingleNode(".//div[@title][@style]"); + var style = nodeDiv.GetAttribute("style", ""); + var thumbUrl = Regex.Match(style, @"url\((https?://[^)]+)\)").Groups[1]?.Value; + var thumb = ThumbClient.FormatThumbUri(thumbUrl); if (thumb is null) continue; - var tokens = nodeA.GetAttribute("href", "").Split(new[] { '/', '-' }); + var tokens = page.GetAttribute("href", "").Split(new[] { '/', '-' }); - if (tokens.Length < 4 || tokens[tokens.Length - 4] != "s") - { + if (tokens.Length < 4 || tokens[tokens.Length - 4] != "s") { continue; } @@ -438,8 +386,7 @@ protected override IAsyncOperation> LoadItemAsync( } return LoadItemsResult.Create(start, this.Skip(start).Take(end - start), false); - async Task getDoc(int imageIndex, CancellationToken cancellationToken, bool reIn = false) - { + async Task getDoc(int imageIndex, CancellationToken cancellationToken, bool reIn = false) { var pageIndex = imageIndex / _PageSize; var needLoadComments = !Comments.IsLoaded; var uri = new Uri(GalleryUri, $"?{(needLoadComments ? "hc=1&" : "")}p={pageIndex.ToString()}"); @@ -447,59 +394,48 @@ async Task getDoc(int imageIndex, CancellationToken cancellationTo cancellationToken.Register(docOp.Cancel); var doc = await docOp; RefreshMetaData(doc); - if (needLoadComments) - { + if (needLoadComments) { Comments.AnalyzeDocument(doc); } - if (reIn) - { + if (reIn) { return doc; } var content = doc.GetElementbyId("gdt"); - if(content.Element("div", "gdts") is not null) - { + if (content.HasClass("gt200") is false) { // 切换到大图模式 - await Client.Current.HttpClient.GetAsync(new Uri("/?inline_set=ts_l", UriKind.Relative)); + await Client.Current.HttpClient.GetAsync(new Uri("/?inline_set=ts_200", UriKind.Relative)); return await getDoc(imageIndex, cancellationToken, true); } - var items = content.Elements("div", "gdtl").ToList(); + var items = content.Elements("a").ToList(); PageSize = items.Count; - if (pageIndex != imageIndex / _PageSize) - { - return await getDoc(imageIndex, cancellationToken, true); + if (pageIndex != imageIndex / _PageSize) { + return await getDoc(imageIndex, cancellationToken, true); } return doc; } }, token)); } - public IAsyncOperation FetchFavoriteNoteAsync() - { - return Run(async token => - { + public IAsyncOperation FetchFavoriteNoteAsync() { + return Run(async token => { var doc = await Client.Current.HttpClient.GetDocumentAsync(new Uri($"gallerypopups.php?gid={Id}&t={Token.ToString()}&act=addfav", UriKind.Relative)); var favdel = doc.GetElementbyId("favdel"); - if (favdel != null) - { + if (favdel != null) { var favSet = false; - for (var i = 0; i < 10; i++) - { + for (var i = 0; i < 10; i++) { var favNode = doc.GetElementbyId($"fav{i}"); var favNameNode = favNode.ParentNode.ParentNode.Elements("div").Skip(2).First(); var settings = Client.Current.Settings; settings.FavoriteCategoryNames[i] = favNameNode.GetInnerText(); settings.StoreCache(); - if (!favSet && favNode.GetAttribute("checked", false)) - { + if (!favSet && favNode.GetAttribute("checked", false)) { FavoriteCategory = Client.Current.Favorites[i]; favSet = true; } } FavoriteNote = doc.DocumentNode.Descendants("textarea").First().GetInnerText(); - } - else - { + } else { FavoriteCategory = Client.Current.Favorites.Removed; FavoriteNote = ""; } @@ -507,36 +443,28 @@ public IAsyncOperation FetchFavoriteNoteAsync() }); } - public virtual IAsyncAction DeleteAsync() - { - return Task.Run(async () => - { + public virtual IAsyncAction DeleteAsync() { + return Task.Run(async () => { var gid = Id; - using (var db = new GalleryDb()) - { + using (var db = new GalleryDb()) { var toDelete = db.GalleryImageSet .Include(gi => gi.Image) .Where(gi => gi.GalleryId == gid) .ToList(); - foreach (var item in toDelete) - { + foreach (var item in toDelete) { var usingCount = db.GalleryImageSet .Count(GalleryImageModel.FKEquals(item.ImageId)); - if (usingCount <= 1) - { + if (usingCount <= 1) { var i = item.PageId - 1; var file = default(StorageFile); - if (i < Count) - { + if (i < Count) { file = this[i].ImageFile; } - if (file is null) - { + if (file is null) { file = await StorageHelper.ImageFolder.TryGetFileAsync(item.Image.FileName); } - if (file != null) - { + if (file != null) { await file.DeleteAsync(); } @@ -546,8 +474,7 @@ public virtual IAsyncAction DeleteAsync() } await db.SaveChangesAsync(); } - for (var i = 0; i < Count; i++) - { + for (var i = 0; i < Count; i++) { UnloadAt(i); } }).AsAsyncAction(); diff --git a/ExClient/Galleries/Rating/RatingStatus.cs b/ExClient/Galleries/Rating/RatingStatus.cs index 16812076..c3f5aca3 100644 --- a/ExClient/Galleries/Rating/RatingStatus.cs +++ b/ExClient/Galleries/Rating/RatingStatus.cs @@ -12,7 +12,7 @@ namespace ExClient.Galleries.Rating { - [DebuggerDisplay(@"\{{userScore} - {averageScore}({ratingCount})\}")] + [DebuggerDisplay(@"\{{_UserScore} - {_AverageScore}({_RatingCount})\}")] public class RatingStatus : ObservableObject { internal RatingStatus(Gallery owner) diff --git a/ExClient/Internal/ThumbClient.cs b/ExClient/Internal/ThumbClient.cs index ad91d240..a553cd34 100644 --- a/ExClient/Internal/ThumbClient.cs +++ b/ExClient/Internal/ThumbClient.cs @@ -8,42 +8,40 @@ using Windows.UI.Xaml.Media.Imaging; using Windows.Web.Http; -namespace ExClient.Internal -{ - internal static class ThumbClient - { - private static readonly HttpClient client = new HttpClient(); - private static readonly Regex thumbUriRegex = new Regex(@"^(http|https)://(ehgt\.org(/t|)|exhentai\.org/t|ul\.ehgt\.org(/t|))/(.+)$", RegexOptions.Compiled | RegexOptions.Singleline); +namespace ExClient.Internal { + internal static class ThumbClient { + private static readonly HttpClient _Client = new(); + private static readonly Regex _ThumbUriRegex = new(@"^(http|https)://((ul\.|)ehgt\.org(/t|)|(s\.|)exhentai\.org/t)/(?.+)$", RegexOptions.Compiled | RegexOptions.Singleline); - public static Uri FormatThumbUri(string uri) - { + private static string _GetTail(string uri) { + var match = _ThumbUriRegex.Match(uri); + if (!match.Success) { + return null; + } + return match.Groups["tail"].Value; + } + + public static Uri FormatThumbUri(string uri) { if (uri.IsNullOrWhiteSpace()) return null; - var match = thumbUriRegex.Match(uri); - if (!match.Success) - { + var tail = _GetTail(uri); + if (tail.IsNullOrEmpty()) return new Uri(uri); - } - var tail = match.Groups[5].Value; - return new Uri("https://ul.ehgt.org/" + tail); + return new Uri("https://ehgt.org/" + tail); } public static Uri FormatThumbUri(Uri uri) => FormatThumbUri(uri?.ToString()); - public static IAsyncOperation FetchThumbAsync(Uri source, BitmapImage target) - { + public static IAsyncOperation FetchThumbAsync(Uri source, BitmapImage target) { if (source is null) throw new ArgumentNullException(nameof(source)); if (target is null) throw new ArgumentNullException(nameof(target)); - return AsyncInfo.Run(async token => - { - var match = thumbUriRegex.Match(source.ToString()); - if (!match.Success) - { + return AsyncInfo.Run(async token => { + var tail = _GetTail(source.ToString()); + if (tail.IsNullOrEmpty()) { return await loadThumbAsync(source, target); } - var tail = match.Groups[5].Value; return await loadThumbAsync(new Uri("https://ehgt.org/" + tail), target) || await loadThumbAsync(new Uri("https://ul.ehgt.org/" + tail), target) || @@ -54,18 +52,13 @@ await loadThumbAsync(new Uri("https://ul.ehgt.org/t/" + tail), target) || }); } - private static async Task loadThumbAsync(Uri source, BitmapImage target) - { - try - { - var buf = await client.GetBufferAsync(source); - using (var stream = buf.AsRandomAccessStream()) - { + private static async Task loadThumbAsync(Uri source, BitmapImage target) { + try { + var buf = await _Client.GetBufferAsync(source); + using (var stream = buf.AsRandomAccessStream()) { await target.SetSourceAsync(stream); } - } - catch (Exception) - { + } catch (Exception) { return false; } return true; diff --git a/ExClient/Status/UserStatus.cs b/ExClient/Status/UserStatus.cs index 1ab75bd1..c24affb0 100644 --- a/ExClient/Status/UserStatus.cs +++ b/ExClient/Status/UserStatus.cs @@ -11,30 +11,25 @@ using Windows.Foundation; -namespace ExClient.Status -{ - public sealed class UserStatus : ObservableObject - { +namespace ExClient.Status { + public sealed class UserStatus : ObservableObject { private static readonly Uri infoUri = new Uri(Internal.DomainProvider.Eh.RootUri, "home.php"); internal UserStatus() { } - private static int deEntitizeAndParse(HtmlNode node) - { - return int.Parse(node.GetInnerText(), System.Globalization.NumberStyles.Integer); + private static int deEntitizeAndParse(HtmlNode node) { + // Use website locale, hardcode "," + return int.Parse(node.GetInnerText().Replace(",", ""), System.Globalization.NumberStyles.Integer); } - private void analyzeToplists(HtmlNode toplistsDiv) - { + private void analyzeToplists(HtmlNode toplistsDiv) { var table = toplistsDiv.Element("table").Descendants("table").FirstOrDefault(); - if (table is null) - { + if (table is null) { toplists.Clear(); return; } var newList = new List(); - foreach (var toplistRecord in table.Elements("tr")) - { + foreach (var toplistRecord in table.Elements("tr")) { var rankNode = toplistRecord.Descendants("strong").FirstOrDefault(); var listNode = toplistRecord.Descendants("a").FirstOrDefault(); if (rankNode is null) @@ -49,8 +44,7 @@ private void analyzeToplists(HtmlNode toplistsDiv) toplists.Update(newList); } - private void analyzeImageLimit(HtmlNode imageLimitDiv) - { + private void analyzeImageLimit(HtmlNode imageLimitDiv) { var values = imageLimitDiv.Descendants("strong").Select(deEntitizeAndParse).ToList(); if (values.Count != 3) throw new InvalidOperationException("Wrong values.Count from analyzeImageLimit"); @@ -59,8 +53,7 @@ private void analyzeImageLimit(HtmlNode imageLimitDiv) ImageUsageResetCost = values[2]; } - private void analyzeModPower(HtmlNode modPowerDiv) - { + private void analyzeModPower(HtmlNode modPowerDiv) { ModerationPower = deEntitizeAndParse(modPowerDiv.Descendants("div").Last()); var values = modPowerDiv.Descendants("td") .Where(n => n.GetAttribute("style", "").Contains("font-weight:bold")) @@ -81,21 +74,16 @@ private void analyzeModPower(HtmlNode modPowerDiv) ModerationPowerCaculated = values.Take(3).Sum() + Math.Min(values.Skip(3).Take(5).Sum(), 25); } - public async Task RefreshAsync() - { + public async Task RefreshAsync() { var doc = await Client.Current.HttpClient.GetDocumentAsync(infoUri); - try - { + try { analyzeDoc(doc); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new InvalidOperationException(LocalizedStrings.Resources.WrongApiResponse, ex); } } - private void analyzeDoc(HtmlDocument doc) - { + private void analyzeDoc(HtmlDocument doc) { if (doc is null) throw new ArgumentNullException(nameof(doc)); var contentDivs = doc.DocumentNode @@ -115,35 +103,27 @@ private void analyzeDoc(HtmlDocument doc) private int imageUsage; private int imageUsageLimit = 5000; private int imageUsageResetCost; - public int ImageUsage - { + public int ImageUsage { get => imageUsage; private set => Set(ref imageUsage, value); } - public int ImageUsageLimit - { + public int ImageUsageLimit { get => imageUsageLimit; private set => Set(ref imageUsageLimit, value); } - public int ImageUsageResetCost - { + public int ImageUsageResetCost { get => imageUsageResetCost; private set => Set(ref imageUsageResetCost, value); } - public IAsyncAction ResetImageUsageAsync() - { - return AsyncInfo.Run(async token => - { + public IAsyncAction ResetImageUsageAsync() { + return AsyncInfo.Run(async token => { var p = Client.Current.HttpClient.PostAsync(infoUri, new KeyValuePair("reset_imagelimit", "reset_imagelimit")); token.Register(p.Cancel); var r = await p; var html = await r.Content.ReadAsStringAsync(); var doc = new HtmlDocument(); doc.LoadHtml(html); - try - { + try { analyzeDoc(doc); - } - catch (Exception) - { + } catch (Exception) { await RefreshAsync(); } }); @@ -166,44 +146,34 @@ public IAsyncAction ResetImageUsageAsync() private double moderationPowerForumActivity; private double moderationPowerUploadsAndHatH; private double moderationPowerAccountAge; - public double ModerationPower - { + public double ModerationPower { get => moderationPower; private set => Set(ref moderationPower, value); } - public double ModerationPowerCaculated - { + public double ModerationPowerCaculated { get => moderationPowerCaculated; private set => Set(ref moderationPowerCaculated, value); } - public double ModerationPowerBase - { + public double ModerationPowerBase { get => moderationPowerBase; private set => Set(ref moderationPowerBase, value); } - public double ModerationPowerAwards - { + public double ModerationPowerAwards { get => moderationPowerAwards; private set => Set(ref moderationPowerAwards, value); } - public double ModerationPowerTagging - { + public double ModerationPowerTagging { get => moderationPowerTagging; private set => Set(ref moderationPowerTagging, value); } - public double ModerationPowerLevel - { + public double ModerationPowerLevel { get => moderationPowerLevel; private set => Set(ref moderationPowerLevel, value); } - public double ModerationPowerDonations - { + public double ModerationPowerDonations { get => moderationPowerDonations; private set => Set(ref moderationPowerDonations, value); } - public double ModerationPowerForumActivity - { + public double ModerationPowerForumActivity { get => moderationPowerForumActivity; private set => Set(ref moderationPowerForumActivity, value); } - public double ModerationPowerUploadsAndHatH - { + public double ModerationPowerUploadsAndHatH { get => moderationPowerUploadsAndHatH; private set => Set(ref moderationPowerUploadsAndHatH, value); } - public double ModerationPowerAccountAge - { + public double ModerationPowerAccountAge { get => moderationPowerAccountAge; private set => Set(ref moderationPowerAccountAge, value); } #endregion diff --git a/ExClient/Tagging/GalleryTag.cs b/ExClient/Tagging/GalleryTag.cs index 6d3effe2..294718ac 100644 --- a/ExClient/Tagging/GalleryTag.cs +++ b/ExClient/Tagging/GalleryTag.cs @@ -4,36 +4,37 @@ namespace ExClient.Tagging { + [System.Diagnostics.DebuggerDisplay(@"({_State}){Content}")] public sealed class GalleryTag : ObservableObject { internal GalleryTag(TagCollection owner, Tag content, TagState state) { - this.owner = owner; + _Owner = owner; Content = content; - this.state = state; + _State = state; } - private readonly TagCollection owner; + private readonly TagCollection _Owner; public Tag Content { get; } - private TagState state; - public TagState State { get => state; internal set => Set(ref state, value); } + private TagState _State; + public TagState State { get => _State; internal set => Set(ref _State, value); } public IAsyncAction VoteAsync(Api.VoteState command) { if (command == Api.VoteState.Default) { - if (state.HasFlag(TagState.Downvoted)) + if (_State.HasFlag(TagState.Downvoted)) { - return owner.VoteAsync(Content, Api.VoteState.Up); + return _Owner.VoteAsync(Content, Api.VoteState.Up); } - else if (state.HasFlag(TagState.Upvoted)) + else if (_State.HasFlag(TagState.Upvoted)) { - return owner.VoteAsync(Content, Api.VoteState.Down); + return _Owner.VoteAsync(Content, Api.VoteState.Down); } } - return owner.VoteAsync(Content, command); + return _Owner.VoteAsync(Content, command); } } }