public static CvtValuePath FromTemplateDefinition(DocTemplateDefinition dtd, DocProject docProject) { if (dtd.Rules.Count > 0 && dtd.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)dtd.Rules[0]; DocEntity docEnt = docProject.GetDefinition(dtd.Type) as DocEntity; if (docEnt != null) { CvtValuePath pathInner = null; if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity) { pathInner = FromModelRule((DocModelRuleEntity)docRuleAtt.Rules[0], docProject); } DocAttribute docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject); string identifier = null; if (docRuleAtt.Name.Equals("IsDefinedBy")) { // hack for compat docRuleAtt.ToString(); // look for identifier if (docRuleAtt.Rules.Count > 0) { try { DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleAtt.Rules[0].Rules[0].Rules[0].Rules[1].Rules[0].Rules[0]; if (docRuleIndexCon != null) { if (docRuleIndexCon.Expression is DocOpStatement) { DocOpStatement docOpStatement = (DocOpStatement)docRuleIndexCon.Expression; if (docOpStatement.Value != null) { identifier = docOpStatement.Value.ToString(); if (identifier.StartsWith("'") && identifier.EndsWith("'")) { identifier = identifier.Substring(1, identifier.Length - 2); } } } } } catch { } } } CvtValuePath pathRoot = new CvtValuePath(docEnt, docAtt, identifier, pathInner); return(pathRoot); } } return(null); }
private static CvtValuePath FromModelRule(DocModelRuleEntity docRuleEntity, DocProject docProject) { DocDefinition docDef = docProject.GetDefinition(docRuleEntity.Name); DocAttribute docAtt = null; string identifier = null; CvtValuePath pathInner = null; if (docDef is DocEntity && docRuleEntity.Rules.Count > 0 && docRuleEntity.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)docRuleEntity.Rules[0]; DocEntity docEnt = (DocEntity)docDef; docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject); if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity) { DocModelRuleEntity docRuleInner = (DocModelRuleEntity)docRuleAtt.Rules[0]; pathInner = FromModelRule(docRuleInner, docProject); // look for identifier if (docRuleInner.Rules.Count > 1 && docRuleInner.Rules[1] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleIndexAtt = (DocModelRuleAttribute)docRuleInner.Rules[1]; if (docRuleIndexAtt.Rules.Count > 0) { DocModelRuleEntity docRuleIndexEnt = (DocModelRuleEntity)docRuleIndexAtt.Rules[0]; if (docRuleIndexEnt.Rules.Count > 0 && docRuleIndexEnt.Rules[0] is DocModelRuleConstraint) { DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleIndexEnt.Rules[0]; if (docRuleIndexCon.Expression is DocOpStatement) { DocOpStatement docOpStatement = (DocOpStatement)docRuleIndexCon.Expression; if (docOpStatement.Value != null) { identifier = docOpStatement.Value.ToString(); if (identifier.StartsWith("'") && identifier.EndsWith("'")) { identifier = identifier.Substring(1, identifier.Length - 2); } } } } } } } } CvtValuePath pathOuter = new CvtValuePath(docDef, docAtt, identifier, pathInner); return(pathOuter); }
private void RemoveRuleConstraint(List <DocModelRule> list, DocModelRuleConstraint ruleCon) { if (list.Contains(ruleCon)) { list.Remove(ruleCon); } foreach (DocModelRule sub in list) { if (sub.Rules != null) { RemoveRuleConstraint(sub.Rules, ruleCon); } } }
private TreeNode LoadTemplateRuleNode(TreeNode parent, object tag, string text) { // if existing, then return foreach (TreeNode tnExist in parent.Nodes) { if (tnExist.Tag == tag) { return(tnExist); } } TreeNode tn = new TreeNode(); tn.Tag = tag; tn.Text = text; if (tag is DocModelRuleEntity) { tn.ImageIndex = 0; } else if (tag is DocModelRuleAttribute) { tn.ImageIndex = 1; } else if (tag is DocModelRuleConstraint) { tn.ImageIndex = 2; DocModelRuleConstraint docCon = (DocModelRuleConstraint)tag; if (docCon.Expression != null) { tn.Text = docCon.Expression.ToString(); } } else if (tag is DocTemplateDefinition) { tn.ImageIndex = 3; } tn.SelectedImageIndex = tn.ImageIndex; parent.Nodes.Add(tn); return(tn); }
private DocOp GetSelectedOp() { TreeNode tn = this.treeViewRules.SelectedNode; if (tn == null) { return(null); } DocOp docop = tn.Tag as DocOp; if (tn.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tn.Tag; docop = dmr.Expression; } return(docop); }
private void SelectRule(TreeNode tn, DocOp selection) { if (tn.Tag == selection) { this.treeViewRules.SelectedNode = tn; return; } else if (tn.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmc = (DocModelRuleConstraint)tn.Tag; if (dmc.Expression == selection) { this.treeViewRules.SelectedNode = tn; } } foreach (TreeNode ts in tn.Nodes) { SelectRule(ts, selection); } }
private void UpdateTemplateGraph(TreeNode tnRule) { DocModelRule docRule = (DocModelRule)tnRule.Tag; tnRule.Text = docRule.Name; if (docRule is DocModelRuleConstraint) { DocModelRuleConstraint docCon = (DocModelRuleConstraint)docRule; if (docCon.Expression != null) { tnRule.Text = docCon.Expression.ToString(); } } if (this.m_parent != null) { DocModelRule[] objpath = this.m_parent.GetRulePath(tnRule.FullPath); if (objpath != null && objpath[objpath.Length - 1] != null) { tnRule.ForeColor = Color.Gray; } } string tooltip = docRule.Name; // decorative text doesn't allow treeview path to work -- use tooltip in UI now instead //tooltip += docRule.GetCardinalityExpression(); if (!String.IsNullOrEmpty(docRule.Identification)) { tooltip += " <" + docRule.Identification + ">"; tnRule.BackColor = Color.LightBlue; // mark parameter } else { tnRule.BackColor = Color.Empty; } tnRule.ToolTipText = tooltip; }
private void toolStripButtonRuleRemove_Click(object sender, EventArgs e) { TreeNode tn = this.treeViewRules.SelectedNode; if (tn == null) { return; } if (tn.Tag is DocModelRuleConstraint) { DocModelRuleConstraint docConstraint = (DocModelRuleConstraint)tn.Tag; docConstraint.Delete(); this.RemoveRuleConstraint(this.Template.Rules, docConstraint); this.LoadRules(null); } else if (tn.Tag is DocOp) { // dissolve parent Logical operator, move other statement into parent DocOp op = (DocOp)tn.Tag; TreeNode tnParent = tn.Parent; DocOpLogical oplog = tnParent.Tag as DocOpLogical; if (tnParent.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnParent.Tag; oplog = dmr.Expression as DocOpLogical; } TreeNode tnGrand = tnParent.Parent; DocOpExpression opOther = null; if (oplog.ExpressionA == op) { opOther = oplog.ExpressionB; oplog.ExpressionB = null; // prevent deletion } else if (oplog.ExpressionB == op) { opOther = oplog.ExpressionA; oplog.ExpressionA = null; // prevent deletion } if (tnParent.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnParent.Tag; dmr.Expression = opOther; } else if (tnGrand != null) { DocOpLogical opGrand = tnGrand.Tag as DocOpLogical; if (tnGrand.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnGrand.Tag; opGrand = dmr.Expression as DocOpLogical; } if (opGrand.ExpressionA == oplog) { opGrand.ExpressionA = opOther; } else if (opGrand.ExpressionB == oplog) { opGrand.ExpressionB = opOther; } } oplog.Delete(); op.Delete(); this.LoadRules(opOther); } }
private void LoadRules(List <DocModelRule> list, DocModelRule parentrule) { if (list == null) { return; } foreach (DocModelRule docRule in list) { if (docRule is DocModelRuleConstraint) { DocModelRuleConstraint rc = (DocModelRuleConstraint)docRule; TreeNode tn = new TreeNode(); tn.Tag = docRule; tn.Text = docRule.Description; tn.ImageIndex = 4; this.treeViewRules.Nodes.Add(tn); // backward compatibility before V6.1 -- generate rule from syntax if (rc.Expression == null && docRule.Description != null) { DocOpReference reference = new DocOpReference(); reference.EntityRule = parentrule as DocModelRuleEntity; DocOpLiteral literal = new DocOpLiteral(); DocOpStatement statement = new DocOpStatement(); statement.Reference = reference; statement.Value = literal; rc.Expression = statement; string value = docRule.Description; int index = value.IndexOfAny(new char[] { '=', '!', '>', '<' }); if (index > 0) { string metric = value.Substring(0, index); switch (metric) { case "Value": ///... break; case "Length": ///... break; } string oper = value.Substring(index, 1); string bench = value.Substring(index + 1); if (value.Length > index + 1 && value[index + 1] == '=') { oper = value.Substring(index, 2); bench = value.Substring(index + 2); } switch (oper) { case "=": statement.Operation = DocOpCode.CompareEqual; break; case "!=": statement.Operation = DocOpCode.CompareNotEqual; break; case "<=": statement.Operation = DocOpCode.CompareLessThanOrEqual; break; case "<": statement.Operation = DocOpCode.CompareLessThan; break; case ">=": statement.Operation = DocOpCode.CompareGreaterThanOrEqual; break; case ">": statement.Operation = DocOpCode.CompareGreaterThan; break; } literal.Literal = bench; } } LoadOpExpression(tn, rc.Expression); } LoadRules(docRule.Rules, docRule); } }
private DocModelRuleEntity ToModelRule() { if (this.Type == null) { return(null); } DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = this.Type.Name; if (this.Property != null) { DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute(); docRuleAttr.Name = this.Property.Name; docRuleEntity.Rules.Add(docRuleAttr); docRuleAttr.ParentRule = docRuleEntity; if (this.InnerPath != null) { DocModelRuleEntity docInner = this.InnerPath.ToModelRule(); if (docInner != null) { docRuleAttr.Rules.Add(docInner); docInner.ParentRule = docRuleAttr; } if (this.Identifier != null) { // traverse to the default attribute DocModelRuleEntity docApplicableRule = docInner; if (this.InnerPath.Type.Name.Equals("IfcRelDefinesByProperties")) { // hack for back compat DocModelRuleAttribute docPsetAttr = docInner.Rules[0] as DocModelRuleAttribute; DocModelRuleEntity docPsetEnt = docPsetAttr.Rules[0] as DocModelRuleEntity; docApplicableRule = docPsetEnt; } DocModelRuleAttribute docWhereAttr = new DocModelRuleAttribute(); docWhereAttr.Name = "Name";//... dynamically check... docApplicableRule.Rules.Add(docWhereAttr); docWhereAttr.ParentRule = docApplicableRule; DocModelRuleEntity docWhereEnt = new DocModelRuleEntity(); docWhereEnt.Name = "IfcLabel";//... dynamically check... docWhereAttr.Rules.Add(docWhereEnt); docWhereEnt.ParentRule = docWhereAttr; DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); // general case docWhereEnt.Rules.Add(docRuleConstraint); docRuleConstraint.ParentRule = docWhereEnt; DocOpLiteral oplit = new DocOpLiteral(); oplit.Operation = DocOpCode.LoadString; oplit.Literal = this.Identifier; DocOpStatement op = new DocOpStatement(); op.Operation = DocOpCode.CompareEqual; op.Value = oplit; DocOpReference opref = new DocOpReference(); opref.Operation = DocOpCode.NoOperation; // ldfld... opref.EntityRule = docWhereEnt; op.Reference = opref; docRuleConstraint.Expression = op; } } } return(docRuleEntity); }
public void DoInsert() { if (this.m_template == null) return; if (this.treeViewTemplate.Nodes.Count == 0) { DocEntity docEntityBase = null; if (this.m_parent is DocTemplateDefinition) { string classname = ((DocTemplateDefinition)this.m_parent).Type; docEntityBase = this.m_project.GetDefinition(classname) as DocEntity; } // get selected entity DocEntity docEntityThis = this.m_project.GetDefinition(this.m_template.Type) as DocEntity; using (FormSelectEntity form = new FormSelectEntity(docEntityBase, docEntityThis, this.m_project, SelectDefinitionOptions.Entity)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { this.m_template.Type = form.SelectedEntity.Name; this.LoadTemplateGraph(); this.ContentChanged(this, EventArgs.Empty); } } return; } if (this.m_attribute != null && !String.IsNullOrEmpty(this.m_attribute.DefinedType)) { DocTemplateDefinition docTemplate = this.m_template; DocAttribute docAttribute = this.m_attribute; string entityname = null; switch (this.m_attribute.DefinedType) { case "BOOLEAN": case "LOGICAL": case "BINARY": case "STRING": case "REAL": case "INTEGER": case "NUMBER": entityname = this.m_attribute.DefinedType; break; default: { // qualify schema DocObject docobj = null; if (!String.IsNullOrEmpty(this.m_template.Code)) { foreach(DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { if (docSchema.Name.Equals(this.m_template.Code, StringComparison.OrdinalIgnoreCase)) { docobj = docSchema.GetDefinition(docAttribute.DefinedType); break; } } } } if (docobj == null) { docobj = this.m_project.GetDefinition(docAttribute.DefinedType); } using (FormSelectEntity form = new FormSelectEntity((DocDefinition)docobj, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { entityname = form.SelectedEntity.Name; } } break; } } if (entityname != null) { // get or add attribute rule TreeNode tn = this.treeViewTemplate.SelectedNode; DocModelRuleAttribute docRuleAtt = null; if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleAttribute) { docRuleAtt = (DocModelRuleAttribute)this.treeViewTemplate.SelectedNode.Tag; } else { docRuleAtt = new DocModelRuleAttribute(); docRuleAtt.Name = docAttribute.Name; if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleEntity) { DocModelRuleEntity docRuleEnt = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Tag; docRuleEnt.Rules.Add(docRuleAtt); } else if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition) { docTemplate.Rules.Add(docRuleAtt); } tn = this.LoadTemplateGraph(tn, docRuleAtt); } // get and add entity rule DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = entityname; docRuleAtt.Rules.Add(docRuleEntity); this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(tn, docRuleEntity); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); this.m_selection = docRuleEntity; this.ContentChanged(this, EventArgs.Empty); this.SelectionChanged(this, EventArgs.Empty); } } else { // pick attribute, including attribute that may be on subtype DocModelRule rule = null; if (this.treeViewTemplate.SelectedNode != null) { rule = this.treeViewTemplate.SelectedNode.Tag as DocModelRule; } //if (rule == null) // return; DocTemplateDefinition docTemplate = (DocTemplateDefinition)this.m_template; string typename = null; if (rule is DocModelRuleEntity) { DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)rule; typename = docRuleEntity.Name; } else { // get applicable entity of target (or parent entity rule) typename = docTemplate.Type; } DocEntity docEntity = this.m_project.GetDefinition(typename) as DocEntity; if (docEntity == null) { #if false // constraints now edited at operations // launch dialog for constraint using (FormConstraint form = new FormConstraint()) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); rule.Rules.Add(docRuleConstraint); docRuleConstraint.Description = form.Expression; docRuleConstraint.Name = form.Expression; // for viewing this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleConstraint); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); } } #endif } else { // launch dialog to pick attribute of entity using (FormSelectAttribute form = new FormSelectAttribute(docEntity, this.m_project, null, true)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.Selection != null) { // then add and update tree DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute(); docRuleAttr.Name = form.Selection; if (rule != null) { rule.Rules.Add(docRuleAttr); } else { docTemplate.Rules.Add(docRuleAttr); } this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleAttr); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); } } } } }
public void DoInsert() { if (this.m_template == null) { return; } if (this.treeViewTemplate.Nodes.Count == 0) { DocEntity docEntityBase = null; if (this.m_parent is DocTemplateDefinition) { string classname = ((DocTemplateDefinition)this.m_parent).Type; docEntityBase = this.m_project.GetDefinition(classname) as DocEntity; } // get selected entity DocEntity docEntityThis = this.m_project.GetDefinition(this.m_template.Type) as DocEntity; using (FormSelectEntity form = new FormSelectEntity(docEntityBase, docEntityThis, this.m_project, SelectDefinitionOptions.Entity)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { this.m_template.Type = form.SelectedEntity.Name; this.LoadTemplateGraph(); this.ContentChanged(this, EventArgs.Empty); } } return; } if (this.m_attribute != null && !String.IsNullOrEmpty(this.m_attribute.DefinedType)) { DocTemplateDefinition docTemplate = this.m_template; DocAttribute docAttribute = this.m_attribute; string entityname = null; switch (this.m_attribute.DefinedType) { case "BOOLEAN": case "LOGICAL": case "BINARY": case "STRING": case "REAL": case "INTEGER": case "NUMBER": entityname = this.m_attribute.DefinedType; break; default: { // qualify schema DocObject docobj = null; if (!String.IsNullOrEmpty(this.m_template.Code)) { foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { if (docSchema.Name.Equals(this.m_template.Code, StringComparison.OrdinalIgnoreCase)) { docobj = docSchema.GetDefinition(docAttribute.DefinedType); break; } } } } if (docobj == null) { docobj = this.m_project.GetDefinition(docAttribute.DefinedType); } using (FormSelectEntity form = new FormSelectEntity((DocDefinition)docobj, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { entityname = form.SelectedEntity.Name; } } break; } } if (entityname != null) { // get or add attribute rule TreeNode tn = this.treeViewTemplate.SelectedNode; DocModelRuleAttribute docRuleAtt = null; if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleAttribute) { docRuleAtt = (DocModelRuleAttribute)this.treeViewTemplate.SelectedNode.Tag; } else { docRuleAtt = new DocModelRuleAttribute(); docRuleAtt.Name = docAttribute.Name; if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleEntity) { DocModelRuleEntity docRuleEnt = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Tag; docRuleEnt.Rules.Add(docRuleAtt); } else if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition) { docTemplate.Rules.Add(docRuleAtt); } tn = this.LoadTemplateGraph(tn, docRuleAtt); } // get and add entity rule DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = entityname; docRuleAtt.Rules.Add(docRuleEntity); this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(tn, docRuleEntity); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); this.m_selection = docRuleEntity; this.ContentChanged(this, EventArgs.Empty); this.SelectionChanged(this, EventArgs.Empty); } } else { // pick attribute, including attribute that may be on subtype DocModelRule rule = null; if (this.treeViewTemplate.SelectedNode != null) { rule = this.treeViewTemplate.SelectedNode.Tag as DocModelRule; } //if (rule == null) // return; DocTemplateDefinition docTemplate = (DocTemplateDefinition)this.m_template; string typename = null; if (rule is DocModelRuleEntity) { DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)rule; typename = docRuleEntity.Name; } else { // get applicable entity of target (or parent entity rule) typename = docTemplate.Type; } DocEntity docEntity = this.m_project.GetDefinition(typename) as DocEntity; if (docEntity == null) { // launch dialog for constraint using (FormConstraint form = new FormConstraint()) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); rule.Rules.Add(docRuleConstraint); docRuleConstraint.Description = form.Expression; docRuleConstraint.Name = form.Expression; // for viewing this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleConstraint); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); } } } else { // launch dialog to pick attribute of entity using (FormSelectAttribute form = new FormSelectAttribute(docEntity, this.m_project, null, true)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.Selection != null) { // then add and update tree DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute(); docRuleAttr.Name = form.Selection; if (rule != null) { rule.Rules.Add(docRuleAttr); } else { docTemplate.Rules.Add(docRuleAttr); } this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleAttr); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); } } } } }
public void DoInsert() { if (this.Template == null) return; DocModelRule docModelRule = this.Rule; if (docModelRule == null) return; if (!(this.Rule is DocModelRuleEntity)) return; TreeNode tnSelect = this.treeViewRules.SelectedNode; DocOpLiteral oplit = new DocOpLiteral(); oplit.Operation = DocOpCode.LoadString; oplit.Literal = null; DocOpStatement op = new DocOpStatement(); op.Operation = DocOpCode.CompareEqual; op.Value = oplit; DocOpReference opref = new DocOpReference(); opref.Operation = DocOpCode.NoOperation; // ldfld... opref.EntityRule = this.Rule as DocModelRuleEntity; op.Reference = opref; if (tnSelect != null) { DocOpExpression opSelect = tnSelect.Tag as DocOpExpression; if (tnSelect.Tag is DocModelRuleConstraint) { opSelect = ((DocModelRuleConstraint)tnSelect.Tag).Expression; } // convert existing node into new Logical operator DocOpLogical opLog = new DocOpLogical(); opLog.Operation = DocOpCode.And; opLog.ExpressionA = opSelect; opLog.ExpressionB = op; if (tnSelect.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnSelect.Tag; dmr.Expression = opLog; } else if (tnSelect.Parent != null) { DocOpLogical opParent = tnSelect.Parent.Tag as DocOpLogical; if (tnSelect.Parent.Tag is DocModelRuleConstraint) { opParent = ((DocModelRuleConstraint)tnSelect.Parent.Tag).Expression as DocOpLogical; } if (tnSelect.Parent.Nodes[0] == tnSelect) { opParent.ExpressionA = opLog; } else if (tnSelect.Parent.Nodes[1] == tnSelect) { opParent.ExpressionB = opLog; } } else if (tnSelect.Parent != null && tnSelect.Parent.Nodes[1] == tnSelect) { DocOpLogical opParent = (DocOpLogical)tnSelect.Parent.Tag; opParent.ExpressionB = opLog; } this.LoadRules(op); } else { // create new constraint DocModelRuleConstraint docCon = new DocModelRuleConstraint(); docCon.Expression = op; docModelRule.Rules.Add(docCon); TreeNode tnCon = new TreeNode(); tnCon.Tag = docCon; tnCon.Text = op.ToString(this.Template); tnCon.ImageIndex = 3; tnCon.SelectedImageIndex = tnCon.ImageIndex; this.treeViewRules.Nodes.Add(tnCon); this.treeViewRules.SelectedNode = tnCon; } }
private void RemoveRuleConstraint(List<DocModelRule> list, DocModelRuleConstraint ruleCon) { if (list.Contains(ruleCon)) { list.Remove(ruleCon); } foreach (DocModelRule sub in list) { if (sub.Rules != null) { RemoveRuleConstraint(sub.Rules, ruleCon); } } }
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); } }
public void DoInsert() { if (this.Template == null) { return; } DocModelRule docModelRule = this.Rule; if (docModelRule == null) { return; } if (!(this.Rule is DocModelRuleEntity)) { return; } TreeNode tnSelect = this.treeViewRules.SelectedNode; DocOpLiteral oplit = new DocOpLiteral(); oplit.Operation = DocOpCode.LoadString; oplit.Literal = null; DocOpStatement op = new DocOpStatement(); op.Operation = DocOpCode.CompareEqual; op.Value = oplit; DocOpReference opref = new DocOpReference(); opref.Operation = DocOpCode.NoOperation; // ldfld... opref.EntityRule = this.Rule as DocModelRuleEntity; op.Reference = opref; if (tnSelect != null) { DocOpExpression opSelect = tnSelect.Tag as DocOpExpression; if (tnSelect.Tag is DocModelRuleConstraint) { opSelect = ((DocModelRuleConstraint)tnSelect.Tag).Expression; } // convert existing node into new Logical operator DocOpLogical opLog = new DocOpLogical(); opLog.Operation = DocOpCode.And; opLog.ExpressionA = opSelect; opLog.ExpressionB = op; if (tnSelect.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnSelect.Tag; dmr.Expression = opLog; } else if (tnSelect.Parent != null) { DocOpLogical opParent = tnSelect.Parent.Tag as DocOpLogical; if (tnSelect.Parent.Tag is DocModelRuleConstraint) { opParent = ((DocModelRuleConstraint)tnSelect.Parent.Tag).Expression as DocOpLogical; } if (tnSelect.Parent.Nodes[0] == tnSelect) { opParent.ExpressionA = opLog; } else if (tnSelect.Parent.Nodes[1] == tnSelect) { opParent.ExpressionB = opLog; } } else if (tnSelect.Parent != null && tnSelect.Parent.Nodes[1] == tnSelect) { DocOpLogical opParent = (DocOpLogical)tnSelect.Parent.Tag; opParent.ExpressionB = opLog; } this.LoadRules(op); } else { // create new constraint DocModelRuleConstraint docCon = new DocModelRuleConstraint(); docCon.Expression = op; docModelRule.Rules.Add(docCon); docCon.ParentRule = docModelRule; TreeNode tnCon = new TreeNode(); tnCon.Tag = docCon; tnCon.Text = op.ToString(this.Template); tnCon.ImageIndex = 3; tnCon.SelectedImageIndex = tnCon.ImageIndex; this.treeViewRules.Nodes.Add(tnCon); this.treeViewRules.SelectedNode = tnCon; } }
internal static DocModelRule ImportMvdRule(AttributeRule mvdRule, Dictionary<EntityRule, DocModelRuleEntity> fixups) { DocModelRuleAttribute docRule = new DocModelRuleAttribute(); docRule.Name = mvdRule.AttributeName; docRule.Description = mvdRule.Description; docRule.Identification = mvdRule.RuleID; //ImportMvdCardinality(docRule, mvdRule.Cardinality); if (mvdRule.EntityRules != null) { foreach (EntityRule mvdEntityRule in mvdRule.EntityRules) { DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = mvdEntityRule.EntityName; docRuleEntity.Description = mvdEntityRule.Description; docRuleEntity.Identification = mvdEntityRule.RuleID; //ImportMvdCardinality(docRule, mvdRule.Cardinality); docRule.Rules.Add(docRuleEntity); if (mvdEntityRule.AttributeRules != null) { foreach (AttributeRule mvdAttributeRule in mvdEntityRule.AttributeRules) { DocModelRule docRuleAttribute = ImportMvdRule(mvdAttributeRule, fixups); docRuleEntity.Rules.Add(docRuleAttribute); } } if (mvdEntityRule.Constraints != null) { foreach (Constraint mvdConstraint in mvdEntityRule.Constraints) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); docRuleConstraint.Description = mvdConstraint.Expression; docRuleEntity.Rules.Add(docRuleConstraint); } } if(mvdEntityRule.References != null) { // add it later, as referenced templates may not necessarily be loaded yet fixups.Add(mvdEntityRule, docRuleEntity); } } } if (mvdRule.Constraints != null) { foreach (Constraint mvdConstraint in mvdRule.Constraints) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); docRuleConstraint.Description = mvdConstraint.Expression; docRule.Rules.Add(docRuleConstraint); } } return docRule; }