We are using models for representing a piping network. Two connected nodes in the piping network always have an intermediate "valve" inbetween. This valve is an AFElement which has a status-attribute, which can be open or closed. So this valve has by design always one incoming connection and one outgoing connection. The problem we are confronted with is that while traversing the network with AF SDK some of these valves now and then apperently fail to have a outgoing connection! When looking at the same valve in Pi Explorer then the connection is actually there.
So in the code below, it should never get into the else-branch that returns false. But actually it does. Without changing anything on the PI/AF tree this problem occurs, goes away and returns on other valves in the network. Does this somehow ring a bell for anybody? Maybe something wrong in the way we work, or we need an update of some library because of a known issue? We are working with AF SDK 2.5.2 .
private bool SetValves(AFElement afmodel, AFElement fromNode, List<Tuple<string, string>> ToNodes, AFTime date)
foreach (AFConnection afConnection in ((AFModel)afmodel).GetConnections(fromNode, AFPortType.Output))
AFElement valve = (AFElement)afConnection.Destination;
IEnumerable<AFConnection> targetConnections = ((AFModel)afmodel).GetConnections(valve,AFPortType.Output);
if (targetConnections.Count() != 1)
AFElement target = (AFElement)targetConnections.ElementAt(0).Destination;
Tuple<string, string> rtn = (from item in ToNodes
where item.Item1 == target.Name
select new Tuple<string, string>(item.Item1, item.Item2)).SingleOrDefault();
if (rtn != null) valve.Attributes[PIAFStrings.Status].SetValue(new AFValue(Convert.ToBoolean(rtn.Item2) ? 1 : 0, date));