This component provides a short overview / example on how to utilize the notification features provided by the SME and shell. At this point in time, there are 5 examples, 3 popups and 2 tray notifications.
const notificationInstance = this.appContextService.notification.create('<noNodename.nodomain.abc.123.xyz.com>');
const inProgressTitle = 'Executing example action';
notificationInstance.showInProgress(
inProgressTitle,
'message 0 something happened that was really interesting. something happened that was really interesting.'
+ ' something happened that was really interesting.'
);
setTimeout(
() => {{ '{' }}
notificationInstance.showInProgress(inProgressTitle, 'message 1');
{{'}'}},
5000);
setTimeout(
() => {{ '{' }}
notificationInstance.showInProgress(inProgressTitle, 'message 2');
{{'}'}},
10000);
setTimeout(
() => {{ '{' }}
notificationInstance.showSuccess('Successfully finished example action', 'message 3');
{{'}'}},
15000);
const notificationInstance = this.appContextService.notification.create('<noNodename.nodomain.abc.123.xyz.com>');
const errorTitle = 'Showing Error example';
++this.alertCount;
notificationInstance.showError(
errorTitle,
'This demo error has been shown: ' + this.alertCount + ' time(s).'
);
const notificationInstance = this.appContextService.notification.create('<noNodename.nodomain.abc.123.xyz.com>');
const informationTitle = 'Showing Information example';
++this.notificationCount;
notificationInstance.showInformation(
informationTitle,
'This demo notification has been shown: ' + this.notificationCount + ' time(s).',
);
public submitWorkItemRequest(shouldSucceed: boolean, targetMachine: string): void {{ '{' }}
this.sendWorkItemRequest(shouldSucceed, targetMachine).subscribe(
result => {{ '{' }}
if (result.error) {{ '{' }}
const notification: ClientNotification = {{ '{' }}
title: 'Long Running Request',
message: 'The long running notification failed',
id: result.id,
state: NotificationState.Error
{{'}'}};
this.appContextService.notification.notify(targetMachine, notification);
{{'}'}}
{{'}'}}
);
{{'}'}}
private sendWorkItemRequest(shouldSucceed: boolean, targetMachine: string): Observable<WorkItemResult> {{ '{' }}
const script = shouldSucceed ?
PowerShellScripts.Notifications.Start_LongRunningTaskSuccessExample
: PowerShellScripts.Notifications.Start_LongRunningTaskFailureExample;
const command = PowerShell.createCommand(script);
const workItem: WorkItemSubmitRequest = {{ '{' }}
typeId: 'longRunning',
powerShellCommand: command,
// in progress notifications
inProgressTitle: 'Executing long running request',
startedMessage: 'The long running request has been started',
progressMessage: 'Working on long running request',
// success notification
successTitle: 'Successfully executed long running request',
successMessage: 'The test {{name}} was successful',
successLinkText: 'Bing',
successLink: 'http://www.bing.com',
successLinkType: NotificationLinkType.Absolute,
// error notification
disableErrorNotification: true,
errorTitle: 'Failed to execute long running request',
errorMessage: 'Error during test'
{{'}'}};
return this.appContextService.workItem.submitAndWait(targetMachine, workItem);
{{'}'}}