import * as vscode from "vscode" ; import * as utils from "../utils" ; import { DigitalTwinConstants } from "./DigitalTwinConstants" ; import { OperationCanceledError } from "../common/Error/OperationCanceledError" ; import { ModelRepositoryManager } from "./pnp/src/modelRepository/modelRepositoryManager" ; import { ApiProvider } from "./pnp/src/api/apiProvider" ; import { DigitalTwinNotInitializedError } from "../common/Error/OperationFailedErrors/DigitalTwinNotInitializedError" ; /**
 * Digital Twin extension utility
 */ export class DigitalTwinUtility { private static extensionInstance : any ; private static channel : vscode . OutputChannel ; param channel static init ( modelRepositoryManager , channel ) { DigitalTwinUtility . extensionInstance = new ApiProvider ( modelRepositoryManager ) ; DigitalTwinUtility . channel = channel ; } /**
     * select capability model
     */ static async selectCapabilityModel ( ) { if ( ! DigitalTwinUtility . extensionInstance ) { throw new DigitalTwinNotInitializedError ( "select capability model" ) ; } let result = "" ; try { result = await DigitalTwinUtility . extensionInstance . selectCapabilityModel ( ) ; } catch { } if ( ! result ) { throw new OperationCanceledError ( `Selected device capability model file cancelled.` ) ; } utils . channelShowAndAppendLine ( DigitalTwinUtility . channel , `${ DigitalTwinConstants . dtPrefix } Selected device capability model file: ${ result }` ) ; return result ; } param folder param capabilityModelFile static async downloadDependentInterface ( folder , capabilityModelFile ) { if ( ! DigitalTwinUtility . extensionInstance ) { throw new DigitalTwinNotInitializedError ( "download dependent interface" ) ; } try { await DigitalTwinUtility . extensionInstance . downloadDependentInterface ( folder , capabilityModelFile ) ; } catch ( error ) { utils . channelShowAndAppendLine ( DigitalTwinUtility . channel , `${ DigitalTwinConstants . dtPrefix } ${ error . message }` ) ; return false ; } return true ; } }