UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

1 lines 7.38 kB
{"version":3,"sources":["../../../packages/core/shared/server-inventory/server-inventory-detail-cache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIpD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAE1H;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,WAAW,CAAC,qBAAqB,EAAE,yBAAyB,EAAE,2BAA2B,CAAC;IAU1H,OAAO,CAAC,UAAU;IAT9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2C;IAClE,OAAO,CAAC,MAAM,CAAC,aAAa,CAAK;IAEjC;;;;;OAKG;gBACiB,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB;IAWxE;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAmFjB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAItB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;OAIG;IACH,OAAO,CAAC,aAAa;CAIxB","file":"server-inventory-detail-cache.d.ts","sourcesContent":["import { Observable, zip } from 'rxjs';\r\nimport { map } from 'rxjs/operators';\r\nimport { AppContext } from '../../data/app-context';\r\nimport { Cim } from '../../data/cim';\r\nimport { NodeRequestOptions } from '../../data/node-connection';\r\nimport { PowerShellScripts } from '../../generated/powershell-scripts';\r\nimport { SharedCache, SharedCacheOptions } from '../shared-cache';\r\nimport { ServerInventoryDetail, ServerInventoryDetailData, ServerInventoryDetailParams } from './server-inventory-detail';\r\n\r\n/**\r\n * Server Inventory cache class.\r\n */\r\nexport class ServerInventoryDetailCache extends SharedCache<ServerInventoryDetail, ServerInventoryDetailData, ServerInventoryDetailParams> {\r\n private static uniqueId = '@msft-sme/shell:serverInventoryDetail';\r\n private static uniqueVersion = 1;\r\n\r\n /**\r\n * Initializes a new instance of the ServerInventoryCache class.\r\n *\r\n * @param appContext the app context.\r\n * @param options the option of shared cache.\r\n */\r\n constructor(private appContext: AppContext, options?: SharedCacheOptions) {\r\n super(\r\n ServerInventoryDetailCache.uniqueId,\r\n ServerInventoryDetailCache.uniqueVersion,\r\n (params) => this.dataInstanceId(params),\r\n (instance) => this.dataSerialize(instance),\r\n (serialized) => this.dataDeserialize(serialized),\r\n (params) => this.dataQuery(params),\r\n options);\r\n }\r\n\r\n /**\r\n * Defines how to collect the server inventory data.\r\n *\r\n * @param params the server inventory detail query params.\r\n * @return the Observable of ServerInventoryDetail data.\r\n */\r\n private dataQuery(params: ServerInventoryDetailParams): Observable<ServerInventoryDetail> {\r\n // query parallel...\r\n return zip(\r\n this.appContext.cim.getInstanceMultiple(\r\n params.name,\r\n Cim.namespace.cimV2,\r\n Cim.cimClass.win32Processor,\r\n <NodeRequestOptions>{\r\n ...params.requestOptions,\r\n ...{ powerShell: PowerShellScripts.Get_CimWin32Processor }\r\n }),\r\n this.appContext.cim.getInstanceMultiple(\r\n params.name,\r\n Cim.namespace.cimV2,\r\n Cim.cimClass.win32PhysicalMemory,\r\n <NodeRequestOptions>{\r\n ...params.requestOptions,\r\n ...{ powerShell: PowerShellScripts.Get_CimWin32PhysicalMemory }\r\n }),\r\n this.appContext.cim.getInstanceMultiple(\r\n params.name,\r\n Cim.namespace.cimV2,\r\n Cim.cimClass.win32LogicalDisks,\r\n <NodeRequestOptions>{\r\n ...params.requestOptions,\r\n ...{ powerShell: PowerShellScripts.Get_CimWin32LogicalDisk }\r\n }),\r\n this.appContext.cim.getInstanceMultiple(\r\n params.name,\r\n Cim.namespace.cimV2,\r\n Cim.cimClass.win32NetworkAdapter,\r\n <NodeRequestOptions>{\r\n ...params.requestOptions,\r\n ...{ powerShell: PowerShellScripts.Get_CimWin32NetworkAdapter }\r\n }))\r\n .pipe(\r\n map(([processors, memory, disks, adapters]) => {\r\n const inventory = new ServerInventoryDetail(params.name);\r\n\r\n // Processors\r\n if (processors && processors.value) {\r\n for (const item of processors.value) {\r\n inventory.processors.push(item.properties.name);\r\n }\r\n }\r\n\r\n // Memory\r\n if (memory && memory.value) {\r\n for (const item of memory.value) {\r\n if (item.properties.capacity) {\r\n inventory.totalMemory += item.properties.capacity;\r\n } else {\r\n // cannot get right capacity data. invalidate the value.\r\n inventory.totalMemory = 0;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // DiskSpace\r\n if (disks && disks.value) {\r\n for (const item of disks.value) {\r\n inventory.totalDisk += item.properties.size;\r\n inventory.totalFreeDiskSpace += item.properties.freeSpace;\r\n }\r\n }\r\n\r\n // Network adapters\r\n if (adapters && adapters.value) {\r\n let count = 0;\r\n for (const item of adapters.value) {\r\n if (<boolean>item.properties.physicalAdapter === true) {\r\n count++;\r\n }\r\n }\r\n\r\n inventory.totalPhysicalNics = count;\r\n }\r\n\r\n return inventory;\r\n }));\r\n }\r\n\r\n /**\r\n * Defines how to identify the cache entry by params.\r\n *\r\n * @param params the server inventory query params.\r\n * @return the id string.\r\n */\r\n private dataInstanceId(params: ServerInventoryDetailParams): string {\r\n return params.name;\r\n }\r\n\r\n /**\r\n * Defines how to de-serialize the class object from serialized data.\r\n *\r\n * @param serialized the serialized string;\r\n */\r\n private dataDeserialize(serialized: string): ServerInventoryDetail {\r\n const inventory: ServerInventoryDetailData = JSON.parse(serialized);\r\n return new ServerInventoryDetail(inventory.serverName, inventory);\r\n }\r\n\r\n /**\r\n * Defines how to serialize the class object to serialized data.\r\n *\r\n * @param instance the class instance.\r\n */\r\n private dataSerialize(instance: ServerInventoryDetail): string {\r\n // automatically stripped out class related data.\r\n return JSON.stringify(instance);\r\n }\r\n}\r\n"]}