//----------------------------------- public void Remove(CRF_DataItem anItem) { int index = FindIndex(anItem); if (index > -1) { this.RemoveAt(index); } }
public int FindIndex(CRF_DataItem anItem) { return(this.FindIndex( delegate(CRF_Flux item) { return item.Source.Key == anItem.Key; } )); }
//----------------------------------- public CRF_Flux Find(CRF_DataItem anItem) { int index = FindIndex(anItem); if (index > -1) { return(this[index]); } else { return(null); } }
//----------------------------------- // Must be Unique public void Add(CRF_Flux anItem) { // Ok, first lets set From and Tos if (anItem.Source == null) { if (FOwner is CRF_Resource) { anItem.Source = (FOwner as CRF_Resource); } } if (anItem.Target == null) { if (FOwner is CRF_Consumer) { anItem.Target = (FOwner as CRF_Consumer); } } // look and see if it is in the list already int index = FindIndex(anItem); if (index < 0) { // if not add it base.Add(anItem); } else { // Ahh! Being added again, what does that mean? // let's generate and exception for now, I need to think about this a bit more throw new Exception("This Flux is a;lready in the list!"); } // OK, Does Flux list have an owner, ie A Resource or a consumer, if not then we are done if (FOwner != null) { // OK this list is owned by someone, // see if the owner of the Flux (flux) is resource or consumer if (FOwner is CRF_Resource) { // OK, this is a bit complicated. This Fluxlist is owned by a Resource, and an Flux is being added to list // Let's make sure that the Target of this Flux, has this Flux in its list CRF_DataItem SDI = anItem.Target; // see if owner of this list is in the SDI list CRF_Flux Target = SDI.Fluxs.Find(anItem); if (Target != null) { // ok, it is there, late make sure that this Fowner is the source, if not change it //if (!FOwner.Equals(Target.Source)) //{ // Target.Source = (FOwner as CRF_Resource); //} // Well maybe not, need to decide if we want to do this } else { // ok it is not there, let's modofy it // create an Flux object //CRF_Flux NewSA = new CRF_Flux(FOwner, anItem.Allocated(), CRF_Flux.Method.amAbsolute); SDI.Fluxs.Add(anItem); } } else { if (FOwner is CRF_Consumer) { // OK, this is a bit complicated. This Fluxlist is owned by a consumer, and an Flux is being added to list // Let's make sure that the Source of this Flux, has this Flux in its list CRF_DataItem SDI = anItem.Source; // see if owener of this list is in the SDI list CRF_Flux Target = SDI.Fluxs.Find(anItem); if (Target != null) { // ok, it is there, late make sure that this consumer is the target, if not change it //if (!FOwner.Equals(Target.Target)) //{ // Target.Target = (FOwner as CRF_Consumer); //} // Well maybe not, need to decide if we want to do this } else { // ok it is not there, add it, of course this is going to cause it to go through this routine again SDI.Fluxs.Add(anItem); } } } } }
public CRF_FluxList(CRF_DataItem DataItemOwner) : base() { FOwner = DataItemOwner; }