//------------------------------------------------------------------------------------------------------------------------ public void HandlePortStates(IEnumerable<TupleS<Port, string>> States) { lock (locker) { List<Yodiwo.Logic.GraphManager.SimultaneousActionRequest> simReq = null; foreach (var portEvent in States) { var port = portEvent.Item1; var portKey = (PortKey)port.PortKey; var state = portEvent.Item2; var thingKey = portKey.ThingKey; //checks if (port == null) { DebugEx.TraceError("Invalid portkey"); continue; } if (portKey.IsInvalid) { DebugEx.TraceError("Invalid portkey"); continue; } //find thing block set var blockSet = ThingKey2ThingInBlockKey.TryGetOrDefault(thingKey); if (blockSet == null) continue; //Update state and revision number lock (port) { //Interlocked.Increment(ref port.RevNum); //TODO: should increase? port.State = state; } //create action update message var data = new Logic.Blocks.Things.ThingUpdateAction { PortKey = portKey, PortState = state, }; //create a simultaneous action requests foreach (var bk in blockSet) { var _req = new Yodiwo.Logic.GraphManager.SimultaneousActionRequest() { BlockKey = bk, BlockActionData = data, }; //add to simReq if (simReq == null) simReq = new List<GraphManager.SimultaneousActionRequest>(); simReq.Add(_req); DebugEx.TraceLog("send event for thing " + thingKey + " block " + bk); } } //send action request if (simReq != null && simReq.Count > 0) GraphManager.RequestGraphAction(simReq); //done } }
//------------------------------------------------------------------------------------------------------------------------ public void HandlePortStates(IEnumerable <TupleS <Port, string> > States) { lock (locker) { List <Yodiwo.Logic.GraphManager.SimultaneousActionRequest> simReq = null; foreach (var portEvent in States) { var port = portEvent.Item1; var portKey = (PortKey)port.PortKey; var state = portEvent.Item2; var thingKey = portKey.ThingKey; //checks if (port == null) { DebugEx.TraceError("Invalid portkey"); continue; } if (portKey.IsInvalid) { DebugEx.TraceError("Invalid portkey"); continue; } //find thing block set var blockSet = ThingKey2ThingInBlockKey.TryGetOrDefault(thingKey); if (blockSet == null) { continue; } //Update state and revision number lock (port) { //Interlocked.Increment(ref port.RevNum); //TODO: should increase? port.State = state; } //create action update message var data = new Logic.Blocks.Things.ThingUpdateAction { PortKey = portKey, PortState = state, }; //create a simultaneous action requests foreach (var bk in blockSet) { var _req = new Yodiwo.Logic.GraphManager.SimultaneousActionRequest() { BlockKey = bk, BlockActionData = data, }; //add to simReq if (simReq == null) { simReq = new List <GraphManager.SimultaneousActionRequest>(); } simReq.Add(_req); DebugEx.TraceLog("send event for thing " + thingKey + " block " + bk); } } //send action request if (simReq != null && simReq.Count > 0) { GraphManager.RequestGraphAction(simReq); } //done } }