コード例 #1
0
        private void AddOrUpdateControllerImplementations(RamlChooserActionParams parameters, string contractsFolderPath, Project proj,
                                                          WebApiGeneratorModel model, ProjectItem folderItem, string extensionPath)
        {
            templatesManager.CopyServerTemplateToProjectFolder(contractsFolderPath, ControllerImplementationTemplateName,
                                                               Settings.Default.ControllerImplementationTemplateTitle, TemplateSubFolder);
            var controllersFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, "Controllers");

            var templatesFolder = Path.Combine(contractsFolderPath, "Templates");
            var controllerImplementationTemplateParams =
                new TemplateParams <ControllerObject>(
                    Path.Combine(templatesFolder, ControllerImplementationTemplateName),
                    controllersFolderItem, "controllerObject", model.Controllers, contractsFolderPath, folderItem,
                    extensionPath, parameters.TargetNamespace, "Controller", false,
                    GetVersionPrefix(parameters.IncludeApiVersionInRoutePrefix, model.ApiVersion))
            {
                TargetFolder     = TargetFolderResolver.GetImplementationControllersFolderPath(proj, parameters.ImplementationControllersFolder),
                RelativeFolder   = parameters.ImplementationControllersFolder,
                Title            = Settings.Default.ControllerImplementationTemplateTitle,
                IncludeHasModels = true,
                HasModels        = model.Objects.Any(o => o.IsScalar == false) || model.Enums.Any(),
                UseAsyncMethods  = parameters.UseAsyncMethods,
                IncludeApiVersionInRoutePrefix = parameters.IncludeApiVersionInRoutePrefix,
                ApiVersion = model.ApiVersion
            };

            codeGenerator.GenerateCodeFromTemplate(controllerImplementationTemplateParams);
        }
コード例 #2
0
        private void AddOrUpdateControllerImplementations(string targetNamespace, string generatedFolderPath, Project proj,
                                                          WebApiGeneratorModel model, ProjectItem folderItem, string extensionPath, bool useAsyncMethods)
        {
            templatesManager.CopyServerTemplateToProjectFolder(generatedFolderPath, ControllerImplementationTemplateName,
                                                               Settings.Default.ControllerImplementationTemplateTitle);
            var controllersFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, "Controllers");
            var controllersFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar + "Controllers" +
                                        Path.DirectorySeparatorChar;
            var templatesFolder = Path.Combine(generatedFolderPath, "Templates");
            var controllerImplementationTemplateParams =
                new TemplateParams <ControllerObject>(Path.Combine(templatesFolder, ControllerImplementationTemplateName),
                                                      controllersFolderItem, "controllerObject", model.Controllers, controllersFolderPath, folderItem,
                                                      extensionPath, targetNamespace, "Controller", false);

            controllerImplementationTemplateParams.Title            = Settings.Default.ControllerImplementationTemplateTitle;
            controllerImplementationTemplateParams.IncludeHasModels = true;
            controllerImplementationTemplateParams.HasModels        = model.Objects.Any() || model.Enums.Any();
            controllerImplementationTemplateParams.UseAsyncMethods  = useAsyncMethods;
            GenerateCodeFromTemplate(controllerImplementationTemplateParams);
        }