Ejemplo n.º 1
0
        private void ValidateNode(TreeNode tn)
        {
            if (this.m_instance != null)
            {
                DocOp docOp = null;
                if (tn.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint con = (DocModelRuleConstraint)tn.Tag;
                    docOp = con.Expression;
                }
                else if (tn.Tag is DocOp)
                {
                    docOp = (DocOp)tn.Tag;
                }

                if (docOp != null)
                {
                    Hashtable hashtable = new Hashtable();
                    object    oresult   = docOp.Eval(this.m_instance, hashtable, this.m_template, null, null);

                    // if hashtable contains a value, that means that entire population must be tested to determine uniqueness
                    if (hashtable.Count > 0 && this.m_population != null)
                    {
                        // must evalulate all for uniqueness
                        foreach (object other in this.m_population)
                        {
                            if (other == this.m_instance)                             // first instance will pass; following duplicate instances will fail
                            {
                                break;
                            }

                            // returning false means there's a duplicate (not unique).
                            object otherresult = docOp.Eval(other, hashtable, this.m_template, null, null);
                            if (otherresult is bool && !(bool)otherresult)
                            {
                                oresult = false;
                                break;
                            }
                        }
                    }

                    if (oresult == null)
                    {
                        tn.BackColor = Color.Yellow;
                    }
                    else if (oresult is bool && (bool)oresult)
                    {
                        tn.BackColor = Color.Lime;
                    }
                    else if (oresult is bool && !(bool)oresult)
                    {
                        tn.BackColor = Color.Red;
                    }
                }
            }
            else
            {
                tn.BackColor = Color.Empty;
            }

            // recurse
            foreach (TreeNode sub in tn.Nodes)
            {
                ValidateNode(sub);
            }
        }
Ejemplo n.º 2
0
        private object TraceOperation(DocTemplateDefinition template, DocOp op, StringBuilder sb, SEntity ent, List<SEntity> population, int level)
        {
            System.Collections.Hashtable hashtable = new System.Collections.Hashtable();
            object result = op.Eval(ent, hashtable, template, null, null);
            if (hashtable.Count > 0)
            {
                // must evaluate all for uniqueness
                foreach (object other in population)
                {
                    if (other == ent) // first instance will pass; following duplicate instances will fail
                        break;

                    // returning false means there's a duplicate (not unique).
                    object otherresult = op.Eval(other, hashtable, template, null, null);
                    if (otherresult is bool && !(bool)otherresult)
                    {
                        result = false;
                        break;
                    }
                }
            }

            if (result is bool && !((bool)result))
            {
                for (int i = 0; i < level; i++ )
                {
                    sb.Append("&nbsp;&nbsp;");
                }

                sb.AppendLine(op.ToString(template) + "<br/>");
            }

            // recurse
            if (op is DocOpLogical)
            {
                DocOpLogical oplog = (DocOpLogical)op;
                TraceOperation(template, oplog.ExpressionA, sb, ent, population, level + 1);
                TraceOperation(template, oplog.ExpressionB, sb, ent, population, level + 1);
            }

            return result;
        }