Ejemplo n.º 1
0
        private static async Task AddGeneratedObjectCodeAsync(
            ConnectedServiceHandlerContext context,
            Project project,
            SalesforceConnectedServiceInstance salesforceInstance,
            GeneratedService generatedService,
            string modelsHintPath)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_BuildingObjectModel);

            IEnumerable <GeneratedObject> generatedObjects = await CodeModelBuilder.BuildObjectModelAsync(
                salesforceInstance.SelectedObjects,
                salesforceInstance.DesignTimeAuthentication,
                generatedService,
                context.Logger);

            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingGeneratedCodeForObjects, generatedObjects.Count());

            await GeneratedCodeHelper.AddGeneratedCodeAsync(
                context,
                project,
                "SalesforceObject",
                modelsHintPath,
                (host) => SalesforceConnectedServiceHandler.GetObjectT4Sessions(host, generatedObjects),
                () => new SalesforceObject(),
                (session) => ((GeneratedObject)session["generatedObject"]).Model.Name);
        }
Ejemplo n.º 2
0
        private static async Task AddGeneratedServiceCodeAsync(
            ConnectedServiceHandlerContext context,
            Project project,
            SalesforceConnectedServiceInstance salesforceInstance,
            GeneratedService generatedService)
        {
            string serviceDirectoryName = SalesforceConnectedServiceHandler.GetServiceDirectoryName(context, salesforceInstance.DesignerData.ServiceName);

            await GeneratedCodeHelper.AddGeneratedCodeAsync(
                context,
                project,
                "SalesforceService",
                serviceDirectoryName,
                (host) => SalesforceConnectedServiceHandler.GetServiceT4Sessions(host, generatedService),
                () => new SalesforceService(),
                (session) => "SalesforceService");

            if (salesforceInstance.RuntimeAuthentication.AuthStrategy == AuthenticationStrategy.WebServerFlow)
            {
                await GeneratedCodeHelper.AddGeneratedCodeAsync(
                    context,
                    project,
                    Constants.OAuthRedirectHandlerTypeName,
                    serviceDirectoryName,
                    (host) => SalesforceConnectedServiceHandler.GetServiceT4Sessions(host, generatedService),
                    () => new SalesforceOAuthRedirectHandler(),
                    (session) => Constants.OAuthRedirectHandlerTypeName);
            }
        }
        public override Task <ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            this.userSettings.Save();

            SalesforceConnectedServiceInstance serviceInstance = new SalesforceConnectedServiceInstance();

            serviceInstance.DesignerData             = this.DesignerData;
            serviceInstance.DesignTimeAuthentication = this.designTimeAuthenticationViewModel.Authentication;
            serviceInstance.RuntimeAuthentication    = this.runtimeAuthenticationConfigViewModel.RuntimeAuthentication;
            serviceInstance.SelectedObjects          = this.objectSelectionViewModel.GetSelectedObjects();
            serviceInstance.TelemetryHelper          = this.telemetryHelper;

            this.telemetryHelper.TrackWizardFinishedEvent(serviceInstance, this.objectSelectionViewModel);

            return(Task.FromResult <ConnectedServiceInstance>(serviceInstance));
        }
        public override async Task <UpdateServiceInstanceResult> UpdateServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_UpdatingConnectedService);

            SalesforceConnectedServiceInstance salesforceInstance = (SalesforceConnectedServiceInstance)context.ServiceInstance;

            try
            {
                Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy);

                await TaskScheduler.Default; // Switch to a worker thread to avoid blocking the UI thread (e.g. the progress dialog).

                // Update currently only supports adding additional scaffolded objects.  Before they are added, ensure the correct NuGets are
                // installed.  Additionally, ensure the required assemblies exist as not all are added initially if no objects are scaffolded.
                await this.AddNuGetPackagesAsync(context, project);

                await SalesforceConnectedServiceHandler.AddAssemblyReferencesAsync(context, salesforceInstance);

                try
                {
                    await SalesforceConnectedServiceHandler.AddGeneratedCodeAsync(context, project, salesforceInstance);
                }
                catch (COMException comException)
                {
                    if (comException.HResult == -2147467259)
                    {
                        // Provide a better exception message for when an invalid path ModelsHintPath was specified.
                        throw new InvalidOperationException(
                                  Resources.LogMessage_InvalidModelsHintPath.FormatCurrentCulture(salesforceInstance.DesignerData.ModelsHintPath),
                                  comException);
                    }
                }

                salesforceInstance.DesignerData.StoreExtendedDesignerData(context);

                salesforceInstance.TelemetryHelper.TrackUpdateServiceSucceededEvent(salesforceInstance);
                await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_UpdatedConnectedService);

                return(new UpdateServiceInstanceResult());
            }
            catch (Exception e)
            {
                salesforceInstance.TelemetryHelper.TrackUpdateServiceFailedEvent(salesforceInstance, e);
                throw;
            }
        }
        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;
            }
        }
Ejemplo n.º 6
0
        private static async Task AddGeneratedCodeAsync(ConnectedServiceHandlerContext context, Project project, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingGeneratedCode);

            string           modelsHintPath   = salesforceInstance.DesignerData.GetDefaultedModelsHintPath();
            GeneratedService generatedService = new GeneratedService()
            {
                ServiceNamespace       = SalesforceConnectedServiceHandler.GetServiceNamespace(project, salesforceInstance.DesignerData.ServiceName),
                ModelsNamespace        = SalesforceConnectedServiceHandler.GetModelsNamespace(project, modelsHintPath),
                DefaultNamespace       = ProjectHelper.GetProjectNamespace(project),
                AuthenticationStrategy = salesforceInstance.RuntimeAuthentication.AuthStrategy,
                ConfigurationKeyNames  = new ConfigurationKeyNames(salesforceInstance.DesignerData.ServiceName),
            };

            if (!context.IsUpdating)
            {
                await SalesforceConnectedServiceHandler.AddGeneratedServiceCodeAsync(context, project, salesforceInstance, generatedService);
            }

            if (salesforceInstance.SelectedObjects.Any())
            {
                // Only set the ModelsHintPath in the case where objects are generated so that it is only added to
                // the ConnectedService.json when it is applicable.
                salesforceInstance.DesignerData.ModelsHintPath = modelsHintPath;

                await SalesforceConnectedServiceHandler.AddGeneratedObjectCodeAsync(context, project, salesforceInstance, generatedService, modelsHintPath);
            }
        }
Ejemplo n.º 7
0
        private static async Task AddAssemblyReferencesAsync(ConnectedServiceHandlerContext context, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingAssemblyReferences);

            await SalesforceConnectedServiceHandler.AddAssemblyReferenceAsync(context, "System.Configuration");

            await SalesforceConnectedServiceHandler.AddAssemblyReferenceAsync(context, "System.Web");

            if (salesforceInstance.SelectedObjects.Any())
            {
                await SalesforceConnectedServiceHandler.AddAssemblyReferenceAsync(context, "System.ComponentModel.DataAnnotations");
            }
        }
Ejemplo n.º 8
0
        private static async Task UpdateConfigFileAsync(ConnectedServiceHandlerContext context, Project project, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // The EditableConfigHelper must run on the UI thread.

            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_UpdatingConfigFile);

            using (EditableXmlConfigHelper configHelper = context.CreateEditableXmlConfigHelper())
            {
                foreach (ConfigSetting configSetting in salesforceInstance.RuntimeAuthentication.GetConfigSettings(salesforceInstance.ConnectedAppName))
                {
                    configHelper.SetAppSetting(
                        ConfigurationKeyNames.GetQualifiedKeyName(configSetting.Key, salesforceInstance.DesignerData.ServiceName),
                        configSetting.Value == null ? string.Empty : configSetting.Value.ToString(),
                        configSetting.Comment);
                }

                if (salesforceInstance.RuntimeAuthentication.AuthStrategy == AuthenticationStrategy.WebServerFlow)
                {
                    string handlerName = Constants.OAuthRedirectHandlerNameFormat.FormatInvariantCulture(salesforceInstance.DesignerData.ServiceName);
                    string qualifiedHandlerTypeName = SalesforceConnectedServiceHandler.GetServiceNamespace(project, salesforceInstance.DesignerData.ServiceName)
                                                      + Type.Delimiter + Constants.OAuthRedirectHandlerTypeName;
                    string redirectUri = ((WebServerFlowInfo)salesforceInstance.RuntimeAuthentication).RedirectUri.ToString();

                    configHelper.RegisterRedirectHandler(handlerName, redirectUri, qualifiedHandlerTypeName);
                }

                configHelper.Save();
            }
        }
Ejemplo n.º 9
0
        private static async Task CreateConnectedAppAsync(ConnectedServiceHandlerContext context, Project project, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_CreatingConnectedApp);

            await ConnectedAppHelper.CreateConnectedAppAsync(salesforceInstance, context.Logger, project);
        }
        public override Task<ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            this.userSettings.Save();

            SalesforceConnectedServiceInstance serviceInstance = new SalesforceConnectedServiceInstance();
            serviceInstance.DesignerData = this.DesignerData;
            serviceInstance.DesignTimeAuthentication = this.designTimeAuthenticationViewModel.Authentication;
            serviceInstance.RuntimeAuthentication = this.runtimeAuthenticationConfigViewModel.RuntimeAuthentication;
            serviceInstance.SelectedObjects = this.objectSelectionViewModel.GetSelectedObjects();
            serviceInstance.TelemetryHelper = this.telemetryHelper;

            this.telemetryHelper.TrackWizardFinishedEvent(serviceInstance, this.objectSelectionViewModel);

            return Task.FromResult<ConnectedServiceInstance>(serviceInstance);
        }
        private static async Task AddGeneratedObjectCodeAsync(
            ConnectedServiceHandlerContext context,
            Project project,
            SalesforceConnectedServiceInstance salesforceInstance,
            GeneratedService generatedService,
            string modelsHintPath)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_BuildingObjectModel);
            IEnumerable<GeneratedObject> generatedObjects = await CodeModelBuilder.BuildObjectModelAsync(
                salesforceInstance.SelectedObjects,
                salesforceInstance.DesignTimeAuthentication,
                generatedService,
                context.Logger);

            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingGeneratedCodeForObjects, generatedObjects.Count());
            await GeneratedCodeHelper.AddGeneratedCodeAsync(
                context,
                project,
                "SalesforceObject",
                modelsHintPath,
                (host) => SalesforceConnectedServiceHandler.GetObjectT4Sessions(host, generatedObjects),
                () => new SalesforceObject(),
                (session) => ((GeneratedObject)session["generatedObject"]).Model.Name);
        }
        private static async Task AddGeneratedServiceCodeAsync(
            ConnectedServiceHandlerContext context,
            Project project,
            SalesforceConnectedServiceInstance salesforceInstance,
            GeneratedService generatedService)
        {
            string serviceDirectoryName = SalesforceConnectedServiceHandler.GetServiceDirectoryName(context, salesforceInstance.DesignerData.ServiceName);

            await GeneratedCodeHelper.AddGeneratedCodeAsync(
                context,
                project,
                "SalesforceService",
                serviceDirectoryName,
                (host) => SalesforceConnectedServiceHandler.GetServiceT4Sessions(host, generatedService),
                () => new SalesforceService(),
                (session) => "SalesforceService");

            if (salesforceInstance.RuntimeAuthentication.AuthStrategy == AuthenticationStrategy.WebServerFlow)
            {
                await GeneratedCodeHelper.AddGeneratedCodeAsync(
                    context,
                    project,
                    Constants.OAuthRedirectHandlerTypeName,
                    serviceDirectoryName,
                    (host) => SalesforceConnectedServiceHandler.GetServiceT4Sessions(host, generatedService),
                    () => new SalesforceOAuthRedirectHandler(),
                    (session) => Constants.OAuthRedirectHandlerTypeName);
            }
        }
        private static async Task AddGeneratedCodeAsync(ConnectedServiceHandlerContext context, Project project, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingGeneratedCode);

            string modelsHintPath = salesforceInstance.DesignerData.GetDefaultedModelsHintPath();
            GeneratedService generatedService = new GeneratedService()
            {
                ServiceNamespace = SalesforceConnectedServiceHandler.GetServiceNamespace(project, salesforceInstance.DesignerData.ServiceName),
                ModelsNamespace = SalesforceConnectedServiceHandler.GetModelsNamespace(project, modelsHintPath),
                DefaultNamespace = ProjectHelper.GetProjectNamespace(project),
                AuthenticationStrategy = salesforceInstance.RuntimeAuthentication.AuthStrategy,
                ConfigurationKeyNames = new ConfigurationKeyNames(salesforceInstance.DesignerData.ServiceName),
            };

            if (!context.IsUpdating)
            {
                await SalesforceConnectedServiceHandler.AddGeneratedServiceCodeAsync(context, project, salesforceInstance, generatedService);
            }

            if (salesforceInstance.SelectedObjects.Any())
            {
                // Only set the ModelsHintPath in the case where objects are generated so that it is only added to
                // the ConnectedService.json when it is applicable.
                salesforceInstance.DesignerData.ModelsHintPath = modelsHintPath;

                await SalesforceConnectedServiceHandler.AddGeneratedObjectCodeAsync(context, project, salesforceInstance, generatedService, modelsHintPath);
            }
        }
        private static async Task AddAssemblyReferencesAsync(ConnectedServiceHandlerContext context, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_AddingAssemblyReferences);

            await SalesforceConnectedServiceHandler.AddAssemblyReferenceAsync(context, "System.Configuration");
            await SalesforceConnectedServiceHandler.AddAssemblyReferenceAsync(context, "System.Web");

            if (salesforceInstance.SelectedObjects.Any())
            {
                await SalesforceConnectedServiceHandler.AddAssemblyReferenceAsync(context, "System.ComponentModel.DataAnnotations");
            }
        }
        private static async Task UpdateConfigFileAsync(ConnectedServiceHandlerContext context, Project project, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // The EditableConfigHelper must run on the UI thread.

            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_UpdatingConfigFile);

            using (EditableXmlConfigHelper configHelper = context.CreateEditableXmlConfigHelper())
            {
                foreach (ConfigSetting configSetting in salesforceInstance.RuntimeAuthentication.GetConfigSettings(salesforceInstance.ConnectedAppName))
                {
                    configHelper.SetAppSetting(
                        ConfigurationKeyNames.GetQualifiedKeyName(configSetting.Key, salesforceInstance.DesignerData.ServiceName),
                        configSetting.Value == null ? string.Empty : configSetting.Value.ToString(),
                        configSetting.Comment);
                }

                if (salesforceInstance.RuntimeAuthentication.AuthStrategy == AuthenticationStrategy.WebServerFlow)
                {
                    string handlerName = Constants.OAuthRedirectHandlerNameFormat.FormatInvariantCulture(salesforceInstance.DesignerData.ServiceName);
                    string qualifiedHandlerTypeName = SalesforceConnectedServiceHandler.GetServiceNamespace(project, salesforceInstance.DesignerData.ServiceName)
                        + Type.Delimiter + Constants.OAuthRedirectHandlerTypeName;
                    string redirectUri = ((WebServerFlowInfo)salesforceInstance.RuntimeAuthentication).RedirectUri.ToString();

                    configHelper.RegisterRedirectHandler(handlerName, redirectUri, qualifiedHandlerTypeName);
                }

                configHelper.Save();
            }
        }
        private static async Task CreateConnectedAppAsync(ConnectedServiceHandlerContext context, Project project, SalesforceConnectedServiceInstance salesforceInstance)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, Resources.LogMessage_CreatingConnectedApp);

            await ConnectedAppHelper.CreateConnectedAppAsync(salesforceInstance, context.Logger, project);
        }