public static async createChild()

in apps/vs-code-designer/src/app/tree/subscriptionTree/SubscriptionTreeItem.ts [98:243]


  public static async createChild(context: ICreateLogicAppContext, subscription: SubscriptionTreeItem): Promise<SlotTreeItem> {
    const version: FuncVersion = await getDefaultFuncVersion(context);
    const language: string | undefined = getWorkspaceSettingFromAnyFolder(projectLanguageSetting);

    context.telemetry.properties.projectRuntime = version;
    context.telemetry.properties.projectLanguage = language;

    const wizardContext: ILogicAppWizardContext = Object.assign(context, subscription.subscription, {
      newSiteKind: AppKind.workflowapp,
      resourceGroupDeferLocationStep: true,
      version,
      language,
      newSiteRuntime: workflowappRuntime,
      ...(await createActivityContext()),
    });

    if (version === FuncVersion.v1) {
      // v1 doesn't support linux
      wizardContext.newSiteOS = WebsiteOS.windows;
    }

    await setRegionsTask(wizardContext);

    const promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[] = [];
    const executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] = [];

    promptSteps.push(new SiteNameStep());

    const locations = await getWebLocations({ ...wizardContext, newPlanSku: wizardContext.newPlanSku ?? { tier: 'ElasticPremium' } });
    CustomLocationListStep.setLocationSubset(wizardContext, Promise.resolve(locations), 'microsoft.resources');
    CustomLocationListStep.addStep(context as any, promptSteps);
    promptSteps.push(new LogicAppHostingPlanStep());

    const storageAccountCreateOptions: INewStorageAccountDefaults = {
      kind: StorageAccountKind.Storage,
      performance: StorageAccountPerformance.Standard,
      replication: StorageAccountReplication.LRS,
    };

    if (context.advancedCreation) {
      promptSteps.push(
        new StorageAccountListStep(storageAccountCreateOptions, {
          kind: [StorageAccountKind.BlobStorage],
          performance: [StorageAccountPerformance.Premium],
          replication: [StorageAccountReplication.ZRS],
          learnMoreLink: 'https://aka.ms/Cfqnrc',
        })
      );
      promptSteps.push(new AzureStorageAccountStep());
      promptSteps.push(new AppInsightsListStep());
    } else {
      wizardContext.runtimeFilter = getFunctionsWorkerRuntime(language);
    }

    const title: string = localize('functionAppCreatingTitle', 'Create new Logic App (Standard) in Azure');
    const wizard: AzureWizard<IAppServiceWizardContext> = new AzureWizard(wizardContext, { promptSteps, executeSteps, title });

    await wizard.prompt();

    if (wizardContext.useHybrid) {
      executeSteps.push(new ConnectEnvironmentStep());
      executeSteps.push(new HybridAppCreateStep());
    } else {
      executeSteps.push(new StorageAccountCreateStep(storageAccountCreateOptions));
      executeSteps.push(new AppInsightsCreateStep());
      executeSteps.push(new VerifyProvidersStep([webProvider, storageProvider, insightsProvider]));
      executeSteps.push(new LogicAppCreateStep());
    }

    if (wizardContext.customLocation && !wizardContext.useHybrid) {
      setSiteOS(wizardContext);
      executeSteps.pop();
    }

    wizardContext.activityTitle = localize(
      'logicAppCreateActivityTitle',
      'Creating Logic App "{0}"',
      nonNullProp(wizardContext, 'newSiteName')
    );

    context.telemetry.properties.os = wizardContext.newSiteOS;
    context.telemetry.properties.runtime = wizardContext.newSiteRuntime;

    if (!context.advancedCreation) {
      const baseName: string | undefined = await wizardContext.relatedNameTask;
      const newName = await generateRelatedName(wizardContext, baseName);
      if (!newName) {
        throw new Error(
          localize('noUniqueName', 'Failed to generate unique name for resources. Use advanced creation to manually enter resource names.')
        );
      }

      wizardContext.newStorageAccountName = newName;
      wizardContext.newAppInsightsName = newName;
    }

    if (ext.deploymentFolderPath) {
      let resourceGroupName: string | undefined;

      if (wizardContext.newResourceGroupName) {
        resourceGroupName = wizardContext.newResourceGroupName;
      } else if (wizardContext.resourceGroup && wizardContext.resourceGroup.name) {
        resourceGroupName = wizardContext.resourceGroup.name;
      }

      if (resourceGroupName) {
        await verifyDeploymentResourceGroup(context, resourceGroupName, ext.deploymentFolderPath);
      }
    }

    await wizard.execute();
    let resolved: LogicAppResourceTree | null = null;

    if (!wizardContext.useHybrid) {
      const site = new ParsedSite(nonNullProp(wizardContext, 'site'), subscription.subscription);
      const client: SiteClient = await site.createClient(context);

      if (!client.isLinux) {
        try {
          await enableFileLogging(client);
        } catch (error) {
          context.telemetry.properties.fileLoggingError = parseError(error).message;
        }
      }

      resolved = new LogicAppResourceTree(subscription.subscription, nonNullProp(wizardContext, 'site'));
      const logicAppMap = ext.subscriptionLogicAppMap.get(subscription.subscription.subscriptionId);
      if (logicAppMap) {
        logicAppMap.set(wizardContext.site.id.toLowerCase(), wizardContext.site);
      }
      await ext.rgApi.appResourceTree.refresh(context);
    }

    const slotTreeItem = new SlotTreeItem(subscription, resolved, {
      isHybridLogiApp: wizardContext.useHybrid,
      hybridSite: wizardContext.hybridSite,
      location: wizardContext.customLocation
        ? wizardContext.customLocation.kubeEnvironment.location.replace(/[()]/g, '')
        : wizardContext._location.name,
      fileShare: wizardContext.fileShare,
      connectedEnvironment: wizardContext.connectedEnvironment,
      resourceGroupName: wizardContext.resourceGroup.name,
      sqlConnectionString: wizardContext.sqlConnectionString,
    });
    return slotTreeItem;
  }