parent
f5dd474ba0
commit
53eaac43e3
|
@ -21,7 +21,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="hostIp">主机IP地址</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetHostIP")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -53,7 +52,7 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetHostIP(ipAddress);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -76,7 +75,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="boardIp">板卡IP地址</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetBoardIP")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -108,7 +106,7 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetBoardIP(ipAddress);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -117,6 +115,13 @@ public class NetConfigController : ControllerBase
|
|||
return StatusCode(StatusCodes.Status500InternalServerError, $"设置失败: {result.Error}");
|
||||
}
|
||||
|
||||
var ret = db.UpdateBoardIpAddr(boardId, ipAddress.ToString());
|
||||
if (ret <= 0)
|
||||
{
|
||||
logger.Error($"数据库更新失败");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, $"数据库更新失败");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -131,7 +136,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="hostMac">主机MAC地址(格式:AA:BB:CC:DD:EE:FF)</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetHostMAC")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -164,7 +168,66 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetHostMAC(macBytes);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error($"设置主机MAC地址失败: {result.Error}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, $"设置失败: {result.Error}");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "设置主机MAC地址时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "设置失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新主机MAC地址
|
||||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("UpdateHostMAC")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateHostMAC(Guid boardId)
|
||||
{
|
||||
if (boardId == Guid.Empty)
|
||||
return BadRequest("板卡ID不能为空");
|
||||
|
||||
byte[]? macBytes = null;
|
||||
try
|
||||
{
|
||||
// 获取本机第一个可用的MAC地址
|
||||
macBytes = System.Net.NetworkInformation.NetworkInterface
|
||||
.GetAllNetworkInterfaces()
|
||||
.Where(nic => nic.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up
|
||||
&& nic.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Loopback)
|
||||
.Select(nic => nic.GetPhysicalAddress()?.GetAddressBytes())
|
||||
.FirstOrDefault(bytes => bytes != null && bytes.Length == 6);
|
||||
|
||||
if (macBytes == null)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "无法获取本机MAC地址");
|
||||
|
||||
// 获取板卡信息
|
||||
using var db = new Database.AppDataConnection();
|
||||
var boardRet = db.GetBoardByID(boardId);
|
||||
if (!boardRet.IsSuccessful)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "数据库操作失败");
|
||||
if (!boardRet.Value.HasValue)
|
||||
return NotFound("未找到对应的板卡");
|
||||
|
||||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetHostMAC(macBytes);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -187,7 +250,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="boardMac">板卡MAC地址(格式:AA:BB:CC:DD:EE:FF)</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetBoardMAC")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -220,7 +282,7 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetBoardMAC(macBytes);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
|
|
@ -542,6 +542,22 @@ public class AppDataConnection : DataConnection
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新实验板的IP地址
|
||||
/// </summary>
|
||||
/// <param name="boardId">实验板的唯一标识符</param>
|
||||
/// <param name="newIpAddr">新的IP地址</param>
|
||||
/// <returns>更新的记录数</returns>
|
||||
public int UpdateBoardIpAddr(Guid boardId, string newIpAddr)
|
||||
{
|
||||
var result = this.BoardTable
|
||||
.Where(b => b.ID == boardId)
|
||||
.Set(b => b.IpAddr, newIpAddr)
|
||||
.Update();
|
||||
logger.Info($"实验板 {boardId} 的IP地址已更新为 {newIpAddr},更新记录数: {result}");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户表
|
||||
/// </summary>
|
||||
|
|
433
src/APIClient.ts
433
src/APIClient.ts
|
@ -470,14 +470,14 @@ export class VideoStreamClient {
|
|||
* 初始化摄像头自动对焦功能
|
||||
* @return 初始化结果
|
||||
*/
|
||||
initAutoFocus(): Promise<FileResponse | null> {
|
||||
initAutoFocus(): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/InitAutoFocus";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -486,40 +486,53 @@ export class VideoStreamClient {
|
|||
});
|
||||
}
|
||||
|
||||
protected processInitAutoFocus(response: Response): Promise<FileResponse | null> {
|
||||
protected processInitAutoFocus(response: Response): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||||
if (fileName) {
|
||||
fileName = decodeURIComponent(fileName);
|
||||
} else {
|
||||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||||
}
|
||||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _headers }; });
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result500 = resultData500 !== undefined ? resultData500 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<FileResponse | null>(null as any);
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行自动对焦
|
||||
* @return 对焦结果
|
||||
*/
|
||||
autoFocus(): Promise<FileResponse | null> {
|
||||
autoFocus(): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/AutoFocus";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -528,26 +541,39 @@ export class VideoStreamClient {
|
|||
});
|
||||
}
|
||||
|
||||
protected processAutoFocus(response: Response): Promise<FileResponse | null> {
|
||||
protected processAutoFocus(response: Response): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||||
if (fileName) {
|
||||
fileName = decodeURIComponent(fileName);
|
||||
} else {
|
||||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||||
}
|
||||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _headers }; });
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result500 = resultData500 !== undefined ? resultData500 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<FileResponse | null>(null as any);
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2653,6 +2679,347 @@ export class MatrixKeyClient {
|
|||
}
|
||||
}
|
||||
|
||||
export class NetConfigClient {
|
||||
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||
private baseUrl: string;
|
||||
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
|
||||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主机IP地址
|
||||
* @param boardId (optional) 板卡ID
|
||||
* @param hostIp (optional) 主机IP地址
|
||||
* @return 操作结果
|
||||
*/
|
||||
setHostIP(boardId: string | undefined, hostIp: string | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/NetConfig/SetHostIP?";
|
||||
if (boardId === null)
|
||||
throw new Error("The parameter 'boardId' cannot be null.");
|
||||
else if (boardId !== undefined)
|
||||
url_ += "boardId=" + encodeURIComponent("" + boardId) + "&";
|
||||
if (hostIp === null)
|
||||
throw new Error("The parameter 'hostIp' cannot be null.");
|
||||
else if (hostIp !== undefined)
|
||||
url_ += "hostIp=" + encodeURIComponent("" + hostIp) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processSetHostIP(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processSetHostIP(response: Response): Promise<boolean> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置板卡IP地址
|
||||
* @param boardId (optional) 板卡ID
|
||||
* @param boardIp (optional) 板卡IP地址
|
||||
* @return 操作结果
|
||||
*/
|
||||
setBoardIP(boardId: string | undefined, boardIp: string | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/NetConfig/SetBoardIP?";
|
||||
if (boardId === null)
|
||||
throw new Error("The parameter 'boardId' cannot be null.");
|
||||
else if (boardId !== undefined)
|
||||
url_ += "boardId=" + encodeURIComponent("" + boardId) + "&";
|
||||
if (boardIp === null)
|
||||
throw new Error("The parameter 'boardIp' cannot be null.");
|
||||
else if (boardIp !== undefined)
|
||||
url_ += "boardIp=" + encodeURIComponent("" + boardIp) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processSetBoardIP(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processSetBoardIP(response: Response): Promise<boolean> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主机MAC地址
|
||||
* @param boardId (optional) 板卡ID
|
||||
* @param hostMac (optional) 主机MAC地址(格式:AA:BB:CC:DD:EE:FF)
|
||||
* @return 操作结果
|
||||
*/
|
||||
setHostMAC(boardId: string | undefined, hostMac: string | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/NetConfig/SetHostMAC?";
|
||||
if (boardId === null)
|
||||
throw new Error("The parameter 'boardId' cannot be null.");
|
||||
else if (boardId !== undefined)
|
||||
url_ += "boardId=" + encodeURIComponent("" + boardId) + "&";
|
||||
if (hostMac === null)
|
||||
throw new Error("The parameter 'hostMac' cannot be null.");
|
||||
else if (hostMac !== undefined)
|
||||
url_ += "hostMac=" + encodeURIComponent("" + hostMac) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processSetHostMAC(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processSetHostMAC(response: Response): Promise<boolean> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新主机MAC地址
|
||||
* @param boardId (optional) 板卡ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
updateHostMAC(boardId: string | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/NetConfig/UpdateHostMAC?";
|
||||
if (boardId === null)
|
||||
throw new Error("The parameter 'boardId' cannot be null.");
|
||||
else if (boardId !== undefined)
|
||||
url_ += "boardId=" + encodeURIComponent("" + boardId) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processUpdateHostMAC(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processUpdateHostMAC(response: Response): Promise<boolean> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置板卡MAC地址
|
||||
* @param boardId (optional) 板卡ID
|
||||
* @param boardMac (optional) 板卡MAC地址(格式:AA:BB:CC:DD:EE:FF)
|
||||
* @return 操作结果
|
||||
*/
|
||||
setBoardMAC(boardId: string | undefined, boardMac: string | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/NetConfig/SetBoardMAC?";
|
||||
if (boardId === null)
|
||||
throw new Error("The parameter 'boardId' cannot be null.");
|
||||
else if (boardId !== undefined)
|
||||
url_ += "boardId=" + encodeURIComponent("" + boardId) + "&";
|
||||
if (boardMac === null)
|
||||
throw new Error("The parameter 'boardMac' cannot be null.");
|
||||
else if (boardMac !== undefined)
|
||||
url_ += "boardMac=" + encodeURIComponent("" + boardMac) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processSetBoardMAC(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processSetBoardMAC(response: Response): Promise<boolean> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 400) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class PowerClient {
|
||||
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||
private baseUrl: string;
|
||||
|
@ -4092,6 +4459,8 @@ export enum BurstType {
|
|||
export class UDPData implements IUDPData {
|
||||
/** 接受到的时间 */
|
||||
dateTime!: Date;
|
||||
/** 数据包时间戳 */
|
||||
timestamp!: number;
|
||||
/** 发送来源的IP地址 */
|
||||
address!: string;
|
||||
/** 发送来源的端口号 */
|
||||
|
@ -4115,6 +4484,7 @@ export class UDPData implements IUDPData {
|
|||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.dateTime = _data["dateTime"] ? new Date(_data["dateTime"].toString()) : <any>undefined;
|
||||
this.timestamp = _data["timestamp"];
|
||||
this.address = _data["address"];
|
||||
this.port = _data["port"];
|
||||
this.taskID = _data["taskID"];
|
||||
|
@ -4133,6 +4503,7 @@ export class UDPData implements IUDPData {
|
|||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["dateTime"] = this.dateTime ? this.dateTime.toISOString() : <any>undefined;
|
||||
data["timestamp"] = this.timestamp;
|
||||
data["address"] = this.address;
|
||||
data["port"] = this.port;
|
||||
data["taskID"] = this.taskID;
|
||||
|
@ -4146,6 +4517,8 @@ export class UDPData implements IUDPData {
|
|||
export interface IUDPData {
|
||||
/** 接受到的时间 */
|
||||
dateTime: Date;
|
||||
/** 数据包时间戳 */
|
||||
timestamp: number;
|
||||
/** 发送来源的IP地址 */
|
||||
address: string;
|
||||
/** 发送来源的端口号 */
|
||||
|
|
Loading…
Reference in New Issue