CssSolution/CSS_Solution/Request/RequestResults.cs

155 lines
5.9 KiB
C#
Raw Normal View History

2024-03-12 08:15:15 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
2024-03-12 08:15:15 +00:00
using System.Text;
using System.Threading.Tasks;
namespace CSS_Solution.Request
{
class Get_Index_Result
{
public int? id;
public string? JSESSIONID;
public string? RND;
public DateTime dateTime;
private string? error_info;
public string Error_info
{
get { return error_info ??= ""; }
set
{
error_info = value;
is_error = true;
}
}
bool is_error;
public Get_Index_Result(int _id, string jSESSIONID, string rND, DateTime dateTime)
{
id = _id;
JSESSIONID = jSESSIONID;
RND = rND;
error_info = "";
this.dateTime = dateTime;
}
public Get_Index_Result(Get_Index get_Index)
{
id = get_Index.Get_Id();
if (get_Index.Get_cookie() == null || get_Index.Get_cookie()?.Count() == 0)
{
foreach (Cookie cookie in Initialize.hc_pool.GetHttpClientHandler(Request_Type.get_index).CookieContainer.GetCookies(new Uri("http://sso.jwc.whut.edu.cn/Certification/login.do")))
if (cookie.Name == "JSESSIONID")
JSESSIONID = cookie.Value;
}
else
JSESSIONID = get_Index.Get_cookie()?.Select(element => new { element.Key, element.Value }).Where(element => element.Key.Equals("JSESSIONID")).First().Value;
2024-03-12 08:15:15 +00:00
RND = get_Index.Get_rnd();
dateTime = DateTime.Now;
error_info = "";
}
public Get_Index_Result(string error_info) => Error_info = error_info;
public bool Wrong_Result() => JSESSIONID == null || RND == null;
public bool isError() => is_error;
}
class Login_Result
{
public List<KeyValuePair<string, string>> cookie = new List<KeyValuePair<string, string>>();
public int? id;
public string? JSESSIONID;
public string? CERLOGIN;
public DateTime dateTime;
private string? error_info;
public string Error_info
{
get { return error_info ??= ""; }
set
{
error_info = value;
is_error = true;
}
}
bool is_error;
public Login_Result(int _id, string jSESSIONID, string cERLOGIN, DateTime dateTime)
{
id = _id;
JSESSIONID = jSESSIONID;
CERLOGIN = cERLOGIN;
dateTime = DateTime.Now;
error_info = "";
cookie = new List<KeyValuePair<string, string>>();
cookie.Add(new KeyValuePair<string, string>("JSESSIONID", JSESSIONID));
cookie.Add(new KeyValuePair<string, string>("CERLOGIN", CERLOGIN));
}
public Login_Result(Login login)
{
id = login.Get_Id();
cookie = login.Get_cookie() ?? throw new InvalidOperationException("Cookie of Login is NULL?!");
for (int i = 0; i < cookie.Count; i++)
if (cookie[i].Key == "JSESSIONID" || cookie[i].Key == "Path")
{
cookie.RemoveAt(i);
i--;
}
JSESSIONID = login.Get_JSESSIONID();
try
{
CERLOGIN = cookie?.Select(x => x).Where(element => element.Key.Equals("CERLOGIN")).First().Value;
cookie?.Add(new KeyValuePair<string, string>("JSESSIONID", JSESSIONID));
}
catch (InvalidOperationException)
{
if (login.Get_cookie() == null || login.Get_cookie()?.Count == 0)
error_info = "Login_failed, Consider account password error!";
}
2024-03-12 08:15:15 +00:00
dateTime = DateTime.Now;
error_info = "";
}
public Login_Result(string error_info) => Error_info = error_info;
public bool Wrong_Result() => JSESSIONID == null || CERLOGIN == null || cookie.Select(x => new { havenull = x.Value == null }).Where(x => x.havenull).Count() > 0;
public bool isError() => is_error;
public List<KeyValuePair<string, string>> Get_cookie() => cookie;
}
class To_Course_Result
{
public List<KeyValuePair<string, string>> cookie = new List<KeyValuePair<string, string>>();
public int? id;
public string? JSESSIONID;
public string? BINGOCLOUDLB;
public DateTime dateTime;
private string? error_info;
public string Error_info
{
get { return error_info ??= ""; }
set
{
error_info = value;
is_error = true;
}
}
bool is_error;
public To_Course_Result(int _id,string jSESSIONID,string bINGOCLOUDLB,DateTime dateTime)
{
id = _id;
JSESSIONID = jSESSIONID;
BINGOCLOUDLB = bINGOCLOUDLB;
error_info = "";
this.dateTime = dateTime;
}
public To_Course_Result(To_Course to_Course)
{
id = to_Course.get_ID();
cookie = to_Course.Get_cookie() ?? throw new InvalidOperationException("Cookie of ToCourse is NULL?!");
JSESSIONID = cookie?.Select(x => x).Where(element => element.Key.Equals("JSESSIONID")).First().Value;
BINGOCLOUDLB = cookie?.Select(x => x).Where(element => element.Key.Equals("BINGOCLOUDLB")).First().Value;
dateTime = DateTime.Now;
error_info = "";
}
public To_Course_Result(string error_info) => Error_info = error_info;
public bool Wrong_Result() => JSESSIONID == null || BINGOCLOUDLB == null || cookie.Select(x => new { havenull = x.Value == null }).Where(x => x.havenull).Count() > 0;
public bool isError() => is_error;
public List<KeyValuePair<string, string>> Get_cookie() => cookie;
}
}