예제 #1
0
        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))));
            }
        }
예제 #2
0
        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))));
        }
예제 #3
0
        public void String()
        {
            var a1 = AsyncOperation <string> .CreateCompleted();

            var a2 = AsyncOperation <string> .CreateCompleted();

            Assert.AreEqual(AsyncStatus.Completed, a1.Status);
            Assert.AreEqual(default, a1.GetResults());
예제 #4
0
        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)));
        }
예제 #5
0
 /// <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())));
 }
예제 #6
0
        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)));
        }
예제 #7
0
        public IAsyncOperation <Gallery> FetchParentAsync()
        {
            if (!(this.ParentInfo is GalleryInfo i))
            {
                return(AsyncOperation <Gallery> .CreateCompleted(null));
            }

            return(i.FetchGalleryAsync());
        }
예제 #8
0
        public IAsyncOperation <Gallery> FetchLatestRevisionAsync()
        {
            if (this.DescendantsInfo.Count == 0)
            {
                return(AsyncOperation <Gallery> .CreateCompleted(this.Owner));
            }

            return(this.DescendantsInfo.Last().Gallery.FetchGalleryAsync());
        }
예제 #9
0
        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));
예제 #10
0
        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.")));
        }
예제 #11
0
        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));
        }
예제 #12
0
        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));
            }
        }
예제 #13
0
        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;
                }));
            }
        }
예제 #14
0
        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))));
            }
        }
예제 #15
0
        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));
        }
예제 #16
0
 public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data)
 {
     GalleryInfo.TryParseGallery(data, out var info);
     return(AsyncOperation <LaunchResult> .CreateCompleted(new GalleryLaunchResult(info, -1, GalleryLaunchStatus.Default)));
 }
예제 #17
0
 public override IAsyncOperation <LaunchResult> HandleAsync(UriHandlerData data)
 => AsyncOperation <LaunchResult> .CreateCompleted(Handle(data));
예제 #18
0
 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)));
 }