add nswag for generate web api
This commit is contained in:
		
							
								
								
									
										14
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										14
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -30,6 +30,7 @@
 | 
			
		||||
        "autoprefixer": "^10.4.20",
 | 
			
		||||
        "daisyui": "^5.0.0",
 | 
			
		||||
        "npm-run-all2": "^7.0.2",
 | 
			
		||||
        "nswag": "^14.3.0",
 | 
			
		||||
        "postcss": "^8.5.3",
 | 
			
		||||
        "tailwindcss": "^4.0.12",
 | 
			
		||||
        "typescript": "~5.7.3",
 | 
			
		||||
@@ -3172,6 +3173,19 @@
 | 
			
		||||
        "url": "https://github.com/sponsors/sindresorhus"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/nswag": {
 | 
			
		||||
      "version": "14.3.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/nswag/-/nswag-14.3.0.tgz",
 | 
			
		||||
      "integrity": "sha512-6/vGw9VtCBn788WFyPLwO4TWxZghDy+KSELjowXt12ZAu/0n3lLfQnJ4ws4rbXrO2Jrv0Tm3uzIfYNatrrs8bQ==",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "bin": {
 | 
			
		||||
        "nswag": "bin/nswag.js"
 | 
			
		||||
      },
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "npm": ">=3.10.8"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/open": {
 | 
			
		||||
      "version": "10.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/open/-/open-10.1.1.tgz",
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,17 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "fpga-weblab",
 | 
			
		||||
  "version": "0.0.0",
 | 
			
		||||
  "version": "0.1.0",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "type": "module",
 | 
			
		||||
  "main": "./server/index.ts",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "dev": "vite",
 | 
			
		||||
    "build": "run-p type-check \"build-only {@}\" --",
 | 
			
		||||
    "preview": "vite preview",
 | 
			
		||||
    "build-only": "vite build",
 | 
			
		||||
    "type-check": "vue-tsc --build",
 | 
			
		||||
    "server": "run --watch ./server/index.ts"
 | 
			
		||||
    "pregen-api": "cd server && dotnet run &",
 | 
			
		||||
    "gen-api": "npx nswag openapi2tsclient /input:http://localhost:5000/swagger/v1/swagger.json /output:src/APIClient.ts",
 | 
			
		||||
    "postgen-api": "pkill server"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@types/lodash": "^4.17.16",
 | 
			
		||||
@@ -35,6 +36,7 @@
 | 
			
		||||
    "autoprefixer": "^10.4.20",
 | 
			
		||||
    "daisyui": "^5.0.0",
 | 
			
		||||
    "npm-run-all2": "^7.0.2",
 | 
			
		||||
    "nswag": "^14.3.0",
 | 
			
		||||
    "postcss": "^8.5.3",
 | 
			
		||||
    "tailwindcss": "^4.0.12",
 | 
			
		||||
    "typescript": "~5.7.3",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										869
									
								
								src/APIClient.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										869
									
								
								src/APIClient.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,869 @@
 | 
			
		||||
//----------------------
 | 
			
		||||
// <auto-generated>
 | 
			
		||||
//     Generated using the NSwag toolchain v14.3.0.0 (NJsonSchema v11.2.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
 | 
			
		||||
// </auto-generated>
 | 
			
		||||
//----------------------
 | 
			
		||||
 | 
			
		||||
/* tslint:disable */
 | 
			
		||||
/* eslint-disable */
 | 
			
		||||
// ReSharper disable InconsistentNaming
 | 
			
		||||
 | 
			
		||||
export class Client {
 | 
			
		||||
    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";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get(): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "GET",
 | 
			
		||||
            headers: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processGet(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processGet(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 !== 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 UDPClient {
 | 
			
		||||
    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";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 页面
 | 
			
		||||
     */
 | 
			
		||||
    index(): Promise<string> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/UDP";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "GET",
 | 
			
		||||
            headers: {
 | 
			
		||||
                "Accept": "application/json"
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processIndex(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processIndex(response: Response): Promise<string> {
 | 
			
		||||
        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 !== 200 && status !== 204) {
 | 
			
		||||
            return response.text().then((_responseText) => {
 | 
			
		||||
            return throwException("An unexpected server error occurred.", status, _responseText, _headers);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        return Promise.resolve<string>(null as any);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 发送字符串
 | 
			
		||||
     * @param address (optional) IPV4 或者 IPV6 地址
 | 
			
		||||
     * @param port (optional) 设备端口号
 | 
			
		||||
     * @param text (optional) 发送的文本
 | 
			
		||||
     * @return 发送成功
 | 
			
		||||
     */
 | 
			
		||||
    sendString(address: string | undefined, port: number | undefined, text: string | undefined): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/UDP/SendString?";
 | 
			
		||||
        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 (text === null)
 | 
			
		||||
            throw new Error("The parameter 'text' cannot be null.");
 | 
			
		||||
        else if (text !== undefined)
 | 
			
		||||
            url_ += "text=" + encodeURIComponent("" + text) + "&";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "POST",
 | 
			
		||||
            headers: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processSendString(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processSendString(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 === 500) {
 | 
			
		||||
            return response.text().then((_responseText) => {
 | 
			
		||||
            return throwException("\u53d1\u9001\u5931\u8d25", 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) IPV4 或者 IPV6 地址
 | 
			
		||||
     * @param port (optional) 设备端口号
 | 
			
		||||
     * @param bytes (optional) 16进制文本
 | 
			
		||||
     */
 | 
			
		||||
    sendBytes(address: string | undefined, port: number | undefined, bytes: string | undefined): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/UDP/SendBytes?";
 | 
			
		||||
        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 (bytes === null)
 | 
			
		||||
            throw new Error("The parameter 'bytes' cannot be null.");
 | 
			
		||||
        else if (bytes !== undefined)
 | 
			
		||||
            url_ += "bytes=" + encodeURIComponent("" + bytes) + "&";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "POST",
 | 
			
		||||
            headers: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processSendBytes(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processSendBytes(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 === 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) IP地址
 | 
			
		||||
     * @param port (optional) UDP 端口号
 | 
			
		||||
     * @param opts 地址包选项
 | 
			
		||||
     */
 | 
			
		||||
    sendAddrPackage(address: string | undefined, port: number | undefined, opts: SendAddrPackOptions): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/UDP/SendAddrPackage?";
 | 
			
		||||
        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(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        const content_ = JSON.stringify(opts);
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            body: content_,
 | 
			
		||||
            method: "POST",
 | 
			
		||||
            headers: {
 | 
			
		||||
                "Content-Type": "application/json",
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processSendAddrPackage(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processSendAddrPackage(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 === 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) IP地址
 | 
			
		||||
     * @param port (optional) UDP 端口号
 | 
			
		||||
     * @param data (optional) 16进制数据
 | 
			
		||||
     */
 | 
			
		||||
    sendDataPackage(address: string | undefined, port: number | undefined, data: string | undefined): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/UDP/SendDataPackage?";
 | 
			
		||||
        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 (data === null)
 | 
			
		||||
            throw new Error("The parameter 'data' cannot be null.");
 | 
			
		||||
        else if (data !== undefined)
 | 
			
		||||
            url_ += "data=" + encodeURIComponent("" + data) + "&";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "POST",
 | 
			
		||||
            headers: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processSendDataPackage(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processSendDataPackage(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 === 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取指定IP地址接受的数据列表
 | 
			
		||||
     * @param address (optional) IP地址
 | 
			
		||||
     */
 | 
			
		||||
    getRecvDataArray(address: string | undefined): Promise<UDPData[]> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/UDP/GetRecvDataArray?";
 | 
			
		||||
        if (address === null)
 | 
			
		||||
            throw new Error("The parameter 'address' cannot be null.");
 | 
			
		||||
        else if (address !== undefined)
 | 
			
		||||
            url_ += "address=" + encodeURIComponent("" + address) + "&";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "GET",
 | 
			
		||||
            headers: {
 | 
			
		||||
                "Accept": "application/json"
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processGetRecvDataArray(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processGetRecvDataArray(response: Response): Promise<UDPData[]> {
 | 
			
		||||
        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);
 | 
			
		||||
            if (Array.isArray(resultData200)) {
 | 
			
		||||
                result200 = [] as any;
 | 
			
		||||
                for (let item of resultData200)
 | 
			
		||||
                    result200!.push(UDPData.fromJS(item));
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                result200 = <any>null;
 | 
			
		||||
            }
 | 
			
		||||
            return result200;
 | 
			
		||||
            });
 | 
			
		||||
        } 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<UDPData[]>(null as any);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class JtagClient {
 | 
			
		||||
    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";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 页面
 | 
			
		||||
     */
 | 
			
		||||
    index(): Promise<string> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/Jtag";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "GET",
 | 
			
		||||
            headers: {
 | 
			
		||||
                "Accept": "application/json"
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processIndex(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processIndex(response: Response): Promise<string> {
 | 
			
		||||
        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 !== 200 && status !== 204) {
 | 
			
		||||
            return response.text().then((_responseText) => {
 | 
			
		||||
            return throwException("An unexpected server error occurred.", status, _responseText, _headers);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        return Promise.resolve<string>(null as any);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 执行一个Jtag命令
 | 
			
		||||
     * @param address (optional) 设备地址
 | 
			
		||||
     * @param port (optional) 设备端口
 | 
			
		||||
     * @param hexDevAddr (optional) 16进制设备目的地址(Jtag)
 | 
			
		||||
     * @param hexCmd (optional) 16进制命令
 | 
			
		||||
     */
 | 
			
		||||
    runCommand(address: string | undefined, port: number | undefined, hexDevAddr: string | undefined, hexCmd: string | undefined): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/Jtag/RunCommand?";
 | 
			
		||||
        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 (hexDevAddr === null)
 | 
			
		||||
            throw new Error("The parameter 'hexDevAddr' cannot be null.");
 | 
			
		||||
        else if (hexDevAddr !== undefined)
 | 
			
		||||
            url_ += "hexDevAddr=" + encodeURIComponent("" + hexDevAddr) + "&";
 | 
			
		||||
        if (hexCmd === null)
 | 
			
		||||
            throw new Error("The parameter 'hexCmd' cannot be null.");
 | 
			
		||||
        else if (hexCmd !== undefined)
 | 
			
		||||
            url_ += "hexCmd=" + encodeURIComponent("" + hexCmd) + "&";
 | 
			
		||||
        url_ = url_.replace(/[?&]$/, "");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            method: "POST",
 | 
			
		||||
            headers: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processRunCommand(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processRunCommand(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 === 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取Jtag ID Code
 | 
			
		||||
     * @param address (optional) 设备地址
 | 
			
		||||
     * @param port (optional) 设备端口
 | 
			
		||||
     */
 | 
			
		||||
    getDeviceIDCode(address: string | undefined, port: number | undefined): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/Jtag/GetDeviceIDCode?";
 | 
			
		||||
        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: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processGetDeviceIDCode(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processGetDeviceIDCode(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 === 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 file (optional) 
 | 
			
		||||
     */
 | 
			
		||||
    uploadBitstream(address: string | undefined, file: FileParameter | null | undefined): Promise<void> {
 | 
			
		||||
        let url_ = this.baseUrl + "/api/Jtag/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 (file !== null && file !== undefined)
 | 
			
		||||
            content_.append("file", file.data, file.fileName ? file.fileName : "file");
 | 
			
		||||
 | 
			
		||||
        let options_: RequestInit = {
 | 
			
		||||
            body: content_,
 | 
			
		||||
            method: "POST",
 | 
			
		||||
            headers: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processUploadBitstream(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processUploadBitstream(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 !== 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 通过Jtag下载比特流文件
 | 
			
		||||
     * @param address (optional) 设备地址
 | 
			
		||||
     * @param port (optional) 设备端口
 | 
			
		||||
     */
 | 
			
		||||
    downloadBitstream(address: string | undefined, port: number | undefined): Promise<void> {
 | 
			
		||||
        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: {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return this.http.fetch(url_, options_).then((_response: Response) => {
 | 
			
		||||
            return this.processDownloadBitstream(_response);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected processDownloadBitstream(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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Package options which to send address to read or write */
 | 
			
		||||
export class SendAddrPackOptions implements ISendAddrPackOptions {
 | 
			
		||||
    /** 突发类型 */
 | 
			
		||||
    burstType?: BurstType;
 | 
			
		||||
    /** 任务ID */
 | 
			
		||||
    commandID?: number;
 | 
			
		||||
    /** 标识写入还是读取 */
 | 
			
		||||
    isWrite?: boolean;
 | 
			
		||||
    /** 突发长度:0是32bits,255是32bits x 256 */
 | 
			
		||||
    burstLength?: number;
 | 
			
		||||
    /** 目标地址 */
 | 
			
		||||
    address?: number;
 | 
			
		||||
 | 
			
		||||
    constructor(data?: ISendAddrPackOptions) {
 | 
			
		||||
        if (data) {
 | 
			
		||||
            for (var property in data) {
 | 
			
		||||
                if (data.hasOwnProperty(property))
 | 
			
		||||
                    (<any>this)[property] = (<any>data)[property];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    init(_data?: any) {
 | 
			
		||||
        if (_data) {
 | 
			
		||||
            this.burstType = _data["burstType"];
 | 
			
		||||
            this.commandID = _data["commandID"];
 | 
			
		||||
            this.isWrite = _data["isWrite"];
 | 
			
		||||
            this.burstLength = _data["burstLength"];
 | 
			
		||||
            this.address = _data["address"];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static fromJS(data: any): SendAddrPackOptions {
 | 
			
		||||
        data = typeof data === 'object' ? data : {};
 | 
			
		||||
        let result = new SendAddrPackOptions();
 | 
			
		||||
        result.init(data);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    toJSON(data?: any) {
 | 
			
		||||
        data = typeof data === 'object' ? data : {};
 | 
			
		||||
        data["burstType"] = this.burstType;
 | 
			
		||||
        data["commandID"] = this.commandID;
 | 
			
		||||
        data["isWrite"] = this.isWrite;
 | 
			
		||||
        data["burstLength"] = this.burstLength;
 | 
			
		||||
        data["address"] = this.address;
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Package options which to send address to read or write */
 | 
			
		||||
export interface ISendAddrPackOptions {
 | 
			
		||||
    /** 突发类型 */
 | 
			
		||||
    burstType?: BurstType;
 | 
			
		||||
    /** 任务ID */
 | 
			
		||||
    commandID?: number;
 | 
			
		||||
    /** 标识写入还是读取 */
 | 
			
		||||
    isWrite?: boolean;
 | 
			
		||||
    /** 突发长度:0是32bits,255是32bits x 256 */
 | 
			
		||||
    burstLength?: number;
 | 
			
		||||
    /** 目标地址 */
 | 
			
		||||
    address?: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Package Burst Type */
 | 
			
		||||
export enum BurstType {
 | 
			
		||||
    ExtendBurst = 0,
 | 
			
		||||
    FixedBurst = 1,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** UDP接受数据包格式 */
 | 
			
		||||
export class UDPData implements IUDPData {
 | 
			
		||||
    /** 接受到的时间 */
 | 
			
		||||
    dateTime?: Date;
 | 
			
		||||
    /** 发送来源的IP地址 */
 | 
			
		||||
    address?: string;
 | 
			
		||||
    /** 发送来源的端口号 */
 | 
			
		||||
    port?: number;
 | 
			
		||||
    /** 接受到的数据 */
 | 
			
		||||
    data?: string;
 | 
			
		||||
    /** 是否被读取过 */
 | 
			
		||||
    hasRead?: boolean;
 | 
			
		||||
 | 
			
		||||
    constructor(data?: IUDPData) {
 | 
			
		||||
        if (data) {
 | 
			
		||||
            for (var property in data) {
 | 
			
		||||
                if (data.hasOwnProperty(property))
 | 
			
		||||
                    (<any>this)[property] = (<any>data)[property];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    init(_data?: any) {
 | 
			
		||||
        if (_data) {
 | 
			
		||||
            this.dateTime = _data["dateTime"] ? new Date(_data["dateTime"].toString()) : <any>undefined;
 | 
			
		||||
            this.address = _data["address"];
 | 
			
		||||
            this.port = _data["port"];
 | 
			
		||||
            this.data = _data["data"];
 | 
			
		||||
            this.hasRead = _data["hasRead"];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static fromJS(data: any): UDPData {
 | 
			
		||||
        data = typeof data === 'object' ? data : {};
 | 
			
		||||
        let result = new UDPData();
 | 
			
		||||
        result.init(data);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    toJSON(data?: any) {
 | 
			
		||||
        data = typeof data === 'object' ? data : {};
 | 
			
		||||
        data["dateTime"] = this.dateTime ? this.dateTime.toISOString() : <any>undefined;
 | 
			
		||||
        data["address"] = this.address;
 | 
			
		||||
        data["port"] = this.port;
 | 
			
		||||
        data["data"] = this.data;
 | 
			
		||||
        data["hasRead"] = this.hasRead;
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** UDP接受数据包格式 */
 | 
			
		||||
export interface IUDPData {
 | 
			
		||||
    /** 接受到的时间 */
 | 
			
		||||
    dateTime?: Date;
 | 
			
		||||
    /** 发送来源的IP地址 */
 | 
			
		||||
    address?: string;
 | 
			
		||||
    /** 发送来源的端口号 */
 | 
			
		||||
    port?: number;
 | 
			
		||||
    /** 接受到的数据 */
 | 
			
		||||
    data?: string;
 | 
			
		||||
    /** 是否被读取过 */
 | 
			
		||||
    hasRead?: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class ProblemDetails implements IProblemDetails {
 | 
			
		||||
    type?: string | undefined;
 | 
			
		||||
    title?: string | undefined;
 | 
			
		||||
    status?: number | undefined;
 | 
			
		||||
    detail?: string | undefined;
 | 
			
		||||
    instance?: string | undefined;
 | 
			
		||||
    extensions?: { [key: string]: any; };
 | 
			
		||||
 | 
			
		||||
    [key: string]: any;
 | 
			
		||||
 | 
			
		||||
    constructor(data?: IProblemDetails) {
 | 
			
		||||
        if (data) {
 | 
			
		||||
            for (var property in data) {
 | 
			
		||||
                if (data.hasOwnProperty(property))
 | 
			
		||||
                    (<any>this)[property] = (<any>data)[property];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    init(_data?: any) {
 | 
			
		||||
        if (_data) {
 | 
			
		||||
            for (var property in _data) {
 | 
			
		||||
                if (_data.hasOwnProperty(property))
 | 
			
		||||
                    this[property] = _data[property];
 | 
			
		||||
            }
 | 
			
		||||
            this.type = _data["type"];
 | 
			
		||||
            this.title = _data["title"];
 | 
			
		||||
            this.status = _data["status"];
 | 
			
		||||
            this.detail = _data["detail"];
 | 
			
		||||
            this.instance = _data["instance"];
 | 
			
		||||
            if (_data["extensions"]) {
 | 
			
		||||
                this.extensions = {} as any;
 | 
			
		||||
                for (let key in _data["extensions"]) {
 | 
			
		||||
                    if (_data["extensions"].hasOwnProperty(key))
 | 
			
		||||
                        (<any>this.extensions)![key] = _data["extensions"][key];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static fromJS(data: any): ProblemDetails {
 | 
			
		||||
        data = typeof data === 'object' ? data : {};
 | 
			
		||||
        let result = new ProblemDetails();
 | 
			
		||||
        result.init(data);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    toJSON(data?: any) {
 | 
			
		||||
        data = typeof data === 'object' ? data : {};
 | 
			
		||||
        for (var property in this) {
 | 
			
		||||
            if (this.hasOwnProperty(property))
 | 
			
		||||
                data[property] = this[property];
 | 
			
		||||
        }
 | 
			
		||||
        data["type"] = this.type;
 | 
			
		||||
        data["title"] = this.title;
 | 
			
		||||
        data["status"] = this.status;
 | 
			
		||||
        data["detail"] = this.detail;
 | 
			
		||||
        data["instance"] = this.instance;
 | 
			
		||||
        if (this.extensions) {
 | 
			
		||||
            data["extensions"] = {};
 | 
			
		||||
            for (let key in this.extensions) {
 | 
			
		||||
                if (this.extensions.hasOwnProperty(key))
 | 
			
		||||
                    (<any>data["extensions"])[key] = (<any>this.extensions)[key];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IProblemDetails {
 | 
			
		||||
    type?: string | undefined;
 | 
			
		||||
    title?: string | undefined;
 | 
			
		||||
    status?: number | undefined;
 | 
			
		||||
    detail?: string | undefined;
 | 
			
		||||
    instance?: string | undefined;
 | 
			
		||||
    extensions?: { [key: string]: any; };
 | 
			
		||||
 | 
			
		||||
    [key: string]: any;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface FileParameter {
 | 
			
		||||
    data: any;
 | 
			
		||||
    fileName: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class ApiException extends Error {
 | 
			
		||||
    message: string;
 | 
			
		||||
    status: number;
 | 
			
		||||
    response: string;
 | 
			
		||||
    headers: { [key: string]: any; };
 | 
			
		||||
    result: any;
 | 
			
		||||
 | 
			
		||||
    constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
 | 
			
		||||
        super();
 | 
			
		||||
 | 
			
		||||
        this.message = message;
 | 
			
		||||
        this.status = status;
 | 
			
		||||
        this.response = response;
 | 
			
		||||
        this.headers = headers;
 | 
			
		||||
        this.result = result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected isApiException = true;
 | 
			
		||||
 | 
			
		||||
    static isApiException(obj: any): obj is ApiException {
 | 
			
		||||
        return obj.isApiException === true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
 | 
			
		||||
    if (result !== null && result !== undefined)
 | 
			
		||||
        throw result;
 | 
			
		||||
    else
 | 
			
		||||
        throw new ApiException(message, status, response, headers, null);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user