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); }
//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(); }
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); }
protected override bool Persist(IPersistence persistence, ref ePersistence phase) { if (persistence.AddRecord()) { string type = IDecisionTreeInterface.BaseNodePersistName(RootNode); persistence.UpsertField(Constants.BaseNode_ClassType, type); phase = ePersistence.Final; return(RootNode.Persist(persistence)); } return(false); }
IBaseNode IDecisionTree.GetDomainObjectByReference(string reference) { List <IBaseNode> domainObjects = IDecisionTreeInterface.GetDomainObjects(); foreach (IBaseNode node in domainObjects) { if (node.Reference == reference) { return(node); } } return(null); }
IBaseNode IDecisionTree.GetVariableByReference(string reference) { List <IBaseNode> variables = IDecisionTreeInterface.GetVariables(); foreach (IBaseNode node in variables) { if (node.Reference == reference) { return(node); } } return(null); }
IBaseNode IDecisionTree.GetVariableByName(string name) { List <IBaseNode> variables = IDecisionTreeInterface.GetVariables(); foreach (IBaseNode node in variables) { if (node.Name == name) { return(node as IVariableDef); } } return(null); }
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); }
bool IDecisionTree.LoadDomainTemplate(IRootNode rootNode) { IPersistence persistence = Persistence.Clone(rootNode.DomainTemplate); if (persistence != null) { IDecisionTree subTree = IDecisionTreeInterface.Clone(); IBaseNode variables = subTree.LoadVariables(persistence); IDecisionTreeInterface.ImportVariables(variables); return(true); } return(false); }
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); }
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++; } } } }
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); }