Пример #1
0
        //public string GetFileNameForDownloading()
        //{
        //    var fileName = $"{Image.Owner.Name}  {Image.SimpleCreateTimeString}.jpg";
        //    var invalidChars = Path.GetInvalidFileNameChars();
        //    foreach (var c in invalidChars)
        //    {
        //        if (fileName.Contains(c))
        //        {
        //            fileName = fileName.Replace(c.ToString(), "");
        //        }
        //    }
        //    return fileName;
        //}

        //public async Task SetDataRequestDataAsync(DataRequest request)
        //{
        //    var requestData = request.Data;
        //    requestData.SetWebLink(new Uri(Image.Urls.Full));
        //    requestData.Properties.Title = $"Share a photo by {Image.Owner?.Name ?? "Unknown"}";
        //    requestData.Properties.ContentSourceWebLink = new Uri(Image.Urls.Full);
        //    requestData.Properties.ContentSourceApplicationLink = new Uri(Image.Urls.Full);

        //    requestData.SetText(ShareText);

        //    var file = await StorageFile.GetFileFromPathAsync(BitmapSource.LocalPath);
        //    if (file != null)
        //    {
        //        List<IStorageItem> imageItems = new List<IStorageItem>
        //        {
        //            file
        //        };
        //        requestData.SetStorageItems(imageItems);

        //        var imageStreamRef = RandomAccessStreamReference.CreateFromFile(file);
        //        requestData.SetBitmap(imageStreamRef);
        //        requestData.Properties.Thumbnail = imageStreamRef;
        //    }
        //}

        //public async Task TryLoadBitmapAsync()
        //{
        //    if (BitmapSource.Bitmap != null) return;
        //    var url = GetUrlFromSettings();

        //    if (string.IsNullOrEmpty(url)) return;

        //    var task = CheckAndGetDownloadedFileAsync();

        //    BitmapSource.ExpectedFileName = Image.ID + ".jpg";
        //    BitmapSource.RemoteUrl = url;
        //    await BitmapSource.LoadBitmapAsync();
        //}

        //public async Task CheckAndGetDownloadedFileAsync()
        //{
        //    var name = GetFileNameForDownloading();
        //    var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MyerSplash", CreationCollisionOption.OpenIfExists);
        //    if (folder != null)
        //    {
        //        if (await folder.TryGetItemAsync(name) is StorageFile file)
        //        {
        //            var pro = await file.GetBasicPropertiesAsync();
        //            if (pro.Size > 10)
        //            {
        //                this.DownloadStatus = DownloadStatus.Ok;
        //                DownloadedFile = file;
        //            }
        //        }
        //    }
        //}

        //public string GetUrlFromSettings()
        //{
        //    var quality = App.AppSettings.LoadQuality;
        //    switch (quality)
        //    {
        //        case 0: return Image.Urls.Regular;
        //        case 1: return Image.Urls.Small;
        //        case 2: return Image.Urls.Thumb;
        //        default: return "";
        //    }
        //}

        //public string GetSaveImageUrlFromSettings()
        //{
        //    var quality = App.AppSettings.SaveQuality;
        //    switch (quality)
        //    {
        //        case 0: return Image.Urls.Raw;
        //        case 1: return Image.Urls.Full;
        //        case 2: return Image.Urls.Regular;
        //        default: return "";
        //    }
        //}

        //public string GetDownloadLocationUrl()
        //{
        //    return Image?.Links?.DownloadLocation;
        //}

        public async Task GetVolDetialAsync()
        {
            var result = await _service.GetVolDetailHtmlAsync(Vol.VolUrl);

            if (result != null)
            {
                // 暂用新的API
                Vol.GetDetailVol_w(result);
                // Check isOnline or file
                // Get Song Json
                var songJson = "";
                if (true)
                {
                    //Change to Washa
                    //var songSourceNum = Vol.GetVolSongSource(result);
                    //songJson = await _service.GetVolDetailHtmlAsync(Request.GetSongListJson(songSourceNum));
                    var WashaVolUriRequest = Request.GetWashaVolUrl(Vol.VolNum);
                    var WashaVolHtml       = await _service.GetVolDetailHtmlAsync(WashaVolUriRequest);

                    var VolUri = Vol.GetWashaVolDetailUri(WashaVolHtml);
                    songJson = Vol.GetWashaVolSongListJson(await _service.GetVolDetailHtmlAsync(VolUri));
                }
                else
                {
                    songJson = Vol.GetVolSongFileJson(result);
                }
                Vol.AddSongsFromJson(songJson);
            }
            //if (result.IsRequestSuccessful)
            //{
            //    JsonObject.TryParse(result.JsonSrc, out JsonObject json);
            //    if (json != null)
            //    {
            //        var exifObject = JsonParser.GetJsonObjFromJsonObj(json, "exif");
            //        if (exifObject != null)
            //        {
            //            Image.Exif = JsonConvert.DeserializeObject<ImageExif>(exifObject.ToString());
            //            RaisePropertyChanged(() => SizeString);
            //        }

            //        var locationObj = JsonParser.GetJsonObjFromJsonObj(json, "location");
            //        if (locationObj != null)
            //        {
            //            Image.Location = JsonConvert.DeserializeObject<ImageLocation>(locationObj.ToString());
            //            RaisePropertyChanged(() => LocationString);
            //        }
            //    }
            //}
        }