@microsoft/windows-admin-center-sdk 2.538.1 → 2.541.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/angular/assets/strings/de-DE/strings.json +1 -1
  2. package/angular/assets/strings/es-ES/strings.json +1 -1
  3. package/angular/assets/strings/it-IT/strings.json +1 -1
  4. package/angular/assets/strings/ko-KR/strings.json +1 -1
  5. package/angular/assets/strings/nl-NL/strings.json +1 -1
  6. package/angular/assets/strings/pt-PT/strings.json +1 -1
  7. package/angular/assets/strings/tr-TR/strings.json +1 -1
  8. package/angular/assets/strings/zh-CN/strings.json +1 -1
  9. package/angular/assets/strings/zh-TW/strings.json +1 -1
  10. package/angular/bundles/microsoft-windows-admin-center-sdk-angular.umd.js +172 -112
  11. package/angular/bundles/microsoft-windows-admin-center-sdk-angular.umd.js.map +1 -1
  12. package/angular/bundles/microsoft-windows-admin-center-sdk-angular.umd.min.js +1 -1
  13. package/angular/bundles/microsoft-windows-admin-center-sdk-angular.umd.min.js.map +1 -1
  14. package/angular/esm2015/src/controls/header/header.component.js +3 -1
  15. package/angular/esm2015/src/controls/header/index.js +2 -2
  16. package/angular/esm2015/src/controls/page-alert-bar/models/page-alert.js +2 -1
  17. package/angular/esm2015/src/controls/page-alert-bar/page-alert-bar.component.js +11 -3
  18. package/angular/esm2015/src/controls/property-grid/property-grid.component.js +2 -2
  19. package/angular/esm2015/src/controls/wizard/wizard-builder.js +13 -1
  20. package/angular/esm2015/src/controls/wizard/wizard.component.js +126 -109
  21. package/angular/esm2015/src/controls/wizard/wizard.module.js +12 -7
  22. package/angular/fesm2015/microsoft-windows-admin-center-sdk-angular.js +156 -113
  23. package/angular/fesm2015/microsoft-windows-admin-center-sdk-angular.js.map +1 -1
  24. package/angular/src/controls/header/header.component.d.ts +7 -0
  25. package/angular/src/controls/header/index.d.ts +1 -1
  26. package/angular/src/controls/page-alert-bar/models/page-alert.d.ts +2 -1
  27. package/angular/src/controls/page-alert-bar/page-alert-bar.component.d.ts +1 -0
  28. package/angular/src/controls/wizard/wizard-builder.d.ts +13 -0
  29. package/angular/src/controls/wizard/wizard.component.d.ts +5 -0
  30. package/angular/src/controls/wizard/wizard.module.d.ts +10 -9
  31. package/core/data/active-directory/active-directory.js +2 -2
  32. package/core/data/active-directory/active-directory.js.map +1 -1
  33. package/core/data/powershell.d.ts +2 -2
  34. package/core/data/powershell.js +2 -2
  35. package/core/data/powershell.js.map +1 -1
  36. package/core/notification/notification-manager.d.ts +0 -18
  37. package/core/notification/notification-manager.js +10 -55
  38. package/core/notification/notification-manager.js.map +1 -1
  39. package/core/notification/notification.d.ts +1 -10
  40. package/core/notification/notification.js +33 -30
  41. package/core/notification/notification.js.map +1 -1
  42. package/core/notification/powershell-notification.d.ts +15 -15
  43. package/core/notification/powershell-notification.js +8 -19
  44. package/core/notification/powershell-notification.js.map +1 -1
  45. package/core/notification/socket-signalr.d.ts +14 -8
  46. package/core/notification/socket-signalr.js +19 -18
  47. package/core/notification/socket-signalr.js.map +1 -1
  48. package/core/notification/work-item-manager.d.ts +0 -4
  49. package/core/notification/work-item-manager.js +20 -76
  50. package/core/notification/work-item-manager.js.map +1 -1
  51. package/package.json +5 -2
  52. package/styles/css/main-v2.css +1 -1
  53. package/tools/wac-cli/src/create/main.js +0 -1
  54. package/tools/wac-cli/src/create/main.js.map +1 -1
  55. package/tools/wac-cli/templates/internal/package.json +4 -0
  56. package/tools/wac-cli/templates/library/angular.json +3 -0
  57. package/tools/wac-cli/templates/wac-template/angular.json +3 -0
  58. package/tools/wac-cli/templates/wac-template/package.json +4 -0
  59. package/tools/wac-cli/templates/wac-template/src/app/default/default.component.spec.ts +2 -3
  60. package/core/notification/notification-message.d.ts +0 -41
  61. package/core/notification/notification-message.js +0 -3
  62. package/core/notification/notification-message.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../packages/core/notification/powershell-notification.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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,IAAI,CAAC;QACzD,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC;;AAtQc,oCAAa,GAAG,oBAAoB,CAAC;AACrC,6BAAM,GAAG,QAAQ,CAAC;AAClB,gCAAS,GAAG,WAAW,CAAC","file":"powershell-notification.js","sourcesContent":["import { Observable, of, Subject } from 'rxjs';\r\nimport { AjaxError } from 'rxjs/ajax';\r\nimport { catchError, map } from 'rxjs/operators';\r\nimport { Net } from '../data/net';\r\nimport { NodeConnection, NodeRequestOptions } from '../data/node-connection';\r\nimport { PowerShellCommand } from '../data/powershell';\r\nimport { LogLevel } from '../diagnostics/log-level';\r\nimport { Logging } from '../diagnostics/logging';\r\nimport { SmeWebTelemetry } from '../diagnostics/sme-web-telemetry';\r\nimport { TelemetryEventStates } from '../diagnostics/sme-web-telemetry-models';\r\nimport { Strings } from '../generated/strings';\r\nimport { NotificationMessage } from './notification-message';\r\nimport { NotificationState } from './notification-state';\r\nimport { SocketMessage, SocketMessageFlags, SocketSignalR } from './socket-signalr';\r\nimport { WorkItemResult } from './work-item-request';\r\n\r\n/**\r\n * PowerShell Submit result object.\r\n */\r\nexport interface PowerShellSubmitResult {\r\n id: string;\r\n completed: boolean;\r\n error: any;\r\n state: NotificationState;\r\n}\r\n\r\n/**\r\n * Powershell work item message.\r\n */\r\nexport interface PowerShellWorkItemMessage {\r\n sessionId?: string;\r\n completed?: string; // True, False\r\n results?: any[];\r\n progress?: any[];\r\n errors?: any[];\r\n exception?: string;\r\n}\r\n\r\n/**\r\n * The PowerShell script based notification class.\r\n */\r\nexport class PowerShellNotification extends SocketSignalR<PowerShellWorkItemMessage | NotificationMessage> {\r\n private static connectionUrl = '/api/notifications';\r\n private static notify = 'Notify';\r\n private static subscribe = 'Subscribe';\r\n private subjectInternal: Subject<SocketMessage<PowerShellWorkItemMessage | NotificationMessage>>;\r\n\r\n /* tslint:disable:no-bitwise */\r\n public static hasConnectionError(item: SocketMessage<PowerShellWorkItemMessage | NotificationMessage>): boolean {\r\n return (item.type & SocketMessageFlags.ConnectionError) === SocketMessageFlags.ConnectionError;\r\n }\r\n\r\n public static hasError(item: SocketMessage<PowerShellWorkItemMessage | NotificationMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Error) === SocketMessageFlags.Error;\r\n }\r\n\r\n public static hasException(item: SocketMessage<PowerShellWorkItemMessage | NotificationMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Exception) === SocketMessageFlags.Exception;\r\n }\r\n\r\n public static hasCompleted(item: SocketMessage<PowerShellWorkItemMessage| NotificationMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Completed) === SocketMessageFlags.Completed;\r\n }\r\n\r\n public static hasData(item: SocketMessage<PowerShellWorkItemMessage| NotificationMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Data) === SocketMessageFlags.Data;\r\n }\r\n\r\n public static hasProgress(item: SocketMessage<PowerShellWorkItemMessage | NotificationMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Progress) === SocketMessageFlags.Progress;\r\n }\r\n\r\n /* tslint:enable:no-bitwise */\r\n\r\n /**\r\n * Initializes a new instance of the GatewaySocket class.\r\n */\r\n constructor(gatewayUrl: string) {\r\n super(gatewayUrl, PowerShellNotification.connectionUrl);\r\n }\r\n\r\n /**\r\n * Gets the subject observable to get notifications.\r\n */\r\n public get subject(): Observable<SocketMessage<PowerShellWorkItemMessage | NotificationMessage>> {\r\n return this.subjectInternal.asObservable();\r\n }\r\n\r\n /**\r\n * Submit PowerShell command as a work item.\r\n *\r\n * @param nodeConnection The node connection.\r\n * @param command The PowerShell command.\r\n * @param metadata The meta data.\r\n * @param nodeRequestOptions The node request options.\r\n * @param create The callback to create new notification.\r\n * @return Observable the observable of initial powershell query result.\r\n */\r\n public submit(\r\n nodeConnection: NodeConnection,\r\n nodeName: string,\r\n command: PowerShellCommand,\r\n metadata: any,\r\n nodeRequestOptions?: NodeRequestOptions,\r\n create?: (result: PowerShellSubmitResult) => void): Observable<WorkItemResult> {\r\n // For a non-powershell long running task (eg: azure site recovery setup):\r\n // The 'command' parameter is null.\r\n // The metadata.id is the workitem id generated by a gateway api.\r\n if (!command && metadata.id) {\r\n const result = <PowerShellSubmitResult>{\r\n id: metadata.id,\r\n completed: false,\r\n error: null,\r\n state: NotificationState.Started\r\n };\r\n if (create) {\r\n create(result);\r\n }\r\n\r\n this.subscribeSession(metadata.id);\r\n return of(<WorkItemResult>{ id: metadata.id, state: NotificationState.Started, error: null });\r\n }\r\n\r\n const data: any = Net.createPropertiesJSONString({\r\n ...command,\r\n useInProcRunspace: nodeRequestOptions.useInProcRunspace,\r\n ...{ metadata: metadata } });\r\n return nodeConnection.post(nodeName, Net.powerShellApiInvokeCommand, data, nodeRequestOptions)\r\n .pipe(\r\n catchError((error: AjaxError, obj) => {\r\n SmeWebTelemetry.tracePowershellEvent(command, TelemetryEventStates.Error,\r\n {response: error.response});\r\n\r\n const result = <PowerShellSubmitResult>{\r\n id: MsftSme.newGuid(),\r\n completed: true,\r\n error: { message: Net.getErrorMessage(error) },\r\n state: NotificationState.Error\r\n };\r\n if (create) {\r\n create(result);\r\n }\r\n\r\n return of(<WorkItemResult>{ id: result.id, state: result.state, error: result.error });\r\n }),\r\n map((response: any) => {\r\n const completed = response.completed === 'True';\r\n\r\n if (response.id) {\r\n // sending back the client for the error.\r\n return <WorkItemResult>response;\r\n }\r\n\r\n let error: any = null;\r\n if (response.errors && response.errors.length > 0) {\r\n const errorObj: any = MsftSme.first(response.errors);\r\n error = { message: errorObj.message };\r\n\r\n SmeWebTelemetry.tracePowershellEvent(command,\r\n TelemetryEventStates.Error,\r\n {response: response});\r\n }\r\n\r\n const result = <PowerShellSubmitResult>{\r\n id: response.sessionId,\r\n completed: completed,\r\n error: error,\r\n state: completed ?\r\n (response.errors ? NotificationState.Error : NotificationState.Success)\r\n : NotificationState.Started\r\n };\r\n\r\n if (result.state === NotificationState.Success) {\r\n result.error = response.results[0];\r\n }\r\n\r\n if (create) {\r\n create(result);\r\n }\r\n\r\n if (!result.completed) {\r\n this.subscribeSession(response.sessionId);\r\n\r\n // store ID here to correlate command with the gateway notification later\r\n const powershellCommandId = response.id ? response.id : response.sessionId;\r\n SmeWebTelemetry.addPowershellId(powershellCommandId, command);\r\n }\r\n\r\n this.processPowerShellData(response);\r\n\r\n // sending back the client.\r\n const workItemResult = <WorkItemResult>{ id: result.id, state: result.state, error: error };\r\n\r\n // passing in the results as object of the workItemResult\r\n if (response.results) {\r\n workItemResult.object = response.results;\r\n }\r\n\r\n return workItemResult;\r\n }));\r\n }\r\n\r\n /**\r\n * Initialize to subscribe the web socket connection.\r\n */\r\n public initialize(): Promise<any> {\r\n if (this.subjectInternal) {\r\n this.subjectInternal.complete();\r\n }\r\n\r\n this.subjectInternal = new Subject<SocketMessage<PowerShellWorkItemMessage | NotificationMessage>>();\r\n this.subscribe(PowerShellNotification.notify);\r\n return this.start();\r\n }\r\n\r\n /**\r\n * Uninitialize to subscribe the web socket connection.\r\n */\r\n public uninitialize(): void {\r\n if (this.subjectInternal) {\r\n this.subjectInternal.complete();\r\n this.subjectInternal = null;\r\n }\r\n\r\n this.unsubscribe(PowerShellNotification.notify);\r\n this.stop();\r\n }\r\n\r\n /**\r\n * Invoke subscribe method to a session.\r\n *\r\n * @param id the session ID of work item.\r\n * @return Promise the promise object.\r\n */\r\n public subscribeSession(id: string): Promise<PowerShellWorkItemMessage | NotificationMessage> {\r\n return this.invoke(PowerShellNotification.subscribe, id);\r\n }\r\n\r\n /**\r\n * The client handler to process message.\r\n *\r\n * @param notification the message notification.\r\n */\r\n protected clientHandler(notification: SocketMessage<PowerShellWorkItemMessage | NotificationMessage>): void {\r\n this.subjectInternal.next(notification);\r\n }\r\n\r\n /**\r\n * Process the message.\r\n *\r\n * @param messages the messages.\r\n */\r\n protected processMessage(message: string): void {\r\n if (!message) {\r\n const message2 = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationEmptyMessage.message;\r\n Logging.log({ source: 'socket', level: LogLevel.Warning, message: message2 });\r\n return;\r\n }\r\n\r\n const data: any = JSON.parse(message);\r\n if (data.sessionId) {\r\n // PowerShell work item.\r\n this.processPowerShellData(data);\r\n return;\r\n }\r\n\r\n if (data.id) {\r\n // Notification message.\r\n this.processMessageData(data);\r\n return;\r\n }\r\n }\r\n\r\n private processPowerShellData(data: PowerShellWorkItemMessage): void {\r\n /* tslint:disable:no-bitwise */\r\n let type: SocketMessageFlags = SocketMessageFlags.None;\r\n if (data.results && data.results.length > 0) {\r\n type |= SocketMessageFlags.Data;\r\n }\r\n\r\n if (data.progress && data.progress.length > 0) {\r\n type |= SocketMessageFlags.Progress;\r\n }\r\n\r\n if (data.errors && data.errors.length > 0) {\r\n type |= SocketMessageFlags.Error;\r\n }\r\n\r\n if (data.exception) {\r\n type |= SocketMessageFlags.Exception;\r\n }\r\n\r\n if (data.completed === 'True') {\r\n type |= SocketMessageFlags.Completed;\r\n }\r\n\r\n /* tslint:enable:no-bitwise */\r\n\r\n this.clientHandler({ type: type, message: data });\r\n }\r\n\r\n private processMessageData(message: NotificationMessage): void {\r\n const type: SocketMessageFlags = SocketMessageFlags.Data;\r\n this.clientHandler({ type, message });\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../../packages/core/notification/powershell-notification.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE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AAC,IAAI,CAAC;SACnC;QAED,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3C,IAAI,IAAI,kBAAkB,CAAC,QAAQ,CAAC;SACvC;QAED,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,IAAI,IAAI,kBAAkB,CAAC,KAAK,CAAC;SACpC;QAED,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,IAAI,IAAI,kBAAkB,CAAC,SAAS,CAAC;SACxC;QAED,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE;YAC3B,IAAI,IAAI,kBAAkB,CAAC,SAAS,CAAC;SACxC;QAED,8BAA8B;QAE9B,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;;AAxPc,oCAAa,GAAG,oBAAoB,CAAC;AACrC,gCAAS,GAAG,iBAAiB,CAAC;AAC9B,6BAAM,GAAG,QAAQ,CAAC;AAClB,gCAAS,GAAG,WAAW,CAAC","file":"powershell-notification.js","sourcesContent":["/// <reference types='jquery' />\r\n\r\nimport { Observable, of, Subject } from 'rxjs';\r\nimport { AjaxError } from 'rxjs/ajax';\r\nimport { catchError, map } from 'rxjs/operators';\r\nimport { Net } from '../data/net';\r\nimport { NodeConnection, NodeRequestOptions } from '../data/node-connection';\r\nimport { PowerShellCommand } from '../data/powershell';\r\nimport { LogLevel } from '../diagnostics/log-level';\r\nimport { Logging } from '../diagnostics/logging';\r\nimport { SmeWebTelemetry } from '../diagnostics/sme-web-telemetry';\r\nimport { TelemetryEventStates } from '../diagnostics/sme-web-telemetry-models';\r\nimport { Strings } from '../generated/strings';\r\nimport { NotificationState } from './notification-state';\r\nimport { SocketMessage, SocketMessageFlags, SocketSignalR } from './socket-signalr';\r\nimport { WorkItemResult } from './work-item-request';\r\n\r\n/**\r\n * PowerShell Submit result object.\r\n */\r\nexport interface PowerShellSubmitResult {\r\n id: string;\r\n completed: boolean;\r\n error: any;\r\n state: NotificationState;\r\n}\r\n\r\n/**\r\n * Powershell work item message.\r\n */\r\nexport interface PowerShellWorkItemMessage {\r\n sessionId?: string;\r\n completed?: string; // True, False\r\n results?: any[];\r\n progress?: any[];\r\n errors?: any[];\r\n exception?: string;\r\n}\r\n\r\n/**\r\n * The PowerShell script based notification class.\r\n */\r\nexport class PowerShellNotification extends SocketSignalR<PowerShellWorkItemMessage> {\r\n private static connectionUrl = '/api/notifications';\r\n private static proxyName = 'notificationHub';\r\n private static notify = 'notify';\r\n private static subscribe = 'Subscribe';\r\n private subjectInternal: Subject<SocketMessage<PowerShellWorkItemMessage>>;\r\n\r\n /* tslint:disable:no-bitwise */\r\n public static hasConnectionError(item: SocketMessage<PowerShellWorkItemMessage>): boolean {\r\n return (item.type & SocketMessageFlags.ConnectionError) === SocketMessageFlags.ConnectionError;\r\n }\r\n\r\n public static hasError(item: SocketMessage<PowerShellWorkItemMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Error) === SocketMessageFlags.Error;\r\n }\r\n\r\n public static hasException(item: SocketMessage<PowerShellWorkItemMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Exception) === SocketMessageFlags.Exception;\r\n }\r\n\r\n public static hasCompleted(item: SocketMessage<PowerShellWorkItemMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Completed) === SocketMessageFlags.Completed;\r\n }\r\n\r\n public static hasData(item: SocketMessage<PowerShellWorkItemMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Data) === SocketMessageFlags.Data;\r\n }\r\n\r\n public static hasProgress(item: SocketMessage<PowerShellWorkItemMessage>): boolean {\r\n return (item.type & SocketMessageFlags.Progress) === SocketMessageFlags.Progress;\r\n }\r\n\r\n /* tslint:enable:no-bitwise */\r\n\r\n /**\r\n * Initializes a new instance of the GatewaySocket class.\r\n */\r\n constructor(gatewayUrl: string) {\r\n super(gatewayUrl, PowerShellNotification.connectionUrl, PowerShellNotification.proxyName);\r\n }\r\n\r\n /**\r\n * Gets the subject observable to get notifications.\r\n */\r\n public get subject(): Subject<SocketMessage<PowerShellWorkItemMessage>> {\r\n return this.subjectInternal;\r\n }\r\n\r\n /**\r\n * Submit PowerShell command as a work item.\r\n *\r\n * @param nodeConnection The node connection.\r\n * @param command The PowerShell command.\r\n * @param metadata The meta data.\r\n * @param nodeRequestOptions The node request options.\r\n * @param create The callback to create new notification.\r\n * @return Observable the observable of initial powershell query result.\r\n */\r\n public submit(\r\n nodeConnection: NodeConnection,\r\n nodeName: string,\r\n command: PowerShellCommand,\r\n metadata: any,\r\n nodeRequestOptions?: NodeRequestOptions,\r\n create?: (result: PowerShellSubmitResult) => void): Observable<WorkItemResult> {\r\n // For a non-powershell long running task (eg: azure site recovery setup):\r\n // The 'command' parameter is null.\r\n // The metadata.id is the workitem id generated by a gateway api.\r\n if (!command && metadata.id) {\r\n const result = <PowerShellSubmitResult>{\r\n id: metadata.id,\r\n completed: false,\r\n error: null,\r\n state: NotificationState.Started\r\n };\r\n if (create) {\r\n create(result);\r\n }\r\n\r\n this.subscribeSession(metadata.id);\r\n return of(<WorkItemResult>{ id: metadata.id, state: NotificationState.Started, error: null });\r\n }\r\n\r\n const data: any = Net.createPropertiesJSONString({\r\n ...command,\r\n useInProcRunspace: nodeRequestOptions.useInProcRunspace,\r\n ...{ metadata: metadata } });\r\n return nodeConnection.post(nodeName, Net.powerShellApiInvokeCommand, data, nodeRequestOptions)\r\n .pipe(\r\n catchError((error: AjaxError, obj) => {\r\n SmeWebTelemetry.tracePowershellEvent(command, TelemetryEventStates.Error,\r\n {response: error.response});\r\n\r\n const result = <PowerShellSubmitResult>{\r\n id: MsftSme.newGuid(),\r\n completed: true,\r\n error: { message: Net.getErrorMessage(error) },\r\n state: NotificationState.Error\r\n };\r\n if (create) {\r\n create(result);\r\n }\r\n\r\n return of(<WorkItemResult>{ id: result.id, state: result.state, error: result.error });\r\n }),\r\n map((response: any) => {\r\n const completed = response.completed === 'True';\r\n\r\n if (response.id) {\r\n // sending back the client for the error.\r\n return <WorkItemResult>response;\r\n }\r\n\r\n let error: any = null;\r\n if (response.errors && response.errors.length > 0) {\r\n const errorObj: any = MsftSme.first(response.errors);\r\n error = { message: errorObj.message };\r\n\r\n SmeWebTelemetry.tracePowershellEvent(command,\r\n TelemetryEventStates.Error,\r\n {response: response});\r\n }\r\n\r\n const result = <PowerShellSubmitResult>{\r\n id: response.sessionId,\r\n completed: completed,\r\n error: error,\r\n state: completed ?\r\n (response.errors ? NotificationState.Error : NotificationState.Success)\r\n : NotificationState.Started\r\n };\r\n\r\n if (result.state === NotificationState.Success) {\r\n result.error = response.results[0];\r\n }\r\n\r\n if (create) {\r\n create(result);\r\n }\r\n\r\n if (!result.completed) {\r\n this.subscribeSession(response.sessionId);\r\n\r\n // store ID here to correlate command with the gateway notification later\r\n const powershellCommandId = response.id ? response.id : response.sessionId;\r\n SmeWebTelemetry.addPowershellId(powershellCommandId, command);\r\n }\r\n\r\n this.processData(response);\r\n\r\n // sending back the client.\r\n const workItemResult = <WorkItemResult>{ id: result.id, state: result.state, error: error };\r\n\r\n // passing in the results as object of the workItemResult\r\n if (response.results) {\r\n workItemResult.object = response.results;\r\n }\r\n\r\n return workItemResult;\r\n }));\r\n }\r\n\r\n /**\r\n * Initialize to subscribe the web socket connection.\r\n */\r\n public initialize(): JQueryPromise<any> {\r\n if (this.subjectInternal) {\r\n this.subjectInternal.complete();\r\n }\r\n\r\n this.subjectInternal = new Subject<SocketMessage<PowerShellWorkItemMessage>>();\r\n this.subscribe(PowerShellNotification.notify);\r\n return this.start();\r\n }\r\n\r\n /**\r\n * Uninitialize to subscribe the web socket connection.\r\n */\r\n public uninitialize(): void {\r\n if (this.subjectInternal) {\r\n this.subjectInternal.complete();\r\n this.subjectInternal = null;\r\n }\r\n\r\n this.unsubscribe(PowerShellNotification.notify);\r\n this.stop();\r\n }\r\n\r\n /**\r\n * Invoke subscribe method to a session.\r\n *\r\n * @param id the session ID of work item.\r\n * @return Promise the promise object.\r\n */\r\n public subscribeSession(id: string): JQueryPromise<any> {\r\n return this.invoke(PowerShellNotification.subscribe, id);\r\n }\r\n\r\n /**\r\n * The client handler to process message.\r\n *\r\n * @param notification the message notification.\r\n */\r\n protected clientHandler(notification: SocketMessage<PowerShellWorkItemMessage>): void {\r\n this.subjectInternal.next(notification);\r\n }\r\n\r\n /**\r\n * Process the message.\r\n *\r\n * @param messages the messages.\r\n */\r\n protected processMessage(message: string): void {\r\n if (!message) {\r\n const message2 = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationEmptyMessage.message;\r\n Logging.log({ source: 'socket', level: LogLevel.Warning, message: message2 });\r\n return;\r\n }\r\n\r\n const data: any = JSON.parse(message);\r\n this.processData(data);\r\n }\r\n\r\n private processData(data: any): void {\r\n /* tslint:disable:no-bitwise */\r\n let type: SocketMessageFlags = SocketMessageFlags.None;\r\n if (data.results && data.results.length > 0) {\r\n type |= SocketMessageFlags.Data;\r\n }\r\n\r\n if (data.progress && data.progress.length > 0) {\r\n type |= SocketMessageFlags.Progress;\r\n }\r\n\r\n if (data.errors && data.errors.length > 0) {\r\n type |= SocketMessageFlags.Error;\r\n }\r\n\r\n if (data.exception) {\r\n type |= SocketMessageFlags.Exception;\r\n }\r\n\r\n if (data.completed === 'True') {\r\n type |= SocketMessageFlags.Completed;\r\n }\r\n\r\n /* tslint:enable:no-bitwise */\r\n\r\n this.clientHandler({ type: type, message: data });\r\n }\r\n}\r\n"]}
@@ -1,4 +1,5 @@
1
- import { HttpError } from '@microsoft/signalr';
1
+ /// <reference types="signalr" />
2
+ /// <reference types="jquery" />
2
3
  /**
3
4
  * Socket message flags. These can be combined.
4
5
  */
@@ -16,7 +17,7 @@ export declare enum SocketMessageFlags {
16
17
  */
17
18
  export interface SocketMessage<T> {
18
19
  type: SocketMessageFlags;
19
- connectionError?: HttpError;
20
+ connectionError?: SignalR.ConnectionError;
20
21
  message: T;
21
22
  }
22
23
  /**
@@ -25,7 +26,9 @@ export interface SocketMessage<T> {
25
26
  export declare abstract class SocketSignalR<T> {
26
27
  private gatewayUrl;
27
28
  private connectionUrl;
29
+ private proxyName;
28
30
  private connection;
31
+ private proxy;
29
32
  private started;
30
33
  private lastError;
31
34
  private processHandler;
@@ -36,13 +39,14 @@ export declare abstract class SocketSignalR<T> {
36
39
  /**
37
40
  * Instantiates a new instance of the SocketSignalR class.
38
41
  */
39
- constructor(gatewayUrl: string, connectionUrl: string);
42
+ constructor(gatewayUrl: string, connectionUrl: string, proxyName: string);
40
43
  /**
41
44
  * Subscribe to the proxy with method name and handler.
42
45
  *
43
46
  * @param name the name of subscription for a method.
47
+ * @return SignalR.Hub.Proxy the proxy.
44
48
  */
45
- subscribe(name: string): void;
49
+ subscribe(name: string): SignalR.Hub.Proxy;
46
50
  /**
47
51
  * Unsubscribe to the subscribed method call.
48
52
  *
@@ -52,11 +56,11 @@ export declare abstract class SocketSignalR<T> {
52
56
  /**
53
57
  * Start request connection.
54
58
  */
55
- start(): Promise<any>;
59
+ start(): JQueryPromise<any>;
56
60
  /**
57
61
  * Stop request connection.
58
62
  */
59
- stop(): void;
63
+ stop(): SignalR.Connection;
60
64
  /**
61
65
  * Invoke a method with parameters.
62
66
  *
@@ -64,7 +68,7 @@ export declare abstract class SocketSignalR<T> {
64
68
  * @param args the parameters to pass.
65
69
  * @return Promise the promise object.
66
70
  */
67
- invoke(name: string, ...args: any[]): Promise<T>;
71
+ invoke(name: string, ...args: any[]): JQueryPromise<any>;
68
72
  /**
69
73
  * The client handler.
70
74
  */
@@ -76,7 +80,9 @@ export declare abstract class SocketSignalR<T> {
76
80
  */
77
81
  protected abstract processMessage(message: string): void;
78
82
  /**
79
- * Initiate the connection to gateway.
83
+ * Initiate the connection to gateway and create a proxy.
84
+ *
85
+ * @param proxyName the proxy name.
80
86
  */
81
87
  private init;
82
88
  /**
@@ -1,4 +1,4 @@
1
- import { HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr';
1
+ /// <reference types='signalr' />
2
2
  /**
3
3
  * Socket message flags. These can be combined.
4
4
  */
@@ -19,9 +19,10 @@ export class SocketSignalR {
19
19
  /**
20
20
  * Instantiates a new instance of the SocketSignalR class.
21
21
  */
22
- constructor(gatewayUrl, connectionUrl) {
22
+ constructor(gatewayUrl, connectionUrl, proxyName) {
23
23
  this.gatewayUrl = gatewayUrl;
24
24
  this.connectionUrl = connectionUrl;
25
+ this.proxyName = proxyName;
25
26
  this.started = false;
26
27
  this.processHandler = (message) => this.processMessage(message);
27
28
  gatewayUrl = gatewayUrl ? gatewayUrl : '';
@@ -36,14 +37,15 @@ export class SocketSignalR {
36
37
  * Subscribe to the proxy with method name and handler.
37
38
  *
38
39
  * @param name the name of subscription for a method.
40
+ * @return SignalR.Hub.Proxy the proxy.
39
41
  */
40
42
  subscribe(name) {
41
- this.init();
43
+ this.init(this.proxyName);
42
44
  if (this.lastError) {
43
45
  // send last error;
44
46
  this.clientHandler({ type: SocketMessageFlags.Error, connectionError: this.lastError, message: null });
45
47
  }
46
- this.connection.on(name, this.processHandler);
48
+ return this.proxy.on(name, this.processHandler);
47
49
  }
48
50
  /**
49
51
  * Unsubscribe to the subscribed method call.
@@ -51,7 +53,7 @@ export class SocketSignalR {
51
53
  * @param name the name of subscription for a method.
52
54
  */
53
55
  unsubscribe(name) {
54
- this.connection.off(name, this.processHandler);
56
+ this.proxy.off(name, this.processHandler);
55
57
  }
56
58
  /**
57
59
  * Start request connection.
@@ -64,7 +66,7 @@ export class SocketSignalR {
64
66
  */
65
67
  stop() {
66
68
  this.started = false;
67
- this.connection.stop();
69
+ return this.connection.stop(true);
68
70
  }
69
71
  /**
70
72
  * Invoke a method with parameters.
@@ -77,22 +79,21 @@ export class SocketSignalR {
77
79
  if (!this.started) {
78
80
  throw new Error('request socket has not been started.');
79
81
  }
80
- if (this.connection.state === HubConnectionState.Disconnected) {
81
- return this.start().then(() => this.connection.invoke(name, ...args));
82
- }
83
- try {
84
- return this.connection.invoke(name, ...args);
85
- }
86
- catch (error) {
87
- this.errorMessage(error);
88
- return Promise.reject(error);
82
+ if (this.connection.state === 4 /* SignalR.ConnectionState.Disconnected: @types/signalr doesn't take conversion properly */) {
83
+ return this.start().then(() => this.proxy.invoke(name, ...args));
89
84
  }
85
+ return this.proxy.invoke(name, ...args);
90
86
  }
91
87
  /**
92
- * Initiate the connection to gateway.
88
+ * Initiate the connection to gateway and create a proxy.
89
+ *
90
+ * @param proxyName the proxy name.
93
91
  */
94
- init() {
95
- this.connection = new HubConnectionBuilder().withUrl(this.url).build();
92
+ init(proxyName) {
93
+ this.connection = $.hubConnection(this.url);
94
+ this.connection.error((error) => this.errorMessage(error));
95
+ this.proxy = this.connection.createHubProxy(proxyName);
96
+ this.proxy.connection.error((error) => this.errorMessage(error));
96
97
  }
97
98
  /**
98
99
  * Error message from signalr connection.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../packages/core/notification/socket-signalr.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExG;;GAEG;AACH,MAAM,CAAN,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC1B,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,mEAAY,CAAA;IACZ,qEAAa,CAAA;IACb,6DAAS,CAAA;IACT,kFAAoB,CAAA;IACpB,sEAAc,CAAA;AAClB,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B;AAWD;;GAEG;AACH,MAAM,OAAgB,aAAa;IAa/B;;OAEG;IACH,YAAoB,UAAkB,EAAU,aAAqB;QAAjD,eAAU,GAAV,UAAU,CAAQ;QAAU,kBAAa,GAAb,aAAa,CAAQ;QAd7D,YAAO,GAAG,KAAK,CAAC;QAEhB,mBAAc,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAavE,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O,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAI,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;SAC5E;QAED,IAAI;YACA,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAI,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;SACnD;QAAC,OAAO,KAAK,EAAE;YACZ,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChC;IACL,CAAC;IAcD;;OAEG;IACK,IAAI;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAoB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACK,YAAY,CAAC,KAAgB;QACjC,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,kBAAkB,CAAC,eAAe,EAAG,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SAC5G;aAAM;YACH,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;SAC1B;IACL,CAAC;CACJ","file":"socket-signalr.js","sourcesContent":["import { HttpError, HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr';\r\n\r\n/**\r\n * Socket message flags. These can be combined.\r\n */\r\nexport enum SocketMessageFlags {\r\n None = 0,\r\n Data = 1,\r\n Progress = 2,\r\n Completed = 4,\r\n Error = 8,\r\n ConnectionError = 16,\r\n Exception = 32\r\n}\r\n\r\n/**\r\n * Socket message.\r\n */\r\nexport interface SocketMessage<T> {\r\n type: SocketMessageFlags;\r\n connectionError?: HttpError;\r\n message: T;\r\n}\r\n\r\n/**\r\n * SignalR based socket class.\r\n */\r\nexport abstract class SocketSignalR<T> {\r\n private connection: HubConnection;\r\n private started = false;\r\n private lastError: HttpError;\r\n private processHandler = (message: string) => this.processMessage(message);\r\n\r\n /**\r\n * Gets signalR connection URL.\r\n */\r\n private get url(): string {\r\n return `${this.gatewayUrl}${this.connectionUrl}`;\r\n }\r\n\r\n /**\r\n * Instantiates a new instance of the SocketSignalR class.\r\n */\r\n constructor(private gatewayUrl: string, private connectionUrl: string) {\r\n gatewayUrl = gatewayUrl ? gatewayUrl : '';\r\n }\r\n\r\n /**\r\n * Subscribe to the proxy with method name and handler.\r\n *\r\n * @param name the name of subscription for a method.\r\n */\r\n public subscribe(name: string): void {\r\n this.init();\r\n if (this.lastError) {\r\n // send last error;\r\n this.clientHandler({ type: SocketMessageFlags.Error, connectionError: this.lastError, message: null });\r\n }\r\n\r\n this.connection.on(name, this.processHandler);\r\n }\r\n\r\n /**\r\n * Unsubscribe to the subscribed method call.\r\n *\r\n * @param name the name of subscription for a method.\r\n */\r\n public unsubscribe(name: string): void {\r\n this.connection.off(name, this.processHandler);\r\n }\r\n\r\n /**\r\n * Start request connection.\r\n */\r\n public start(): Promise<any> {\r\n return this.connection.start().then(() => this.started = true);\r\n }\r\n\r\n /**\r\n * Stop request connection.\r\n */\r\n public stop(): void {\r\n this.started = false;\r\n this.connection.stop();\r\n }\r\n\r\n /**\r\n * Invoke a method with parameters.\r\n *\r\n * @param name the method name to execute.\r\n * @param args the parameters to pass.\r\n * @return Promise the promise object.\r\n */\r\n public invoke(name: string, ...args: any[]): Promise<T> {\r\n if (!this.started) {\r\n throw new Error('request socket has not been started.');\r\n }\r\n\r\n if (this.connection.state === HubConnectionState.Disconnected) {\r\n return this.start().then(() => this.connection.invoke<T>(name, ...args));\r\n }\r\n\r\n try {\r\n return this.connection.invoke<T>(name, ...args);\r\n } catch (error) {\r\n this.errorMessage(error);\r\n return Promise.reject(error);\r\n }\r\n }\r\n\r\n /**\r\n * The client handler.\r\n */\r\n protected abstract clientHandler(messages: SocketMessage<T>): void;\r\n\r\n /**\r\n * Process the message.\r\n *\r\n * @param messages the messages.\r\n */\r\n protected abstract processMessage(message: string): void;\r\n\r\n /**\r\n * Initiate the connection to gateway.\r\n */\r\n private init(): void {\r\n this.connection = new HubConnectionBuilder().withUrl(this.url).build();\r\n }\r\n\r\n /**\r\n * Error message from signalr connection.\r\n *\r\n * @param error the error produced on the connection.\r\n */\r\n private errorMessage(error: HttpError): void {\r\n if (this.clientHandler) {\r\n this.clientHandler({ type: SocketMessageFlags.ConnectionError, connectionError: error, message: null });\r\n } else {\r\n this.lastError = error;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../../packages/core/notification/socket-signalr.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC;;GAEG;AACH,MAAM,CAAN,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC1B,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,mEAAY,CAAA;IACZ,qEAAa,CAAA;IACb,6DAAS,CAAA;IACT,kFAAoB,CAAA;IACpB,sEAAc,CAAA;AAClB,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B;AAWD;;GAEG;AACH,MAAM,OAAgB,aAAa;IAc/B;;OAEG;IACH,YAAoB,UAAkB,EAAU,aAAqB,EAAU,SAAiB;QAA5E,eAAU,GAAV,UAAU,CAAQ;QAAU,kBAAa,GAAb,aAAa,CAAQ;QAAU,cAAS,GAAT,SAAS,CAAQ;QAdxF,YAAO,GAAG,KAAK,CAAC;QAEhB,mBAAc,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAavE,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;IAZD;;OAEG;IACH,IAAY,GAAG;QACX,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IACrD,CAAC;IASD;;;;;OAKG;IACI,SAAS,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CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;IAcD;;;;OAIG;IACK,IAAI,CAAC,SAAiB;QAC1B,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5C,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC;IAED;;;;OAIG;IACK,YAAY,CAAC,KAA8B;QAC/C,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,kBAAkB,CAAC,eAAe,EAAG,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SAC5G;aAAM;YACH,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;SAC1B;IACL,CAAC;CACJ","file":"socket-signalr.js","sourcesContent":["/// <reference types='signalr' />\r\n\r\n/**\r\n * Socket message flags. These can be combined.\r\n */\r\nexport enum SocketMessageFlags {\r\n None = 0,\r\n Data = 1,\r\n Progress = 2,\r\n Completed = 4,\r\n Error = 8,\r\n ConnectionError = 16,\r\n Exception = 32\r\n}\r\n\r\n/**\r\n * Socket message.\r\n */\r\nexport interface SocketMessage<T> {\r\n type: SocketMessageFlags;\r\n connectionError?: SignalR.ConnectionError;\r\n message: T;\r\n}\r\n\r\n/**\r\n * SignalR based socket class.\r\n */\r\nexport abstract class SocketSignalR<T> {\r\n private connection: SignalR.Hub.Connection;\r\n private proxy: SignalR.Hub.Proxy;\r\n private started = false;\r\n private lastError: SignalR.ConnectionError;\r\n private processHandler = (message: string) => this.processMessage(message);\r\n\r\n /**\r\n * Gets signalR connection URL.\r\n */\r\n private get url(): string {\r\n return `${this.gatewayUrl}${this.connectionUrl}`;\r\n }\r\n\r\n /**\r\n * Instantiates a new instance of the SocketSignalR class.\r\n */\r\n constructor(private gatewayUrl: string, private connectionUrl: string, private proxyName: string) {\r\n gatewayUrl = gatewayUrl ? gatewayUrl : '';\r\n }\r\n\r\n /**\r\n * Subscribe to the proxy with method name and handler.\r\n *\r\n * @param name the name of subscription for a method.\r\n * @return SignalR.Hub.Proxy the proxy.\r\n */\r\n public subscribe(name: string): SignalR.Hub.Proxy {\r\n this.init(this.proxyName);\r\n if (this.lastError) {\r\n // send last error;\r\n this.clientHandler({ type: SocketMessageFlags.Error, connectionError: this.lastError, message: null });\r\n }\r\n\r\n return this.proxy.on(name, this.processHandler);\r\n }\r\n\r\n /**\r\n * Unsubscribe to the subscribed method call.\r\n *\r\n * @param name the name of subscription for a method.\r\n */\r\n public unsubscribe(name: string): void {\r\n this.proxy.off(name, this.processHandler);\r\n }\r\n\r\n /**\r\n * Start request connection.\r\n */\r\n public start(): JQueryPromise<any> {\r\n return this.connection.start().then(() => this.started = true);\r\n }\r\n\r\n /**\r\n * Stop request connection.\r\n */\r\n public stop(): SignalR.Connection {\r\n this.started = false;\r\n return this.connection.stop(true);\r\n }\r\n\r\n /**\r\n * Invoke a method with parameters.\r\n *\r\n * @param name the method name to execute.\r\n * @param args the parameters to pass.\r\n * @return Promise the promise object.\r\n */\r\n public invoke(name: string, ...args: any[]): JQueryPromise<any> {\r\n if (!this.started) {\r\n throw new Error('request socket has not been started.');\r\n }\r\n\r\n if (this.connection.state === 4 /* SignalR.ConnectionState.Disconnected: @types/signalr doesn't take conversion properly */) {\r\n return this.start().then(() => this.proxy.invoke(name, ...args));\r\n }\r\n\r\n return this.proxy.invoke(name, ...args);\r\n }\r\n\r\n /**\r\n * The client handler.\r\n */\r\n protected abstract clientHandler(messages: SocketMessage<T>): void;\r\n\r\n /**\r\n * Process the message.\r\n *\r\n * @param messages the messages.\r\n */\r\n protected abstract processMessage(message: string): void;\r\n\r\n /**\r\n * Initiate the connection to gateway and create a proxy.\r\n *\r\n * @param proxyName the proxy name.\r\n */\r\n private init(proxyName: string): void {\r\n this.connection = $.hubConnection(this.url);\r\n this.connection.error((error) => this.errorMessage(error));\r\n this.proxy = this.connection.createHubProxy(proxyName);\r\n this.proxy.connection.error((error) => this.errorMessage(error));\r\n }\r\n\r\n /**\r\n * Error message from signalr connection.\r\n *\r\n * @param error the error produced on the connection.\r\n */\r\n private errorMessage(error: SignalR.ConnectionError): void {\r\n if (this.clientHandler) {\r\n this.clientHandler({ type: SocketMessageFlags.ConnectionError, connectionError: error, message: null });\r\n } else {\r\n this.lastError = error;\r\n }\r\n }\r\n}\r\n"]}
@@ -14,8 +14,6 @@ export declare class WorkItemManager {
14
14
  private nodeConnection;
15
15
  notificationConnection: NotificationConnection;
16
16
  private static apiWorkItems24hours;
17
- private static apiNotificationMessageStored;
18
- private static apiNotificationMessageSubscriptionId;
19
17
  active: boolean;
20
18
  private startSubscription;
21
19
  private powerShellNotification;
@@ -25,7 +23,6 @@ export declare class WorkItemManager {
25
23
  private sequenceCounter;
26
24
  private sequencePackets;
27
25
  private rpcWorkItemSubjectServer;
28
- private rootSubscriptionId;
29
26
  /**
30
27
  * Initializes a new instance of the WorkItemManager class.
31
28
  *
@@ -57,5 +54,4 @@ export declare class WorkItemManager {
57
54
  * @return Observable the WorkItemResult observable.
58
55
  */
59
56
  queryWorkItem(request: RpcWorkItem): Observable<WorkItemResult>;
60
- private getErrorLevel;
61
57
  }
@@ -1,4 +1,4 @@
1
- import { forkJoin, from, of, throwError } from 'rxjs';
1
+ import { from, of, throwError } from 'rxjs';
2
2
  import { catchError, switchMap } from 'rxjs/operators';
3
3
  import { Net } from '../data/net';
4
4
  import { PowerShell } from '../data/powershell';
@@ -44,71 +44,48 @@ export class WorkItemManager {
44
44
  this.startSubscription = this.gatewayConnection.get(WorkItemManager.apiWorkItems24hours)
45
45
  .pipe(catchError((error, obj) => {
46
46
  const message = MsftSme.getStrings().MsftSmeShell.Core.Error.NotificationNoWorkItemFound.message;
47
- Logging.logError('Notification', message.format(Net.getErrorMessage(error)));
47
+ Logging.log({
48
+ source: 'Notification',
49
+ level: LogLevel.Error,
50
+ message: message.format(Net.getErrorMessage(error))
51
+ });
48
52
  return of({ response: { value: null } });
49
53
  }), switchMap(response => {
50
54
  if (response.value) {
51
- response.value.forEach(element => this.notificationManager.addFromRecover(element));
55
+ response.value.forEach(element => {
56
+ this.notificationManager.addFromRecover(element);
57
+ });
52
58
  }
53
59
  // start websocket status query.
54
60
  this.powerShellNotification = new PowerShellNotification(this.gatewayConnection.gatewayUrl);
55
- return from(this.powerShellNotification.initialize());
61
+ return from(
62
+ // converting jQueryPromise to native Promise.
63
+ new Promise((resolve, reject) => this.powerShellNotification.initialize().then(resolve, reject)));
56
64
  }))
57
65
  .subscribe(() => {
58
66
  // notification from the gateway...
59
67
  this.notificationSubscription = this.powerShellNotification.subject
60
68
  .subscribe(item => {
61
- const message = item.message;
62
- if (message && message.sessionId) {
63
- // PowerShell Work Item message.
64
- const workItem = message;
65
- const psSessionId = workItem.sessionId;
69
+ if (item && item.message && item.message.sessionId) {
70
+ const psSessionId = item.message.sessionId;
66
71
  // Pass in psSessionId so telemetry can search up the PSCommand for this
67
72
  if (PowerShellNotification.hasError(item)) {
68
- SmeWebTelemetry.tracePowershellEvent(null, TelemetryEventStates.Error, { response: workItem, id: psSessionId });
73
+ SmeWebTelemetry.tracePowershellEvent(null, TelemetryEventStates.Error, { response: item.message, id: psSessionId });
69
74
  }
70
75
  else if (PowerShellNotification.hasCompleted(item)) {
71
76
  SmeWebTelemetry.removePowershellId(psSessionId);
72
77
  }
73
78
  if (!this.notificationManager.updateFromMessage(psSessionId, item)) {
74
- const unexpectedMessage = MsftSme.getStrings().MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;
79
+ const message = MsftSme.getStrings()
80
+ .MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;
75
81
  Logging.log({
76
- source: 'Notification', level: LogLevel.Warning, message: unexpectedMessage.format(psSessionId),
82
+ source: 'Notification',
83
+ level: LogLevel.Warning,
84
+ message: message.format(psSessionId)
77
85
  });
78
86
  }
79
87
  }
80
- else if (message && message.id) {
81
- // PowerShell Work Item message.
82
- const notification = message;
83
- const state = this.getErrorLevel(notification);
84
- // Pass in psSessionId so telemetry can search up the PSCommand for this
85
- if (state === NotificationState.Error) {
86
- SmeWebTelemetry.tracePowershellEvent(null, TelemetryEventStates.Error, { response: message, id: message.id });
87
- }
88
- else if (state === NotificationState.Success) {
89
- SmeWebTelemetry.removePowershellId(message.id);
90
- }
91
- if (this.notificationManager.addForNotificationMessage(state, notification)) {
92
- this.powerShellNotification.subscribeSession(notification.id);
93
- }
94
- if (!this.notificationManager.updateFromNotificationMessage(state, message)) {
95
- const unexpectedMessage = MsftSme.getStrings().MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;
96
- Logging.logWarning('Notification', unexpectedMessage.format(message.id));
97
- }
98
- }
99
88
  });
100
- this.notificationSubscription.add(forkJoin([
101
- this.gatewayConnection.get(WorkItemManager.apiNotificationMessageSubscriptionId),
102
- this.gatewayConnection.get(WorkItemManager.apiNotificationMessageStored),
103
- ]).subscribe(([idData, storedData]) => {
104
- this.rootSubscriptionId = idData.id;
105
- this.powerShellNotification.subscribeSession(this.rootSubscriptionId);
106
- storedData.value.forEach(element => {
107
- const state = this.getErrorLevel(element);
108
- this.notificationManager.addForNotificationMessage(state, element);
109
- this.powerShellNotification.subscribeSession(element.id);
110
- });
111
- }));
112
89
  // workItem request from rpc...
113
90
  this.rpcWorkItemSubscription = this.rpcWorkItemSubjectServer.subject
114
91
  .subscribe(item => {
@@ -260,40 +237,7 @@ export class WorkItemManager {
260
237
  const message = MsftSme.getStrings().MsftSmeShell.Core.Error.NotificationNoIdFound.message;
261
238
  return throwError(message.format(request.id));
262
239
  }
263
- getErrorLevel(notification) {
264
- switch (notification.errorLevel) {
265
- // Notification is unknown.
266
- case 0:
267
- case 'None':
268
- return NotificationState.Informational;
269
- // Notification is in progress. (non-terminated message.)
270
- case 1:
271
- case 'InProgress':
272
- return NotificationState.InProgress;
273
- // Notification is success. (terminated message.)
274
- case 2:
275
- case 'Success':
276
- return NotificationState.Success;
277
- // Notification is informational. (terminated message.)
278
- case 3:
279
- case 'Informational':
280
- return NotificationState.Informational;
281
- // Notification is warning. (terminated message.)
282
- case 4:
283
- case 'Warning':
284
- return NotificationState.Warning;
285
- // Notification is error. (terminated message.)
286
- case 5:
287
- case 'Error':
288
- return NotificationState.Error;
289
- // Notification is unknown.
290
- default:
291
- throw new Error('Couldn\'t get expected error level from a message notification.');
292
- }
293
- }
294
240
  }
295
241
  WorkItemManager.apiWorkItems24hours = '/workitems?lastMinutes=1440';
296
- WorkItemManager.apiNotificationMessageStored = '/NotificationMessage/stored';
297
- WorkItemManager.apiNotificationMessageSubscriptionId = '/NotificationMessage/id';
298
242
 
299
243
  //# sourceMappingURL=work-item-manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../packages/core/notification/work-item-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAc,EAAE,EAAgB,UAAU,EAAE,MAAM,MAAM,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EA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D;YACjD,KAAK,CAAC,CAAC;YACP,KAAK,SAAS;gBACV,OAAO,iBAAiB,CAAC,OAAO,CAAC;YAErC,+CAA+C;YAC/C,KAAK,CAAC,CAAC;YACP,KAAK,OAAO;gBACR,OAAO,iBAAiB,CAAC,KAAK,CAAC;YAEnC,2BAA2B;YAC3B;gBACI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;SAC1F;IACL,CAAC;;AAvVc,mCAAmB,GAAG,6BAA6B,CAAC;AACpD,4CAA4B,GAAG,6BAA6B,CAAC;AAC7D,oDAAoC,GAAG,yBAAyB,CAAC","file":"work-item-manager.js","sourcesContent":["\r\nimport { forkJoin, from, Observable, of, Subscription, throwError } from 'rxjs';\r\nimport { catchError, switchMap } from 'rxjs/operators';\r\nimport { GatewayConnection } from '../data/gateway-connection';\r\nimport { Net } from '../data/net';\r\nimport { NodeConnection } from '../data/node-connection';\r\nimport { PowerShell, PowerShellCommand } from '../data/powershell';\r\nimport { LogLevel } from '../diagnostics/log-level';\r\nimport { Logging } from '../diagnostics/logging';\r\nimport { SmeWebTelemetry } from '../diagnostics/sme-web-telemetry';\r\nimport { TelemetryEventStates } from '../diagnostics/sme-web-telemetry-models';\r\nimport { Strings } from '../generated/strings';\r\nimport { Rpc } from '../rpc/rpc';\r\nimport { RpcWorkItem } from '../rpc/work-item/rpc-work-item-model';\r\nimport { RpcWorkItemSubjectServer } from '../rpc/work-item/rpc-work-item-subject-server';\r\nimport { NotificationConnection } from './notification-connection';\r\nimport { NotificationManager } from './notification-manager';\r\nimport { NotificationMessage } from './notification-message';\r\nimport { NotificationState } from './notification-state';\r\nimport { PowerShellNotification, PowerShellWorkItemMessage } from './powershell-notification';\r\nimport { SocketMessage } from './socket-signalr';\r\nimport { WorkItemRequestType, WorkItemResult } from './work-item-request';\r\n\r\n/**\r\n * Work item manager class.\r\n */\r\nexport class WorkItemManager {\r\n private static apiWorkItems24hours = '/workitems?lastMinutes=1440';\r\n private static apiNotificationMessageStored = '/NotificationMessage/stored';\r\n private static apiNotificationMessageSubscriptionId = '/NotificationMessage/id';\r\n\r\n public active = false;\r\n\r\n private startSubscription: Subscription;\r\n private powerShellNotification: PowerShellNotification;\r\n private notificationSubscription: Subscription;\r\n private rpcWorkItemSubscription: Subscription;\r\n private notificationManager: NotificationManager;\r\n private sequenceCounter = 1;\r\n private sequencePackets: { [index: number]: { success: boolean, data: WorkItemResult | any } } = {};\r\n private rpcWorkItemSubjectServer: RpcWorkItemSubjectServer;\r\n private rootSubscriptionId: string;\r\n\r\n /**\r\n * Initializes a new instance of the WorkItemManager class.\r\n *\r\n * @param rpc the RPC object.\r\n * @param gatewayConnection the gateway connection service.\r\n * @param nodeConnection the node connection service.\r\n * @param notificationManager the notification manager.\r\n */\r\n constructor(\r\n private rpc: Rpc,\r\n private gatewayConnection: GatewayConnection,\r\n private nodeConnection: NodeConnection,\r\n public notificationConnection: NotificationConnection) {\r\n this.notificationManager = this.notificationConnection.notificationManager;\r\n this.start();\r\n }\r\n\r\n /**\r\n * Start the work item management.\r\n */\r\n public start(): void {\r\n this.stop();\r\n this.rpcWorkItemSubjectServer = new RpcWorkItemSubjectServer(this.rpc);\r\n this.active = true;\r\n\r\n // pickup active work items for last 24hours\r\n this.startSubscription = this.gatewayConnection.get(WorkItemManager.apiWorkItems24hours)\r\n .pipe(\r\n catchError((error, obj) => {\r\n const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationNoWorkItemFound.message;\r\n Logging.logError('Notification', message.format(Net.getErrorMessage(error)));\r\n return of({ response: { value: null } });\r\n }),\r\n switchMap(response => {\r\n if (response.value) {\r\n response.value.forEach(element => this.notificationManager.addFromRecover(element));\r\n }\r\n\r\n // start websocket status query.\r\n this.powerShellNotification = new PowerShellNotification(this.gatewayConnection.gatewayUrl);\r\n return from(this.powerShellNotification.initialize());\r\n }))\r\n .subscribe(\r\n () => {\r\n // notification from the gateway...\r\n this.notificationSubscription = this.powerShellNotification.subject\r\n .subscribe(item => {\r\n const message: any = item.message;\r\n if (message && message.sessionId) {\r\n // PowerShell Work Item message.\r\n const workItem: PowerShellWorkItemMessage = message;\r\n const psSessionId = workItem.sessionId;\r\n\r\n // Pass in psSessionId so telemetry can search up the PSCommand for this\r\n if (PowerShellNotification.hasError(item)) {\r\n SmeWebTelemetry.tracePowershellEvent(\r\n null, TelemetryEventStates.Error, { response: workItem, id: psSessionId});\r\n } else if (PowerShellNotification.hasCompleted(item)) {\r\n SmeWebTelemetry.removePowershellId(psSessionId);\r\n }\r\n\r\n if (!this.notificationManager.updateFromMessage(\r\n psSessionId, <SocketMessage<PowerShellWorkItemMessage>>item)) {\r\n const unexpectedMessage =\r\n MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;\r\n Logging.log({\r\n source: 'Notification', level: LogLevel.Warning, message: unexpectedMessage.format(psSessionId),\r\n });\r\n }\r\n } else if (message && message.id) {\r\n // PowerShell Work Item message.\r\n const notification: NotificationMessage = message;\r\n const state = this.getErrorLevel(notification);\r\n\r\n // Pass in psSessionId so telemetry can search up the PSCommand for this\r\n if (state === NotificationState.Error) {\r\n SmeWebTelemetry.tracePowershellEvent(\r\n null, TelemetryEventStates.Error, { response: message, id: message.id});\r\n } else if (state === NotificationState.Success) {\r\n SmeWebTelemetry.removePowershellId(message.id);\r\n }\r\n\r\n if (this.notificationManager.addForNotificationMessage(state, notification)) {\r\n this.powerShellNotification.subscribeSession(notification.id);\r\n }\r\n\r\n if (!this.notificationManager.updateFromNotificationMessage(state, message)) {\r\n const unexpectedMessage =\r\n MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;\r\n Logging.logWarning('Notification', unexpectedMessage.format(message.id));\r\n }\r\n }\r\n });\r\n\r\n this.notificationSubscription.add(\r\n forkJoin([\r\n this.gatewayConnection.get(WorkItemManager.apiNotificationMessageSubscriptionId),\r\n this.gatewayConnection.get(WorkItemManager.apiNotificationMessageStored),\r\n ]).subscribe(([idData, storedData]) => {\r\n this.rootSubscriptionId = idData.id;\r\n this.powerShellNotification.subscribeSession(this.rootSubscriptionId);\r\n storedData.value.forEach(element => {\r\n const state = this.getErrorLevel(element);\r\n this.notificationManager.addForNotificationMessage(state, element);\r\n this.powerShellNotification.subscribeSession(element.id);\r\n });\r\n }));\r\n\r\n // workItem request from rpc...\r\n this.rpcWorkItemSubscription = this.rpcWorkItemSubjectServer.subject\r\n .subscribe(item => {\r\n switch (item.data.type) {\r\n // legacy support for quick submission. it was expected 3 seconds response.\r\n case WorkItemRequestType.PowerShellSubmit:\r\n this.submitWorkItem(item.data).toPromise().then(item.deferred.resolve, item.deferred.reject);\r\n break;\r\n\r\n // new support for longer submission case like manage-as dialog displays.\r\n case WorkItemRequestType.WorkItemSubmit:\r\n const submitSequenceId = this.sequenceCounter++;\r\n item.data.sequenceId = submitSequenceId;\r\n this.submitWorkItem(item.data)\r\n .subscribe(\r\n data => this.sequencePackets[submitSequenceId] = { success: true, data: data },\r\n error => this.sequencePackets[submitSequenceId] = { success: false, data: error });\r\n\r\n // using sequence id, submission return immediately.\r\n item.deferred.resolve(<WorkItemResult>{ sequenceId: submitSequenceId, id: null });\r\n break;\r\n\r\n // query to notification by 'id' or query to submission result by 'sequenceId'.\r\n case WorkItemRequestType.StateQuery:\r\n default:\r\n if (item.data.id) {\r\n // query to 'id'\r\n this.queryWorkItem(item.data).toPromise().then(item.deferred.resolve, item.deferred.reject);\r\n } else {\r\n // query to 'sequenceId'\r\n const querySequenceId = item.data.sequenceId;\r\n const result = this.sequencePackets[querySequenceId];\r\n if (result) {\r\n // have a result, delete it and pass back as response.\r\n delete this.sequencePackets[querySequenceId];\r\n if (result.success) {\r\n item.deferred.resolve(result.data);\r\n } else {\r\n item.deferred.reject(result.data);\r\n }\r\n } else {\r\n // no result yet.\r\n item.deferred.resolve(<WorkItemResult>{ sequenceId: querySequenceId, id: null });\r\n }\r\n }\r\n\r\n break;\r\n\r\n }\r\n });\r\n\r\n // subscribe the session notification to the gateway...\r\n this.notificationManager.items.forEach((value) => {\r\n // only if it's not finalized.\r\n if (value.state === NotificationState.Started || value.state === NotificationState.InProgress) {\r\n this.powerShellNotification.subscribeSession(value.id);\r\n }\r\n });\r\n },\r\n error => {\r\n const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationWebsocketInitialize.message;\r\n Logging.log({\r\n source: 'Notification',\r\n level: LogLevel.Error,\r\n message: message.format(Net.getErrorMessage(error))\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Stop the work item management.\r\n */\r\n public stop(): void {\r\n this.active = false;\r\n if (this.startSubscription) {\r\n this.startSubscription.unsubscribe();\r\n this.startSubscription = null;\r\n }\r\n\r\n if (this.notificationSubscription) {\r\n this.notificationSubscription.unsubscribe();\r\n this.notificationSubscription = null;\r\n }\r\n\r\n if (this.powerShellNotification) {\r\n this.powerShellNotification.uninitialize();\r\n this.powerShellNotification = null;\r\n }\r\n\r\n if (this.rpcWorkItemSubscription) {\r\n this.rpcWorkItemSubscription.unsubscribe();\r\n this.rpcWorkItemSubscription = null;\r\n }\r\n }\r\n\r\n /**\r\n * Create and submit a workItem.\r\n *\r\n * @param request the work item request.\r\n * @return Observable the WorkItemResult observable.\r\n */\r\n public submitWorkItem(request: RpcWorkItem): Observable<WorkItemResult> {\r\n let command: PowerShellCommand = null;\r\n const notificationId = request.id || MsftSme.newGuid();\r\n\r\n if (request.powerShellCommand || request.powerShellScript) {\r\n // For a non-powershell long running task (eg: azure site recovery setup), command is null.\r\n command = PowerShell.getPowerShellCommand(request.powerShellCommand || request.powerShellScript);\r\n }\r\n\r\n if (request.powerShellScript) {\r\n delete request['powerShellScript'];\r\n }\r\n\r\n if (request.powerShellCommand) {\r\n delete request['powerShellCommand'];\r\n }\r\n\r\n const nodeRequestOptions = PowerShell.newEndpointOptions(request.nodeRequestOptions);\r\n if (request.nodeRequestOptions) {\r\n delete request['nodeRequestOptions'];\r\n }\r\n\r\n // remember current URL where original request generated.\r\n request.locationPathname = window.location.pathname;\r\n request.locationSearch = window.location.search;\r\n\r\n // send submit notification\r\n this.notificationManager.addFromWorkItem(\r\n notificationId,\r\n request,\r\n request.submittedMessage ? NotificationState.Submitted : NotificationState.Started);\r\n\r\n return this.powerShellNotification.submit(\r\n this.nodeConnection,\r\n request.nodeName,\r\n command,\r\n request,\r\n nodeRequestOptions,\r\n result => {\r\n if (!this.notificationManager.updateWorkItemWithPsSession(\r\n notificationId, result.id, request, result.state, result.error)) {\r\n const message = MsftSme.getStrings<Strings>()\r\n .MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;\r\n Logging.log({\r\n source: 'Notification',\r\n level: LogLevel.Warning,\r\n message: message.format(notificationId)\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Query a workItem.\r\n *\r\n * @param request the work item request.\r\n * @return Observable the WorkItemResult observable.\r\n */\r\n public queryWorkItem(request: RpcWorkItem): Observable<WorkItemResult> {\r\n const notification = this.notificationManager.find(request.id);\r\n if (notification) {\r\n if (notification.state === NotificationState.Error) {\r\n return of(<WorkItemResult>{\r\n id: notification.id,\r\n state: notification.state,\r\n percent: notification.progressPercent,\r\n error: notification.object\r\n });\r\n }\r\n\r\n return of(<WorkItemResult>{\r\n id: notification.id,\r\n state: notification.state,\r\n percent: notification.progressPercent,\r\n object: notification.object\r\n });\r\n }\r\n\r\n const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationNoIdFound.message;\r\n return throwError(message.format(request.id));\r\n }\r\n\r\n private getErrorLevel(notification: NotificationMessage): NotificationState {\r\n switch (notification.errorLevel) {\r\n // Notification is unknown.\r\n case 0:\r\n case 'None':\r\n return NotificationState.Informational;\r\n\r\n // Notification is in progress. (non-terminated message.)\r\n case 1:\r\n case 'InProgress':\r\n return NotificationState.InProgress;\r\n\r\n // Notification is success. (terminated message.)\r\n case 2:\r\n case 'Success':\r\n return NotificationState.Success;\r\n\r\n // Notification is informational. (terminated message.)\r\n case 3:\r\n case 'Informational':\r\n return NotificationState.Informational;\r\n\r\n // Notification is warning. (terminated message.)\r\n case 4:\r\n case 'Warning':\r\n return NotificationState.Warning;\r\n\r\n // Notification is error. (terminated message.)\r\n case 5:\r\n case 'Error':\r\n return NotificationState.Error;\r\n\r\n // Notification is unknown.\r\n default:\r\n throw new Error('Couldn\\'t get expected error level from a message notification.');\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../../packages/core/notification/work-item-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAc,EAAE,EAAgB,UAAU,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAI/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAGzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAkB,MAAM,qBAAqB,CAAC;AAE1E;;GAEG;AACH,MAAM,OAAO,eAAe;IAcxB;;;;;;;OAOG;IACH,YACY,GAAQ,EACR,iBAAoC,EACpC,cAA8B,EAC/B,sBAA8C;QAH7C,QAAG,GAAH,GAAG,CAAK;QACR,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,mBAAc,GAAd,cAAc,CAAgB;QAC/B,2BAAsB,GAAtB,sBAAsB,CAAwB;QAvBlD,WAAM,GAAG,KAAK,CAAC;Q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,CAAC,KAAK,CAAC,8BAA8B,CAAC,OAAO,CAAC;gBACpE,OAAO,CAAC,GAAG,CAAC;oBACR,MAAM,EAAE,cAAc;oBACtB,KAAK,EAAE,QAAQ,CAAC,OAAO;oBACvB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;iBAC1C,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACX,CAAC;IAED;;;;;OAKG;IACI,aAAa,CAAC,OAAoB;QACrC,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/D,IAAI,YAAY,EAAE;YACd,IAAI,YAAY,CAAC,KAAK,KAAK,iBAAiB,CAAC,KAAK,EAAE;gBAChD,OAAO,EAAE,CAAiB;oBACtB,EAAE,EAAE,YAAY,CAAC,EAAE;oBACnB,KAAK,EAAE,YAAY,CAAC,KAAK;oBACzB,OAAO,EAAE,YAAY,CAAC,eAAe;oBACrC,KAAK,EAAE,YAAY,CAAC,MAAM;iBAC7B,CAAC,CAAC;aACN;YAED,OAAO,EAAE,CAAiB;gBACtB,EAAE,EAAE,YAAY,CAAC,EAAE;gBACnB,KAAK,EAAE,YAAY,CAAC,KAAK;gBACzB,OAAO,EAAE,YAAY,CAAC,eAAe;gBACrC,MAAM,EAAE,YAAY,CAAC,MAAM;aAC9B,CAAC,CAAC;SACN;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAW,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC;QACpG,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC;;AAnRc,mCAAmB,GAAG,6BAA6B,CAAC","file":"work-item-manager.js","sourcesContent":["\r\nimport { from, Observable, of, Subscription, throwError } from 'rxjs';\r\nimport { catchError, switchMap } from 'rxjs/operators';\r\nimport { GatewayConnection } from '../data/gateway-connection';\r\nimport { Net } from '../data/net';\r\nimport { NodeConnection } from '../data/node-connection';\r\nimport { PowerShell, PowerShellCommand } from '../data/powershell';\r\nimport { LogLevel } from '../diagnostics/log-level';\r\nimport { Logging } from '../diagnostics/logging';\r\nimport { SmeWebTelemetry } from '../diagnostics/sme-web-telemetry';\r\nimport { TelemetryEventStates } from '../diagnostics/sme-web-telemetry-models';\r\nimport { Strings } from '../generated/strings';\r\nimport { Rpc } from '../rpc/rpc';\r\nimport { RpcWorkItem } from '../rpc/work-item/rpc-work-item-model';\r\nimport { RpcWorkItemSubjectServer } from '../rpc/work-item/rpc-work-item-subject-server';\r\nimport { NotificationConnection } from './notification-connection';\r\nimport { NotificationManager } from './notification-manager';\r\nimport { NotificationState } from './notification-state';\r\nimport { PowerShellNotification } from './powershell-notification';\r\nimport { WorkItemRequestType, WorkItemResult } from './work-item-request';\r\n\r\n/**\r\n * Work item manager class.\r\n */\r\nexport class WorkItemManager {\r\n private static apiWorkItems24hours = '/workitems?lastMinutes=1440';\r\n\r\n public active = false;\r\n\r\n private startSubscription: Subscription;\r\n private powerShellNotification: PowerShellNotification;\r\n private notificationSubscription: Subscription;\r\n private rpcWorkItemSubscription: Subscription;\r\n private notificationManager: NotificationManager;\r\n private sequenceCounter = 1;\r\n private sequencePackets: { [index: number]: { success: boolean, data: WorkItemResult | any } } = {};\r\n private rpcWorkItemSubjectServer: RpcWorkItemSubjectServer;\r\n\r\n /**\r\n * Initializes a new instance of the WorkItemManager class.\r\n *\r\n * @param rpc the RPC object.\r\n * @param gatewayConnection the gateway connection service.\r\n * @param nodeConnection the node connection service.\r\n * @param notificationManager the notification manager.\r\n */\r\n constructor(\r\n private rpc: Rpc,\r\n private gatewayConnection: GatewayConnection,\r\n private nodeConnection: NodeConnection,\r\n public notificationConnection: NotificationConnection) {\r\n this.notificationManager = this.notificationConnection.notificationManager;\r\n this.start();\r\n }\r\n\r\n /**\r\n * Start the work item management.\r\n */\r\n public start(): void {\r\n this.stop();\r\n this.rpcWorkItemSubjectServer = new RpcWorkItemSubjectServer(this.rpc);\r\n this.active = true;\r\n\r\n // pickup active work items for last 24hours\r\n this.startSubscription = this.gatewayConnection.get(WorkItemManager.apiWorkItems24hours)\r\n .pipe(\r\n catchError((error, obj) => {\r\n const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationNoWorkItemFound.message;\r\n Logging.log({\r\n source: 'Notification',\r\n level: LogLevel.Error,\r\n message: message.format(Net.getErrorMessage(error))\r\n });\r\n return of({ response: { value: null } });\r\n }),\r\n switchMap(response => {\r\n if (response.value) {\r\n response.value.forEach(element => {\r\n this.notificationManager.addFromRecover(element);\r\n });\r\n }\r\n\r\n // start websocket status query.\r\n this.powerShellNotification = new PowerShellNotification(this.gatewayConnection.gatewayUrl);\r\n return from(\r\n // converting jQueryPromise to native Promise.\r\n new Promise((resolve, reject) => this.powerShellNotification.initialize().then(resolve, reject))\r\n );\r\n }))\r\n .subscribe(\r\n () => {\r\n // notification from the gateway...\r\n this.notificationSubscription = this.powerShellNotification.subject\r\n .subscribe(item => {\r\n if (item && item.message && item.message.sessionId) {\r\n const psSessionId = item.message.sessionId;\r\n\r\n // Pass in psSessionId so telemetry can search up the PSCommand for this\r\n if (PowerShellNotification.hasError(item)) {\r\n SmeWebTelemetry.tracePowershellEvent(null,\r\n TelemetryEventStates.Error,\r\n { response: item.message, id: psSessionId});\r\n } else if (PowerShellNotification.hasCompleted(item)) {\r\n SmeWebTelemetry.removePowershellId(psSessionId);\r\n }\r\n\r\n if (!this.notificationManager.updateFromMessage(psSessionId, item)) {\r\n const message = MsftSme.getStrings<Strings>()\r\n .MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;\r\n Logging.log({\r\n source: 'Notification',\r\n level: LogLevel.Warning,\r\n message: message.format(psSessionId)\r\n });\r\n }\r\n }\r\n });\r\n\r\n // workItem request from rpc...\r\n this.rpcWorkItemSubscription = this.rpcWorkItemSubjectServer.subject\r\n .subscribe(item => {\r\n switch (item.data.type) {\r\n // legacy support for quick submission. it was expected 3 seconds response.\r\n case WorkItemRequestType.PowerShellSubmit:\r\n this.submitWorkItem(item.data).toPromise().then(item.deferred.resolve, item.deferred.reject);\r\n break;\r\n\r\n // new support for longer submission case like manage-as dialog displays.\r\n case WorkItemRequestType.WorkItemSubmit:\r\n const submitSequenceId = this.sequenceCounter++;\r\n item.data.sequenceId = submitSequenceId;\r\n this.submitWorkItem(item.data)\r\n .subscribe(\r\n data => this.sequencePackets[submitSequenceId] = { success: true, data: data },\r\n error => this.sequencePackets[submitSequenceId] = { success: false, data: error });\r\n\r\n // using sequence id, submission return immediately.\r\n item.deferred.resolve(<WorkItemResult>{ sequenceId: submitSequenceId, id: null });\r\n break;\r\n\r\n // query to notification by 'id' or query to submission result by 'sequenceId'.\r\n case WorkItemRequestType.StateQuery:\r\n default:\r\n if (item.data.id) {\r\n // query to 'id'\r\n this.queryWorkItem(item.data).toPromise().then(item.deferred.resolve, item.deferred.reject);\r\n } else {\r\n // query to 'sequenceId'\r\n const querySequenceId = item.data.sequenceId;\r\n const result = this.sequencePackets[querySequenceId];\r\n if (result) {\r\n // have a result, delete it and pass back as response.\r\n delete this.sequencePackets[querySequenceId];\r\n if (result.success) {\r\n item.deferred.resolve(result.data);\r\n } else {\r\n item.deferred.reject(result.data);\r\n }\r\n } else {\r\n // no result yet.\r\n item.deferred.resolve(<WorkItemResult>{ sequenceId: querySequenceId, id: null });\r\n }\r\n }\r\n\r\n break;\r\n\r\n }\r\n });\r\n\r\n // subscribe the session notification to the gateway...\r\n this.notificationManager.items.forEach((value) => {\r\n // only if it's not finalized.\r\n if (value.state === NotificationState.Started || value.state === NotificationState.InProgress) {\r\n this.powerShellNotification.subscribeSession(value.id);\r\n }\r\n });\r\n },\r\n error => {\r\n const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationWebsocketInitialize.message;\r\n Logging.log({\r\n source: 'Notification',\r\n level: LogLevel.Error,\r\n message: message.format(Net.getErrorMessage(error))\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Stop the work item management.\r\n */\r\n public stop(): void {\r\n this.active = false;\r\n if (this.startSubscription) {\r\n this.startSubscription.unsubscribe();\r\n this.startSubscription = null;\r\n }\r\n\r\n if (this.notificationSubscription) {\r\n this.notificationSubscription.unsubscribe();\r\n this.notificationSubscription = null;\r\n }\r\n\r\n if (this.powerShellNotification) {\r\n this.powerShellNotification.uninitialize();\r\n this.powerShellNotification = null;\r\n }\r\n\r\n if (this.rpcWorkItemSubscription) {\r\n this.rpcWorkItemSubscription.unsubscribe();\r\n this.rpcWorkItemSubscription = null;\r\n }\r\n }\r\n\r\n /**\r\n * Create and submit a workItem.\r\n *\r\n * @param request the work item request.\r\n * @return Observable the WorkItemResult observable.\r\n */\r\n public submitWorkItem(request: RpcWorkItem): Observable<WorkItemResult> {\r\n let command: PowerShellCommand = null;\r\n const notificationId = request.id || MsftSme.newGuid();\r\n\r\n if (request.powerShellCommand || request.powerShellScript) {\r\n // For a non-powershell long running task (eg: azure site recovery setup), command is null.\r\n command = PowerShell.getPowerShellCommand(request.powerShellCommand || request.powerShellScript);\r\n }\r\n\r\n if (request.powerShellScript) {\r\n delete request['powerShellScript'];\r\n }\r\n\r\n if (request.powerShellCommand) {\r\n delete request['powerShellCommand'];\r\n }\r\n\r\n const nodeRequestOptions = PowerShell.newEndpointOptions(request.nodeRequestOptions);\r\n if (request.nodeRequestOptions) {\r\n delete request['nodeRequestOptions'];\r\n }\r\n\r\n // remember current URL where original request generated.\r\n request.locationPathname = window.location.pathname;\r\n request.locationSearch = window.location.search;\r\n\r\n // send submit notification\r\n this.notificationManager.addFromWorkItem(\r\n notificationId,\r\n request,\r\n request.submittedMessage ? NotificationState.Submitted : NotificationState.Started\r\n );\r\n\r\n return this.powerShellNotification.submit(\r\n this.nodeConnection,\r\n request.nodeName,\r\n command,\r\n request,\r\n nodeRequestOptions,\r\n result => {\r\n if (!this.notificationManager.updateWorkItemWithPsSession(\r\n notificationId, result.id, request, result.state, result.error)) {\r\n const message = MsftSme.getStrings<Strings>()\r\n .MsftSmeShell.Core.Error.NotificationUnexpectedReceived.message;\r\n Logging.log({\r\n source: 'Notification',\r\n level: LogLevel.Warning,\r\n message: message.format(notificationId)\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Query a workItem.\r\n *\r\n * @param request the work item request.\r\n * @return Observable the WorkItemResult observable.\r\n */\r\n public queryWorkItem(request: RpcWorkItem): Observable<WorkItemResult> {\r\n const notification = this.notificationManager.find(request.id);\r\n if (notification) {\r\n if (notification.state === NotificationState.Error) {\r\n return of(<WorkItemResult>{\r\n id: notification.id,\r\n state: notification.state,\r\n percent: notification.progressPercent,\r\n error: notification.object\r\n });\r\n }\r\n\r\n return of(<WorkItemResult>{\r\n id: notification.id,\r\n state: notification.state,\r\n percent: notification.progressPercent,\r\n object: notification.object\r\n });\r\n }\r\n\r\n const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.NotificationNoIdFound.message;\r\n return throwError(message.format(request.id));\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "author": {
22
22
  "name": "Microsoft Corporation"
23
23
  },
24
- "version": "2.538.1",
24
+ "version": "2.541.0",
25
25
  "private": false,
26
26
  "dependencies": {
27
27
  "@angular/animations": "11.2.14",
@@ -32,7 +32,6 @@
32
32
  "@angular/platform-browser": "11.2.14",
33
33
  "@angular/platform-browser-dynamic": "11.2.14",
34
34
  "@angular/router": "11.2.14",
35
- "@microsoft/signalr": "^6.0.8",
36
35
  "@types/fs-extra": "9.0.11",
37
36
  "base64-arraybuffer": "0.1.5",
38
37
  "chart.js": "2.9.4",
@@ -40,6 +39,7 @@
40
39
  "fs-extra": "4.0.0",
41
40
  "guid-typescript": "1.0.9",
42
41
  "ip-address": "7.1.0",
42
+ "jquery": "3.6.0",
43
43
  "marked": "4.0.10",
44
44
  "minimist-lite": "2.2.0",
45
45
  "monaco-editor": "0.17.1",
@@ -48,6 +48,7 @@
48
48
  "path-exists": "3.0.0",
49
49
  "rxjs": "6.6.0",
50
50
  "semver": "5.5.0",
51
+ "signalr": "2.4.1",
51
52
  "tslib": "^2.0.0",
52
53
  "web-vitals": "2.1.4",
53
54
  "zone.js": "~0.11.3"
@@ -66,11 +67,13 @@
66
67
  "@types/chart.js": "2.9.32",
67
68
  "@types/fetch-mock": "^7.2.2",
68
69
  "@types/jasmine": "~3.6.0",
70
+ "@types/jquery": "3.3.29",
69
71
  "@types/karma": "~5.0.0",
70
72
  "@types/marked": "4.0.1",
71
73
  "@types/node": "^12.20.33",
72
74
  "@types/selenium-webdriver": "3.0.8",
73
75
  "@types/semver": "5.5.0",
76
+ "@types/signalr": "2.2.36",
74
77
  "ajv": "6.4.0",
75
78
  "autoprefixer": "^10.2.6",
76
79
  "axe-core": "4.1.4",