// This is the function that will check for default transitions if // no other transitions were satisfied. // public override bool defaultTransitions(InternalEvent ie) { bool done = false; // Since this function can be called from multiple threads, // we use a mutex to ensure only one state transition is // active at a time. mutex.WaitOne(); // Invoke the FSM transition for this event. try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("PingClient_PingClientFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ReportHeartbeatPulse().getID()) { ReportHeartbeatPulse msg = new ReportHeartbeatPulse(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); pPingClient_PingClientFSM.context.ReportHeartbeatPulseTransition(); done = true; } } } catch (Exception e) {} mutex.ReleaseMutex(); return(done); }
// This is the function that will process an event either generated // by the service, sent to it by another service on the same component, // or as a message sent by a different component. public override bool processTransitions(InternalEvent ie) { bool done = false; // Since this function can be called from multiple threads, // we use a mutex to ensure only one state transition is // active at a time. mutex.WaitOne(); // Invoke the FSM transition for this event. try { if (ie.getName().CompareTo("InitToReadyEventDef") == 0 && (ie.getSource().CompareTo("AdditionClientServiceDef_additionClientFSM") != 0) && (!done)) { InitToReadyEventDef casted_ie = (InitToReadyEventDef)ie; pAdditionClientServiceDef_additionClientFSM.context.InitToReadyEventDefTransition(); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_Ready") == 0 && (ie.getSource().CompareTo("AdditionClientServiceDef_additionClientFSM") != 0) && (!done)) { pAdditionClientServiceDef_additionClientFSM.context.InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_ReadyTransition(ie); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("AdditionClientServiceDef_additionClientFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ReportAddition().getID()) { ReportAddition msg = new ReportAddition(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); pAdditionClientServiceDef_additionClientFSM.context.ReportAdditionTransition(msg); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_Init") == 0 && (ie.getSource().CompareTo("AdditionClientServiceDef_additionClientFSM") != 0) && (!done)) { pAdditionClientServiceDef_additionClientFSM.context.InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_InitTransition(ie); done = true; } } catch (Exception e) {} mutex.ReleaseMutex(); return(done); }
public override void processInternalEvent(InternalEvent ie) { bool done = false; // // When a component receives an internal event, it passes it // to the services to handling, children services first. If the // event is not processed by normal transitions, it's passed // again to the services (children first) for default transitions. // A given event may only be processed by at most one service. // for (int i = serviceList.Count; i > 0; i--) { if (!done) { done = serviceList[i - 1].processTransitions(ie); } } for (int i = serviceList.Count; i > 0; i--) { if (!done) { done = serviceList[i - 1].defaultTransitions(ie); } } }
// Token: 0x06001329 RID: 4905 RVA: 0x0001B934 File Offset: 0x0001A934 protected override void OnMessage(OnTriggerEnter message) { InternalInstance internalInstance = InstanceCatalog.Get().Find(message.TriggerKey); if (internalInstance != null && message.PersonaId == base.Event.Entrants[0].PersonaId && internalInstance.IsTypeOf(ObjType.kObjType_Trigger)) { TreasureHuntScoringState treasureHuntScoringState = base.Event.Entrants[0].ScoringState as TreasureHuntScoringState; if (treasureHuntScoringState != null) { for (uint num = 0u; num < base.Event.EventDef.Num_Coins(); num += 1u) { if (base.Event.EventDef.Coins(num).GetCollectionKey() == message.TriggerKey) { treasureHuntScoringState.CoinsCollected |= 1u << (int)num; InternalEvent.UpdateCoinsCollected(treasureHuntScoringState.CoinsCollected); break; } } } PointOfInterest pointOfInterest = base.Event.PointsOfInterest.Find((PointOfInterest p) => p.Key == message.TriggerKey); if (pointOfInterest != null) { pointOfInterest.Disable(); pointOfInterest.Hide(); base.Event.Manager.PointsOfInterest.Dispose(pointOfInterest); } this.Close(); } }
public void InvokeAllEvents() { PublicEvent?.Invoke(); PrivateEvent?.Invoke(); InternalEvent?.Invoke(); ProtectedEvent?.Invoke(); ProtectedInternalEvent?.Invoke(); }
public void EnqueueInternalEvent(InternalEvent internalEvent) { if (this.ConnectionManager != null) { this.EventQueue.Enqueue(internalEvent); this.ConnectionManager.EnqueueClientConnectionWithInternalEventQueueToProcess(this); } }
private int HandleQueuedQos1SendSubscribeAndSendUnsubscribe( MqttConnection connection, MqttMsgContext msgContext, MqttMsgBase msgInflight, int timeout) { InternalEvent internalEvent; // QoS 1, PUBLISH or SUBSCRIBE/UNSUBSCRIBE message to send to broker, state change to wait PUBACK or SUBACK/UNSUBACK if (msgContext.Flow == MqttMsgFlow.ToPublish) { msgContext.Timestamp = Environment.TickCount; msgContext.Attempt++; if (msgInflight.Type == MqttMsgBase.MQTT_MSG_PUBLISH_TYPE) { // PUBLISH message to send, wait for PUBACK msgContext.State = MqttMsgState.WaitForPuback; // retry ? set dup flag [v3.1.1] only for PUBLISH message if (msgContext.Attempt > 1) { msgInflight.DupFlag = true; } } else if (msgInflight.Type == MqttMsgBase.MQTT_MSG_SUBSCRIBE_TYPE) { // SUBSCRIBE message to send, wait for SUBACK msgContext.State = MqttMsgState.WaitForSuback; } else if (msgInflight.Type == MqttMsgBase.MQTT_MSG_UNSUBSCRIBE_TYPE) { // UNSUBSCRIBE message to send, wait for UNSUBACK msgContext.State = MqttMsgState.WaitForUnsuback; } outgoingMessageHandler.Send(connection, msgInflight); // update timeout : minimum between delay (based on current message sent) or current timeout timeout = connection.Settings.DelayOnRetry < timeout ? connection.Settings.DelayOnRetry : timeout; // re-enqueue message (I have to re-analyze for receiving PUBACK, SUBACK or UNSUBACK) connection.EnqueueInflight(msgContext); } // QoS 1, PUBLISH message received from broker to acknowledge, send PUBACK else if (msgContext.Flow == MqttMsgFlow.ToAcknowledge) { outgoingMessageHandler.Puback(connection, msgInflight.MessageId); internalEvent = new InternalEvent(msgInflight); // notify published message from broker and acknowledged connection.EnqueueInternalEvent(internalEvent); } return(timeout); }
public void AddListener <T0, T1>(string eventName, Action <T0, T1> callback) { if (!_eventDictionary.TryGetValue(eventName, out var @event)) { @event = new InternalEvent(); _eventDictionary.Add(eventName, @event); } @event.AddListener(callback); }
private MqttMsgBase WaitForPubrel( MqttConnection connection, MqttMsgContext msgContext, MqttMsgBase msgInflight, ref bool msgReceivedProcessed) { // QoS 2, waiting for PUBREL of a PUBREC message sent if (msgContext.Flow != MqttMsgFlow.ToAcknowledge) { return(null); } if (!connection.InternalQueue.TryPeek(out MqttMsgBase msgReceived)) { return(null); } InternalEvent internalEvent; // it is a PUBREL message if (msgReceived != null && msgReceived.Type == MqttMsgBase.MQTT_MSG_PUBREL_TYPE) { if (msgReceived.MessageId == msgInflight.MessageId) { // received message processed connection.InternalQueue.TryDequeue(out MqttMsgBase dequeuedMsg); msgReceivedProcessed = true; outgoingMessageHandler.Pubcomp(connection, msgInflight.MessageId); internalEvent = new InternalEvent(msgInflight); // notify published message from broker and acknowledged connection.EnqueueInternalEvent(internalEvent); // PUBREL received (and PUBCOMP sent) for PUBLISH message with QoS Level 2, remove from session state if (msgInflight.Type == MqttMsgBase.MQTT_MSG_PUBLISH_TYPE && connection.Session != null && connection.Session.InflightMessages.ContainsKey(msgContext.Key)) { connection.Session.InflightMessages.TryRemove( msgContext.Key, out MqttMsgContext contextToBeRemoved); } } else { // re-enqueue message connection.EnqueueInflight(msgContext); } } else { connection.EnqueueInflight(msgContext); } return(msgReceived); }
// This is the function that will process an event either generated // by the service, sent to it by another service on the same component, // or as a message sent by a different component. public override bool processTransitions(InternalEvent ie) { bool done = false; // Since this function can be called from multiple threads, // we use a mutex to ensure only one state transition is // active at a time. mutex.WaitOne(); // Invoke the FSM transition for this event. try { if ((!done) && ie.getName().CompareTo("Send") == 0 && (ie.getSource().CompareTo("Transport_SendFSM") != 0)) { Send casted_ie = (Send)ie; Send msg = casted_ie; pTransport_SendFSM.context.SendTransition(msg); done = true; } } catch (Exception e) {} try { if ((!done) && ie.getName().CompareTo("BroadcastLocal") == 0 && (ie.getSource().CompareTo("Transport_SendFSM") != 0)) { BroadcastLocal casted_ie = (BroadcastLocal)ie; BroadcastLocal msg = casted_ie; pTransport_SendFSM.context.BroadcastLocalTransition(msg); done = true; } } catch (Exception e) {} try { if ((!done) && ie.getName().CompareTo("BroadcastGlobal") == 0 && (ie.getSource().CompareTo("Transport_SendFSM") != 0)) { BroadcastGlobal casted_ie = (BroadcastGlobal)ie; BroadcastGlobal msg = casted_ie; pTransport_SendFSM.context.BroadcastGlobalTransition(msg); done = true; } } catch (Exception e) {} mutex.ReleaseMutex(); return(done); }
private void HandleQueuedQos0( MqttConnection connection, MqttMsgContext msgContext, MqttMsgBase msgInflight) { // QoS 0, PUBLISH message to send to broker, no state change, no acknowledge if (msgContext.Flow == MqttMsgFlow.ToPublish) { outgoingMessageHandler.Send(connection, msgInflight); } // QoS 0, no need acknowledge else if (msgContext.Flow == MqttMsgFlow.ToAcknowledge) { var internalEvent = new InternalEvent(msgInflight); connection.EnqueueInternalEvent(internalEvent); } }
protected MessageFinalResponse OnAppDequeue(string message, IConsumer sender, ulong deliveryTag) { #if DEBUG Debug.WriteLine(message); #endif // load the message try { var jsonMsg = (JObject)JToken.Parse(message); var eventName = jsonMsg.SelectToken("type").Value <string>(); var type = _client.Asm.GetType("AsterNET.ARI.Models." + eventName + "Event"); // Get the instance of BrokeredSession for this dialogue and pass as sender // to InternalEvent if (type != null) { InternalEvent.Invoke(this, (Event)JsonConvert.DeserializeObject(jsonMsg.SelectToken("ari_body").Value <string>(), type)); } else { InternalEvent.Invoke(this, (Event)JsonConvert.DeserializeObject(jsonMsg.SelectToken("ari_body").Value <string>())); } } catch (Exception ex) { #if DEBUG Debug.WriteLine("Raise Event Failed: ", ex.Message); #endif } return(MessageFinalResponse.Accept); }
public void InternalStateChange_To_ManagementOCU_ManagementOcuFSM_HandleMenuTransition(InternalEvent ie) { transition_ = "InternalStateChange_To_ManagementOCU_ManagementOcuFSM_HandleMenuTransition"; State.InternalStateChange_To_ManagementOCU_ManagementOcuFSM_HandleMenuTransition(this, ie); transition_ = ""; return; }
public Demo(IMessageQueue messageQueue) { MessageQueue = messageQueue; PrepareCreatedEvent = new InternalEvent <DemoModel, UserInfo>(); //PrepareCreatedEvent = new MessageEvent<DemoModel, UserInfo>("Demo.PrepareCreatedEvent", MessageQueue); CreatedEvent = new MessageEvent <DemoModel, UserInfo>("Demo.CreatedEvent", MessageQueue); PrepareModifiedEvent = new InternalEvent <DemoModel, UserInfo>(); //PrepareModifiedEvent = new MessageEvent<DemoModel, UserInfo>("Demo.PrepareModifiedEvent", MessageQueue); ModifiedEvent = new MessageEvent <DemoModel, UserInfo>("Demo.ModifiedEvent", MessageQueue); PrepareDeleteEvent = new InternalEvent <DemoModel, UserInfo>(); //PrepareDeleteEvent = new MessageEvent<DemoModel, UserInfo>("Demo.PrepareDeleteEvent", MessageQueue); DeleteEvent = new MessageEvent <DemoModel, UserInfo>("Demo.DeleteEvent", MessageQueue); //注入消息队列 PrepareCreatedEvent.Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"预创建验证监听失败测试, 创建人:{userInfo.UserName}, 附加消息:{data.Message}"); return(new ApiResult <DBNull, DBNull> { Success = true, Message = "测试通过" }); }).Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"预创建验证监听成功2, 创建人:{userInfo.UserName}, 附加消息:{data.Message}"); return(new ApiResult <DBNull, DBNull> { Success = true, Message = "测试通过" }); }); CreatedEvent.Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"创建结束监听成功, 创建人:{userInfo.UserName}, 附加消息:{data.Message}"); }).Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"创建结束监听成功1, 创建人:{userInfo.UserName}, 附加消息:{data.Message}"); }); PrepareModifiedEvent.Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"预修改验证监听成功, 修改人:{userInfo.UserName}, 附加消息:{data.Message}"); return(new ApiResult <DBNull, DBNull> { Success = true, Message = "测试通过" }); }); ModifiedEvent.Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"修改结束监听成功, 修改人:{userInfo.UserName}, 附加消息:{data.Message}"); }); PrepareDeleteEvent.Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"预删除验证监听成功, 删除人:{userInfo.UserName}, 附加消息:{data.Message}"); return(new ApiResult <DBNull, DBNull> { Success = true, Message = "测试不通过测试" }); }); DeleteEvent.Subscribe((DemoModel data, UserInfo userInfo) => { Console.WriteLine($"删除结束监听成功, 删除人:{userInfo.UserName}, 附加消息:{data.Message}"); }); }
private void OnInternalEvent(InternalEvent e) { InternalEventHandlerInvokeCount++; }
static NormalState ParseState(XmlNode states_nd, XmlNamespaceManager xmlnsManager, int nestCount, List <NormalState> StateActionList) { StringBuilder spacer = new StringBuilder(); for (int i = 0; i < nestCount; i++) { spacer.Append(" "); } //Console.WriteLine($"{spacer}NodeType: " + states_nd.LocalName); var attrnd_id = states_nd.SelectSingleNode("@xmi.id"); //Console.WriteLine($"{spacer}xmi.id : " + attrnd_id.Value); var attrnd_name = states_nd.SelectSingleNode("@name"); //Console.WriteLine($"{spacer}xmi.name : " + attrnd_name.Value); var normalState = new NormalState { Id = attrnd_id.Value, Name = attrnd_name.Value }; AllStateList.Add(normalState); // 内部遷移 var internalTransitionNodes = states_nd.SelectNodes("UML:State.internalTransition/UML:Transition", xmlnsManager); foreach (XmlNode interTrans_nd in internalTransitionNodes) { string triggerName = "", actionName = ""; var triggerNode = interTrans_nd.SelectSingleNode("UML:Transition.trigger/UML:Event/@name", xmlnsManager); //Console.WriteLine($"{spacer}InterTrans Event[name]: " + triggerNode.Value); triggerName = triggerNode.Value; var actionNode = interTrans_nd.SelectSingleNode("UML:Transition.effect/UML:Action/@name", xmlnsManager); if (actionNode != null) { //Console.WriteLine($"{spacer}InterTrans Action[name]: " + actionNode.Value); actionName = actionNode.Value; } var events = new InternalEvent { Name = triggerName, MethodName = actionName }; AddTransition(triggerName, events); normalState.InternalEvent.Add(events); } // 開始疑似状態 var pseudoStates = states_nd.SelectSingleNode("UML:CompositeState.subvertex/UML:Pseudostate", xmlnsManager); if (pseudoStates != null) { var pseudo_id = pseudoStates.SelectSingleNode("@xmi.id"); var pseudo_name = pseudoStates.SelectSingleNode("@name"); PseudoState pseudoState = new PseudoState() { Id = pseudo_id.Value, Name = pseudo_name.Value }; normalState.PseudoState = pseudoState; AllStateList.Add(pseudoState); //Console.WriteLine($"{spacer}開始状態 {pseudo_name.Value} ({pseudo_id.Value})"); } // Entry var entryNode = states_nd.SelectSingleNode("UML:State.entry", xmlnsManager); if (entryNode != null) { normalState.EntryMethod = entryNode.SelectSingleNode("UML:Action/@name", xmlnsManager).Value; } // Exit var exitNode = states_nd.SelectSingleNode("UML:State.exit", xmlnsManager); if (exitNode != null) { normalState.ExitMethod = exitNode.SelectSingleNode("UML:Action/@name", xmlnsManager).Value; } StateActionList.Add(normalState); // サブ状態 var substatesList = states_nd.SelectNodes("UML:CompositeState.subvertex/UML:CompositeState", xmlnsManager); if (substatesList.Count > 0) { if (normalState.PseudoState == null) { throw new ApplicationException("サブ状態を定義している場合は、開始疑似状態が必須です。"); } foreach (XmlNode states_nd2 in substatesList) { normalState.SubState.Add( ParseState(states_nd2, xmlnsManager, nestCount + 1, StateActionList) ); } } return(normalState); }
public void InternalStateChange_To_ManagementOCU_ManagementOcuFSM_WaitForControlTransition(InternalEvent ie) { transition_ = "InternalStateChange_To_ManagementOCU_ManagementOcuFSM_WaitForControlTransition"; State.InternalStateChange_To_ManagementOCU_ManagementOcuFSM_WaitForControlTransition(this, ie); transition_ = ""; return; }
public void InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_ReadyTransition(InternalEvent ie) { transition_ = "InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_ReadyTransition"; State.InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_ReadyTransition(this, ie); transition_ = ""; return; }
// This is the function that will process an event either generated // by the service, sent to it by another service on the same component, // or as a message sent by a different component. public override bool processTransitions(InternalEvent ie) { bool done = false; // Since this function can be called from multiple threads, // we use a mutex to ensure only one state transition is // active at a time. mutex.WaitOne(); // Invoke the FSM transition for this event. try { if ((!done) && ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("DiscoveryClient_ReceiveFSM") != 0)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ReportHeartbeatPulse().getID()) { ReportHeartbeatPulse msg = new ReportHeartbeatPulse(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pDiscoveryClient_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if ((!done) && ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("DiscoveryClient_ReceiveFSM") != 0)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ReportServices().getID()) { ReportServices msg = new ReportServices(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pDiscoveryClient_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if ((!done) && ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("DiscoveryClient_ReceiveFSM") != 0)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ReportIdentification().getID()) { ReportIdentification msg = new ReportIdentification(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pDiscoveryClient_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if ((!done) && ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("DiscoveryClient_ReceiveFSM") != 0)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new GrantNodeID().getID()) { GrantNodeID msg = new GrantNodeID(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pDiscoveryClient_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if ((!done) && ie.getName().CompareTo("RHP_Timeout") == 0 && (ie.getSource().CompareTo("DiscoveryClient_ReceiveFSM") != 0)) { RHP_Timeout casted_ie = (RHP_Timeout)ie; pDiscoveryClient_ReceiveFSM.context.RHP_TimeoutTransition(); done = true; } } catch (Exception e) {} mutex.ReleaseMutex(); return(done); }
protected internal virtual void InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_ReadyTransition(AdditionClientServiceDef_additionClientFSMContext context, InternalEvent ie) { Default(context); }
private MqttMsgBase HandleWaitForPubackSubackUbsuback( MqttConnection connection, MqttMsgContext msgContext, MqttMsgBase msgInflight, ref bool msgReceivedProcessed, ref int timeout) { // QoS 1, waiting for PUBACK of a PUBLISH message sent or // waiting for SUBACK of a SUBSCRIBE message sent or // waiting for UNSUBACK of a UNSUBSCRIBE message sent or if (msgContext.Flow != MqttMsgFlow.ToPublish) { return(null); } if (!connection.InternalQueue.TryPeek(out MqttMsgBase msgReceived)) { return(null); } var acknowledge = false; InternalEvent internalEvent; // PUBACK message or SUBACK/UNSUBACK message for the current message if (msgReceived.Type == MqttMsgBase.MQTT_MSG_PUBACK_TYPE && msgInflight.Type == MqttMsgBase.MQTT_MSG_PUBLISH_TYPE && msgReceived.MessageId == msgInflight.MessageId || msgReceived.Type == MqttMsgBase.MQTT_MSG_SUBACK_TYPE && msgInflight.Type == MqttMsgBase.MQTT_MSG_SUBSCRIBE_TYPE && msgReceived.MessageId == msgInflight.MessageId || msgReceived.Type == MqttMsgBase.MQTT_MSG_UNSUBACK_TYPE && msgInflight.Type == MqttMsgBase.MQTT_MSG_UNSUBSCRIBE_TYPE && msgReceived.MessageId == msgInflight.MessageId) { // received message processed connection.InternalQueue.TryDequeue(out MqttMsgBase dequeuedMsg); acknowledge = true; msgReceivedProcessed = true; // if PUBACK received, confirm published with flag if (msgReceived.Type == MqttMsgBase.MQTT_MSG_PUBACK_TYPE) { internalEvent = new PublishedInternalEvent(msgReceived, true); } else { internalEvent = new InternalEvent(msgReceived); } // notify received acknowledge from broker of a published message or subscribe/unsubscribe message connection.EnqueueInternalEvent(internalEvent); // PUBACK received for PUBLISH message with QoS Level 1, remove from session state if (msgInflight.Type == MqttMsgBase.MQTT_MSG_PUBLISH_TYPE && connection.Session != null && connection.Session.InflightMessages.ContainsKey(msgContext.Key)) { connection.Session.InflightMessages.TryRemove(msgContext.Key, out MqttMsgContext contextToBeRemoved); } } // current message not acknowledged, no PUBACK or SUBACK/UNSUBACK or not equal messageid if (!acknowledge) { var delta = Environment.TickCount - msgContext.Timestamp; // check timeout for receiving PUBACK since PUBLISH was sent or // for receiving SUBACK since SUBSCRIBE was sent or // for receiving UNSUBACK since UNSUBSCRIBE was sent if (delta >= connection.Settings.DelayOnRetry) { // max retry not reached, resend if (msgContext.Attempt < connection.Settings.AttemptsOnRetry) { msgContext.State = MqttMsgState.QueuedQos1; // re-enqueue message connection.EnqueueInflight(msgContext); // update timeout (0 -> reanalyze queue immediately) timeout = 0; } else { // if PUBACK for a PUBLISH message not received after retries, raise event for not published if (msgInflight.Type == MqttMsgBase.MQTT_MSG_PUBLISH_TYPE) { // PUBACK not received in time, PUBLISH retries failed, need to remove from session inflight messages too if (connection.Session != null && connection.Session.InflightMessages.ContainsKey(msgContext.Key)) { connection.Session.InflightMessages.TryRemove( msgContext.Key, out MqttMsgContext contextToBeRemoved); } internalEvent = new PublishedInternalEvent(msgInflight, false); // notify not received acknowledge from broker and message not published connection.EnqueueInternalEvent(internalEvent); } // NOTE : not raise events for SUBACK or UNSUBACK not received // for the user no event raised means subscribe/unsubscribe failed } } else { // re-enqueue message (I have to re-analyze for receiving PUBACK, SUBACK or UNSUBACK) connection.EnqueueInflight(msgContext); // update timeout var msgTimeout = connection.Settings.DelayOnRetry - delta; timeout = msgTimeout < timeout ? msgTimeout : timeout; } } return(msgReceived); }
// This is the function that will process an event either generated // by the service, sent to it by another service on the same component, // or as a message sent by a different component. public override bool processTransitions(InternalEvent ie) { bool done = false; // Since this function can be called from multiple threads, // we use a mutex to ensure only one state transition is // active at a time. mutex.WaitOne(); // Invoke the FSM transition for this event. try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new QueryEvents().getID()) { QueryEvents msg = new QueryEvents(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new QueryEventTimeout().getID()) { QueryEventTimeout msg = new QueryEventTimeout(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new CreateEvent().getID()) { CreateEvent msg = new CreateEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new CreateEvent().getID()) { CreateEvent msg = new CreateEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new CreateEvent().getID()) { CreateEvent msg = new CreateEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new UpdateEvent().getID()) { UpdateEvent msg = new UpdateEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new UpdateEvent().getID()) { UpdateEvent msg = new UpdateEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new CancelEvent().getID()) { CancelEvent msg = new CancelEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new CancelEvent().getID()) { CancelEvent msg = new CancelEvent(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); Receive.Body.ReceiveRec transportData = casted_ie.getBody().getReceiveRec(); pEvents_ReceiveFSM.context.ReceiveTransition(msg, transportData); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("EventOccurred") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { EventOccurred casted_ie = (EventOccurred)ie; pEvents_ReceiveFSM.context.EventOccurredTransition(); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("EventError") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { EventError casted_ie = (EventError)ie; pEvents_ReceiveFSM.context.EventErrorTransition(); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("Timeout") == 0 && (ie.getSource().CompareTo("Events_ReceiveFSM") != 0) && (!done)) { Timeout casted_ie = (Timeout)ie; pEvents_ReceiveFSM.context.TimeoutTransition(); done = true; } } catch (Exception e) {} mutex.ReleaseMutex(); return(done); }
private IObservable <object> Filter(InternalEvent @event) => Filter <object>(@event);
private void InternalEventHandler(InternalEvent e) { InternalEventHandlerInvokeCount++; }
internal WurmCharacterLogFiles([NotNull] CharacterName characterName, [NotNull] string fullDirPathToCharacterLogsDir, [NotNull] IWurmApiLogger logger, [NotNull] LogFileInfoFactory logFileInfoFactory, [NotNull] IInternalEventInvoker internalEventInvoker, [NotNull] TaskManager taskManager) { if (characterName == null) { throw new ArgumentNullException(nameof(characterName)); } if (fullDirPathToCharacterLogsDir == null) { throw new ArgumentNullException(nameof(fullDirPathToCharacterLogsDir)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (logFileInfoFactory == null) { throw new ArgumentNullException(nameof(logFileInfoFactory)); } if (internalEventInvoker == null) { throw new ArgumentNullException(nameof(internalEventInvoker)); } if (taskManager == null) { throw new ArgumentNullException(nameof(taskManager)); } this.logger = logger; this.logFileInfoFactory = logFileInfoFactory; this.taskManager = taskManager; CharacterName = characterName; FullDirPathToCharacterLogsDir = fullDirPathToCharacterLogsDir; onFilesAddedOrRemoved = internalEventInvoker.Create(() => new CharacterLogFilesAddedOrRemoved(CharacterName)); try { Refresh(); } catch (Exception exception) { logger.Log(LogLevel.Error, "Error at initial WurmCharacterLogFiles refresh: " + CharacterName, this, exception); } directoryWatcher = new FileSystemWatcher(fullDirPathToCharacterLogsDir) { Filter = "*.txt", NotifyFilter = NotifyFilters.FileName }; directoryWatcher.Created += DirectoryWatcherOnChanged; directoryWatcher.Deleted += DirectoryWatcherOnChanged; directoryWatcher.Renamed += DirectoryWatcherOnChanged; directoryWatcher.Changed += DirectoryWatcherOnChanged; directoryWatcher.EnableRaisingEvents = true; taskHandle = new TaskHandle(Refresh, "WurmCharacterLogFiles refresh: " + CharacterName); taskManager.Add(taskHandle); taskHandle.Trigger(); }
/// <summary> /// Handles the <see cref="E:RollbarEvent" /> event. /// </summary> /// <param name="e">The <see cref="RollbarEventArgs"/> instance containing the event data.</param> internal virtual void OnRollbarEvent(RollbarEventArgs e) { InternalEvent?.Invoke(this, e); }
protected internal override void InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_InitTransition(AdditionClientServiceDef_additionClientFSMContext context, InternalEvent ie) { AdditionClientServiceDef_additionClientFSM ctxt = context.Owner; #if TRACE Trace.WriteLine( "TRANSITION : AdditionClientServiceDef_additionClientFSM_SM.Ready.InternalStateChange_To_AdditionClientServiceDef_additionClientFSM_InitTransition(, InternalEvent ie)"); #endif context.State.Exit(context); context.ClearState(); try { ctxt.serviceStartedAction(); ctxt.processNotifications("Init", ie); } finally { context.State = AdditionClientServiceDef_additionClientFSM_SM.Init; context.State.Entry(context); } return; }
// This is the function that will process an event either generated // by the service, sent to it by another service on the same component, // or as a message sent by a different component. public override bool processTransitions(InternalEvent ie) { bool done = false; // Since this function can be called from multiple threads, // we use a mutex to ensure only one state transition is // active at a time. mutex.WaitOne(); // Invoke the FSM transition for this event. try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ConfirmControl().getID()) { ConfirmControl msg = new ConfirmControl(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); pManagementOCU_ManagementOcuFSM.context.ConfirmControlTransition(msg); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("MenuItemEntered") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { MenuItemEntered casted_ie = (MenuItemEntered)ie; MenuItemEntered msg = casted_ie; pManagementOCU_ManagementOcuFSM.context.MenuItemEnteredTransition(msg); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("MenuItemEntered") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { MenuItemEntered casted_ie = (MenuItemEntered)ie; MenuItemEntered msg = casted_ie; pManagementOCU_ManagementOcuFSM.context.MenuItemEnteredTransition(msg); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ConfirmControl().getID()) { ConfirmControl msg = new ConfirmControl(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); pManagementOCU_ManagementOcuFSM.context.ConfirmControlTransition(msg); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("InternalStateChange_To_ManagementOCU_ManagementOcuFSM_HandleMenu") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { pManagementOCU_ManagementOcuFSM.context.InternalStateChange_To_ManagementOCU_ManagementOcuFSM_HandleMenuTransition(ie); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("MenuItemEntered") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { MenuItemEntered casted_ie = (MenuItemEntered)ie; MenuItemEntered msg = casted_ie; pManagementOCU_ManagementOcuFSM.context.MenuItemEnteredTransition(msg); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("MenuItemEntered") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { MenuItemEntered casted_ie = (MenuItemEntered)ie; MenuItemEntered msg = casted_ie; pManagementOCU_ManagementOcuFSM.context.MenuItemEnteredTransition(msg); done = true; } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new RejectControl().getID()) { RejectControl msg = new RejectControl(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); pManagementOCU_ManagementOcuFSM.context.RejectControlTransition(msg); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("Receive") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { Receive casted_ie = (Receive)ie; int pos = 0; ushort id = BitConverter.ToUInt16(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); if (id == new ReportStatus().getID()) { ReportStatus msg = new ReportStatus(); msg.decode(casted_ie.getBody().getReceiveRec().getMessagePayload().getData(), pos); pManagementOCU_ManagementOcuFSM.context.ReportStatusTransition(msg); done = true; } } } catch (Exception e) {} try { if (ie.getName().CompareTo("InternalStateChange_To_ManagementOCU_ManagementOcuFSM_WaitForControl") == 0 && (ie.getSource().CompareTo("ManagementOCU_ManagementOcuFSM") != 0) && (!done)) { pManagementOCU_ManagementOcuFSM.context.InternalStateChange_To_ManagementOCU_ManagementOcuFSM_WaitForControlTransition(ie); done = true; } } catch (Exception e) {} mutex.ReleaseMutex(); return(done); }
private IObservable <T> Filter <T>(InternalEvent @event) => eventHub.Events.Where(o => o.Event == @event) .Select(o => (T)o.Data);
private void Operation_OperationComplete(object sender, OperationStateEventArgs e) { InternalEvent.SafeInvoke(sender, e); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(InternalEvent obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }