Exemplo n.º 1
0
 	private static void NewViewsConvention()
 	{
 		codeGenServiceFake = new Mock<ICodeGeneratorService>();
 		viewsConvention = new ViewsConvention(codeGenServiceFake.Object, new ModelFactory());
 	}
Exemplo n.º 2
0
        public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            pcbOutput = 0;

            var t4CodeGenerator = new T4CodeGeneratorService();
            var statusBarService = new VsStatusBarService();

            var projectItem = GetService(typeof (EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
            var dte = projectItem.DTE;

            var factory = new VsIntegrationModelFactory(dte);
            var solution = factory.NewSolution(dte.FullName);

            statusBarService.SetText(string.Format(statusBarStringTemplate, "Code generation begins"));

            var mvvmParser = new Parser();
            var mvvmSpec = mvvmParser.Parse(Code.Inline(bstrInputFileContents));

            var mvvmFile = TreeWalker.FindFileInSolution(solution, wszInputFilePath);

            var mvvmConfig = new HashSet<string>();

            var mvvmConfigFileName = string.Format("{0}conf", mvvmFile.Name);
            if (mvvmFile.Parent.HasFile(mvvmConfigFileName))
            {
                var codeGenConfigDslParser = new CodeGeneratorConfig.Parser();
                mvvmConfig = codeGenConfigDslParser.Parse(Code.FromFile(Path.Combine(mvvmFile.DirectoryPath, mvvmConfigFileName)));
            }

            statusBarService.SetText(string.Format(statusBarStringTemplate, "Generating ViewModels"));
            var viewModelsConvention = new GeneratedViewModelsConvention(t4CodeGenerator);
            viewModelsConvention.Apply(mvvmSpec, mvvmFile);

            if (mvvmConfig.Contains("partial viewmodels"))
            {
                statusBarService.SetText(string.Format(statusBarStringTemplate, "Generating Partial classes for ViewModels"));
                var partialViewModelsConvention = new PartialViewModelsConvention(t4CodeGenerator);
                partialViewModelsConvention.Apply(mvvmSpec, mvvmFile);
            }

            if (mvvmConfig.Contains("views"))
            {
                statusBarService.SetText(string.Format(statusBarStringTemplate, "Generating Views for ViewModels"));
                var viewsConvention = new ViewsConvention(t4CodeGenerator, factory);
                viewsConvention.Apply(mvvmSpec, mvvmFile);
            }

            if (mvvmConfig.Contains("controllers"))
            {
                statusBarService.SetText(string.Format(statusBarStringTemplate, "Generating Controllers for ViewModels"));
                var controllersConvention = new ControllersConvention(t4CodeGenerator, factory);
                controllersConvention.Apply(mvvmSpec, mvvmFile);
            }

            if (mvvmConfig.Contains("tests"))
            {
                statusBarService.SetText(string.Format(statusBarStringTemplate, "Generating Unit Tests for ViewModels"));
                var unitTestsConvention = new UnitTestsConvention(t4CodeGenerator, factory);
                unitTestsConvention.Apply(mvvmSpec, mvvmFile);
            }

            statusBarService.SetText(string.Format(statusBarStringTemplate, "Generating ViewModels Completed :)"));

            return VSConstants.S_OK;
        }