@Xiaodi Yan , This is the caller method.
private async void GetDatabaseData()
{
AppUtils.PrintDebug("==========Start", CLASS_NAME, "GetSharedMobileResource");
if (AppUtils.HasInternet())
{
AppUtils.PrintDebug("==========Has Internet ", CLASS_NAME, "GetSharedMobileResource");
await restWSClient.GetMobileResource(classroomId).ContinueWith(async responseMsg =>
{
AppUtils.PrintDebug("==========GetSharedMobileResource Response : " + responseMsg.Result, CLASS_NAME, "GetSharedMobileResource()");
if (responseMsg != null && responseMsg.Result != null && !responseMsg.IsFaulted)
{
var responseContent = responseMsg.Result.Content.ReadAsStringAsync();
if (responseMsg.Result.StatusCode == HttpStatusCode.OK)
{
AppUtils.PrintDebug("=========OK ", CLASS_NAME, "GetSharedMobileResource()");
if (responseContent != null && responseContent.Result != null && !responseContent.IsFaulted)
{
AppUtils.PrintDebug("=========content : " + responseContent.Result, CLASS_NAME, "GetSharedMobileResource()");
string json = responseContent.Result;
JObject joResponse = JObject.Parse(responseContent.Result);
JArray payloadArray = (JArray)joResponse["payload"];
AppUtils.PrintDebug("=========payloadArray : " + payloadArray, CLASS_NAME, "GetSharedMobileResource()");
if (payloadArray != null)
{
string serverIP = "";
foreach (JObject resource in payloadArray)
{
if (resource != null)
{
string jsonResource = resource.ToString();
serverIP = (string)JObject.Parse(jsonResource)["IWIP"];
App.fileType = (string)JObject.Parse(jsonResource)["ResourceType"];
string path = (string)JObject.Parse(jsonResource)["ResourcePath"];
App.fileName = Path.GetFileName(path);
prevSharedFileId = sharedFileId;
sharedFileId = (string)JObject.Parse(jsonResource)["Id"];
}
}
if (sharedFileId != "" && prevSharedFileId != sharedFileId)
{
StudentShareClient shareClient = new StudentShareClient(serverIP);
if (App.fileType == "Image" || App.fileType == "Video")
{
await ExtractFileData();
}
}
}
else
{
//payload null
AppUtils.PrintDebug("=========payload is null ", CLASS_NAME, "GetSharedMobileResource()");
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
else
{
//content null
AppUtils.PrintDebug("=========content is null ", CLASS_NAME, "GetSharedMobileResource()");
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
else if (responseMsg.Result.StatusCode == Constants.HTTP440)
{
// Redirect to Login
Frame rootFrame = Window.Current.Content as Frame;
rootFrame.Navigate(typeof(LoginScreen), null, new SuppressNavigationTransitionInfo());
}
else if (responseMsg.Result.StatusCode == HttpStatusCode.InternalServerError)
{
//Internal Server Error
AppUtils.PrintDebug("=========InternalServerError ", CLASS_NAME, "GetSharedMobileResource()");
if (responseContent != null && responseContent.Result != null && !responseContent.IsFaulted)
{
AppUtils.PrintDebug("=========content : " + responseContent.Result, CLASS_NAME, "GetSharedMobileResource()");
try
{
JObject joResponse = JObject.Parse(responseContent.Result);
JObject statusMsg = (JObject)joResponse["status"];
AppUtils.PrintDebug("=========status : " + statusMsg, CLASS_NAME, "GetSharedMobileResource()");
if (statusMsg != null)
{
string msgDesc = (string)statusMsg["message"];
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(msgDesc);
});
}
else
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_INTERNAL);
});
}
}
catch (Exception e)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
else
{
//content null
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
else
{
//Unexpected error
AppUtils.PrintDebug("=========Other error ", CLASS_NAME, "GetSharedMobileResource()");
if (responseContent != null && responseContent.Result != null && !responseContent.IsFaulted)
{
AppUtils.PrintDebug("=========content : " + responseContent.Result, CLASS_NAME, "GetSharedMobileResource()");
try
{
JObject joResponse = JObject.Parse(responseContent.Result);
JObject statusMsg = (JObject)joResponse["status"];
AppUtils.PrintDebug("=========status : " + statusMsg, CLASS_NAME, "GetSharedMobileResource()");
if (statusMsg != null)
{
string msgDesc = (string)statusMsg["message"];
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(msgDesc);
});
}
else
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
catch (Exception e)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
else
{
//content null
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
}
}
else
{
//responseMsg or responseMsg.Result is null
AppUtils.PrintDebug("=========responseMsg or responseMsg.Result is null ", CLASS_NAME, "GetSharedMobileResource()");
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_CONTACT_ADMIN);
});
}
});
AppUtils.PrintDebug("==========End", CLASS_NAME, "GetSharedMobileResource");
}
else
{
AppUtils.PrintDebug("==========No internet", CLASS_NAME, "GetSharedMobileResource");
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await AppUtils.ShowMessage(Constants.ERROR_NO_INTERNET_ACCESS);
});
}
}