public void Apply(ModelSpecification mvvmDefinition, File mvvmFile) { var project = mvvmFile.Project; if (!project.HasFolder(Views)) { project.AddFolder(factory.NewFolder(Views, project)); } foreach (var viewModel in mvvmDefinition.ViewModels) { var fileName = string.Format("{0}.xaml", viewModel.Name); var codeBehindFileName = string.Format("{0}.xaml.cs", viewModel.Name); var viewsFolder = project.GetSubFolder(Views); if (!viewsFolder.HasFile(fileName)) { var viewFile = factory.NewFile(fileName, viewsFolder); viewsFolder.AddFile(viewFile); codeGeneratorService.Generate(mvvmFile, viewFile, new CodeGeneratorArgs(mvvmDefinition, viewModel, viewCodeGenTemplate)); var viewCodeBehindFile = viewFile.NewCodeBehindFile(codeBehindFileName); codeGeneratorService.Generate(mvvmFile, viewCodeBehindFile, new CodeGeneratorArgs(mvvmDefinition, viewModel, viewCodeBehindCodeGenTemplate)); } } }
public void Apply(ModelSpecification viewModelSpecification, File mvvmFile) { this.mvvmFile = mvvmFile; this.viewModelSpecification = viewModelSpecification; RemoveDeletedViewModelsFromCodeBehind(); AddNewViewModelsToCodeBehind(); }
internal static Stack<Folder> GetFolderStack(File file) { var folderStack = new Stack<Folder>(); Folder parent = file.Parent; while (parent != null && !(parent is Project)) { folderStack.Push(parent); parent = parent.Parent; } return folderStack; }
public void Apply(ModelSpecification mvvmDefinition, File mvvmFile) { var viewModelFolder = mvvmFile.Parent; foreach (var viewModel in mvvmDefinition.ViewModels) { var name = string.Format("{0}.cs", viewModel.Name); if (!viewModelFolder.HasFile(name)) { var newFile = viewModelFolder.NewFile(name); codeGeneratorService.Generate(mvvmFile, newFile, new CodeGeneratorArgs(mvvmDefinition, viewModel, codeGeneratorTemplate)); } } }
private Folder CreateFolderInUnitTestProject(File mvvmFile, Project testProject) { var folderStack = TreeWalker.GetFolderStack(mvvmFile); var folderInUnitTestProj = testProject as Folder; while (folderStack.Count > 0) { var folderToCreate = folderStack.Pop(); if (!folderInUnitTestProj.HasFolder(folderToCreate.Name)) folderInUnitTestProj.AddFolder(factory.NewFolder(folderToCreate.Name, folderInUnitTestProj)); folderInUnitTestProj = folderInUnitTestProj.GetSubFolder(folderToCreate.Name); } return folderInUnitTestProj; }
public void Apply(ModelSpecification viewModelSpecification, File mvvmFile) { var project = mvvmFile.Project; var solution = project.Solution; var testProject = solution.Projects.Where(p => p.Name == string.Format("{0}.Tests", project.Name) || p.Name == string.Format("{0}Tests", project.Name)).FirstOrDefault(); if (testProject != null) { Folder folderInUnitTestProj = CreateFolderInUnitTestProject(mvvmFile, testProject); if (!folderInUnitTestProj.HasFolder("TestScenarios")) folderInUnitTestProj.AddFolder(factory.NewFolder("TestScenarios", folderInUnitTestProj)); var testScenariosFolder = folderInUnitTestProj.GetSubFolder("TestScenarios"); foreach (var viewModel in viewModelSpecification.ViewModels) { var testScenarioFileName = string.Format("{0}TestScenario.cs", viewModel.Name); var unitTestFileName = string.Format("{0}Tests.cs", viewModel.Name); if (!testScenariosFolder.HasFile(testScenarioFileName)) { var testScenarioFile = factory.NewFile(testScenarioFileName, testScenariosFolder); testScenariosFolder.AddFile(testScenarioFile); } codeGeneratorService.Generate(mvvmFile, testScenariosFolder.GetFile(testScenarioFileName), new CodeGeneratorArgs(viewModelSpecification, viewModel, testScenarioCodeGenTemplate)); //UnitTests if (!folderInUnitTestProj.HasFile(unitTestFileName)) { var unitTestFile = factory.NewFile(unitTestFileName, folderInUnitTestProj); folderInUnitTestProj.AddFile(unitTestFile); codeGeneratorService.Generate(mvvmFile, unitTestFile, new CodeGeneratorArgs(viewModelSpecification, viewModel, unitTestCodeGenTemplate)); } } } }
public void Apply(ModelSpecification viewModelSpecification, File mvvmFile) { var project = mvvmFile.Project as Project; if (!project.HasFolder(Controllers)) project.AddFolder(factory.NewFolder(Controllers, project)); var controllersFolder = project.GetSubFolder(Controllers); foreach (var viewModel in viewModelSpecification.ViewModels) { var fileName = string.Format("{0}Controller.cs", viewModel.Name); if (!controllersFolder.HasFile(fileName)) { controllersFolder.NewFile(fileName); var controllerFile = controllersFolder.GetFile(fileName); codeGeneratorService.Generate(mvvmFile, controllerFile, new CodeGeneratorArgs(viewModelSpecification, viewModel, codeGenTemplate)); } } }
public void File_is_spawned() { file = folder.NewFile(filename); }
public virtual void AddFile(File file) { if (file == null) throw new ArgumentNullException(); Items.Add(file); }
public virtual File NewFile(string name) { if (HasFile(name)) throw new ArgumentException("File already exists"); ThrowExceptionIfPathIsNotSet(); var newFile = new File(this) { Name = name }; newFile.Parent = this; newFile.DirectoryPath = DirectoryPath; Items.Add(newFile); return newFile; }