예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuleViewModel" /> class.
        /// </summary>
        /// <param name="rootProject">The root project this rule belongs to.</param>
        /// <param name="rule">The rule.</param>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="uiVisualizerService">The UI visualizer service.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="rootProject" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="rootProject" /> is <c>null</c>.</exception>
        public RuleViewModel(RootProject rootProject, Rule rule, IVisualStudioService visualStudioService, IUIVisualizerService uiVisualizerService)
        {
            Argument.IsNotNull(() => rootProject);
            Argument.IsNotNull(() => rule);
            Argument.IsNotNull(() => visualStudioService);
            Argument.IsNotNull(() => uiVisualizerService);

            _uiVisualizerService = uiVisualizerService;

            var project = visualStudioService.GetProjectByName(rootProject.Name);
            if (project != null)
            {
                _rootProjectItem = new ProjectItem(project);
            }

            Rule = rule;

            RuleTypes = Enum<RuleType>.ToList();
            ProjectTypes = new ObservableCollection<SelectableProjectType>();

            foreach (var projectType in ProjectTypeHelper.GetAvailableProjectTypes())
            {
                bool isSelected = rule.ProjectTypes.Contains(projectType);
                var selectableProjectType = new SelectableProjectType(projectType, isSelected);
                this.SubscribeToWeakPropertyChangedEvent(selectableProjectType, OnSelectableProjectTypePropertyChanged);
                ProjectTypes.Add(selectableProjectType);
            }

            SelectProjectItem = new Command(OnSelectProjectItemExecute, OnSelectProjectItemCanExecute);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RootProjectViewModel" /> class.
        /// </summary>
        /// <param name="rootProject">The root project.</param>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="uiVisualizerService">The UI visualizer service.</param>
        /// <param name="messageService">The message service.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="rootProject" /> is <c>null</c>.</exception>
        public RootProjectViewModel(RootProject rootProject, IVisualStudioService visualStudioService, IUIVisualizerService uiVisualizerService,
            IMessageService messageService)
        {
            Argument.IsNotNull(() => rootProject);
            Argument.IsNotNull(() => visualStudioService);
            Argument.IsNotNull(() => uiVisualizerService);
            Argument.IsNotNull(() => messageService);

            _uiVisualizerService = uiVisualizerService;
            _messageService = messageService;

            AvailableProjects = new List<string>();
            var availableProjects = visualStudioService.GetAllProjects();

            foreach (var availableProject in availableProjects)
            {
                AvailableProjects.Add(availableProject.Name);
            }

            RootProject = rootProject;

            Add = new Command(OnAddExecute, OnAddCanExecute);
            Edit = new Command(OnEditExecute, OnEditCanExecute);
            Remove = new Command(OnRemoveExecute, OnRemoveCanExecute);
        }
예제 #3
0
        /// <summary>
        /// Determines whether the specified <paramref name="item" /> matches the specified rule.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="rootProjectConfiguration">The root project configuration.</param>
        /// <param name="ruleType">Type of the rule.</param>
        /// <param name="targetProjectType">Type of the target project.</param>
        /// <returns><c>true</c> if the item matches the rule; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="item" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="rootProjectConfiguration" /> is <c>null</c>.</exception>
        private bool MatchesRule(ProjectItem item, RootProject rootProjectConfiguration, RuleType ruleType, ProjectType targetProjectType)
        {
            Argument.IsNotNull("item", item);
            Argument.IsNotNull("rootProjectConfiguration", rootProjectConfiguration);

            foreach (var rule in rootProjectConfiguration.Rules)
            {
                if (rule.Type == ruleType)
                {
                    if (string.Compare(rule.Name, item.GetNameRelativeToRoot()) == 0)
                    {
                        foreach (var ruledProjectType in rule.ProjectTypes)
                        {
                            if (ruledProjectType == targetProjectType)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }
        /// <summary>
        /// Method to invoke when the Add command is executed.
        /// </summary>
        private void OnAddExecute()
        {
            var rootProject = new RootProject();

            var vm = TypeFactory.Default.CreateInstanceWithParametersAndAutoCompletion<RootProjectViewModel>(rootProject);

            if (_uiVisualizerService.ShowDialog(vm) ?? false)
            {
                RootProjects.Add(rootProject);
                SelectedRootProject = rootProject;
            }
        }
예제 #5
0
        protected override bool Save()
        {
            var rootProject = _configuration.RootProjects.FirstOrDefault(project => string.Equals(RootProject, project.Name));
            if (rootProject == null)
            {
                rootProject = new RootProject();
                rootProject.Name = RootProject;
                _configuration.RootProjects.Add(rootProject);
            }

            foreach (var itemToAdd in ItemsToAdd)
            {
                bool alreadyContainsRule = (from rule in rootProject.Rules
                                            where string.Equals(rule.Name, itemToAdd)
                                            select rule).Any();
                if (!alreadyContainsRule)
                {
                    var rule = new Rule { Name = itemToAdd, Type = RuleType };

                    foreach (var selectableProjectType in ProjectTypes)
                    {
                        if (selectableProjectType.IsSelected)
                        {
                            rule.ProjectTypes.Add(selectableProjectType.ProjectType);
                        }
                    }

                    rootProject.Rules.Add(rule);
                }
            }

            return true;
        }