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.ControllersNamespace, "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,
                ModelsNamespace = parameters.ModelsNamespace
            };

            codeGenerator.GenerateCodeFromTemplate(controllerImplementationTemplateParams);
        }
        private void AddOrUpdateModels(RamlChooserActionParams parameters, string contractsFolderPath, ProjectItem ramlItem, WebApiGeneratorModel model, ProjectItem contractsFolderItem, string extensionPath)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            templatesManager.CopyServerTemplateToProjectFolder(contractsFolderPath, ModelTemplateName,
                                                               RAML.Tools.Properties.Settings.Default.ModelsTemplateTitle, TemplateSubFolder);
            var templatesFolder = Path.Combine(contractsFolderPath, "Templates");

            var models = model.Objects;

            // when is an XML model, skip empty objects
            if (model.Objects.Any(o => !string.IsNullOrWhiteSpace(o.GeneratedCode)))
            {
                models = model.Objects.Where(o => o.Properties.Any() || !string.IsNullOrWhiteSpace(o.GeneratedCode));
            }

            // when array has no properties, set it collection on base type
            foreach (var arrayModel in models.Where(o => o.IsArray && o.Properties.Count == 0 && o.Type != null &&
                                                    CollectionTypeHelper.IsCollection(o.Type) && !NewNetTypeMapper.IsPrimitiveType(CollectionTypeHelper.GetBaseType(o.Type))))
            {
                arrayModel.BaseClass = arrayModel.Type.Substring(1); // remove the initil "I" to make it a concrete class
            }
            // skip array of primitives
            models = models.Where(o => o.Type == null || !(CollectionTypeHelper.IsCollection(o.Type) &&
                                                           NewNetTypeMapper.IsPrimitiveType(CollectionTypeHelper.GetBaseType(o.Type))));
            models = models.Where(o => !o.IsScalar); // skip scalar types

            var targetFolderPath = GetTargetFolderPath(contractsFolderPath, ramlItem.FileNames[0]);

            var apiObjectTemplateParams = new TemplateParams <ApiObject>(
                Path.Combine(templatesFolder, ModelTemplateName), ramlItem, "apiObject", models,
                contractsFolderPath, contractsFolderItem, extensionPath, parameters.ControllersNamespace,
                GetVersionPrefix(parameters.IncludeApiVersionInRoutePrefix, model.ApiVersion) +
                (parameters.AddGeneratedSuffixToFiles ? ".generated" : string.Empty))
            {
                Title          = RAML.Tools.Properties.Settings.Default.ModelsTemplateTitle,
                RelativeFolder = parameters.ModelsFolder,
                TargetFolder   = TargetFolderResolver.GetModelsTargetFolder(ramlItem.ContainingProject,
                                                                            targetFolderPath, parameters.ModelsFolder),
                ModelsNamespace = parameters.ModelsNamespace
            };

            codeGenerator.GenerateCodeFromTemplate(apiObjectTemplateParams);
        }
        private void AddOrUpdateEnums(RamlChooserActionParams parameters, string contractsFolderPath, ProjectItem ramlItem, WebApiGeneratorModel model, ProjectItem folderItem, string extensionPath)
        {
            templatesManager.CopyServerTemplateToProjectFolder(contractsFolderPath, EnumTemplateName,
                                                               Settings.Default.EnumsTemplateTitle, TemplateSubFolder);
            var templatesFolder = Path.Combine(contractsFolderPath, "Templates");

            var targetFolderPath = GetTargetFolderPath(contractsFolderPath, ramlItem.FileNames[0]);

            var apiEnumTemplateParams = new TemplateParams <ApiEnum>(
                Path.Combine(templatesFolder, EnumTemplateName), ramlItem, "apiEnum", model.Enums,
                targetFolderPath, folderItem, extensionPath, parameters.ControllersNamespace,
                GetVersionPrefix(parameters.IncludeApiVersionInRoutePrefix, model.ApiVersion))
            {
                Title          = Settings.Default.ModelsTemplateTitle,
                RelativeFolder = parameters.ModelsFolder,
                TargetFolder   = TargetFolderResolver.GetModelsTargetFolder(ramlItem.ContainingProject,
                                                                            targetFolderPath, parameters.ModelsFolder),
                ModelsNamespace = parameters.ModelsNamespace
            };

            codeGenerator.GenerateCodeFromTemplate(apiEnumTemplateParams);
        }