我制作了一个可以在Google Chrome中正常运行的API,然后创建了一个项目来存储数据和缓存,但是当我构建解决方案并使用Chrome运行API时,Android模拟器未显示任何数据,并且错误列表为0错误。有人帮我检查我的代码吗?我有5个班级,我认为可能有一些我找不到的错误。谢谢 首先在数据文件夹 AppCache.cs
public class AppCache
{
IBlobCache Cache = null;
public AppCache()
{
Cache = BlobCache.LocalMachine;
}
public event PropertyChangedEventHandler SessionsCacheChanged;
public async Task GetAllSessionsAsync()
{
var cachedSessions = Cache.GetOrFetchObject<List<Session>>(
"AllSessions",
async () => await (new SessionManager()).FetchSessionsAsync(), DateTimeOffset.Now.AddHours(3)
).Subscribe((List<Session> obj) =>
SessionsCacheChanged(obj,
new PropertyChangedEventArgs("SessionsCache"))
);
}
}
} 数据文件夹中的第二类 SessionManager.cs
public class SessionManager
{
HttpClient client = new HttpClient();
List<Session> ConferenceSessions = null;
public async Task<List<Session>> FetchSessionsAsync()
{
string url = "http://192.168.56.1:45455/api/conferencesessions";
try
{
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
ConferenceSessions = JsonConvert.DeserializeObject<List<Session>>(content);
}
}
catch (Exception ex)
{
Debug.WriteLine("@ ERROR{0}", ex.Message);
}
return ConferenceSessions;
}
}
} 在ViewModel文件夹中。 SessionListViewModel.cs
public class SessionListViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private ObservableCollection<Session> _sessionslist;
public ObservableCollection<Session> SessionList
{
get { return _sessionslist; }
set
{
_sessionslist = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SessionsList"));
}
}
public async Task FetchDataAsync()
{
var AppCache = new AppCache();
AppCache.SessionsCacheChanged +=
(sender, e) => { SessionList = new ObservableCollection<Session>((List<Session>)sender); };
await AppCache.GetAllSessionsAsync();
}
public SessionListViewModel()
{
FetchDataAsync();
}
}
}