import { window } from "vscode" ; import { AzureTreeItem , parseError } from "vscode-azureextensionui" ; import { showSavePromptConfigKey } from "../../../constants" ; import { localize } from "../../../localize" ; import { processError } from "../../../utils/errorUtil" ; import { nameUtil } from "../../../utils/nameUtil" ; import { IServiceTreeRoot } from "../../IServiceTreeRoot" ; import { Editor } from "../Editor" ; export abstract class BaseArmResourceEditor < TRoot extends IServiceTreeRoot > extends Editor < AzureTreeItem < TRoot > > { constructor ( ) { super ( showSavePromptConfigKey ) ; } public abstract get entityType ( ) : string ; public abstract getDataInternal ( context ) ; public abstract updateDataInternal ( context , payload ) ; public async getData ( context ) { try { const response = await this . getDataInternal ( context ) ; return JSON . stringify ( response , null , "\t" ) ; } catch ( error ) { throw new Error ( `${ parseError ( error ) . message }` ) ; } } public async updateData ( context , data ) { try { const payload = JSON . parse ( data ) ; const response = await this . updateDataInternal ( context , payload ) ; window . showInformationMessage ( localize ( "updateSucceded" , `Changes to ${ this . entityType } were succefully uploaded to cloud.` ) ) ; return JSON . stringify ( response , null , "\t" ) ; } catch ( error ) { throw new Error ( processError ( error , localize ( "updateFailed" , `Changes to ${ this . entityType } could not be uploaded to cloud.` ) ) ) ; } } public async getDiffFilename ( context ) { return `${ nameUtil ( context . root ) }-${ this . entityType . toLowerCase ( ) }-arm.json` ; } public async getFilename ( context ) { return `${ nameUtil ( context . root ) }-${ this . entityType . toLowerCase ( ) }-arm-tempFile.json` ; } public async getSize ( ) { throw new Error ( localize ( "" , "Method not implemented." ) ) ; } public async getSaveConfirmationText ( ) { return localize ( "saveConfirmation" , "Do you want to upload the azure resource changes to cloud?" ) ; } }