public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { var keyword = UnescapeKeyword(data.Queries.GetString("f_search") ?? ""); var category = Client.Current.Favorites.All; var ap = data.Queries.GetBoolean("f_apply"); { var cat = data.Queries.GetString("favcat") ?? "all"; if (cat != "all") { var index = cat.QueryValueAsInt32(); index = Math.Max(0, index); index = Math.Min(9, index); category = Client.Current.Favorites[index]; } } if (!ap) { return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(category.Search("")))); } else { return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(category.Search(keyword)))); } }
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { var category = categoryDic[data.Path0]; var keyword = GetKeyword(data); var advanced = GetAdvancedSearchOptions(data); return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(Client.Current.Search(keyword, category, advanced)))); }
public void String() { var a1 = AsyncOperation <string> .CreateCompleted(); var a2 = AsyncOperation <string> .CreateCompleted(); Assert.AreEqual(AsyncStatus.Completed, a1.Status); Assert.AreEqual(default, a1.GetResults());
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { var sr = data.Queries.ContainsKey("f_shash") ? handleFileSearch(data) : handleSearch(data); return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(sr))); }
/// <summary> /// Show share UI. /// </summary> /// <param name="manager"><see cref="DataTransferManager"/> of sharing.</param> /// <param name="dataPackageProvider">Provides <see cref="DataPackage"/> to share.</param> /// <exception cref="ArgumentNullException"><paramref name="manager"/> or <paramref name="dataPackageProvider"/> is <see langword="null"/>.</exception> /// <exception cref="NotSupportedException">Sharing is not supported.</exception> public static IAsyncAction ShareAsync(this DataTransferManager manager, Func <DataPackage> dataPackageProvider) { if (dataPackageProvider is null) { throw new ArgumentNullException(nameof(dataPackageProvider)); } return(ShareAsync(manager, () => AsyncOperation <DataPackage> .CreateCompleted(dataPackageProvider()))); }
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { var sr = data.Queries.GetString("f_shash").IsNullOrEmpty() ? handleSearch(data) : handleFileSearch(data); return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(sr))); }
public IAsyncOperation <Gallery> FetchParentAsync() { if (!(this.ParentInfo is GalleryInfo i)) { return(AsyncOperation <Gallery> .CreateCompleted(null)); } return(i.FetchGalleryAsync()); }
public IAsyncOperation <Gallery> FetchLatestRevisionAsync() { if (this.DescendantsInfo.Count == 0) { return(AsyncOperation <Gallery> .CreateCompleted(this.Owner)); } return(this.DescendantsInfo.Last().Gallery.FetchGalleryAsync()); }
public static IAsyncOperation <Record> GetAsync(string title) { using (var db = new WikiDb()) { var record = db.Table.AsNoTracking().SingleOrDefault(r => r.Title == title); if (record != null && record.IsValid) { return(AsyncOperation <Record> .CreateCompleted(record)); } if (record is null || record.LastUpdate.AddDays(7) < DateTimeOffset.Now) { return(FetchAsync(title)); } return(AsyncOperation <Record> .CreateCompleted(default));
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { var v = unescape2(data.Paths[1]); var category = GetCategory(data); var advanced = GetAdvancedSearchOptions(data); switch (data.Path0) { case "tag": return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(Tag.Parse(v.TrimEnd(trim)).Search(category, advanced)))); case "uploader": return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(Client.Current.Search(v, null, category, advanced)))); } return(AsyncOperation <LaunchResult> .CreateFault(new NotSupportedException("Unsupported uri."))); }
public IAsyncOperation <bool> NotifyAsync(object data) { if (this.isopen || !(data is ContentDialogNotificationData notificationData)) { return(AsyncOperation <bool> .CreateCompleted(false)); } this.Title = notificationData.Title; this.Content = notificationData.Content; this.PrimaryButtonText = notificationData.PrimaryButtonText; this.PrimaryButtonCommand = notificationData.PrimaryButtonCommand; this.PrimaryButtonCommandParameter = notificationData.PrimaryButtonCommandParameter; this.SecondaryButtonText = notificationData.SecondaryButtonText; this.SecondaryButtonCommand = notificationData.SecondaryButtonCommand; this.SecondaryButtonCommandParameter = notificationData.SecondaryButtonCommandParameter; this.CloseButtonText = notificationData.CloseButtonText; this.DefaultButton = notificationData.DefaultButton; return(ShowAsync().ContinueWith(a => true)); }
public IAsyncOperation <bool> NotifyAsync(object data) { if (!RootControl.RootController.Available) { return(AsyncOperation <bool> .CreateCompleted(false)); } switch (data) { case Exception ex: RootControl.RootController.SendToast(ex, null); return(AsyncOperation <bool> .CreateCompleted(true)); case string str: RootControl.RootController.SendToast(str, null); return(AsyncOperation <bool> .CreateCompleted(true)); default: return(AsyncOperation <bool> .CreateCompleted(false)); } }
public static IAsyncOperation <IList <Gallery> > FetchGalleriesAsync(IReadOnlyList <GalleryInfo> galleryInfo) { if (galleryInfo is null) { throw new ArgumentNullException(nameof(galleryInfo)); } if (galleryInfo.Count <= 0) { return(AsyncOperation <IList <Gallery> > .CreateCompleted(Array.Empty <Gallery>())); } if (galleryInfo.Count <= 25) { return(Run <IList <Gallery> >(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 <IList <Gallery> >(async token => { var result = new List <Gallery>(galleryInfo.Count); var pageCount = MathHelper.GetPageCount(galleryInfo.Count, 25); 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); var data = re.GalleryMetaData; data.ForEach(async g => await g.InitAsync()); result.AddRange(data); } return result; })); } }
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { var keyword = ""; var category = Client.Current.Favorites.All; var ap = false; foreach (var item in data.Queries) { switch (item.Key) { case "f_apply": ap = item.Value.QueryValueAsBoolean(); break; case "favcat": if (item.Value != "all") { var index = item.Value.QueryValueAsInt32(); index = Math.Max(0, index); index = Math.Min(9, index); category = Client.Current.Favorites[index]; } break; case "f_search": keyword = UnescapeKeyword(item.Value); break; } } if (!ap) { return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(category.Search("")))); } else { return(AsyncOperation <LaunchResult> .CreateCompleted(new SearchLaunchResult(category.Search(keyword)))); } }
public static IAsyncOperation <string> GetDisplayContentAsync(this Tag tag) { var settings = SettingCollection.Current; if (settings.UseChineseTagTranslation) { var r = tag.GetEhTagTranslatorRecord(); if (r != null) { return(AsyncOperation <string> .CreateCompleted(r.Translated.Text)); } } if (settings.UseJapaneseTagTranslation) { return(tag.GetEhWikiRecordAsync().ContinueWith(action => { if (action.Status == AsyncStatus.Completed) { var r = action.GetResults(); if (!match(tag, r)) { return tag.Content; } else { return r.Japanese ?? tag.Content; } } else { throw action.ErrorCode; } })); } return(AsyncOperation <string> .CreateCompleted(tag.Content)); }
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { GalleryInfo.TryParseGallery(data, out var info); return(AsyncOperation <LaunchResult> .CreateCompleted(new GalleryLaunchResult(info, -1, GalleryLaunchStatus.Default))); }
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) => AsyncOperation <LaunchResult> .CreateCompleted(Handle(data));
public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data) { GalleryInfo.TryParseGalleryPopup(data, out var info, out var type); return(AsyncOperation <LaunchResult> .CreateCompleted(new GalleryLaunchResult(info, -1, type))); }