sconfig.ts 2.6 KB

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