Esempio n. 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);
        }
Esempio n. 2
0
        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
            var currentFile     = DTEHelper.GetProjectItemRelativePath(projectItem);
            var viewLocation    = Path.GetDirectoryName(DTEHelper.GetProjectItemRelativePath(projectItem));
            var allProjectItems = DTEHelper.GetAllProjectItems().Select(DTEHelper.GetProjectItemRelativePath).ToList();

            viewModel = new PageWindowViewModel()
            {
                ViewName          = projectItem.Name,
                ViewLocation      = viewLocation,
                CreateViewModel   = true,
                ViewModelName     = WizardHelpers.GenerateViewModelName(Path.GetFileNameWithoutExtension(projectItem.Name)),
                ViewModelLocation = WizardHelpers.GenerateViewModelLocation(viewLocation),
                MasterPages       = allProjectItems
                                    .Where(p => p.EndsWith(".dotmaster", StringComparison.CurrentCultureIgnoreCase))
                                    .OrderBy(p => p)
                                    .Where(p => !string.Equals(p, currentFile, StringComparison.CurrentCultureIgnoreCase))
                                    .ToList(),
                Folders = allProjectItems
                          .Select(p => p.Substring(0, p.LastIndexOfAny(new[] { '/', '\\' }) + 1).TrimEnd('/', '\\'))
                          .Distinct()
                          .OrderBy(p => p)
                          .ToList()
            };

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

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

            // generate items
            DTEHelper.ExecuteSafe(() => GenerateView(viewModel, projectItem), "Couldn't create the view!");
            if (viewModel.CreateViewModel)
            {
                DTEHelper.ExecuteSafe(() => GenerateViewModel(viewModel, projectItem.ContainingProject), "Couldn't create the viewmodel!");
            }
        }
Esempio n. 3
0
        private void GenerateView(PageWindowViewModel pageWindowViewModel, ProjectItem projectItem)
        {
            if (pageWindowViewModel.EmbedInMasterPage)
            {
                // try to extract placeholders from the master page
                var masterPageFileName = Path.Combine(DTEHelper.GetProjectPath(projectItem.ContainingProject), pageWindowViewModel.MasterPageLocation);
                pageWindowViewModel.ContentPlaceHolderIds = new MasterPageBuilder().ExtractPlaceHolderIds(masterPageFileName);
            }

            // generate namespace for viewmodel
            var rootNamespace = projectItem.ContainingProject.Properties.Item("DefaultNamespace").Value as string;

            pageWindowViewModel.ViewModelNamespace     = WizardHelpers.GenerateViewModelNamespace(rootNamespace, pageWindowViewModel.ViewModelLocation);
            pageWindowViewModel.ViewModelRootNamespace = rootNamespace;

            // run template
            var template = new PageTemplate()
            {
                ViewModel = pageWindowViewModel
            };

            File.WriteAllText(DTEHelper.GetProjectItemFullPath(projectItem), template.TransformText(), Encoding.UTF8);
        }
Esempio n. 4
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!");
            }
        }