コード例 #1
0
        private void mnuNodesImport_Click(object sender, EventArgs e)
        {
            IBaseNode currentNode = TreeNodeAsBaseNode(tvDecisionTree.SelectedNode);

            if (currentNode != null)
            {
                BulkImportForm frm = new BulkImportForm(currentNode, App);
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    currentNode.Nodes.Clear();
                    foreach (IBaseNode baseNode in frm.ImportVariables)
                    {
                        currentNode.AddNode(baseNode);
                    }

                    tvDecisionTree.SelectedNode.Nodes.Clear();
                    RefreshTree(tvDecisionTree.SelectedNode, currentNode);
                }
            }
        }
コード例 #2
0
        private void RootNode_NodeLoaded(object sender, EventArgs e)
        {
            IBaseNode node = sender as IBaseNode;

            if (node != null && node.NodeType == eNodeType.VariableDefinitions)
            {
                if (Persistence != null)
                {
                    int i = 0;
                    while (i < SubModels.Keys.Count)
                    {
                        IPersistence persistence = getSubModel(i);

                        if (persistence != null)
                        {
                            IDecisionTree subTree = IDecisionTreeInterface.Clone();

                            IBaseNode variables = subTree.LoadVariables(persistence);
                            foreach (IBaseNode subModel in subTree.SubModels.Keys)
                            {
                                IDecisionTreeInterface.AddSubModel(subModel as IDomainObject);
                            }

                            IBaseNode baseNode = SubModels.Keys.ElementAt(i);

                            List <IBaseNode> linkedVariables = LinkVariables(node, variables);
                            foreach (IBaseNode linkedNode in linkedVariables)
                            {
                                baseNode.AddNode(linkedNode);
                            }
                        }

                        i++;
                    }
                }
            }
        }
コード例 #3
0
        public static bool Merge(IBaseNode dest, IBaseNode src)
        {
            Dictionary <IBaseNode, string>    destPaths      = new Dictionary <IBaseNode, string>();
            Dictionary <IBaseNode, string>    srcPaths       = new Dictionary <IBaseNode, string>();
            Dictionary <IBaseNode, IBaseNode> replacedList   = new Dictionary <IBaseNode, IBaseNode>();
            Dictionary <IBaseNode, string>    addList        = new Dictionary <IBaseNode, string>();
            Dictionary <string, string>       IsReplacedList = new Dictionary <string, string>();

            foreach (IBaseNode node in dest.Nodes)
            {
                recursion(node, destPaths);
            }

            foreach (IBaseNode node in src.Nodes)
            {
                recursion(node, srcPaths);
            }

            IBaseNode tmpParent = dest;

            // Determine which node to add and which to replace
            foreach (KeyValuePair <IBaseNode, string> tmpSrcIbn in srcPaths)
            {
                // Generate a Add and Replace list
                IBaseNode tmpDestIbn = FindNode(tmpSrcIbn.Key, tmpSrcIbn.Value, destPaths);
                if (tmpDestIbn != null)
                {
                    replacedList.Add(tmpDestIbn, tmpSrcIbn.Key);
                    //NodeEqualityCollection nec = tmpDestIbn.Compare(tmpSrcIbn.Key, eCompareMode.Full);
                    //if (nec.Items.Count > 0)
                    //{
                    //    if (nec.Items[0].Equality != Convert.ToInt16(eNodeEquality.equal))
                    //    {
                    //        replacedList.Add(tmpDestIbn, tmpSrcIbn.Key);
                    //    }
                    //}
                }
                else
                {
                    addList.Add(tmpSrcIbn.Key, ExtractParentPath(tmpSrcIbn.Value));
                }
            }

            // Replace nodes
            foreach (KeyValuePair <IBaseNode, IBaseNode> replacedListItem in replacedList)
            {
                if (replacedListItem.Key.Nodes.Count > 0)
                {
                    foreach (var _tmpNode in replacedListItem.Key.Nodes)
                    {
                        int _tmpIndexOld = replacedListItem.Key.Nodes.IndexOf(_tmpNode);
                        replacedListItem.Value.Nodes.Insert(_tmpIndexOld, _tmpNode);
                        _tmpNode.Parent = replacedListItem.Value;
                    }
                }
                IBaseNode _tmpIbn       = FindInDest(dest, replacedListItem.Key);
                IBaseNode _tmpIbnParent = _tmpIbn.Parent;
                int       _index        = _tmpIbnParent.Nodes.IndexOf(replacedListItem.Key);

                _tmpIbnParent.Nodes.RemoveAt(_index);
                if (_tmpIbnParent.Nodes.Contains(replacedListItem.Value))
                {
                    _tmpIbnParent.Nodes.Remove(replacedListItem.Value);
                }

                _tmpIbnParent.Nodes.Insert(_index, replacedListItem.Value);
                replacedListItem.Value.Parent = _tmpIbnParent;
            }

            // Add missing nodes
            Dictionary <IBaseNode, string> _destPaths = new Dictionary <IBaseNode, string>();

            foreach (IBaseNode node in dest.Nodes)
            {
                recursion(node, _destPaths);
            }

            foreach (KeyValuePair <IBaseNode, string> addListItem in addList)
            {
                if (addListItem.Value == "")
                {
                    // Add to Variables
                    dest.AddNode(addListItem.Key);
                }
                else
                {
                    // Add to Parent with path
                    IBaseNode _tmpParent = FindNodeWithPath(_destPaths, addListItem.Value);
                    _tmpParent.AddNode(addListItem.Key);
                }
            }

            return(true);
        }
コード例 #4
0
        IBaseNode IDecisionTree.CreateNewNode(eNodeType nodeType, IBaseNode parent, string name)
        {
            IBaseNode result = null;

            if (name == "")
            {
                name = GetNodeName(nodeType.ToString(), parent);
            }

            switch (nodeType)
            {
            case eNodeType.Root:
                result = IDecisionTreeInterface.CreateNewNode(typeof(IRootNodeImpl).ToString());
                break;

            case eNodeType.VariableDefinitions:
                name   = Constants.VariableTreeName;
                result = IDecisionTreeInterface.CreateNewNode(typeof(IBaseNodeImpl).ToString());
                break;

            case eNodeType.VarDefinition:
                name   = GetNodeName("variable", parent);
                result = IDecisionTreeInterface.CreateNewNode(typeof(CharVariableImpl).ToString());
                break;

            case eNodeType.DomainObject:
                name   = GetNodeName("domain object", parent);
                result = IDecisionTreeInterface.CreateNewNode(typeof(IDomainObjectImpl).ToString());
                break;

            case eNodeType.Expression:
                result = IDecisionTreeInterface.CreateNewNode(typeof(IExpressionImpl).ToString());
                break;

            case eNodeType.Branch:
                result = IDecisionTreeInterface.CreateNewNode(typeof(IBranchImpl).ToString());
                break;

            case eNodeType.DataObjects:
                name            = Constants.DataNodesTreeName;
                result          = IDecisionTreeInterface.CreateNewNode(typeof(IBaseNodeImpl).ToString());
                result.NodeType = eNodeType.DataObjects;
                break;

            case eNodeType.DataObject:
                name   = GetNodeName("data object", parent);
                result = IDecisionTreeInterface.CreateNewNode(typeof(IDataObjectImpl).ToString());
                break;

            case eNodeType.DataSources:
                name            = Constants.DataSourcesTreeName;
                result          = IDecisionTreeInterface.CreateNewNode(typeof(IBaseNodeImpl).ToString());
                result.NodeType = eNodeType.DataSources;
                break;

            case eNodeType.DataSource:
                name   = GetNodeName("data source", parent);
                result = IDecisionTreeInterface.CreateNewNode(typeof(IDataSourceImpl).ToString());
                break;

            case eNodeType.DataDefinition:
                name   = GetNodeName("data definition", parent);
                result = IDecisionTreeInterface.CreateNewNode(typeof(IDataDefinitionImpl).ToString());
                break;
            }

            if (result != null)
            {
                result.Parent = parent;

                result.NodeType = nodeType;
                result.Name     = name;
                result.Tree     = this;

                if (parent != null)
                {
                    parent.AddNode(result);
                }
            }

            return(result);
        }