コード例 #1
0
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessMessage(G2H)"))
            {
                bool   result    = default(bool);
                string ipAddress = string.Empty;

                try
                {
                    using (FFTgtExecutionContext context = new FFTgtExecutionContext(request))
                    {
                        Stack <IFreeformEntity> st = new Stack <IFreeformEntity>();
                        request.CopyTo(st);

                        // push all the grandchildren into stack and process again
                        while (st.Count != 0)
                        {
                            IFreeformEntity_MsgTgt target = st.Pop() as IFreeformEntity_MsgTgt;
                            if (target == null || target.IsLeafNode)
                            {
                                continue;
                            }

                            _requestResponseMappings.Persist(request, target);
                            string targetKey = CreateSessionTargetKey((int)request.SessionID, target.TypeKey);
                            if (_targetHandlers.ContainsKey(targetKey))
                            {
                                _HandlerInfo info = _targetHandlers[targetKey];
                                context.HandlerAttribute = info.HandlerAttribute;
                                info.Handler.Execute(context, target);
                            }

                            target.CopyTo(st);
                        }

                        if (request.TransactionID <= 0)
                        {
                            request.TransactionID = FFMsgHandlerFactory.NewTransactionId;
                        }

                        if (request.SessionID != FF_AppId_SessionIds.Internal)
                        {
                            // ok everything processed, now do the external or internal processing
                            if (request.FlowDirection == FF_FlowDirection.G2H)
                            {
                                // add the monitor meters
                                if (context.MonitorMeters.IsValueCreated)
                                {
                                    context.MonitorTargets.Value.Add(context.MonitorMeters.Value);
                                }
                                _msgTransmitter.ProcessMessage(request as FFMsg_G2H, context.MonitorTargets.Value);
                            }
                            else if (request.FlowDirection == FF_FlowDirection.H2G)
                            {
                                _msgTransmitter.ProcessMessage(request as FFMsg_H2G);
                            }

                            // process the internal messages
                            if (context.FreeformTargets != null &&
                                context.FreeformTargets.Count > 0)
                            {
                                FFMsg_H2G h2gMessage = null;
                                foreach (var freeformEntity in context.FreeformTargets)
                                {
                                    if (freeformEntity is IFreeformEntity_Msg)
                                    {
                                        FFMsgHandlerFactory.Current.Execute(freeformEntity as IFreeformEntity_Msg);
                                    }
                                    else if (freeformEntity is IFreeformEntity_MsgTgt)
                                    {
                                        if (h2gMessage == null)
                                        {
                                            h2gMessage = FreeformEntityFactory.CreateEntity <FFMsg_H2G>(FF_FlowDirection.H2G,
                                                                                                        new FFCreateEntityRequest_H2G()
                                            {
                                                IPAddress     = request.IpAddress,
                                                PollCode      = FF_AppId_H2G_PollCodes.FreeformNoResponse,
                                                SessionID     = request.SessionID,
                                                TransactionID = request.TransactionID,
                                            });
                                        }
                                        h2gMessage.Targets.Add(freeformEntity as IFreeformEntity_MsgTgt);
                                    }
                                }

                                if (h2gMessage != null)
                                {
                                    FFMsgHandlerFactory.Current.Execute(h2gMessage);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
コード例 #2
0
        /// <summary>
        /// Converts Monitor entity message to Freeform entity message
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Freeform entity message.</returns>
        public FFMsg_H2G CreateEntity(MonMsg_H2G request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CreateEntity"))
            {
                FFMsg_H2G result = null;
                try
                {
                    if (request == null || request.Targets.Count == 0)
                    {
                        Log.Info("Unable to create the freeform message (Invalid targets found).");
                        return(null);
                    }

                    string key = request.FaultSourceTypeKey;

                    foreach (var monTgt in request.Targets)
                    {
                        IMonTgtParser parser = null;
                        MonTgtParserMappingH2GAttribute mappingAttribute = null;

                        //if (_tgtParserMappingsH2G.ContainsKey(key))
                        //{
                        //    parser = _tgtParserMappingsH2G[key];
                        //    mappingAttribute = parser.MappingAttributeH2G;
                        //}

                        //if (parser == null)
                        //{
                        key = monTgt.GetType().FullName;
                        if (_tgtParserMappingsByTypeH2G.ContainsKey(key))
                        {
                            parser           = _tgtParserMappingsByTypeH2G[key];
                            mappingAttribute = parser.MappingAttributeH2G;
                        }
                        //}

                        if (parser != null)
                        {
                            IFreeformEntity_MsgTgt ffTgt = parser.CreateEntity(request, monTgt) as IFreeformEntity_MsgTgt;
                            if (ffTgt != null)
                            {
                                if (result == null)
                                {
                                    result = FreeformEntityFactory.CreateEntity <FFMsg_H2G>(FF_FlowDirection.H2G,
                                                                                            new FFCreateEntityRequest_H2G()
                                    {
                                        PollCode  = mappingAttribute.PollCode,
                                        SessionID = mappingAttribute.SessionID,
                                        IPAddress = request.IpAddress,
                                    });
                                    result.InstallationNo = request.InstallationNo;
                                }
                                result.Targets.Add(ffTgt);
                            }
                        }
                    }

                    if (result == null)
                    {
                        Log.Info("Unable to create the freeform message");
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
コード例 #3
0
 protected virtual bool OnModifyMessageH2G(ILogMethod method, FFMsg_H2G message)
 {
     return(true);
 }
コード例 #4
0
 protected virtual void OnModifyMessage(ILogMethod method, FFMsg_H2G message)
 {
 }
コード例 #5
0
 protected abstract bool ProcessMessageInternal(ILogMethod method, FFMsg_H2G message);
コード例 #6
0
        private void OnReceiveUdpEntityFromSocket(UdpSocketReceiveData message)
        {
            using (ILogMethod method = Log.LogMethod(LOGGER, this.DYN_MODULE_NAME, "OnReceiveUdpEntityFromSocket"))
            {
                try
                {
                    // create the raw entity message
                    method.InfoV("RECV_SOCK : Received from {0} / {1:D}",
                                 message.RemoteEndpoint.ToString(), message.BufferLength);
                    UdpFreeformEntity udpEntity = FreeformEntityFactory.CreateUdpEntity(FF_FlowDirection.G2H, message.Buffer);
                    if (udpEntity == null ||
                        udpEntity.RawData == null ||
                        udpEntity.RawData.Length == 0)
                    {
                        method.Info("RECV_SOCK : Unable to parse the data from socket (Invalida message format).");
                        if (udpEntity != null &&
                            udpEntity.Address != null)
                        {
                            // send the nack
                            this.Send(FreeformEntityFactory.CreateH2GMessageAckNack(udpEntity.AddressString, true));
                        }
                        return;
                    }

                    // convert the freeform entity message
                    FFMsg_G2H g2hMessage = FreeformEntityFactory.CreateEntity(FF_FlowDirection.G2H, udpEntity) as FFMsg_G2H;
                    if (g2hMessage == null)
                    {
                        method.Info("RECV_SOCK : Unable to create the freeform entity from udp entity message.");
                        // send the nack
                        this.Send(FreeformEntityFactory.CreateH2GMessageAckNack(udpEntity.AddressString, true));
                        return;
                    }

                    // send the ack message (if necessary)
                    FFMsg_H2G msgAck = FreeformEntityFactory.CreateH2GMessageAckNack(udpEntity.AddressString, g2hMessage.Command);
                    if (msgAck != null)
                    {
                        this.Send(msgAck);
                    }

                    // process the message
                    udpEntity.EntityData = g2hMessage;
                    method.InfoV("RECV_SOCK (Success) : {0} [{1}] was received for processing.",
                                 udpEntity, udpEntity.ProcessDate.ToStringSafe());
                    if (_configStore.LogRawFreeformMessages)
                    {
                        string udpEntityString = udpEntity.ToStringRaw(FF_FlowDirection.G2H);
                        Log.Info(udpEntityString);
                        LOGGER.WriteLogInfo(udpEntityString + Environment.NewLine);
                        LOGGER_UDP_RECV.WriteLogInfo(udpEntity.ProcessDate.ToStringSafe());
                        LOGGER_UDP_RECV.WriteLogInfo(udpEntityString + Environment.NewLine);
                    }
                    this.OnReceiveFromSocket(udpEntity);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }