private void OnActionCompleted(ActionBase action, ActionResult result) { if (result is MemoryGetIdResult && result) { _setupNodeLifelineTask.NodeId = _memoryGetId.SpecificResult.NodeId; } else if (result is SerialApiGetInitDataResult && result) { if (_addNode is AddNodeOperation) { (_addNode as AddNodeOperation).NodesBefore = (result as SerialApiGetInitDataResult).IncludedNodes; } } else if (result is AddRemoveNodeResult) { if (result) { _setupNodeLifelineTask.TargetNodeId = _addNode.SpecificResult.Id; _setupNodeLifelineTask.BasicDeviceType = _addNode.SpecificResult.Basic; if (_addNode.SpecificResult.Id == _getSucNodeId.SpecificResult.SucNodeId) { _requestInclusionController.Token.SetCancelled(); } else { if (_addNode.SpecificResult.AddRemoveNodeStatus == AddRemoveNodeStatuses.Replicated) { _setupNodeLifelineTask.Token.SetCancelled(); _requestInclusionController.Token.SetCancelled(); } else { byte stepId = _addNode.SpecificResult.AddRemoveNodeStatus == AddRemoveNodeStatuses.Replaced ? PROXY_INCLUSION_REPLACE : PROXY_INCLUSION; _requestInclusionController.SetCommandParameters(_addNode.SpecificResult.Id, stepId); } } if ((result as AddRemoveNodeResult).SubstituteStatus == SubstituteStatuses.Failed && _isSmartStart) { if (_isFailedNodeOperation != null) { _isFailedNodeOperation.NodeId = _addNode.SpecificResult.Id; } else { _isFailedNodeOperation = new IsFailedNodeOperation(_addNode.SpecificResult.Id); } } else { _isFailedNodeOperation.Token.SetCancelled(); _removeFailedNodeIdOperation.Token.SetCancelled(); } } else { //this.Token.Result.TraceLog.Add(result.TraceLog); _setupNodeLifelineTask.Token.SetCancelled(); _requestInclusionController.Token.SetCancelled(); //if (result.State == ActionStates.Failed) //{ // SetStateFailed(null); //} //else if (result.State == ActionStates.Expired) //{ // SetStateExpired(null); //} } } else if (result is RequestDataResult && result) { var requestRes = (RequestDataResult)result; if (requestRes.Command != null && requestRes.Command.Length > 2 && requestRes.Command[0] == COMMAND_CLASS_INCLUSION_CONTROLLER.ID && requestRes.Command[1] == COMMAND_CLASS_INCLUSION_CONTROLLER.COMPLETE.ID) { COMMAND_CLASS_INCLUSION_CONTROLLER.COMPLETE cmd = requestRes.Command; if (cmd.status == 0x01) { SpecificResult.AddRemoveNode.SubstituteStatus = SubstituteStatuses.Done; } } } else if (result is IsFailedNodeResult) { if ((result as IsFailedNodeResult).RetValue) { _setupNodeLifelineTask.Token.SetCancelled(); SpecificResult.AddRemoveNode.AddRemoveNodeStatus = AddRemoveNodeStatuses.None; if (_removeFailedNodeIdOperation != null) { _removeFailedNodeIdOperation.ReplacedNodeId = _addNode.SpecificResult.Id; } else { _removeFailedNodeIdOperation = new RemoveFailedNodeIdOperation(_addNode.SpecificResult.Id); } } else { _removeFailedNodeIdOperation.Token.SetCancelled(); } } }
protected override void OnHandledInternal(DataReceivedUnit ou) { byte nodeId = ReceivedAchData.SrcNodeId; byte[] command = ReceivedAchData.Command; if (command != null && command.Length > 1) { if (command[1] == COMMAND_CLASS_INCLUSION_CONTROLLER.INITIATE.ID && nodeIdToInclude == 0) { var initiateCommand = (COMMAND_CLASS_INCLUSION_CONTROLLER.INITIATE)command; if (initiateCommand.stepId == PROXY_INCLUSION || initiateCommand.stepId == PROXY_INCLUSION_REPLACE) { /*TO# 07220 - Delay before request Node Info*/ Thread.Sleep(2000); //if we're not SIS then ignore if (_securityManagerInfo.Network.SucNodeId == _securityManagerInfo.Network.NodeId) { //Start add node for example nodeIdToInclude = initiateCommand.nodeId; var isVirtualNodeOperation = new IsVirtualNodeOperation(nodeIdToInclude); if (ReceivedAchData.CommandType != CommandTypes.CmdApplicationCommandHandler_Bridge) { isVirtualNodeOperation.Token.SetCancelled(); } var stepId = initiateCommand.stepId; var sendDataComplete = new InclusionController.Complete(nodeId, TxOptions); sendDataComplete.SetCommandParameters(STEP_OK, stepId); var requestDataStep2 = new InclusionController.Initiate(0, nodeId, TxOptions, 20000); requestDataStep2.SetCommandParameters(nodeIdToInclude, S0_INCLUSION); var sendDataRejectComplete = new InclusionController.Complete(nodeId, TxOptions); sendDataRejectComplete.SetCommandParameters(STEP_USER_REJECTED, stepId); var addNodeOperation = new AddNodeS2Operation(_securityManagerInfo); addNodeOperation.SetInclusionControllerInitiateParameters(nodeIdToInclude); var setupNodeLifelineTask = new SetupNodeLifelineTask(_securityManagerInfo.Network); setupNodeLifelineTask.NodeId = _securityManagerInfo.Network.NodeId; setupNodeLifelineTask.SucNodeId = _securityManagerInfo.Network.NodeId; setupNodeLifelineTask.TargetNodeId = nodeIdToInclude; setupNodeLifelineTask.CompletedCallback = OnNodeInfoCompleted; var serialGroup = new ActionSerialGroup(OnInitiateFlowActionCompleted, isVirtualNodeOperation, new RequestNodeInfoOperation(nodeIdToInclude) { SubstituteSettings = new SubstituteSettings(SubstituteFlags.DenySecurity, 0) }, addNodeOperation, requestDataStep2, setupNodeLifelineTask, sendDataComplete); serialGroup.ActionUnitStop = new ActionUnit(sendDataRejectComplete); //hack serialGroup.Token.Result = new AddRemoveNodeResult(); serialGroup.CompletedCallback = OnS2SerialGroupCompleted; if (_inclusionControllerStatusUpdateCallback != null) { _inclusionControllerStatusUpdateCallback(serialGroup.Token, false); } ou.SetNextActionItems(serialGroup); } } else if (initiateCommand.stepId == S0_INCLUSION) { //only if asked from SIS if (_securityManagerInfo.Network.SucNodeId == nodeId) { InclusionController.Complete sendDataComplete = null; //Start S0 nodeIdToInclude = initiateCommand.nodeId; if (_securityManagerInfo.Network.HasSecurityScheme(SecuritySchemes.S0)) { sendDataComplete = new InclusionController.Complete(nodeId, TxOptions); sendDataComplete.SetCommandParameters(STEP_OK, S0_INCLUSION); var addNodeOperation = new AddNodeS0Operation(_securityManagerInfo); addNodeOperation.SetInclusionControllerInitiateParameters(nodeIdToInclude); var nodeInfoOperation = new RequestNodeInfoOperation(nodeIdToInclude); nodeInfoOperation.CompletedCallback = OnNodeInfoCompleted; var serialGroup = new ActionSerialGroup(new RequestNodeInfoOperation(nodeIdToInclude) { SubstituteSettings = new SubstituteSettings(SubstituteFlags.DenySecurity, 0) }, addNodeOperation, nodeInfoOperation, sendDataComplete); //hack serialGroup.Token.Result = new AddRemoveNodeResult(); ou.SetNextActionItems(serialGroup); } else { sendDataComplete = new InclusionController.Complete(nodeId, TxOptions); sendDataComplete.SetCommandParameters(STEP_NOT_SUPPORTED, S0_INCLUSION); ou.SetNextActionItems(sendDataComplete); } } } } else if (command[1] == COMMAND_CLASS_INCLUSION_CONTROLLER.COMPLETE.ID) { } } }