sconfig.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { DynamicNode} from '@/ua/DynamicNode';
  2. import JSZip from "jszip";
  3. export class ServerConfig {
  4. public manufacturerName: string;
  5. public productName: string;
  6. public softwareVersion: string;
  7. public applicationUri: string;
  8. public productUri: string;
  9. public applicationName: string;
  10. public port: number;
  11. public allowAnonymous: boolean;
  12. public maxConnections: number;
  13. public dynamics?:DynamicNode[]=[];
  14. public nodesets?:string[]=[];
  15. constructor() {
  16. this.manufacturerName = "...";
  17. this.productName = "...";
  18. this.softwareVersion = "...";
  19. this.applicationUri= "...";
  20. this.productUri = "...";
  21. this.applicationName = "...";
  22. this.allowAnonymous = true;
  23. this.port = 4840;
  24. this.maxConnections = 100;
  25. }
  26. addDynamic(dyn:DynamicNode){
  27. this.dynamics?.forEach((dyn)=>{
  28. if(dyn.ident == dyn.ident){
  29. return false;
  30. }
  31. })
  32. this.dynamics?.push(dyn);
  33. return true;
  34. }
  35. removeDynamic(ident:string){
  36. this.dynamics?.forEach((dyn, idx)=>{
  37. if(dyn.ident == ident){
  38. this.dynamics?.splice(idx,1);
  39. return true;
  40. }
  41. })
  42. return false;
  43. }
  44. toPlainObject(){
  45. const obj = {
  46. manufacturerName: this.manufacturerName,
  47. productName: this.productName,
  48. softwareVersion: this.softwareVersion,
  49. applicationUri: this.applicationUri,
  50. productUri: this.productUri,
  51. applicationName: this.applicationName,
  52. port: this.port,
  53. maxConnections: this.maxConnections,
  54. allowAnonymous: this.allowAnonymous,
  55. dynamics: [{}]
  56. }
  57. this.dynamics?.forEach((d)=>{
  58. obj.dynamics.push(d.toPlainObject());
  59. })
  60. return obj;
  61. }
  62. public exportConfig() {
  63. try{
  64. const zip = new JSZip();
  65. zip.file("serverconfig.json", JSON.stringify(this.toPlainObject()));
  66. return zip.generateAsync({type:'blob'});}
  67. catch(err){
  68. console.error(err);
  69. }
  70. }
  71. }
  72. export interface ServerConfigOptions {
  73. manufacturerName: string;
  74. productName: string;
  75. softwareVersion: string;
  76. applicationUri: string;
  77. productUri: string;
  78. applicationName: string;
  79. port: number;
  80. allowAnonymous: boolean;
  81. maxConnections: number;
  82. dynamics:DynamicNode[];
  83. nodesets:string[];
  84. }