Ejemplo n.º 1
0
        public void TestMethod1()
        {
            IDictionary <string, object> src = new Dictionary <string, object>();
            var dest = new List <ExpandoObject>();

            src.Add(new KeyValuePair <string, object>("objectOne", "valueOne"));
            src.Add(new KeyValuePair <string, object>("objectTwo", "valueTwo"));
            src.Add(new KeyValuePair <string, object>("objectThree", "valueThree"));
            src.Add(new KeyValuePair <string, object>("objectFour", "valueFour"));

            var ruleList = new RuleList();
            var ruleOne  = new IncludeRule("!=", "string", "valueZero", true);
            var ruleSet  = new RuleSet();
            var iRules   = new List <IRule> {
                ruleOne
            };

            ruleList.RuleSets.Add(ruleSet);
            var ruleTwo   = new IncludeRule("==", "string", "valueOne", true);
            var ruleThree = new IncludeRule("==", "string", "valueTwo", true);
            var ruleFour  = new IncludeRule("==", "string", "valueThree", true);
            var ruleFive  = new ExcludeRule("==", "string", "valueThree", true);
            var ruleSix   = new ErrorCheckRule("!=", "string", "valueZero", true);


            //ruleList.RuleSets.Add();
            ruleList.Execute(src, ref dest);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Occurs when the user double clicks in the listview.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> containing event data.</param>
        private void OnListViewDoubleClick(object sender, EventArgs e)
        {
            var directoryInfo = this.GetSelectedDirectory();
            var fileInfo      = this.GetSelectedFile();
            var shortcutInfo  = this.GetSelectedFileSystemInfo() as OutputShortcutInfo;

            var lvi = this.listView1.SelectedItems.Count > 0 ? this.listView1.SelectedItems[0] : null;

            if (directoryInfo != null)
            {
                var parentNode = this.listView1.Tag as TreeNode;

                if (parentNode != null)
                {
                    foreach (var nodeObject in parentNode.Nodes)
                    {
                        var node = nodeObject as TreeNode;

                        if (node != null && node.Tag == directoryInfo)
                        {
                            this.treeView1.SelectedNode = node;
                            break;
                        }
                    }
                }
            }
            else if (fileInfo != null || shortcutInfo != null)
            {
                IncludeRule includeRule = null;

                if (fileInfo != null)
                {
                    includeRule = fileInfo.IncludeRule;
                }
                else if (shortcutInfo != null)
                {
                    var targetFile = shortcutInfo.Target as OutputFileInfo;

                    if (targetFile != null)
                    {
                        includeRule = targetFile.IncludeRule;
                    }
                }

                if (includeRule != null && lvi != null)
                {
                    if (IncludeRuleEditForm.ShowDialog(this, includeRule) == DialogResult.OK)
                    {
                        if (fileInfo != null)
                        {
                            this.PopulateListViewItem(lvi, fileInfo);
                        }
                        else if (shortcutInfo != null)
                        {
                            this.PopulateListViewItem(lvi, shortcutInfo);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Includes the rules from the specified validator
        /// </summary>
        public void Include(IValidator <T> rulesToInclude)
        {
            rulesToInclude.Guard("Cannot pass null to Include");
            var rule = IncludeRule.Create <T>(rulesToInclude, () => CascadeMode);

            AddRule(rule);
        }
Ejemplo n.º 4
0
        private void PopulateListView(IncludeRule rule)
        {
            var lvi = new ListViewItem();

            this.PopulateListView(lvi, rule);

            this.listView2.Items.Add(lvi);
        }
Ejemplo n.º 5
0
        private void PopulateListView(ListViewItem lvi, IncludeRule rule)
        {
            lvi.Tag = rule;

            int i = 0;

            this.PopulateListViewItem(lvi, i++, rule.Path);
            this.PopulateListViewItem(lvi, i++, rule.Folder);
            this.PopulateListViewItem(lvi, i++, rule.FileName);
        }
Ejemplo n.º 6
0
        public void Include(IValidator <T> rulesToInclude)
        {
            if (rulesToInclude == null)
            {
                throw new ArgumentNullException("Cannot pass null to Include");
            }
            var rule = IncludeRule.Create <T>(rulesToInclude, () => CascadeMode);

            NestedValidators.Add(rule);
        }
Ejemplo n.º 7
0
        public static DialogResult ShowDialog(IWin32Window owner, IncludeRule includeRule)
        {
            if (includeRule == null)
            {
                throw new ArgumentNullException("includeRule");
            }

            using (var f = new IncludeRuleEditForm())
            {
                f.Value = includeRule;

                return(f.ShowDialog(owner));
            }
        }
Ejemplo n.º 8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tbPath.Text))
            {
                MessageBox.Show(this, "The path must not be empty", this.Text);
                return;
            }

            if (this.includeRule == null)
            {
                this.includeRule = new IncludeRule();
                this.includeRule.XmlReplacementRules = this.xmlReplacementListControl1.Items;
            }
            else if (this.includeRule.XmlReplacementRules.Count > 0 && !this.checkBox1.Checked)
            {
                var dialogResult = MessageBox.Show(
                    "Warning! You are about to save the include rule with the XML box unchecked.\r\n" +
                    "If you continue,  all XML rules for this file will be deleted.\r\n" +
                    "Are you sure you want to continue?",
                    "Saving changes",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button2);

                if (dialogResult == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            this.includeRule.FileName = this.tbFileName.Text;
            this.includeRule.Folder   = this.tbFolder.Text;
            this.includeRule.Path     = this.tbPath.Text;

            if (this.cbCreateStartMenuShortcut.Checked)
            {
                this.includeRule.StartMenuShortcut = this.tbShortcutFileName.Text;
            }
            else
            {
                this.includeRule.StartMenuShortcut = null;
            }

            if (!this.checkBox1.Checked)
            {
                this.includeRule.XmlReplacementRules.Clear();
            }

            this.Close(DialogResult.OK);
        }
Ejemplo n.º 9
0
        public void SerializeRules()
        {
            var rule1 = new IncludeRule
            {
                ComparisonOperator = "==",
                ComparisonType     = "int",
                CompareRuleObject  = new KeyValuePair <string, object>("ShpId", "13"),
                ExpectedResult     = false
            };
            var rule2 = new IncludeRule
            {
                ComparisonOperator = "==",
                ComparisonType     = "int",
                CompareRuleObject  = new KeyValuePair <string, object>("ShpId", "14"),
                ExpectedResult     = false
            };
            var rule3 = new ExcludeRule
            {
                ComparisonOperator = "!=",
                ComparisonType     = "int",
                CompareRuleObject  = new KeyValuePair <string, object>("ShpId", "13"),
                ExpectedResult     = false
            };
            var rule4 = new ErrorCheckRule
            {
                ComparisonOperator = ">",
                ComparisonType     = "int",
                CompareRuleObject  = new KeyValuePair <string, object>("ShpId", "19"),
                ExpectedResult     = false
            };
            var ruleSet = new RuleSet();

            ruleSet.RuleSets.Add(rule1);
            ruleSet.RuleSets.Add(rule2);

            var ruleSet2 = new RuleSet();

            ruleSet2.RuleSets.Add(rule3);

            var ruleSet3 = new RuleSet();

            ruleSet3.RuleSets.Add(rule4);

            var ruleSets = new List <RuleSet> {
                ruleSet, ruleSet2, ruleSet3
            };

            var json = JsonConvert.SerializeObject(ruleSets);
        }
Ejemplo n.º 10
0
        public static DialogResult ShowDialog(IWin32Window owner, out IncludeRule includeRule)
        {
            using (var f = new IncludeRuleEditForm())
            {
                var dialogResult = f.ShowDialog(owner);

                if (dialogResult == DialogResult.OK)
                {
                    includeRule = f.Value;
                }
                else
                {
                    includeRule = null;
                }

                return(dialogResult);
            }
        }
Ejemplo n.º 11
0
        public static DialogResult ShowDialog(IWin32Window owner, out IncludeRule includeRule)
        {
            using (var f = new IncludeRuleEditForm())
            {
                var dialogResult = f.ShowDialog(owner);

                if (dialogResult == DialogResult.OK)
                {
                    includeRule = f.Value;
                }
                else
                {
                    includeRule = null;
                }

                return dialogResult;
            }
        }
Ejemplo n.º 12
0
        public static DialogResult ShowDialog(IWin32Window owner, IncludeRule includeRule)
        {
            if (includeRule == null)
            {
                throw new ArgumentNullException("includeRule");
            }

            using (var f = new IncludeRuleEditForm())
            {
                f.Value = includeRule;

                return f.ShowDialog(owner);
            }
        }
Ejemplo n.º 13
0
 private void QuickSort(object sender, int left, int right, Comparison <ISpectrum> comparison, SwapHandler swap, IncludeRule irule, short direction)
 {
     if (left < right)
     {
         ISpectrum ispectrum;
         ISpectrum leftspectrum = ((DataGridViewSpectrumRow)Rows[left]).Spectrum;
         int       m            = left;
         for (int i = left + 1; i < right; i++)
         {
             if (irule(sender, ispectrum = ((DataGridViewSpectrumRow)Rows[i]).Spectrum))
             {
                 //ispectrum = ((DataGridViewSpectrumRow)Rows[i]).Spectrum;
                 if (direction * comparison(ispectrum, leftspectrum) < 0)
                 {
                     m++;
                     while (!irule(sender, ((DataGridViewSpectrumRow)Rows[m]).Spectrum))
                     {
                         if (++m >= i)
                         {
                             break;
                         }
                     }
                     if (i != m)
                     {
                         SwapRows(m, i);
                         if (swap != null)
                         {
                             swap(m - 1, i - 1);
                         }
                     }
                 }
             }// else m++;
         }
         SwapRows(left, m);
         if (swap != null)
         {
             swap(left - 1, m - 1);
         }
         QuickSort(sender, left, m, comparison, swap, irule, direction);
         m++;
         if (m < right)
         {
             while (!irule(sender, ((DataGridViewSpectrumRow)Rows[m]).Spectrum))
             {
                 if (++m >= right)
                 {
                     break;
                 }
             }
             QuickSort(sender, m, right, comparison, swap, irule, direction);
         }
     }
 }
Ejemplo n.º 14
0
        public void Sort(object sender, Comparison <ISpectrum> comparison, SwapHandler swap, IncludeRule irule)
        {
            short direction;

            if (currentSortOrder == SortOrder.Ascending)
            {
                currentSortOrder = SortOrder.Descending;
                direction        = -1;
            }
            else
            {
                currentSortOrder = SortOrder.Ascending;
                direction        = 1;
            }
            int left = 1;

            while (!irule(sender, ((DataGridViewSpectrumRow)Rows[left]).Spectrum))
            {
                if (++left >= RowCount)
                {
                    break;
                }
            }
            if (left < RowCount)
            {
                QuickSort(sender, left, RowCount, comparison, swap, irule, direction);
            }
        }
Ejemplo n.º 15
0
        private void Add(IncludeRule rule)
        {
            this.collection.Add(rule);

            this.PopulateListView(rule);
        }
Ejemplo n.º 16
0
 public override bool IsMatch(DateTime day)
 {
     return(IncludeRule.IsMatch(day) && !ExcludeRule.IsMatch(day));
 }
Ejemplo n.º 17
0
        private void PopulateListView(IncludeRule rule)
        {
            var lvi = new ListViewItem();

            this.PopulateListView(lvi, rule);

            this.listView2.Items.Add(lvi);
        }
Ejemplo n.º 18
0
        private void PopulateListView(ListViewItem lvi, IncludeRule rule)
        {
            lvi.Tag = rule;

            int i = 0;
            this.PopulateListViewItem(lvi, i++, rule.Path);
            this.PopulateListViewItem(lvi, i++, rule.Folder);
            this.PopulateListViewItem(lvi, i++, rule.FileName);
        }
Ejemplo n.º 19
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tbPath.Text))
            {
                MessageBox.Show(this, "The path must not be empty", this.Text);
                return;
            }

            if (this.includeRule == null)
            {
                this.includeRule = new IncludeRule();
                this.includeRule.XmlReplacementRules = this.xmlReplacementListControl1.Items;
            }
            else if (this.includeRule.XmlReplacementRules.Count > 0 && !this.checkBox1.Checked)
            {
                var dialogResult = MessageBox.Show(
                    "Warning! You are about to save the include rule with the XML box unchecked.\r\n" +
                    "If you continue,  all XML rules for this file will be deleted.\r\n" +
                    "Are you sure you want to continue?",
                    "Saving changes",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button2);

                if (dialogResult == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            this.includeRule.FileName = this.tbFileName.Text;
            this.includeRule.Folder = this.tbFolder.Text;
            this.includeRule.Path = this.tbPath.Text;

            if (this.cbCreateStartMenuShortcut.Checked)
            {
                this.includeRule.StartMenuShortcut = this.tbShortcutFileName.Text;
            }
            else
            {
                this.includeRule.StartMenuShortcut = null;
            }

            if (!this.checkBox1.Checked)
            {
                this.includeRule.XmlReplacementRules.Clear();
            }

            this.Close(DialogResult.OK);
        }
Ejemplo n.º 20
0
        private void Add(IncludeRule rule)
        {
            this.collection.Add(rule);

            this.PopulateListView(rule);
        }