Beispiel #1
0
        private void GenerateControl(ControlWindowViewModel controlWindowViewModel, ProjectItem projectItem)
        {
            // generate namespace for code behind
            var rootNamespace = projectItem.ContainingProject.Properties.Item("DefaultNamespace").Value as string;

            controlWindowViewModel.CodeBehindClassNamespace     = WizardHelpers.GenerateViewModelNamespace(rootNamespace, controlWindowViewModel.CodeBehindClassLocation);
            controlWindowViewModel.CodeBehindClassRootNamespace = rootNamespace;

            // run template
            var template = new ControlTemplate()
            {
                ViewModel = controlWindowViewModel
            };

            File.WriteAllText(DTEHelper.GetProjectItemFullPath(projectItem), template.TransformText(), Encoding.UTF8);
        }
Beispiel #2
0
        private void GenerateCodeBehindClass(ControlWindowViewModel controlWindowViewModel, Project project)
        {
            // find path
            var folder = DTEHelper.GetOrCreateFolder(project.ProjectItems, controlWindowViewModel.CodeBehindClassLocation);
            var codeBehindClassTemplatePath = Path.Combine(templateDir, "DotvvmControlCodeBehind.zip\\DotvvmControlCodeBehind.vstemplate");

            // create a code behind
            folder.AddFromTemplate(codeBehindClassTemplatePath, controlWindowViewModel.CodeBehindClassName);
            var projectItem = folder.OfType <ProjectItem>().FirstOrDefault(p => p.Name == controlWindowViewModel.CodeBehindClassName + ".cs");

            if (projectItem != null)
            {
                // regenerate the codebehind
                var template = new ControlCodeBehindTemplate()
                {
                    ViewModel = controlWindowViewModel
                };
                File.WriteAllText(DTEHelper.GetProjectItemFullPath(projectItem), template.TransformText(), Encoding.UTF8);
            }
        }
Beispiel #3
0
        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
            var controlLocation = Path.GetDirectoryName(DTEHelper.GetProjectItemRelativePath(projectItem));
            var allProjectItems = DTEHelper.GetAllProjectItems().Select(DTEHelper.GetProjectItemRelativePath).ToList();

            viewModel = new ControlWindowViewModel()
            {
                ControlName             = projectItem.Name,
                ControlLocation         = controlLocation,
                CreateCodeBehind        = false,
                CodeBehindClassName     = WizardHelpers.GenerateCodeBehindClassName(Path.GetFileNameWithoutExtension(projectItem.Name)),
                CodeBehindClassLocation = controlLocation,
                Folders = allProjectItems
                          .Select(p => p.Substring(0, p.LastIndexOfAny(new[] { '/', '\\' }) + 1).TrimEnd('/', '\\'))
                          .Distinct()
                          .OrderBy(p => p)
                          .ToList()
            };

            var window = new ControlWindow()
            {
                DataContext = viewModel
            };

            if (window.ShowDialog() != true)
            {
                throw new WizardCancelledException();
            }

            // generate items
            DTEHelper.ExecuteSafe(() => GenerateControl(viewModel, projectItem), "Couldn't create the control!");
            if (viewModel.CreateCodeBehind)
            {
                DTEHelper.ExecuteSafe(() => GenerateCodeBehindClass(viewModel, projectItem.ContainingProject), "Couldn't create the code behind file!");
            }
        }