public void Load()
{
string uuid = System.Guid.NewGuid().ToString();
Uri uri;
if (Path == null)
{
uri = new Uri(WebClientInfo.BaseAddress);
}
else if (Path != null && Path.Equals("null"))
{
return;
}
else
{
uri = new Uri(WebClientInfo.BaseAddress + "/" + Path.Replace("%", "%25").Replace("#", "%23") + "?uuid=" + uuid);
}
WebClient client = new WebClient();
client.DownloadStringCompleted += (o, a) =>
{
Log.Debug("加载数据完成");
if (a.Error == null)
{
//更新数据
JsonObject item = JsonValue.Parse(a.Result) as JsonObject;
if(item.ContainsKey("error"))
{
Error = item["error"];
State = State.LoadError;
}
else
{
FromJson(item);
State = State.Loaded;
}
}
else
{
Error = a.Error.GetMessage();
State = State.LoadError;
}
IsBusy = false;
//通知加载完成
OnCompleted(a);
OnDataLoaded(a);
};
IsBusy = true;
OnLoading();
State = State.StartLoad;
Log.Debug("开始加载数据, 路径为: " + WebClientInfo.BaseAddress + "/" + Path);
client.DownloadStringAsync(uri);
}