/// <summary>
        /// Loads the exclusions type combo box.
        /// </summary>
        private void LoadExclusionsTypeComboBox()
        {
            this.ExclusionTypeComboBox.Items.Clear();
            this.ExclusionTypeComboBox.Items.Add(new ComboBoxItem(Resources.Text_ChooseOne, null));

            SortedList <string, ComboBoxItem> tempCollection = new SortedList <string, ComboBoxItem>();

            foreach (PolicyExclusionType exclusionType in Utilities.GetPolicyExclusionTypes())
            {
                ExclusionAttribute attribute = Utilities.GetExclusionAttributeByEnum(exclusionType);
                if (attribute != null)
                {
                    string name = Resources.ResourceManager.GetString(attribute.NameResourceId);

                    tempCollection.Add(name, new ComboBoxItem(name, exclusionType));
                }
            }

            if (tempCollection.Count > 0)
            {
                foreach (object item in tempCollection.Values)
                {
                    this.ExclusionTypeComboBox.Items.Add(item);
                }
            }

            this.ExclusionTypeComboBox.SelectedIndex = 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a <see cref="ExclusionAttribute"/> for the field specified.
        /// </summary>
        /// <param name="field">The field to check.</param>
        /// <returns>A <see cref="ExclusionAttribute"/> if available, otherwise a null reference (<b>Nothing</b> in Visual Basic).</returns>
        public static ExclusionAttribute GetExclusionAttributeByField(FieldInfo field)
        {
            ExclusionAttribute result = null;

            object[] attributes = field.GetCustomAttributes(typeof(ExclusionAttribute), false);
            if (attributes != null && attributes.Length > 0)
            {
                result = (ExclusionAttribute)attributes[0];
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves a <see cref="ExclusionAttribute"/> for the exclusion type specified.
        /// </summary>
        /// <param name="exclusionType">The exclusion type to check.</param>
        /// <returns>A <see cref="ExclusionAttribute"/> if available, otherwise a null reference (<b>Nothing</b> in Visual Basic).</returns>
        public static ExclusionAttribute GetExclusionAttributeByEnum(PolicyExclusionType exclusionType)
        {
            ExclusionAttribute attribute = null;

            FieldInfo field = typeof(PolicyExclusionType).GetField(exclusionType.ToString());

            if (field != null)
            {
                attribute = GetExclusionAttributeByField(field);
            }

            return(attribute);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a collection containing all the policy exclusion types.
        /// </summary>
        /// <returns>A new collection of policy exclusion types.</returns>
        public static Collection <PolicyExclusionType> GetPolicyExclusionTypes()
        {
            Collection <PolicyExclusionType> result = new Collection <PolicyExclusionType>();

            foreach (FieldInfo field in typeof(PolicyExclusionType).GetFields())
            {
                ExclusionAttribute attribute = GetExclusionAttributeByField(field);
                if (attribute != null)
                {
                    result.Add((PolicyExclusionType)Enum.Parse(typeof(PolicyExclusionType), field.Name, true));
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves a <see cref="ExclusionAttribute"/> for the type specified.
        /// </summary>
        /// <param name="type">The type to check.</param>
        /// <returns>A <see cref="ExclusionAttribute"/> if available, otherwise a null reference (<b>Nothing</b> in Visual Basic).</returns>
        public static ExclusionAttribute GetExclusionAttributeByType(Type type)
        {
            ExclusionAttribute attribute = null;

            if (type != null)
            {
                object[] attributes = type.GetCustomAttributes(typeof(ExclusionAttribute), false);
                if (attributes != null && attributes.Length > 0)
                {
                    attribute = (ExclusionAttribute)attributes[0];
                }
            }

            return(attribute);
        }
        /// <summary>
        /// Updates the description label for the currently selected item.
        /// </summary>
        private void UpdateDescriptionLabel()
        {
            object exclusionType = ((ComboBoxItem)this.ExclusionTypeComboBox.SelectedItem).Tag;

            if (exclusionType == null)
            {
                this.DescriptionLabel.Text = string.Empty;
            }
            else
            {
                ExclusionAttribute attribute = Utilities.GetExclusionAttributeByEnum((PolicyExclusionType)exclusionType);
                if (attribute != null)
                {
                    this.DescriptionLabel.Text = Resources.ResourceManager.GetString(attribute.DescriptionResourceId);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Loads the policy exclusion.
        /// </summary>
        /// <param name="exclusion">A policy exclusion to load.</param>
        private void LoadPolicyExclusion(PolicyExclusionConfigInfo exclusion)
        {
            if (exclusion == null)
            {
                return;
            }

            ExclusionAttribute attribute = Utilities.GetExclusionAttributeByEnum(exclusion.ExclusionType);

            if (attribute != null)
            {
                ListViewItem item = new ListViewItem();

                item.Text = Resources.ResourceManager.GetString(attribute.NameResourceId);

                StringBuilder sb = new StringBuilder();
                foreach (string key in exclusion.Configuration.AllKeys)
                {
                    if (string.Equals(key, PolicyExclusion.EnabledProperty, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    string value = exclusion.Configuration[key];

                    sb.Append(key).Append('=').Append(value).Append(';');
                }

                item.SubItems.Add(sb.ToString());
                item.Tag = exclusion;

                if (bool.Parse(exclusion.Configuration[PolicyExclusion.EnabledProperty]))
                {
                    EnableListViewItem(item);
                }
                else
                {
                    DisableListViewItem(item);
                }

                this.ExclusionControl.Items.Add(item);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Edits a policy exclusion.
        /// </summary>
        /// <param name="mode">The editor mode to load.</param>
        /// <param name="exclusionType">The type of exclusion.</param>
        /// <param name="config">The exclusion configuration being modified.</param>
        /// <returns><b>true</b> if the item was modified, otherwise <b>false</b>.</returns>
        private bool EditPolicyExclusion(EditorMode mode, PolicyExclusionType exclusionType, ref PolicyExclusionConfigInfo config)
        {
            bool retval = false;

            if (exclusionType != PolicyExclusionType.None)
            {
                ExclusionAttribute attribute = Utilities.GetExclusionAttributeByEnum(exclusionType);
                if (attribute != null)
                {
                    using (BaseEditorDialog dialog = (BaseEditorDialog)Activator.CreateInstance(attribute.EditorType))
                    {
                        dialog.EditMode = mode;
                        dialog.Value    = config.Configuration;

                        retval = dialog.ShowDialog(this) == DialogResult.OK;
                    }
                }
            }

            return(retval);
        }