Beispiel #1
0
        public static async Task <IEnumerable <GeneratedObject> > BuildObjectModelAsync(
            IEnumerable <SObjectDescription> sObjects,
            DesignTimeAuthentication authentication,
            GeneratedService generatedService,
            ConnectedServiceLogger logger)
        {
            IEnumerable <SObjectDescription> sObjectsWithDetails = await MetadataLoader.LoadObjectDetailsAsync(sObjects, authentication);

            IEnumerable <GeneratedObject> generatedObjects = sObjectsWithDetails
                                                             .Select(o => new GeneratedObject()
            {
                Model             = o,
                Service           = generatedService,
                StorageProperties = CodeModelBuilder.BuildStorageProperties(o, logger)
            })
                                                             .ToArray();

            return(generatedObjects);
        }
        public static async Task<IEnumerable<GeneratedObject>> BuildObjectModelAsync(
            IEnumerable<SObjectDescription> sObjects,
            DesignTimeAuthentication authentication,
            GeneratedService generatedService,
            ConnectedServiceLogger logger)
        {
            IEnumerable<SObjectDescription> sObjectsWithDetails = await MetadataLoader.LoadObjectDetailsAsync(sObjects, authentication);

            IEnumerable<GeneratedObject> generatedObjects = sObjectsWithDetails
                .Select(o => new GeneratedObject()
                {
                    Model = o,
                    Service = generatedService,
                    StorageProperties = CodeModelBuilder.BuildStorageProperties(o, logger)
                })
                .ToArray();

            return generatedObjects;
        }
        private static IEnumerable<ITextTemplatingSession> GetServiceT4Sessions(ITextTemplatingSessionHost host, GeneratedService generatedService)
        {
            ITextTemplatingSession session = host.CreateSession();
            session["generatedService"] = generatedService;

            yield return session;
        }
        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);
            }
        }