User Profile

This component provides a short overview / example on how to save and retrieve user specific settings for your extension. The values of the form below were restored from user settings for this extension.

Versioned Object

Versioning your data store is a very important part of maintaining forward/backward compatibility. For the reason using the the UserProfileService requires you to extend the VersionedObject class for saving and retrieving your data Here is an example of this in code:

/** * The Versioned representation of the Hello Extension Settings */ export class ExtensionProfileSettings extends VersionedObject {{'{'}} /** * Getter for the latest version of the user profile. */ public get latestVersion(): number{{'{'}} return 0; } /** * Getter for the example property. * You must use 'getProperty' to get values from the internal object properties store */ public get booleanExample(): boolean {{'{'}} return <boolean>this.getProperty('booleanExample') } /** * Setter for the example property. * You must use 'setProperty' to set values from the internal object properties store */ public set booleanExample(value: boolean) {{'{'}} this.setProperty('booleanExample', value); } /** * upgrades the current properties to the latest version * if this.currentVersion is null or undefined, then the upgrade should initialize to the latest version */ protected upgrade() {{'{'}} // For now, we dont need to do anything but initialize to the latest version. // NOTE: When latestVersion is updated, then we need to add logic here to upgrade old settings objects if (MsftSme.isNullOrUndefined(this.currentVersion)) {{'{'}} this.clear(); this.booleanExample = false; this.currentVersion = this.latestVersion; return; } } }

Example

// get my extensions settings appContextService.userProfileManager // get the settings into the type for the versionedObject extension we defined earlier .getExtensionSettings(ExtensionProfileSettings) .pipe( take(1)) .flatMap( settings => {{'{'}} // change settings settings.booleanExample = true; // save the settings return settings.save(); // alternativly we can save and revert if there is a failure. return settings.trySaver(() => {{'{'}} settings.booleanExample = true; }); });