feat: change test view to basic jtag upload and download page
This commit is contained in:
640
src/APIClient.ts
640
src/APIClient.ts
@@ -8,9 +8,6 @@
|
||||
/* eslint-disable */
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
import { batchSetConstraintStates, notifyConstraintChange } from './stores/constraints';
|
||||
import type { ConstraintLevel } from './stores/constraints';
|
||||
|
||||
export class Client {
|
||||
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||
private baseUrl: string;
|
||||
@@ -473,7 +470,7 @@ export class JtagClient {
|
||||
* @param address (optional) 设备地址
|
||||
* @param port (optional) 设备端口
|
||||
*/
|
||||
getDeviceIDCode(address: string | undefined, port: number | undefined): Promise<void> {
|
||||
getDeviceIDCode(address: string | undefined, port: number | undefined): Promise<number> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/GetDeviceIDCode?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
@@ -485,6 +482,61 @@ export class JtagClient {
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processGetDeviceIDCode(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetDeviceIDCode(response: Response): Promise<number> {
|
||||
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 === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result500 = Exception.fromJS(resultData500);
|
||||
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<number>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态寄存器
|
||||
* @param address (optional) 设备地址
|
||||
* @param port (optional) 设备端口
|
||||
*/
|
||||
readStatusReg(address: string | undefined, port: number | undefined): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/ReadStatusReg?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||
if (port === null)
|
||||
throw new Error("The parameter 'port' cannot be null.");
|
||||
else if (port !== undefined)
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
@@ -492,11 +544,11 @@ export class JtagClient {
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processGetDeviceIDCode(_response);
|
||||
return this.processReadStatusReg(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetDeviceIDCode(response: Response): Promise<void> {
|
||||
protected processReadStatusReg(response: Response): Promise<void> {
|
||||
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) {
|
||||
@@ -520,7 +572,7 @@ export class JtagClient {
|
||||
* @param address (optional) 设备地址
|
||||
* @param file (optional)
|
||||
*/
|
||||
uploadBitstream(address: string | undefined, file: FileParameter | null | undefined): Promise<void> {
|
||||
uploadBitstream(address: string | undefined, file: FileParameter | null | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/UploadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
@@ -536,6 +588,7 @@ export class JtagClient {
|
||||
body: content_,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -544,7 +597,147 @@ export class JtagClient {
|
||||
});
|
||||
}
|
||||
|
||||
protected processUploadBitstream(response: Response): Promise<void> {
|
||||
protected processUploadBitstream(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 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
});
|
||||
} 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过Jtag下载比特流文件
|
||||
* @param address (optional) 设备地址
|
||||
* @param port (optional) 设备端口
|
||||
*/
|
||||
downloadBitstream(address: string | undefined, port: number | undefined): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||
if (port === null)
|
||||
throw new Error("The parameter 'port' cannot be null.");
|
||||
else if (port !== undefined)
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processDownloadBitstream(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDownloadBitstream(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 = 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 = Exception.fromJS(resultData500);
|
||||
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<boolean>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class RemoteUpdaterClient {
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传远程更新比特流文件
|
||||
* @param address (optional) 设备地址
|
||||
* @param goldenBitream (optional)
|
||||
* @param bitstream1 (optional)
|
||||
* @param bitstream2 (optional)
|
||||
* @param bitstream3 (optional)
|
||||
* @return 上传结果
|
||||
*/
|
||||
uploadBitstreams(address: string | undefined, goldenBitream: FileParameter | null | undefined, bitstream1: FileParameter | null | undefined, bitstream2: FileParameter | null | undefined, bitstream3: FileParameter | null | undefined): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/RemoteUpdater/UploadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
const content_ = new FormData();
|
||||
if (goldenBitream !== null && goldenBitream !== undefined)
|
||||
content_.append("goldenBitream", goldenBitream.data, goldenBitream.fileName ? goldenBitream.fileName : "goldenBitream");
|
||||
if (bitstream1 !== null && bitstream1 !== undefined)
|
||||
content_.append("bitstream1", bitstream1.data, bitstream1.fileName ? bitstream1.fileName : "bitstream1");
|
||||
if (bitstream2 !== null && bitstream2 !== undefined)
|
||||
content_.append("bitstream2", bitstream2.data, bitstream2.fileName ? bitstream2.fileName : "bitstream2");
|
||||
if (bitstream3 !== null && bitstream3 !== undefined)
|
||||
content_.append("bitstream3", bitstream3.data, bitstream3.fileName ? bitstream3.fileName : "bitstream3");
|
||||
|
||||
let options_: RequestInit = {
|
||||
body: content_,
|
||||
method: "POST",
|
||||
headers: {
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processUploadBitstreams(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processUploadBitstreams(response: Response): Promise<void> {
|
||||
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) {
|
||||
@@ -567,12 +760,13 @@ export class JtagClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过Jtag下载比特流文件
|
||||
* 远程更新单个比特流文件
|
||||
* @param address (optional) 设备地址
|
||||
* @param port (optional) 设备端口
|
||||
* @param bitstreamNum (optional) 比特流位号
|
||||
*/
|
||||
downloadBitstream(address: string | undefined, port: number | undefined): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
|
||||
updateBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/RemoteUpdater/DownloadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
@@ -581,6 +775,10 @@ export class JtagClient {
|
||||
throw new Error("The parameter 'port' cannot be null.");
|
||||
else if (port !== undefined)
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
if (bitstreamNum === null)
|
||||
throw new Error("The parameter 'bitstreamNum' cannot be null.");
|
||||
else if (bitstreamNum !== undefined)
|
||||
url_ += "bitstreamNum=" + encodeURIComponent("" + bitstreamNum) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
@@ -590,11 +788,11 @@ export class JtagClient {
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processDownloadBitstream(_response);
|
||||
return this.processUpdateBitstream(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDownloadBitstream(response: Response): Promise<void> {
|
||||
protected processUpdateBitstream(response: Response): Promise<void> {
|
||||
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) {
|
||||
@@ -619,6 +817,308 @@ export class JtagClient {
|
||||
}
|
||||
return Promise.resolve<void>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载多个比特流文件
|
||||
* @param address (optional) 设备地址
|
||||
* @param port (optional) 设备端口
|
||||
* @param bitstreamNum (optional) 比特流编号
|
||||
* @return 总共上传比特流的数量
|
||||
*/
|
||||
downloadMultiBitstreams(address: string | undefined, port: number | undefined, bitstreamNum: number | null | undefined): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/RemoteUpdater/DownloadMultiBitstreams?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||
if (port === null)
|
||||
throw new Error("The parameter 'port' cannot be null.");
|
||||
else if (port !== undefined)
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
if (bitstreamNum !== undefined && bitstreamNum !== null)
|
||||
url_ += "bitstreamNum=" + encodeURIComponent("" + bitstreamNum) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processDownloadMultiBitstreams(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDownloadMultiBitstreams(response: Response): Promise<void> {
|
||||
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) => {
|
||||
return;
|
||||
});
|
||||
} 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 === 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<void>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 热复位比特流文件
|
||||
* @param address (optional) 设备地址
|
||||
* @param port (optional) 设备端口
|
||||
* @param bitstreamNum (optional) 比特流编号
|
||||
* @return 操作结果
|
||||
*/
|
||||
hotResetBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/RemoteUpdater/HotResetBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||
if (port === null)
|
||||
throw new Error("The parameter 'port' cannot be null.");
|
||||
else if (port !== undefined)
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
if (bitstreamNum === null)
|
||||
throw new Error("The parameter 'bitstreamNum' cannot be null.");
|
||||
else if (bitstreamNum !== undefined)
|
||||
url_ += "bitstreamNum=" + encodeURIComponent("" + bitstreamNum) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processHotResetBitstream(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processHotResetBitstream(response: Response): Promise<void> {
|
||||
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) => {
|
||||
return;
|
||||
});
|
||||
} 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 === 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<void>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class DataClient {
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据库表
|
||||
* @return 插入的记录数
|
||||
*/
|
||||
createTables(): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/api/Data/CreateTable";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processCreateTables(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processCreateTables(response: Response): Promise<FileResponse> {
|
||||
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 }; });
|
||||
} 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 as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据库表
|
||||
* @return 插入的记录数
|
||||
*/
|
||||
dropTables(): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/api/Data/DropTables";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processDropTables(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDropTables(response: Response): Promise<FileResponse> {
|
||||
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 }; });
|
||||
} 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 as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有用户
|
||||
* @return 用户列表
|
||||
*/
|
||||
allUsers(): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/api/Data/AllUsers";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processAllUsers(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processAllUsers(response: Response): Promise<FileResponse> {
|
||||
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 }; });
|
||||
} 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 as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册新用户
|
||||
* @param name (optional) 用户名
|
||||
* @return 操作结果
|
||||
*/
|
||||
signUpUser(name: string | undefined): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/api/Data/SignUpUser?";
|
||||
if (name === null)
|
||||
throw new Error("The parameter 'name' cannot be null.");
|
||||
else if (name !== undefined)
|
||||
url_ += "name=" + encodeURIComponent("" + name) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processSignUpUser(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processSignUpUser(response: Response): Promise<FileResponse> {
|
||||
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 }; });
|
||||
} 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 as any);
|
||||
}
|
||||
}
|
||||
|
||||
/** Package options which to send address to read or write */
|
||||
@@ -687,8 +1187,8 @@ export interface ISendAddrPackOptions {
|
||||
|
||||
/** Package Burst Type */
|
||||
export enum BurstType {
|
||||
ExtendBurst = 0,
|
||||
FixedBurst = 1,
|
||||
FixedBurst = 0,
|
||||
ExtendBurst = 1,
|
||||
}
|
||||
|
||||
/** UDP接受数据包格式 */
|
||||
@@ -755,6 +1255,54 @@ export interface IUDPData {
|
||||
hasRead?: boolean;
|
||||
}
|
||||
|
||||
export class Exception implements IException {
|
||||
message?: string;
|
||||
innerException?: Exception | undefined;
|
||||
source?: string | undefined;
|
||||
stackTrace?: string | undefined;
|
||||
|
||||
constructor(data?: IException) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.message = _data["Message"];
|
||||
this.innerException = _data["InnerException"] ? Exception.fromJS(_data["InnerException"]) : <any>undefined;
|
||||
this.source = _data["Source"];
|
||||
this.stackTrace = _data["StackTrace"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): Exception {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new Exception();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["Message"] = this.message;
|
||||
data["InnerException"] = this.innerException ? this.innerException.toJSON() : <any>undefined;
|
||||
data["Source"] = this.source;
|
||||
data["StackTrace"] = this.stackTrace;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IException {
|
||||
message?: string;
|
||||
innerException?: Exception | undefined;
|
||||
source?: string | undefined;
|
||||
stackTrace?: string | undefined;
|
||||
}
|
||||
|
||||
export class ProblemDetails implements IProblemDetails {
|
||||
type?: string | undefined;
|
||||
title?: string | undefined;
|
||||
@@ -840,6 +1388,13 @@ export interface FileParameter {
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export interface FileResponse {
|
||||
data: Blob;
|
||||
status: number;
|
||||
fileName?: string;
|
||||
headers?: { [name: string]: any };
|
||||
}
|
||||
|
||||
export class ApiException extends Error {
|
||||
message: string;
|
||||
status: number;
|
||||
@@ -869,57 +1424,4 @@ function throwException(message: string, status: number, response: string, heade
|
||||
throw result;
|
||||
else
|
||||
throw new ApiException(message, status, response, headers, null);
|
||||
}
|
||||
|
||||
// 约束通信相关方法
|
||||
export function receiveConstraintUpdates(constraints: Record<string, ConstraintLevel>) {
|
||||
// 批量更新约束状态
|
||||
batchSetConstraintStates(constraints);
|
||||
}
|
||||
|
||||
export function sendConstraintUpdate(constraint: string, level: ConstraintLevel) {
|
||||
// 向后端发送约束状态变化
|
||||
console.log(`发送约束 ${constraint} 状态变化为 ${level}`);
|
||||
|
||||
// TODO: 实际的WebSocket或HTTP请求发送约束变化
|
||||
// 例如:
|
||||
// socket.emit('constraintUpdate', { constraint, level });
|
||||
// 或
|
||||
// fetch('/api/constraints', {
|
||||
// method: 'POST',
|
||||
// body: JSON.stringify({ constraint, level }),
|
||||
// headers: { 'Content-Type': 'application/json' }
|
||||
// });
|
||||
}
|
||||
|
||||
// 初始化约束通信
|
||||
export function initConstraintCommunication() {
|
||||
// 监听服务器发来的约束状态变化
|
||||
// 示例:
|
||||
// socket.on('constraintUpdates', (data) => {
|
||||
// receiveConstraintUpdates(data);
|
||||
// });
|
||||
|
||||
// 模拟接收一些初始约束状态
|
||||
setTimeout(() => {
|
||||
receiveConstraintUpdates({
|
||||
'A1': 'high',
|
||||
'A2': 'low',
|
||||
'A3': 'undefined'
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// 覆盖全局notifyConstraintChange,加入发送逻辑
|
||||
const originalNotifyConstraintChange = notifyConstraintChange;
|
||||
const wrappedNotifyConstraintChange = (constraint: string, level: ConstraintLevel) => {
|
||||
// 调用原始方法更新本地状态
|
||||
originalNotifyConstraintChange(constraint, level);
|
||||
|
||||
// 向后端发送更新
|
||||
sendConstraintUpdate(constraint, level);
|
||||
};
|
||||
|
||||
// 替换全局方法
|
||||
(window as any).__notifyConstraintChange = notifyConstraintChange;
|
||||
(window as any).notifyConstraintChange = wrappedNotifyConstraintChange;
|
||||
}
|
||||
Reference in New Issue
Block a user