/**********************************************************************************/ public TPlanNode GetById <TPlanNode>(Guid id) where TPlanNode : PlanNodeDO { lock (_loadedNodes) { LoadedPlan loadedPlan; // if we have loaded this node before? if (!_loadedNodes.TryGetValue(id, out loadedPlan)) { // try to load plan for this node var plan = GetPlanByMemberId(id); // non existent node or new node that has not been saved yet if (plan == null) { return(null); } loadedPlan = new LoadedPlan(plan); _loadedPlans.Add(loadedPlan); // add all noded to the loaded nodes list PlanTreeHelper.Visit(plan, x => _loadedNodes.Add(x.Id, loadedPlan)); } // search for the node in the corresponding plans return((TPlanNode)loadedPlan.Find(id)); } }
/**********************************************************************************/ // this is just simplification for the first implementation. // We can only insert plans. If we want to edit plan, we need to get corresponding node and edit it's children public void Add(PlanDO plan) { lock (_loadedNodes) { var loadedPlan = new LoadedPlan(plan, true); PlanTreeHelper.Visit(plan, x => { if (x.Id == Guid.Empty) { x.Id = Guid.NewGuid(); } _loadedNodes.Add(x.Id, loadedPlan); }); _loadedPlans.Add(loadedPlan); } }