Ejemplo n.º 1
0
        protected override bool Retrieve(IPersistence persistence, ref ePersistence phase)
        {
            Persistence = persistence;

            while (persistence.NextRecord())
            {
                string type = persistence.GetFieldValue(Constants.BaseNode_ClassType, Constants.BaseNode_Type);
                if (type == "sakwa.IBaseNodeImpl")
                {
                    type = "sakwa.IRootNodeImpl";
                }

                RootNode        = IDecisionTreeInterface.CreateNewNode(type);
                RootNode.Parent = this;
                RootNode.Tree   = this;

                phase = ePersistence.Final;

                RootNode.NodeLoaded += RootNode_NodeLoaded;

                return(RootNode.Retrieve(persistence));
            }

            return(false);
        }
Ejemplo n.º 2
0
        IBaseNode IDecisionTree.LoadVariables(IPersistence persistence)
        {
            if (persistence.NextRecord())
            {
                string    type = persistence.GetFieldValue(Constants.BaseNode_ClassType, Constants.BaseNode_ClassType);
                IBaseNode node = IDecisionTreeInterface.CreateNewNode(type);

                node.Reference = persistence.GetFieldValue(Constants.BaseNode_Reference, new Guid().ToString());
                int count = persistence.GetFieldValue(Constants.BaseNode_NodeCount, 0);
                node.NodeType = (eNodeType)Enum.Parse(typeof(eNodeType), persistence.GetFieldValue(Constants.BaseNode_Type, eNodeType.unknown.ToString()), true);
                node.Name     = persistence.GetFieldValue(Constants.BaseNode_Name, "");

                node.Parent = this;
                node.Tree   = this;

                if (persistence.NextRecord())
                {
                    type = persistence.GetFieldValue(Constants.BaseNode_ClassType, Constants.BaseNode_ClassType);
                    IBaseNode variables = IDecisionTreeInterface.CreateNewNode(type);

                    variables.Parent = node;
                    variables.Tree   = this;
                    variables.Retrieve(persistence);

                    return(variables);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        //Used when Domain template is added later
        void IDecisionTree.ImportVariables(List <IBaseNode> importVariables)
        {
            IBaseNode variables = IDecisionTreeInterface.RootNode.GetNode(eNodeType.VariableDefinitions);

            if (variables != null)
            {
                if (variables.Nodes.Count == 0)
                {
                    foreach (IBaseNode var in importVariables)
                    {
                        variables.Nodes.Add(var);
                    }
                }
                else
                {
                    //TODO Slim algorithme om variabelen met dezelfde naam
                    //en pad naar root te vervangen
                    //Domain object-1
                    //      Variable-1
                    //Variabele-1
                    //
                    //In het beslismodel zelf alle referenties van de oude variabele . domain object
                    //ook veranderen

                    IBaseNode source = IDecisionTreeInterface.CreateNewNode(eNodeType.VariableDefinitions);
                    source.Nodes.AddRange(importVariables.ToArray());
                    DomainTemplateMerger.Merge(variables, source);
                }
            }
            (RootNode as IBaseNodeImpl).OnUpdatedAndRefresh();
        }
Ejemplo n.º 4
0
        public IDecisionTreeImpl(Assembly assembly, SakwaMapping mapping, PostNodeInitialize nodeInitialization, string rootName)
        {
            NodeType    = eNodeType.Tree;
            appAssembly = assembly;

            InitMapping();
            if (mapping != null)
            {
                this.SakwaMappings.Insert(0, mapping);
            }

            PostNodeInitialize = nodeInitialization;

            IDecisionTreeInterface.RootNode = IDecisionTreeInterface.CreateNewNode(eNodeType.Root, null, rootName);
        }
Ejemplo n.º 5
0
        IVariableDef IDecisionTree.ChangeVariable(IVariableDef previousVar)
        {
            IVariableDef result = null;

            switch (previousVar.VariableType)
            {
            case eVariableType.character:
                result = IDecisionTreeInterface.CreateNewNode(typeof(CharVariableImpl).ToString()) as IVariableDef;
                break;

            case eVariableType.numeric:
                result = IDecisionTreeInterface.CreateNewNode(typeof(NumericVariableImpl).ToString()) as IVariableDef;
                break;

            case eVariableType.enumeration:
                result = IDecisionTreeInterface.CreateNewNode(typeof(EnumVariableImpl).ToString()) as IVariableDef;
                break;

            case eVariableType.date:
                result = IDecisionTreeInterface.CreateNewNode(typeof(DateVariableImpl).ToString()) as IVariableDef;
                break;

            case eVariableType.boolean:
                result = IDecisionTreeInterface.CreateNewNode(typeof(BoolVariableImpl).ToString()) as IVariableDef;
                break;
            }

            if (result != null)
            {
                result.Name = previousVar.Name;

                int index = previousVar.Parent.Nodes.IndexOf(previousVar);
                previousVar.Parent.Nodes.Remove(previousVar);
                previousVar.Parent.Nodes.Insert(index, result);

                result.Parent = previousVar.Parent;
                (result as IBaseNode).Tree = this;

                OnUpdated();
            }

            return(result);
        }
Ejemplo n.º 6
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);
        }