using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tool
{
///
/// 请求结果
///
public class Result
{
public Result()
{
}
///
/// 是否成功
///
public bool IsSucceed { get; set; } = true;
private string _Err;
///
/// 异常消息
///
public string Err
{
get
{
return _Err;
}
set
{
_Err = value;
AddErr2List();
}
}
///
/// 异常Code
/// 408 连接失败
///
public int ErrCode { get; set; }
///
/// 详细异常
///
public Exception Exception { get; set; }
///
/// 异常集合
///
public List ErrList { get; private set; } = new List();
///
/// 请求报文
///
public string Requst { get; set; }
///
/// 响应报文
///
public string Response { get; set; }
///
/// 请求报文2
///
public string Requst2 { get; set; }
///
/// 响应报文2
///
public string Response2 { get; set; }
///
/// 耗时(毫秒)
///
public double? TimeConsuming { get; private set; }
///
/// 结束时间统计
///
internal Result EndTime()
{
TimeConsuming = (DateTime.Now - InitialTime).TotalMilliseconds;
return this;
}
///
/// 开始时间
///
public DateTime InitialTime { get; protected set; } = DateTime.Now;
///
/// 设置异常信息和Succeed状态
///
///
///
public Result SetErrInfo(Result result)
{
IsSucceed = result.IsSucceed;
Err = result.Err;
ErrCode = result.ErrCode;
Exception = result.Exception;
foreach (var err in result.ErrList)
{
if (!ErrList.Contains(err))
ErrList.Add(err);
}
return this;
}
///
/// 添加异常到异常集合
///
public void AddErr2List()
{
if (!ErrList.Contains(Err))
ErrList.Add(Err);
}
}
///
/// 请求结果
///
public class Result : Result
{
public Result()
{
}
public Result(T data)
{
Value = data;
}
public Result(Result result)
{
Assignment(result);
}
public Result(Result result, T data)
{
Assignment(result);
Value = data;
}
///
/// 数据结果
///
public T Value { get; set; }
///
/// 结束时间统计
///
internal new Result EndTime()
{
base.EndTime();
return this;
}
///
/// 赋值
///
private void Assignment(Result result)
{
IsSucceed = result.IsSucceed;
InitialTime = result.InitialTime;
Err = result.Err;
Requst = result.Requst;
Response = result.Response;
Exception = result.Exception;
ErrCode = result.ErrCode;
base.EndTime();
foreach (var err in result.ErrList)
{
if (!ErrList.Contains(err))
ErrList.Add(err);
}
}
///
/// 设置异常信息和Succeed状态
///
///
///
public new Result SetErrInfo(Result result)
{
base.SetErrInfo(result);
return this;
}
}
}