コード例 #1
0
        /// <summary>
        /// Loads the rules from the register into list.
        /// </summary>
        public void Load()
        {
            string[] rules = (string[])m_settings.rules;
            m_logger.DebugFormat("Loaded rules from registry. {0} lines.", rules.Length);
            try
            {
                for (int k = 0; k < rules.Length; k++)
                {
                    m_logger.DebugFormat("Rule read: {0}", rules[k]);
                    string[] srule  = rules[k].Split('\n');
                    String   stage  = srule[0];
                    string   action = srule[1];
                    string   val1   = srule[2];
                    string   val2   = null;
                    if (srule.Length > 3)
                    {
                        val2 = srule[3];
                    }


                    IUsernameRule rule = CreateRule(stage, action, val1, val2);
                    m_logger.DebugFormat("Rule created: {0}", rule);
                    list.Add(rule);
                }
            }
            catch (Exception e)
            {
                throw new UsernameModPluginException("Unable to load rules from registry.", e);
            }
        }
コード例 #2
0
 /// <summary>
 /// Adds a rule to the list, putting it at the end of the stage
 /// </summary>
 /// <param name="rule"></param>
 public void Add(IUsernameRule rule)
 {
     //Add the rule as the last item for the gateway
     for (int k = 0; k < list.Count; k++)
     {
         if (rule.stage.CompareTo(list[k].stage) < 0)
         {
             list.Insert(k, rule);
             return;
         }
     }
     list.Add(rule);
 }
コード例 #3
0
        /// <summary>
        /// Moves the rule at the specified index down one (e.g. index=2 becomes index=3).
        ///
        /// Will not move an item if it's at the bottom, or if it will be below a rule with a later step.
        /// (e.g. An authorization rule will not move below a gateway rule)
        /// </summary>
        /// <param name="index"></param>
        /// <returns>True if the move was successful</returns>
        public bool MoveDown(int index)
        {
            IUsernameRule rule = list.ElementAt(index);

            if (index < list.Count - 1)
            {
                if (list.ElementAt(index + 1).stage == rule.stage)
                {
                    list.RemoveAt(index);
                    list.Insert(index + 1, rule);
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Moves the rule at the specified index up one (e.g. index=2 becomes index=1).
        ///
        /// Will not move an item if it's at the top, or if it will be above a rule with an earlier step.
        /// (e.g. A gateway rule can not be above a authorization rule)
        /// </summary>
        /// <param name="index"></param>
        /// <returns>True if the move was successful</returns>
        public bool MoveUp(int index)
        {
            IUsernameRule rule = list.ElementAt(index);

            if (index > 0)
            {
                if (list.ElementAt(index - 1).stage == rule.stage)
                {
                    list.RemoveAt(index);
                    list.Insert(index - 1, rule);
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
ファイル: Configuration.cs プロジェクト: ComputerBits/pGina
        /// <summary>
        /// Validates input and adds the rule to the ListOfRules.
        /// Displays warning if validation fails.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddRule_Click(object sender, EventArgs e)
        {
            Stage stage;

            if (authButton.Checked)
            {
                stage = Stage.Authentication;
            }
            else if (authZButton.Checked)
            {
                stage = Stage.Authorization;
            }
            else if (gatewayButton.Checked)
            {
                stage = Stage.Gateway;
            }
            else
            {
                MessageBox.Show("Authentication, Authorization or Gateway button must be checked.");
                return;
            }

            string action = (string)actionBox.SelectedItem;
            string val1   = textBox1.Text;
            string val2   = (textBox2.Enabled ? textBox2.Text : null);

            try
            {
                IUsernameRule rule = ListOfRules.CreateRule(stage, action, val1, val2);
                rules.Add(rule);
                updateListView();
            }
            catch (UsernameModPluginException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #6
0
ファイル: UsernameRule.cs プロジェクト: hellyhe/pgina
 /// <summary>
 /// Adds a rule to the list, putting it at the end of the stage
 /// </summary>
 /// <param name="rule"></param>
 public void Add(IUsernameRule rule)
 {
     //Add the rule as the last item for the gateway
     for (int k = 0; k < list.Count; k++)
     {
         if (rule.stage.CompareTo(list[k].stage) < 0)
         {
             list.Insert(k, rule);
             return;
         }
     }
     list.Add(rule);
 }