Пример #1
0
        private TreeNode LoadTemplateGraph(TreeNode tnParent, DocModelRule docRule)
        {
            TreeNode tnRule = LoadTemplateRuleNode(tnParent, docRule, docRule.Name);

            UpdateTemplateGraph(tnRule);
            tnRule.Nodes.Clear();

            foreach (DocModelRule docSub in docRule.Rules)
            {
                LoadTemplateGraph(tnRule, docSub);
            }

            if (docRule is DocModelRuleEntity)
            {
                DocModelRuleEntity dme = (DocModelRuleEntity)docRule;
                foreach (DocTemplateDefinition dtd in dme.References)
                {
                    TreeNode tnTemplate = LoadTemplateRuleNode(tnRule, dtd, dtd.Name);
                    if (dtd.Rules != null)
                    {
                        foreach (DocModelRule docTemplateRule in dtd.Rules)
                        {
                            LoadTemplateGraph(tnTemplate, docTemplateRule);
                        }
                    }
                }
            }

            return(tnRule);
        }
Пример #2
0
        private void UpdateTemplateGraph(TreeNode tnRule)
        {
            DocModelRule docRule = (DocModelRule)tnRule.Tag;

            tnRule.Text = docRule.Name;

            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;
        }
Пример #3
0
        private void toolStripButtonTemplateUpdate_Click(object sender, EventArgs e)
        {
            if (this.treeViewTemplate.SelectedNode != null && this.treeViewTemplate.SelectedNode.Tag is DocModelRule)
            {
                DocModelRule docRule = (DocModelRule)this.treeViewTemplate.SelectedNode.Tag;
                if (docRule is DocModelRuleConstraint)
                {
                    using (FormConstraint form = new FormConstraint())
                    {
                        form.Expression = docRule.Description;
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK)
                        {
                            docRule.Description = form.Expression;
                            docRule.Name        = form.Expression; // repeat for visibility
                        }
                    }
                }
                else
                {
                    using (FormRule form = new FormRule(docRule))
                    {
                        form.ShowDialog(this);
                    }
                }

                // update text in treeview
                this.UpdateTemplateGraph(this.treeViewTemplate.SelectedNode);

                // propagate rule
                this.m_template.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);
            }
        }
Пример #4
0
        private void MoveRule(int offset)
        {
            TreeNode     tnSelect   = this.treeViewTemplate.SelectedNode;
            TreeNode     tnParent   = tnSelect.Parent;
            DocModelRule ruleSelect = (DocModelRule)tnSelect.Tag;

            if (tnParent.Tag is DocModelRule)
            {
                DocModelRule ruleParent = (DocModelRule)tnParent.Tag;
                int          index      = ruleParent.Rules.IndexOf(ruleSelect);
                ruleParent.Rules.RemoveAt(index);

                index += offset;

                ruleParent.Rules.Insert(index, ruleSelect);
                tnSelect.Remove();
                tnParent.Nodes.Insert(index, tnSelect);
            }
            else if (tnParent.Tag is DocTemplateDefinition)
            {
                DocTemplateDefinition ruleParent = (DocTemplateDefinition)tnParent.Tag;
                int index = ruleParent.Rules.IndexOf(ruleSelect);
                ruleParent.Rules.RemoveAt(index);

                index += offset;

                ruleParent.Rules.Insert(index, ruleSelect);
                tnSelect.Remove();
                tnParent.Nodes.Insert(index, tnSelect);
            }

            this.treeViewTemplate.SelectedNode = tnSelect;
        }
Пример #5
0
        private void dataGridViewConceptRules_CellValidated(object sender, DataGridViewCellEventArgs e)
        {
            if (this.m_editcon)
            {
                return;
            }

            // format parameters

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this.dataGridViewConceptRules.Columns.Count - 1; i++)
            {
                object val = this.dataGridViewConceptRules[i, e.RowIndex].Value;
                if (val != null)
                {
                    DataGridViewColumn col = this.dataGridViewConceptRules.Columns[i];
                    if (col.Tag is DocModelRule)
                    {
                        DocModelRule rule = (DocModelRule)col.Tag;

                        sb.Append(rule.Identification);
                        sb.Append("=");
                        sb.Append(val as string);
                        sb.Append(";");
                    }
                    else
                    {
                        this.ToString(); // description???
                    }
                }
            }

            List <DocTemplateItem> listItems = null;

            if (this.m_conceptleaf != null)
            {
                listItems = this.m_conceptleaf.Items;
            }
            else
            {
                listItems = this.m_conceptroot.ApplicableItems;
            }

            if (listItems.Count > e.RowIndex)
            {
                DocTemplateItem docItem = listItems[e.RowIndex];
                docItem.RuleParameters = sb.ToString();
                object val = this.dataGridViewConceptRules[this.dataGridViewConceptRules.Columns.Count - 1, e.RowIndex].Value;
                docItem.Documentation = val as string;

                object usage = this.dataGridViewConceptRules[0, e.RowIndex].Value;
                docItem.SetUsage(usage as string);
            }
        }
Пример #6
0
        private void treeViewTemplate_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.m_attribute = null;
            this.m_selection = e.Node.Tag as DocModelRule;
            UpdateCommands();

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Пример #7
0
        private void CtlConcept_MouseMove(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;

            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            DocAttribute attr;

            this.m_highlight = Pick(pt, out this.m_iHighlight, out attr, out this.m_rcHighlight);
            this.Invalidate();
        }
Пример #8
0
        public FormRule(DocModelRule rule, DocProject project, DocTemplateDefinition template)
            : this()
        {
            this.m_rule     = rule;
            this.m_project  = project;
            this.m_template = template;

            this.Text = this.m_rule.Name;
            this.textBoxIdentifier.Text    = this.m_rule.Identification;
            this.textBoxIdentifier.Enabled = !String.IsNullOrEmpty(this.m_rule.Identification);
            if (String.IsNullOrEmpty(this.m_rule.Identification))
            {
                this.comboBoxUsage.SelectedIndex = 0;
            }
            else if (this.m_rule.Description != null && this.m_rule.Description.Equals("*"))
            {
                // convention indicating filter
                this.comboBoxUsage.SelectedIndex = 1;
            }
            else
            {
                // indicates parameter constraint
                this.comboBoxUsage.SelectedIndex = 2;
            }

            if (rule is DocModelRuleEntity)
            {
                this.textBoxPrefix.Enabled = true;
                this.textBoxPrefix.Text    = ((DocModelRuleEntity)rule).Prefix;
            }


            if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 0)
            {
                this.comboBoxCardinality.SelectedIndex = 0;
            }
            else if (this.m_rule.CardinalityMin == -1 && this.m_rule.CardinalityMax == -1)
            {
                this.comboBoxCardinality.SelectedIndex = 1;
            }
            else if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 1)
            {
                this.comboBoxCardinality.SelectedIndex = 2;
            }
            else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == 1)
            {
                this.comboBoxCardinality.SelectedIndex = 3;
            }
            else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == -1)
            {
                this.comboBoxCardinality.SelectedIndex = 4;
            }
        }
Пример #9
0
        private void CtlConcept_MouseDown(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;

            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            this.m_selection = Pick(pt, out this.m_iSelection, out this.m_attribute, out this.m_rcSelection);
            this.Invalidate();

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Пример #10
0
        private void toolStripButtonTemplateRemove_Click(object sender, EventArgs e)
        {
            if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition)
            {
                DocTemplateDefinition dtd = (DocTemplateDefinition)this.treeViewTemplate.SelectedNode.Tag;
                if (treeViewTemplate.SelectedNode.Parent != null)
                {
                    DocModelRuleEntity dme = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Parent.Tag;
                    dme.References.Remove(dtd);
                    this.m_template.PropagateRule(this.treeViewTemplate.SelectedNode.Parent.FullPath);

                    this.treeViewTemplate.SelectedNode.Remove();
                }
                else
                {
                    this.m_template.Type = null;
                    this.treeViewTemplate.Nodes.Clear();
                }
                UpdateCommands();
                this.ContentChanged(this, EventArgs.Empty);
                return;
            }

            DocModelRule ruleTarget = this.treeViewTemplate.SelectedNode.Tag as DocModelRule;
            DocModelRule ruleParent = null;

            if (this.treeViewTemplate.SelectedNode.Parent != null)
            {
                ruleParent = this.treeViewTemplate.SelectedNode.Parent.Tag as DocModelRule;
            }

            if (ruleParent != null)
            {
                ruleParent.Rules.Remove(ruleTarget);
            }
            else
            {
                this.m_template.Rules.Remove(ruleTarget);
            }

            // copy to child templates (before clearing selection)
            this.m_template.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);

            ruleTarget.Delete();
            this.treeViewTemplate.SelectedNode.Remove();

            this.ContentChanged(this, EventArgs.Empty);
        }
Пример #11
0
        public FormRule(DocModelRule rule, DocProject project, DocTemplateDefinition template)
            : this()
        {
            this.m_rule = rule;
            this.m_project = project;
            this.m_template = template;

            this.Text = this.m_rule.Name;
            this.textBoxIdentifier.Text = this.m_rule.Identification;
            this.textBoxIdentifier.Enabled = !String.IsNullOrEmpty(this.m_rule.Identification);
            if (String.IsNullOrEmpty(this.m_rule.Identification))
            {
                this.comboBoxUsage.SelectedIndex = 0;
            }
            else if (this.m_rule.Description != null && this.m_rule.Description.Equals("*"))
            {
                // convention indicating filter
                this.comboBoxUsage.SelectedIndex = 1;
            }
            else
            {
                // indicates parameter constraint
                this.comboBoxUsage.SelectedIndex = 2;
            }

            if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 0)
            {
                this.comboBoxCardinality.SelectedIndex = 0;
            }
            else if (this.m_rule.CardinalityMin == -1 && this.m_rule.CardinalityMax == -1)
            {
                this.comboBoxCardinality.SelectedIndex = 1;
            }
            else if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 1)
            {
                this.comboBoxCardinality.SelectedIndex = 2;
            }
            else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == 1)
            {
                this.comboBoxCardinality.SelectedIndex = 3;
            }
            else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == -1)
            {
                this.comboBoxCardinality.SelectedIndex = 4;
            }

            this.UpdateBehavior();
        }
Пример #12
0
        public FormRule(DocModelRule rule)
            : this()
        {
            this.m_rule = rule;

            this.Text = this.m_rule.Name;
            this.textBoxIdentifier.Text    = this.m_rule.Identification;
            this.textBoxIdentifier.Enabled = !String.IsNullOrEmpty(this.m_rule.Identification);
            if (String.IsNullOrEmpty(this.m_rule.Identification))
            {
                this.comboBoxUsage.SelectedIndex = 0;
            }
            else if (this.m_rule.Description != null && this.m_rule.Description.Equals("*"))
            {
                // convention indicating filter
                this.comboBoxUsage.SelectedIndex = 1;
            }
            else
            {
                // indicates parameter constraint
                this.comboBoxUsage.SelectedIndex = 2;
            }

            if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 0)
            {
                this.comboBoxCardinality.SelectedIndex = 0;
            }
            else if (this.m_rule.CardinalityMin == -1 && this.m_rule.CardinalityMax == -1)
            {
                this.comboBoxCardinality.SelectedIndex = 1;
            }
            else if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 1)
            {
                this.comboBoxCardinality.SelectedIndex = 2;
            }
            else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == 1)
            {
                this.comboBoxCardinality.SelectedIndex = 3;
            }
            else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == -1)
            {
                this.comboBoxCardinality.SelectedIndex = 4;
            }

            this.UpdateBehavior();
        }
Пример #13
0
        private void dataGridViewConceptRules_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (this.m_columns == null)
            {
                return;
            }

            if (e.ColumnIndex >= 0 && e.ColumnIndex < this.m_columns.Length)
            {
                this.m_selectedcolumn = this.m_columns[e.ColumnIndex];
            }
            else
            {
                this.m_selectedcolumn = null;
            }

            if (this.SelectedColumnChanged != null)
            {
                this.SelectedColumnChanged(this, EventArgs.Empty);
            }
        }
Пример #14
0
        private static CardinalityType ExportCardinalityType(DocModelRule rule)
        {
            if (rule.CardinalityMin == 0 && rule.CardinalityMax == 0)
            {
                return CardinalityType._asSchema;
            }
            else if (rule.CardinalityMin == -1 && rule.CardinalityMax == -1)
            {
                return CardinalityType.Zero;
            }
            else if (rule.CardinalityMin == 0 && rule.CardinalityMax == 1)
            {
                return CardinalityType.ZeroToOne;
            }
            else if (rule.CardinalityMin == 1 && rule.CardinalityMax == 1)
            {
                return CardinalityType.One;
            }
            else if (rule.CardinalityMin == 1 && rule.CardinalityMax == -1)
            {
                return CardinalityType.OneToMany;
            }

            return CardinalityType._asSchema;
        }
Пример #15
0
        private void CtlConcept_MouseDown(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;
            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            this.m_selection = Pick(pt, out this.m_iSelection, out this.m_attribute, out this.m_rcSelection);
            this.Invalidate();

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Пример #16
0
        private void CtlConcept_MouseMove(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;
            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            DocAttribute attr;
            this.m_highlight = Pick(pt, out this.m_iHighlight, out attr, out this.m_rcHighlight);
            this.Invalidate();
        }
Пример #17
0
        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);
                        }
                    }
                }
            }
        }
Пример #18
0
        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
                            {
                                DocModelRule rule0 = docRuleAtt.Rules[0];
                                if (rule0.Rules.Count > 0)
                                {
                                    DocModelRule rule1 = rule0.Rules[0];
                                    if (rule1.Rules.Count > 0)
                                    {
                                        DocModelRule rule2 = rule1.Rules[0];
                                        if (rule2.Rules.Count > 1)
                                        {
                                            DocModelRule rule3 = rule2.Rules[1];
                                            if (rule3.Rules.Count > 0)
                                            {
                                                DocModelRule rule4 = rule3.Rules[0];
                                                if (rule4.Rules.Count > 0)
                                                {
                                                    DocModelRuleConstraint docRuleIndexCon = rule4.Rules[0] as DocModelRuleConstraint;
                                                    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);
        }
Пример #19
0
        private string FormatRule(DocModelRule rule, string key)
        {
            string comp = null;

            if (rule.Identification == null || !rule.Identification.Equals(key))
            {
                // recurse
                foreach (DocModelRule sub in rule.Rules)
                {
                    comp = FormatRule(sub, key);
                    if (comp != null)
                    {
                        break;
                    }
                }

                if (comp == null)
                    return null;
            }

            // generate rule if found
            if (rule is DocModelRuleAttribute)
            {
                return "." + rule.Name + comp;
            }
            else if (rule is DocModelRuleEntity)
            {
                return @"\" + rule.Name + comp;
            }

            return null;
        }
Пример #20
0
        private void dataGridViewConceptRules_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            // for button types, launch dialog
            DataGridViewCell cell      = this.dataGridViewConceptRules.Rows[e.RowIndex].Cells[e.ColumnIndex];
            DocDefinition    docEntity = cell.Tag as DocDefinition;

            if (docEntity == null)
            {
                return;
            }

            DocDefinition docSelect = null;

            if (cell.Value != null && this.m_map.ContainsKey(cell.Value.ToString()))
            {
                docSelect = this.m_map[cell.Value.ToString()] as DocDefinition;
            }

            if (docEntity.Name != null && docEntity.Name.Equals("IfcReference"))
            {
                DocDefinition docDef = this.m_conceptroot.ApplicableEntity as DocDefinition;

                // special case for building reference paths
                using (FormReference form = new FormReference(this.m_project, docDef, this.m_map, cell.Value as string))
                {
                    DialogResult res = form.ShowDialog(this);
                    if (res == System.Windows.Forms.DialogResult.OK)
                    {
                        if (form.ValuePath != null && form.ValuePath.StartsWith("\\"))
                        {
                            cell.Value = form.ValuePath.Substring(1);
                        }
                        else if (form.ValuePath == "")
                        {
                            cell.Value = String.Empty;// "\\";
                        }
                        dataGridViewConceptRules_CellValidated(this, e);
                        this.dataGridViewConceptRules.NotifyCurrentCellDirty(true);
                    }
                }
            }
            else
            {
                // new: if a referenced concept template applies, then edit that; otherwise, edit type

                // get the model view

                DocTemplateDefinition docTemplateInner = null;
                DocModelRule          docRule          = this.m_columns[e.ColumnIndex];
                if (docRule is DocModelRuleAttribute)
                {
                    DocModelRuleAttribute dma = (DocModelRuleAttribute)docRule;
                    if (dma.Rules.Count > 0 && dma.Rules[0] is DocModelRuleEntity)
                    {
                        DocModelRuleEntity dme = (DocModelRuleEntity)dma.Rules[0];
                        if (dme.References.Count == 1)
                        {
                            docTemplateInner = dme.References[0];

                            if (dma.Rules.Count > 1)
                            {
                                // prompt user to select which template...
                            }
                        }
                    }
                }

                if (docTemplateInner != null)
                {
                    DocTemplateItem docConceptItem = (DocTemplateItem)this.dataGridViewConceptRules.Rows[e.RowIndex].Tag;
                    if (docConceptItem != null)
                    {
                        DocTemplateUsage docConceptInner = docConceptItem.RegisterParameterConcept(docRule.Identification, docTemplateInner);

                        using (FormParameters form = new FormParameters())
                        {
                            form.Project         = this.m_project;
                            form.ConceptRoot     = this.m_conceptroot;
                            form.ConceptItem     = docConceptItem;
                            form.ConceptLeaf     = docConceptInner;
                            form.CurrentInstance = this.m_instance;
                            form.ShowDialog(this);
                        }
                    }
                }
                else
                {
                    // set type of item
                    using (FormSelectEntity form = new FormSelectEntity(docEntity, docSelect, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK && form.SelectedEntity != null)
                        {
                            cell.Value = form.SelectedEntity.Name;
                            this.dataGridViewConceptRules.NotifyCurrentCellDirty(true);
                        }
                    }
                }
            }
        }
Пример #21
0
        private void dataGridViewConceptRules_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (this.m_columns == null)
                return;

            if (e.ColumnIndex >= 0 && e.ColumnIndex < this.m_columns.Length)
            {
                this.m_selectedcolumn = this.m_columns[e.ColumnIndex];
            }
            else
            {
                this.m_selectedcolumn = null;
            }

            if (this.SelectedColumnChanged != null)
            {
                this.SelectedColumnChanged(this, EventArgs.Empty);
            }
        }
Пример #22
0
        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);
            }
        }
Пример #23
0
        private void treeViewTemplate_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.m_attribute = null;
            this.m_selection = e.Node.Tag as DocModelRule;
            UpdateCommands();

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Пример #24
0
        private static void ExportMvdRule(AttributeRule mvdRule, DocModelRule docRule)
        {
            if (!String.IsNullOrEmpty(docRule.Identification))
            {
                mvdRule.RuleID = docRule.Identification;
            }
            mvdRule.Description = docRule.Description;
            mvdRule.AttributeName = docRule.Name;
            //mvdRule.Cardinality = ExportCardinalityType(docRule);

            foreach (DocModelRule docRuleEntity in docRule.Rules)
            {
                if (docRuleEntity is DocModelRuleEntity)
                {
                    if(mvdRule.EntityRules == null)
                    {
                        mvdRule.EntityRules = new List<EntityRule>();
                    }

                    EntityRule mvdRuleEntity = new EntityRule();
                    mvdRule.EntityRules.Add(mvdRuleEntity);
                    mvdRuleEntity.RuleID = docRuleEntity.Identification;
                    mvdRuleEntity.Description = docRuleEntity.Description;
                    mvdRuleEntity.EntityName = docRuleEntity.Name;
                    //mvdRuleEntity.Cardinality = ExportCardinalityType(docRuleEntity);

                    foreach (DocModelRule docRuleAttribute in docRuleEntity.Rules)
                    {
                        if (docRuleAttribute is DocModelRuleAttribute)
                        {
                            if(mvdRuleEntity.AttributeRules == null)
                            {
                                mvdRuleEntity.AttributeRules = new List<AttributeRule>();
                            }

                            AttributeRule mvdRuleAttribute = new AttributeRule();
                            mvdRuleEntity.AttributeRules.Add(mvdRuleAttribute);
                            ExportMvdRule(mvdRuleAttribute, docRuleAttribute);
                        }
                        else if (docRuleAttribute is DocModelRuleConstraint && !String.IsNullOrEmpty(docRuleAttribute.Description))
                        {

                            if(mvdRuleEntity.Constraints == null)
                            {
                                mvdRuleEntity.Constraints = new List<Constraint>();
                            }

                            Constraint mvdConstraint = new Constraint();
                            mvdRuleEntity.Constraints.Add(mvdConstraint);
                            mvdConstraint.Expression = docRuleAttribute.Description;
                        }
                    }

                    DocModelRuleEntity dme = (DocModelRuleEntity)docRuleEntity;
                    if(dme.References.Count > 0)
                    {
                        mvdRuleEntity.References = new List<TemplateRef>();
                        foreach (DocTemplateDefinition dtd in dme.References)
                        {
                            TemplateRef tr = new TemplateRef();
                            tr.Ref = dtd.Uuid;
                            mvdRuleEntity.References.Add(tr);
                        }
                    }
                }
                else if (docRuleEntity is DocModelRuleConstraint)
                {
                    if(mvdRule.Constraints == null)
                    {
                        mvdRule.Constraints = new List<Constraint>();
                    }

                    Constraint mvdConstraint = new Constraint();
                    mvdRule.Constraints.Add(mvdConstraint);
                    mvdConstraint.Expression = docRuleEntity.Description;
                }
            }
        }
Пример #25
0
        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);
            }
        }
Пример #26
0
        private void CompileConcept(DocTemplateUsage concept, DocModelView view, TypeBuilder tb)
        {
            bool includeconcept = true;

            if (this.m_exchange != null)
            {
                includeconcept = false;
                foreach (DocExchangeItem ei in concept.Exchanges)
                {
                    if (ei.Exchange == this.m_exchange && ei.Applicability == DocExchangeApplicabilityEnum.Export &&
                        (ei.Requirement == DocExchangeRequirementEnum.Mandatory || ei.Requirement == DocExchangeRequirementEnum.Optional))
                    {
                        includeconcept = true;
                    }
                }
            }

            // bool ConceptTemplateA([Parameter1, ...]);
            // {
            //    // for loading reference value:
            //    .ldfld [AttributeRule]
            //    .ldelem [Index] // for collection, get element by index
            //    .castclass [EntityRule] for entity, cast to expected type;
            //    // for object graphs, repeat the above instructions to load value
            //
            //    for loading constant:
            //    .ldstr 'value'
            //
            //    for comparison functions:
            //    .cge
            //
            //    for logical aggregations, repeat each item, pushing 2 elements on stack, then run comparison
            //    .or
            //
            //    return the boolean value on the stack
            //    .ret;
            // }

            // bool[] ConceptA()
            // {
            //    bool[] result = new bool[2];
            //
            //    if parameters are specified, call for each template rule; otherwise call just once
            //    result[0] = ConceptTemplateA([Parameter1, ...]); // TemplateRule#1
            //    result[1] = ConceptTemplateA([Parameter1, ...]); // TemplateRule#2
            //
            //    return result;
            // }

            // compile a method for the template definition, where parameters are passed to the template


#if true
            if (includeconcept && concept.Definition != null)
            {
                MethodInfo methodTemplate = this.RegisterTemplate(concept.Definition);

                // verify that definition is compatible with entity (user error)
                if (methodTemplate != null && methodTemplate.DeclaringType.IsAssignableFrom(tb))
                {
                    string methodname = DocumentationISO.MakeLinkName(view) + "_" + DocumentationISO.MakeLinkName(concept.Definition);



                    MethodBuilder method    = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool[]), null);
                    ILGenerator   generator = method.GetILGenerator();

                    DocModelRule[] parameters = concept.Definition.GetParameterRules();

                    if (parameters != null && parameters.Length > 0)
                    {
                        // allocate array of booleans, store as local variable
                        generator.DeclareLocal(typeof(bool[]));
                        generator.Emit(OpCodes.Ldc_I4, concept.Items.Count);
                        generator.Emit(OpCodes.Newarr, typeof(bool));
                        generator.Emit(OpCodes.Stloc_0);

                        // call for each item with specific parameters
                        for (int row = 0; row < concept.Items.Count; row++)
                        {
                            DocTemplateItem docItem = concept.Items[row];

                            generator.Emit(OpCodes.Ldloc_0);                               // push the array object onto the stack, for storage later
                            generator.Emit(OpCodes.Ldc_I4, row);                           // push the array index onto the stack for storage later

                            generator.Emit(OpCodes.Ldarg_0);                               // push the *this* pointer for the IFC object instance

                            // push parameters onto stack
                            for (int col = 0; col < parameters.Length; col++)
                            {
                                DocModelRule docParam   = parameters[col];
                                string       paramvalue = docItem.GetParameterValue(docParam.Identification);
                                if (paramvalue != null)
                                {
                                    DocDefinition docParamType = concept.Definition.GetParameterType(docParam.Identification, this.m_definitions);
                                    if (docParamType is DocDefined)
                                    {
                                        DocDefined docDefined = (DocDefined)docParamType;
                                        switch (docDefined.DefinedType)
                                        {
                                        case "INTEGER":
                                        {
                                            Int64 ival = 0;
                                            Int64.TryParse(paramvalue, out ival);
                                            generator.Emit(OpCodes.Ldc_I8, ival);
                                            generator.Emit(OpCodes.Box);
                                        }
                                        break;

                                        case "REAL":
                                        {
                                            Double dval = 0.0;
                                            Double.TryParse(paramvalue, out dval);
                                            generator.Emit(OpCodes.Ldc_R8, dval);
                                            generator.Emit(OpCodes.Box);
                                        }
                                        break;

                                        case "STRING":
                                            generator.Emit(OpCodes.Ldstr, paramvalue);
                                            break;

                                        default:
                                            generator.Emit(OpCodes.Ldstr, paramvalue);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        // assume string
                                        generator.Emit(OpCodes.Ldstr, paramvalue);
                                    }
                                }
                                else
                                {
                                    generator.Emit(OpCodes.Ldnull);
                                }
                            }

                            generator.Emit(OpCodes.Call, methodTemplate);                  // call the validation function for the concept template
                            generator.Emit(OpCodes.Stelem_I1);                             // store the result (bool) into an array slot
                        }

                        // return the array of boolean results
                        generator.Emit(OpCodes.Ldloc_0);
                        generator.Emit(OpCodes.Ret);
                    }
                    else
                    {
                        // allocate array of booleans, store as local variable
                        generator.DeclareLocal(typeof(bool[]));
                        generator.Emit(OpCodes.Ldc_I4, 1);
                        generator.Emit(OpCodes.Newarr, typeof(bool));
                        generator.Emit(OpCodes.Stloc_0);

                        generator.Emit(OpCodes.Ldloc_0);                           // push the array object onto the stack, for storage later
                        generator.Emit(OpCodes.Ldc_I4, 0);                         // push the array index onto the stack for storage later

                        // call once
                        generator.Emit(OpCodes.Ldarg_0);                           // push the *this* pointer for the IFC object instance
                        generator.Emit(OpCodes.Call, methodTemplate);              // call the validation function for the concept template
                        generator.Emit(OpCodes.Stelem_I1);                         // store the result (bool) into an array slot

                        // return the array of boolean results
                        generator.Emit(OpCodes.Ldloc_0);
                        generator.Emit(OpCodes.Ret);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Incompatible template: " + tb.Name + " - " + concept.Definition.Name);
                }
            }
#endif
            // recurse
            foreach (DocTemplateUsage docChild in concept.Concepts)
            {
                CompileConcept(docChild, view, tb);
            }
        }
Пример #27
0
        private void InitUsageFromTemplateRule(DocTemplateDefinition docTemp, DocTemplateDefinition docSource, DocModelRule docRule)
        {
            if (docRule is DocModelRuleEntity)
            {
                DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)docRule;
                if (docRuleEntity.References.Contains(docSource))
                {
                    DocObject[] usagepath = new DocObject[] { docTemp };

                    ListViewItem lvi = new ListViewItem();
                    lvi.Tag = usagepath;
                    lvi.Text = "[Template]";
                    lvi.SubItems.Add(docTemp.Name);
                    this.listViewUsage.Items.Add(lvi);
                }
            }

            // recurse
            foreach(DocModelRule docInner in docRule.Rules)
            {
                InitUsageFromTemplateRule(docTemp, docSource, docInner);
            }
        }
Пример #28
0
        private bool TraceRule(DocTemplateDefinition template, DocModelRule rule, StringBuilder sb, SEntity ent, List<SEntity> population)
        {
            bool pass = true;
            if (rule is DocModelRuleConstraint)
            {
                DocModelRuleConstraint ruleCon = (DocModelRuleConstraint)rule;
                object result = TraceOperation(template, ruleCon.Expression, sb, ent, population, 0);
                if(result is bool && !((bool)result))
                    pass = false;
            }

            foreach(DocModelRule sub in rule.Rules)
            {
                bool eachpass = TraceRule(template, sub, sb, ent, population);
                if (!eachpass)
                    pass = false;
            }

            return pass;
        }
Пример #29
0
        private static void WriteModelRule(FormatHTM format, DocModelRule docRule, string path)
        {
            format.Write("<tr><td>" + path + "</td><td>" + /*docRule.GetCardinalityExpression() + */"</td><td>" + docRule.Identification + "</td></tr>");

            if (docRule.Rules != null)
            {
                foreach (DocModelRule docSub in docRule.Rules)
                {
                    if (docSub is DocModelRuleAttribute)
                    {
                        WriteModelRule(format, docSub, path + "." + docSub.Name);
                    }
                    else if (docSub is DocModelRuleEntity)
                    {
                        WriteModelRule(format, docSub, path + "\\" + docSub.Name);
                    }
                }
            }
        }
Пример #30
0
        internal static void ImportMvdCardinality(DocModelRule docRule, CardinalityType cardinality)
        {
            switch (cardinality)
            {
                case CardinalityType._asSchema:
                    docRule.CardinalityMin = 0;
                    docRule.CardinalityMax = 0; // same as unitialized file
                    break;

                case CardinalityType.Zero:
                    docRule.CardinalityMin = -1; // means 0:0
                    docRule.CardinalityMax = -1;
                    break;

                case CardinalityType.ZeroToOne:
                    docRule.CardinalityMin = 0;
                    docRule.CardinalityMax = 1;
                    break;

                case CardinalityType.One:
                    docRule.CardinalityMin = 1;
                    docRule.CardinalityMax = 1;
                    break;

                case CardinalityType.OneToMany:
                    docRule.CardinalityMin = 1;
                    docRule.CardinalityMax = -1;
                    break;
            }
        }
Пример #31
0
        private MethodInfo RegisterTemplate(DocTemplateDefinition dtd)
        {
            if (dtd == null || dtd.Rules == null)
            {
                return(null);
            }

            MethodInfo methodexist = null;

            if (this.m_templates.TryGetValue(dtd, out methodexist))
            {
                return(methodexist);
            }

            Type[]         paramtypes = null;
            DocModelRule[] parameters = dtd.GetParameterRules();
            if (parameters != null && parameters.Length > 0)
            {
                paramtypes = new Type[parameters.Length];
                for (int iParam = 0; iParam < parameters.Length; iParam++)
                {
#if false
                    DocModelRule param = parameters[iParam];
                    if (param is DocModelRuleAttribute)
                    {
                        DocDefinition paramtype = dtd.GetParameterType(param.Name, this.m_definitions);
                        if (paramtype != null)
                        {
                            paramtypes[iParam] = RegisterType(paramtype.Name);
                        }
                    }
                    else if (param is DocModelRuleEntity)
                    {
                        paramtypes[iParam] = RegisterType(param.Name);
                    }
#endif

                    if (paramtypes[iParam] == null)
                    {
                        paramtypes[iParam] = typeof(string);                         // fallback
                    }
                }
            }

            if (dtd.Type == null)
            {
                return(null);
            }

            TypeBuilder tb = (System.Reflection.Emit.TypeBuilder) this.RegisterType(dtd.Type);
            if (tb == null)
            {
                return(null);
            }

            string methodname;
            if (dtd.Name != null)
            {
                methodname = dtd.Name;
            }
            else
            {
                methodname = dtd.UniqueId;
            }
            methodname = methodname.Replace(' ', '_').Replace(':', '_').Replace('-', '_');
            MethodBuilder method    = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool), paramtypes);
            ILGenerator   generator = method.GetILGenerator();
            foreach (DocModelRule docRule in dtd.Rules)
            {
                docRule.EmitInstructions(this, generator, dtd);
            }

            // if made it to the end, then successful, so return true
            generator.Emit(OpCodes.Ldc_I4_1);
            generator.Emit(OpCodes.Ret);

            return(method);
        }
Пример #32
0
        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);
                        }
                    }
                }

            }
        }
Пример #33
0
        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;
            }
        }
Пример #34
0
        private TreeNode LoadTemplateGraph(TreeNode tnParent, DocModelRule docRule)
        {
            TreeNode tnRule = LoadTemplateRuleNode(tnParent, docRule, docRule.Name);
            UpdateTemplateGraph(tnRule);
            tnRule.Nodes.Clear();

            foreach (DocModelRule docSub in docRule.Rules)
            {
                LoadTemplateGraph(tnRule, docSub);
            }

            if (docRule is DocModelRuleEntity)
            {
                DocModelRuleEntity dme = (DocModelRuleEntity)docRule;
                foreach (DocTemplateDefinition dtd in dme.References)
                {
                    TreeNode tnTemplate = LoadTemplateRuleNode(tnRule, dtd, dtd.Name);
                    if (dtd.Rules != null)
                    {
                        foreach (DocModelRule docTemplateRule in dtd.Rules)
                        {
                            LoadTemplateGraph(tnTemplate, docTemplateRule);
                        }
                    }
                }
            }

            return tnRule;
        }