import { inject , injectable } from "inversify" ; import { ParameterType , TYPES } from "./bll/utils/constants" ; import { GetSuitableConfigs } from "./bll/commands/getsuitableconfigs" ; import { SelectFilesForRemoteRun } from "./bll/commands/selectfilesforremoterun" ; import { SignIn } from "./bll/commands/signin" ; import { RemoteRun } from "./bll/commands/remoterun" ; import { SignOut } from "./bll/commands/signout" ; import { CredentialsStore } from "./bll/credentialsstore/credentialsstore" ; import { ShowMyChanges } from "./bll/commands/showmychanges" ; import { IProviderManager } from "./view/iprovidermanager" ; import { Logger } from "./bll/utils/logger" ; import { Utils } from "./bll/utils/utils" ; import { MessageManager } from "./view/messagemanager" ; import { BuildConfigItem } from "./bll/entities/presentable/buildconfigitem" ; import { CustomizeBuild } from "./bll/commands/CustomizeBuild" ; import { AddEditBuildParameter } from "./bll/commands/AddEditBuildParameter" ; import { ParameterItem } from "./bll/entities/presentable/ParameterItem" ; import { RemoveBuildParameter } from "./bll/commands/RemoveBuildParameter" ; import { QueueAtTop } from "./bll/commands/QueueAtTop" ; import { OpenInBrowser } from "./bll/commands/OpenInBrowser" ; import { ChangeItem } from "./bll/entities/presentable/changeitem" ; import { BuildConfig } from "./bll/entities/buildconfig" ; @ injectable ( ) export class CommandHolder { constructor ( @ inject ( TYPES . SignIn ) private readonly _signIn , @ inject ( TYPES . SignOut ) private readonly _signOut , @ inject ( TYPES . SelectFilesForRemoteRun ) private readonly _selectForRemoteRun , @ inject ( TYPES . GetSuitableConfigs ) private readonly _getSuitableConfigs , @ inject ( TYPES . RemoteRun ) private readonly _remoteRun , @ inject ( TYPES . ShowMyChangesCommand ) private readonly _showMyChanges , @ inject ( TYPES . ProviderManager ) private readonly providerManager , @ inject ( TYPES . CredentialsStore ) private readonly credentialsStore , @ inject ( TYPES . CustomizeBuild ) private readonly _customizeBuild , @ inject ( TYPES . AddEditBuildParameter ) private readonly _addBuildParameter , @ inject ( TYPES . RemoveBuildParameter ) private readonly _removeBuildParameter , @ inject ( TYPES . QueueAtTop ) private readonly _queueAtTop , @ inject ( TYPES . OpenInBrowser ) private readonly _openInBrowser , @ inject ( TYPES . MessageManager ) private readonly messageManager ) { } public async signIn ( fromPersistentStore = false ) { if ( await this . tryExecuteCommand ( this . _signIn , fromPersistentStore ) && this . credentialsStore . getCredentialsSilently ( ) ) { await this . showMyChanges ( true ) ; } } public async signOut ( ) { if ( await this . tryExecuteCommand ( this . _signOut ) ) { this . providerManager . resetAll ( ) ; this . providerManager . showChangesProvider ( ) ; } } public async selectFilesForRemoteRun ( ) { try { const loggedIn = await this . credentialsStore . getCredentials ( ) ; if ( loggedIn && await this . tryExecuteCommand ( this . _selectForRemoteRun ) ) { this . providerManager . showResourceProvider ( ) ; } } catch ( err ) { Logger . logError ( `[selectFilesForRemoteRun]  ${ Utils . formatErrorMessageForLogging ( err ) }` ) ; this . messageManager . showErrorMessage ( Utils . formatErrorMessage ( err ) ) ; } } public async getSuitableConfigs ( ) { if ( await this . tryExecuteCommand ( this . _getSuitableConfigs ) ) { this . providerManager . showBuildProvider ( ) ; } } public async remoteRunWithChosenConfigs ( ) { await this . tryExecuteCommand ( this . _remoteRun , false ) ; } public async preTestedCommit ( ) { await this . tryExecuteCommand ( this . _remoteRun , true ) ; } public async backToChangesDataProvider ( ) { this . providerManager . showChangesProvider ( ) ; return this . showMyChanges ( true ) ; } public backToBuildExplorer ( ) { this . providerManager . showBuildProvider ( ) ; } public backToSelectFilesForRemoteRun ( ) { this . providerManager . showResourceProvider ( ) ; } public async showMyChanges ( isSilent = false ) { if ( await this . tryExecuteCommand ( this . _showMyChanges , isSilent ) ) { this . providerManager . showChangesProvider ( ) ; } } public async customizeBuild ( buildConfigItem ) { await this . tryExecuteCommand ( this . _customizeBuild , buildConfigItem ) ; } public async addParameter ( type ) { await this . tryExecuteCommand ( this . _addBuildParameter , type ) ; } public async editParameter ( param ) { await this . tryExecuteCommand ( this . _addBuildParameter , param ) ; } public async removeParameter ( param ) { await this . tryExecuteCommand ( this . _removeBuildParameter , param ) ; } public async queueAtTop ( ) { await this . tryExecuteCommand ( this . _queueAtTop ) ; } public async openInBrowser ( presentableItem ) { await this . tryExecuteCommand ( this . _openInBrowser , presentableItem ) ; } private async tryExecuteCommand ( command , ... args ) { let result ; try { if ( args && args . length > 0 ) { result = await command . exec ( args ) ; } else { result = await command . exec ( ) ; } if ( typeof result === "boolean" ) { return result ; } } catch ( err ) { Logger . logError ( `[tryExecuteCommand] ${ Utils . formatErrorMessageForLogging ( err ) }` ) ; this . messageManager . showErrorMessage ( Utils . formatErrorMessage ( err ) ) ; return false ; } return true ; } public static resetBuildConfiguration ( buildConfigItem ) { const build = buildConfigItem . entity ; build . resetCustomization ( ) ; } }