/// <summary> /// Returns a suffix for the generated artifacts which guarantees that they don't conflict with any /// existing artifacts in the project. /// </summary> private static string GetGeneratedArtifactSuffix(ConnectedServiceHandlerContext context, Project project, AuthenticationStrategy authStrategy) { using (XmlConfigHelper configHelper = context.CreateReadOnlyXmlConfigHelper()) { return(GeneralUtilities.GetUniqueSuffix(suffix => { string serviceName = SalesforceConnectedServiceHandler.GetServiceInstanceName(suffix); return configHelper.IsPrefixUsedInAppSettings(serviceName) || (authStrategy == AuthenticationStrategy.WebServerFlow && configHelper.IsHandlerNameUsed(Constants.OAuthRedirectHandlerNameFormat.FormatInvariantCulture(serviceName))) || SalesforceConnectedServiceHandler.IsSuffixUsedInGeneratedFilesDirectories(context, serviceName, project); })); } }
public override async Task <AddServiceInstanceResult> AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct) { await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingConnectedService); SalesforceConnectedServiceInstance salesforceInstance = (SalesforceConnectedServiceInstance)context.ServiceInstance; try { Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy); string generatedArtifactSuffix = SalesforceConnectedServiceHandler.GetGeneratedArtifactSuffix( context, project, salesforceInstance.RuntimeAuthentication.AuthStrategy); salesforceInstance.DesignerData.ServiceName = SalesforceConnectedServiceHandler.GetServiceInstanceName(generatedArtifactSuffix); await TaskScheduler.Default; // Switch to a worker thread to avoid blocking the UI thread (e.g. the progress dialog). await SalesforceConnectedServiceHandler.CreateConnectedAppAsync(context, project, salesforceInstance); await SalesforceConnectedServiceHandler.UpdateConfigFileAsync(context, project, salesforceInstance); await this.AddNuGetPackagesAsync(context, project); await SalesforceConnectedServiceHandler.AddAssemblyReferencesAsync(context, salesforceInstance); await SalesforceConnectedServiceHandler.AddGeneratedCodeAsync(context, project, salesforceInstance); salesforceInstance.DesignerData.StoreExtendedDesignerData(context); salesforceInstance.TelemetryHelper.TrackAddServiceSucceededEvent(salesforceInstance); await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddedConnectedService); return(new AddServiceInstanceResult( salesforceInstance.DesignerData.ServiceName, new Uri(Constants.NextStepsUrl))); } catch (Exception e) { salesforceInstance.TelemetryHelper.TrackAddServiceFailedEvent(salesforceInstance, e); throw; } }