|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { AzureWizardPromptStep, type AzureWizardExecuteStep, type IWizardOptions } from '@microsoft/vscode-azext-utils'; |
| 7 | +import { type MessageItem } from 'vscode'; |
| 8 | +import { ConnectionType } from '../../../../constants'; |
| 9 | +import { useEmulator } from '../../../../constants-nls'; |
| 10 | +import { localize } from '../../../../localize'; |
| 11 | +import { DTSConnectionCustomPromptStep } from './DTSConnectionCustomPromptStep'; |
| 12 | +import { DTSConnectionSetSettingStep } from './DTSConnectionSetSettingStep'; |
| 13 | +import { DTSEmulatorStartStep } from './DTSEmulatorStartStep'; |
| 14 | +import { DTSHubNameCustomPromptStep } from './DTSHubNameCustomPromptStep'; |
| 15 | +import { DTSHubNameSetSettingStep } from './DTSHubNameSetSettingStep'; |
| 16 | +import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; |
| 17 | + |
| 18 | +export class DTSConnectionTypeListStep<T extends IDTSConnectionWizardContext> extends AzureWizardPromptStep<T> { |
| 19 | + constructor(readonly connectionTypes: Set<ConnectionType>) { |
| 20 | + super(); |
| 21 | + } |
| 22 | + |
| 23 | + public async prompt(context: T): Promise<void> { |
| 24 | + const connectAzureButton = { title: localize('connectAzureTaskScheduler', 'Connect Azure Task Scheduler'), data: ConnectionType.Azure }; |
| 25 | + const connectEmulatorButton = { title: useEmulator, data: ConnectionType.Emulator }; |
| 26 | + const connectCustomDTSButton = { title: localize('connectCustomTaskScheduler', 'Manually Set a Connection String'), data: ConnectionType.Custom }; |
| 27 | + |
| 28 | + const buttons: MessageItem[] = []; |
| 29 | + if (this.connectionTypes.has(ConnectionType.Azure)) { |
| 30 | + buttons.push(connectAzureButton); |
| 31 | + } |
| 32 | + if (this.connectionTypes.has(ConnectionType.Emulator)) { |
| 33 | + buttons.push(connectEmulatorButton); |
| 34 | + } |
| 35 | + if (this.connectionTypes.has(ConnectionType.Custom)) { |
| 36 | + buttons.push(connectCustomDTSButton); |
| 37 | + } |
| 38 | + |
| 39 | + const message: string = localize('selectDTSConnection', 'Durable Functions needs to be configured to use a Durable Task Scheduler.'); |
| 40 | + context.dtsConnectionType = (await context.ui.showWarningMessage(message, { modal: true }, ...buttons) as { |
| 41 | + title: string; |
| 42 | + data: ConnectionType; |
| 43 | + }).data; |
| 44 | + |
| 45 | + context.telemetry.properties.dtsConnectionType = context.dtsConnectionType; |
| 46 | + } |
| 47 | + |
| 48 | + public shouldPrompt(context: T): boolean { |
| 49 | + return !context.dtsConnectionType; |
| 50 | + } |
| 51 | + |
| 52 | + public async getSubWizard(context: T): Promise<IWizardOptions<T> | undefined> { |
| 53 | + const promptSteps: AzureWizardPromptStep<T>[] = []; |
| 54 | + const executeSteps: AzureWizardExecuteStep<T>[] = []; |
| 55 | + |
| 56 | + switch (context.dtsConnectionType) { |
| 57 | + case ConnectionType.Azure: |
| 58 | + throw new Error('Needs implementation.'); |
| 59 | + case ConnectionType.Emulator: |
| 60 | + executeSteps.push(new DTSEmulatorStartStep()); |
| 61 | + break; |
| 62 | + case ConnectionType.Custom: |
| 63 | + promptSteps.push( |
| 64 | + new DTSConnectionCustomPromptStep(), |
| 65 | + new DTSHubNameCustomPromptStep(), |
| 66 | + ); |
| 67 | + break; |
| 68 | + } |
| 69 | + |
| 70 | + executeSteps.push( |
| 71 | + new DTSConnectionSetSettingStep(), |
| 72 | + new DTSHubNameSetSettingStep(), |
| 73 | + ); |
| 74 | + |
| 75 | + return { promptSteps, executeSteps }; |
| 76 | + } |
| 77 | +} |
0 commit comments