using System;
using Newtonsoft.Json;
using BP.DA;
namespace BP.GPM.DTalk.DDSDK
{
///
/// 分析器
///
public class Analyze
{
#region Get Function
///
/// 发起GET请求
///
///
///
///
public static T Get(String requestUrl) where T : ResultPackage, new()
{
String resultJson = RequestHelper.Get(requestUrl);
return AnalyzeResult(resultJson);
}
#endregion
#region Post Function
///
/// 发起POST请求
///
///
///
///
///
public static T Post(String requestUrl, String requestParamOfJsonStr) where T : ResultPackage, new()
{
String resultJson = RequestHelper.Post(requestUrl, requestParamOfJsonStr);
return AnalyzeResult(resultJson);
}
#endregion
///
/// 下载文件
///
///
///
///
public static bool HttpDownLoadFile(string downLoadUrl, string saveFullName)
{
return RequestHelper.HttpDownLoadFile(downLoadUrl, saveFullName);
}
#region AnalyzeResult
///
/// 分析结果
///
///
///
///
private static T AnalyzeResult(string resultJson) where T : ResultPackage, new()
{
ResultPackage tempResult = null;
if (!DataType.IsNullOrEmpty(resultJson))
{
tempResult = JsonConvert.DeserializeObject(resultJson);
}
T result = null;
if (tempResult != null && tempResult.IsOK())
{
result = JsonConvert.DeserializeObject(resultJson);
}
else if (tempResult != null)
{
result = tempResult as T;
}
else if (tempResult == null)
{
result = new T();
}
//结果wei
if (result == null && tempResult != null)
{
result = JsonConvert.DeserializeObject(resultJson);
}
result.Json = resultJson;
return result;
}
#endregion
}
}