public void LoadCOnfiguration(List <DependentItemConfig> dependents) { foreach (var d in dependents) { if (!ItemsList.TryGetValue(d.Parnet, out DependentItem parent)) { parent = new DependentItem(d.Parnet); ItemsList.Add(d.Parnet, parent); } /*DependentItem p; * if (DependentItemsList.ContainsKey(d.Parnet)) * { * p = DependentItemsList[d.Parnet]; * } * else * { * p = new DependentItem(d.Parnet); * DependentItemsList.Add(d.Parnet, p); * };*/ if (!ItemsList.TryGetValue(d.Child, out DependentItem child)) { child = new DependentItem(d.Child); ItemsList.Add(d.Child, child); } parent.AddChild(child); Console.WriteLine($"Config line suceess: {d.Parnet} - {d.Child}"); } }
public bool AddParent(DependentItem parent) { if (Parents.Add(parent)) { Status = ItemStatus.Dependent; return(true); } return(false); }
public bool AddChild(DependentItem child) { if (Childs.Add(child)) { if (child.AddParent(this)) { return(true); } else { throw new Exception($"Failed to add Parent ({Id}) to child ({child.Id})..."); } } // Throw Exception here... throw new Exception($"Could not add Child {child.Id} to child list in {Id}..."); //return false; }
private bool RemoveParent(DependentItem parent) { if (Parents.Remove(parent)) { // Status may change to Independet - // when no more parents and previous state was dependent if (Parents.Count == 0 && Status == ItemStatus.Dependent) { Status = ItemStatus.Independent; } return(true); } throw new Exception("Could not find parent here..."); // return false; }