public void ScaffoldToProject(RamlChooserActionParams parameters, Project proj)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            var data = parameters.Data;

            if (data == null || data.RamlDocument == null)
            {
                return;
            }

            var model = new WebApiGeneratorService(data.RamlDocument, parameters.ControllersNamespace, parameters.ModelsNamespace).BuildModel();

            var unitTestsFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, UnitTestsFolderName);
            var unitTestsFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar +
                                      UnitTestsFolderName + Path.DirectorySeparatorChar;

            var templates = new[]
            {
                UnitTestsControllerTemplateName,
                UnitTestsControllerImplementationTemplateName,
                ModelTemplateName,
                EnumTemplateName
            };

            if (!templatesManager.ConfirmWhenIncompatibleServerTemplate(unitTestsFolderPath, templates))
            {
                return;
            }

            var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar;

            AddOrUpdateUnitTestsControllerBase(parameters, unitTestsFolderPath, model, unitTestsFolderItem, extensionPath);
            AddOrUpdateUnitTestsControllerImplementations(parameters, unitTestsFolderPath, proj, model, unitTestsFolderItem, extensionPath);
        }
        public void Scaffold(string ramlSource, RamlChooserActionParams parameters)
        {
            var data = parameters.Data;

            if (data == null || data.RamlDocument == null)
            {
                return;
            }

            var model = new WebApiGeneratorService(data.RamlDocument, parameters.ControllersNamespace, parameters.ModelsNamespace).BuildModel();

            var dte  = ServiceProvider.GetService(typeof(SDTE)) as DTE;
            var proj = VisualStudioAutomationHelper.GetActiveProject(dte);

            var contractsFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, ContractsFolderName);
            var ramlItem            =
                contractsFolderItem.ProjectItems.Cast <ProjectItem>()
                .First(i => i.Name.ToLowerInvariant() == parameters.TargetFileName.ToLowerInvariant());
            var contractsFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar +
                                      ContractsFolderName + Path.DirectorySeparatorChar;

            var templates = new[]
            {
                ControllerBaseTemplateName,
                ControllerInterfaceTemplateName,
                ControllerImplementationTemplateName,
                ModelTemplateName,
                EnumTemplateName
            };

            if (!templatesManager.ConfirmWhenIncompatibleServerTemplate(contractsFolderPath, templates))
            {
                return;
            }

            var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar;

            AddOrUpdateModels(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath);

            AddOrUpdateEnums(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath);

            AddOrUpdateControllerBase(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath);

            AddOrUpdateControllerInterfaces(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath);

            AddOrUpdateControllerImplementations(parameters, contractsFolderPath, proj, model, contractsFolderItem, extensionPath);

            AddJsonSchemaParsingErrors(model.Warnings, contractsFolderPath, contractsFolderItem, ramlItem);

            if (parameters.GenerateUnitTests.HasValue && parameters.GenerateUnitTests.Value)
            {
                var testsProj = VisualStudioAutomationHelper.GetProject(dte, parameters.TestsProjectName);

                parameters.TestsNamespace = VisualStudioAutomationHelper.GetDefaultNamespace(testsProj) + "." +
                                            NetNamingMapper.GetObjectName(Path.GetFileNameWithoutExtension(parameters.RamlFilePath));

                var unitTestsScaffoldService = UnitTestsScaffoldServiceBase.GetScaffoldService(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider);
                unitTestsScaffoldService.InstallDependencies(testsProj);
                unitTestsScaffoldService.ScaffoldToProject(parameters, testsProj);
            }
        }