2,854 questions
solved 。
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
here is my code(only useful)
using JNGWpfControlLibrary;
using onedrive_mongo;
using QQmusicDLL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Cache;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using JNGDataTypes.Music;
using System.Net.NetworkInformation;
using JNGWpfControlLibrary.Controls.UserControls;
namespace jngyy2024.Pes
{
/// <summary>
/// MusicFoundPage.xaml 的交互逻辑
/// </summary>
public partial class MusicFoundPage : Page
{
static Dictionary<int, ValueTuple<int, string>> contentCaches = new Dictionary<int, ValueTuple<int, string>>();
int ID;
Albumbase myalbum;
//static string strcontent = string.Empty;
bool hadcache = false;
qqmusic QM = new qqmusic();
public static int GetCacheCount()
{
return contentCaches.Count;
}
public MusicFoundPage(int id = 0)
{
InitializeComponent();
ID = id;
//MessageBox.Show(index.ToString());
//if (hadcache)
//{
// JLV.SelectedIndex = selectindex;
// ShowID(strcontent, selectindex);
// hadcache = false;
//}
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
//frame工作原理,实例化一次,但会执行load和unload,不会释放实例,所以可以用变量记录上次操作值
}
private void ShowID(string content, int id)
{
if (content == string.Empty)
return;
WP.Children.Clear();
if (id == 0)
{
JsonNode jobj = JsonNode.Parse(content);
JsonArray JsonArray = jobj["req_1"]["data"]["group"][0]["toplist"] as JsonArray;
foreach (var a in JsonArray)
{
JViewButton jView = new JViewButton
{
Height = 150,
Width = 350,
Title = a["title"].ToString(),
Background = new ImageBrush(BitmapFrame.Create(new Uri(a["frontPicUrl"].ToString()), BitmapCreateOptions.None, BitmapCacheOption.None)),
PicStr = a["frontPicUrl"].ToString(),
OverContent = $"🎧{Math.Round(a["listenNum"].GetValue<double>() / 10000, 1)}万",
Tags = ((JsonArray)a["song"]).Select(x => $"{x["title"]} - {x["singerName"]}").ToArray(),
Mid = a["topId"].ToString(),
CTime = a["updateTime"].ToString(),
Tag = a["period"]
};
jView.Click += async (sender, e) =>
{
JViewButton jViewButton = sender as JViewButton;
MainWindow.Me.Frame.Navigate(new AlbumDetailPage(new SongList
{
AMid = jViewButton.Mid,
Name = jViewButton.Title,
Singers = new singer[] { new singer { name = "群青" } },
Style = "Mix",
Time = jViewButton.CTime,
//Pic = jViewButton.Background,
PicStr = jViewButton.PicStr,
Songis = await QM.GetSongsByTopID(jViewButton.Mid, MidStation.userData.usefast, jViewButton.Tag.ToString()),
}, AlbumDetailPage.ShowType.Network, new Albumbase { Type = "QQ", State = Albumbase.States.Static }));
};
//await Task.Delay(1000);
//string fpbase = "Imas";
//if (!Directory.Exists(fpbase))
// Directory.CreateDirectory(fpbase);
//string fwpath = a["frontPicUrl"].ToString();
//string flpath = Path.Combine(fpbase, Path.GetFileName(fwpath));
//if (!File.Exists(flpath))
//{
// HttpClient hc = new HttpClient();
// File.WriteAllBytes(flpath, await hc.GetByteArrayAsync(fwpath));
//}
//jView.Background = new ImageBrush(new BitmapImage(new Uri(flpath, UriKind.Relative)));
//BitmapImage bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.IgnoreColorProfile };
//bitmapImage.BeginInit();
//bitmapImage.UriSource = new Uri(Path.Combine(Environment.CurrentDirectory, flpath));
//bitmapImage.EndInit();
WP.Children.Add(jView);
}
}
else if (id == 1)
{
JsonArray root = JsonNode.Parse(content)["documents"] as JsonArray;
foreach (var i in root)
{
string dname = i["UserName"].GetValue<string>();
string em = i["UserEmail"].GetValue<string>();
string[] parts = i["Content"].GetValue<string>().Split(MidStation.SPStr);
Albumbase headers = JsonSerializer.Deserialize<Albumbase>(parts[0]);
List<SongItem> body = JsonSerializer.Deserialize<List<SongItem>>(parts[1]);
JViewButton jView = new JViewButton
{
Height = 150,
Width = 350,
Title = headers.Name,
Background = new ImageBrush(BitmapFrame.Create(new Uri(headers.Ima), BitmapCreateOptions.None, BitmapCacheOption.None)),
PicStr = headers.Ima,
OverContent = dname,
Tags = body.Select(x => $"{x.songname} - {x.songars}").Take(3).ToArray(),
Mid = em,
CTime = headers.CTime,
Tag = ""
};
body.ForEach(v => v.islove = MidStation.userData.LoveMids.Contains(v.mid) ? true : false);
jView.Click += async (sender, e) =>
{
JNGWpfControlLibrary.Controls.UserControls.JViewButton jViewButton = sender as JNGWpfControlLibrary.Controls.UserControls.JViewButton;
MainWindow.Me.Frame.Navigate(new AlbumDetailPage(new SongList
{
AMid = jViewButton.Mid,
Name = jViewButton.Title,
Singers = new singer[] { new singer { name = "群青" } },
Style = $"由 {dname} 创建",
Time = jViewButton.CTime,
//Pic = jViewButton.Background,
PicStr = jViewButton.PicStr,
Songis = body,
}, AlbumDetailPage.ShowType.Mongo, headers));
};
WP.Children.Add(jView);
}
}
//contentCaches[ID] = (id, content);
}
private async void JListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//if ((hadcache) /*|| (selectindex == JLV.SelectedIndex)*/)
// return;
var selectindex = JLV.SelectedIndex;
if (hadcache)
{
hadcache = false;
return;
}
if (!NetworkInterface.GetIsNetworkAvailable())
return;
if (selectindex == 0)
{
//MessageBox.Show("");
HttpClient httpClient = new HttpClient();
var HR = new HttpRequestMessage(HttpMethod.Post, "https://u.y.qq.com/cgi-bin/musicu.fcg") { Content = new StringContent("{\"comm\":{\"cv\":4747474,\"ct\":24,\"format\":\"json\",\"inCharset\":\"utf-8\",\"outCharset\":\"utf-8\",\"notice\":0,\"platform\":\"yqq.json\",\"needNewCode\":1,\"uin\":0,\"g_tk_new_20200303\":5381,\"g_tk\":5381},\"req_1\":{\"module\":\"musicToplist.ToplistInfoServer\",\"method\":\"GetAll\",\"param\":{}}}") };
HttpResponseMessage? HR1 = null;
try
{
HR1 = await httpClient.SendAsync(HR);
}
catch { return; }
httpClient.Dispose();
if (HR1.IsSuccessStatusCode)
{
ShowID(await HR1.Content.ReadAsStringAsync(), 0);
}
}
else if (selectindex == 1)
{//!!!!!!!!!!!!!islove要根据客户端。
//style为作者名字
//sign为作者邮箱
//state一定为dy
string? jarrstr = await mongodb.Getall(MidStation.AlbumListStr);
if (jarrstr == null)
return;
ShowID(jarrstr, 1);
}
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
}
private void JLV_Loaded(object sender, RoutedEventArgs e)
{
if (!contentCaches.ContainsKey(ID))
contentCaches.Add(ID, (0, string.Empty));
else
{
hadcache = true;
JLV.SelectedIndex = contentCaches[ID].Item1;
ShowID(contentCaches[ID].Item2, contentCaches[ID].Item1);
}
}
}
}
and the errr:
and turn to the file DefaultBinder.cs,isn't my file,also didn't point out the err-line.
i have no ideas cuz another similar file worked well.
add:
if i remove 'int id = 0' then nothing goes wrong,and i haven't use this class to realize a instance,also i even no coding the class