UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

86 lines (84 loc) 3.67 kB
import { map } from 'rxjs/operators'; import { SharedCache } from '../shared-cache'; import { GatewayInstallationType, GatewayInventory, GatewayMode, GatewayOperationalMode } from './gateway-inventory'; /** * Gateway Inventory cache class. */ export class GatewayInventoryCache extends SharedCache { appContext; static uniqueId = '@msft-sme/shell:gatewayInventory'; static uniqueVersion = 6; static gatewayName = 'gateway'; /** * Initializes a new instance of the GatewayInventoryCache class. * * @param appContext the app context. * @param options the option of shared cache. */ constructor(appContext, options) { super(GatewayInventoryCache.uniqueId, GatewayInventoryCache.uniqueVersion, () => this.dataInstanceId(), (instance) => this.dataSerialize(instance), (serialized) => this.dataDeserialize(serialized), () => this.dataQuery(), options); this.appContext = appContext; } /** * Defines how to collect the gateway inventory data. * * @return the Observable of ServerInventory data. */ dataQuery() { return this.appContext.gateway.get('gateway/status') .pipe(map((data) => { const inventory = new GatewayInventory(); if (data) { inventory.availableMemoryMByte = data.availableMemoryMByte; inventory.gatewayWorkingSetMByte = data.gatewayWorkingSetMByte; inventory.totalCpuUtilizationPercent = data.totalCpuUtilizationPercent; inventory.gatewayCpuUtilizationPercent = data.gatewayCpuUtilizationPercent; inventory.gatewayVersion = data.gatewayVersion; inventory.gatewayDisplayVersion = data.gatewayDisplayVersion; inventory.friendlyOsName = data.friendlyOsName; inventory.installedDate = data.installedDate; inventory.logicalProcessorCount = data.logicalProcessorCount; inventory.name = data.name.toLowerCase(); inventory.isGatewayProcessElevated = data.isGatewayProcessElevated; inventory.mode = GatewayMode[data.gatewayMode] || GatewayMode.Desktop; inventory.gatewayOperationalMode = GatewayOperationalMode[data.gatewayOperationalMode] || GatewayOperationalMode.Production; inventory.jwk = JSON.stringify(data.jwk); inventory.installationType = data.installationType || GatewayInstallationType.Standard; inventory.allowedHostOrigins = data.allowedHostOrigins || []; if (MsftSme.isShell()) { inventory.allowedHostOrigins.push(MsftSme.getSafeOrigin()); } } return inventory; })); } /** * Defines how to identify the cache entry by params. * * @return the id string. */ dataInstanceId() { // dont use the passed in name. Gateway cache is always to the same name return GatewayInventoryCache.gatewayName; } /** * Defines how to deserialize the class object from seralized data. * * @param serialized the serialized string; */ dataDeserialize(serialized) { const inventory = JSON.parse(serialized); return new GatewayInventory(inventory); } /** * Defines how to serialize the class object to seralized data. * * @param instance the class instance. */ dataSerialize(instance) { // automatically stripped out class related data. return JSON.stringify(instance); } } //# sourceMappingURL=gateway-inventory-cache.js.map