protected override void OnParseEntityPart2(FFMsg_G2H msg, ref List <byte> buffer)
        {
            FFMsg_G2H_1 msg2 = msg as FFMsg_G2H_1;

            buffer.SetValue(msg2.SegmentCount, 2);
            buffer.SetValue(msg2.SegmentNumber, 2);
        }
        internal override IFreeformEntity ParseBufferInternal(ref IFreeformEntity entity, IFreeformEntity rootEntity, int id, byte[] buffer)
        {
            // get and verify the session id
            bool isResponseRequired       = false;
            int  actualSessionId          = 0;
            FF_AppId_SessionIds sessionId = this.GetSessionId(buffer, FreeformConstants.IDX_RECV_SESSION_ID, ref actualSessionId, ref isResponseRequired);

            if (sessionId == FF_AppId_SessionIds.None)
            {
                Log.Warning("Invalid message passed (Invalid session)");
                return(null);
            }

            // create the message
            entity = this.CreateEntity();
            FFMsg_G2H msg = entity as FFMsg_G2H;

            if (msg != null)
            {
                int offset = 0;
                msg.IsResponseRequired = isResponseRequired;
                this.OnParseBufferPart1(msg, buffer, sessionId, ref offset);
                this.OnParseBufferPart2(msg, buffer, ref offset);
                this.OnParseBufferPart3(msg, buffer, ref offset);
            }

            msg.IsResponseRequired = isResponseRequired;
            msg.ActualSessionID    = actualSessionId;
            return(msg);
        }
        protected override bool ProcessMessageInternal(ILogMethod method, FFMsg_G2H message)
        {
            if (message == null)
            {
                method.Info("Freeform message (G2H) was null.");
                return false;

            }

            this.OnModifyMessage(method, message);
            
            // convert the monitor message from freeform message
            MonMsg_G2H monMsg = MonitorEntityFactory.CreateEntity(message);
            if (monMsg == null)
            {
                method.Info("Unable to convert the monitor message from freeform message.");
                return false;
            }

            // post the monitor message into monitor processor
            if (!this.MonitorProcessor.ProcessG2HMessage(monMsg))
            {
                method.Info("Unable to post the message to monitor processor.");
                return false;
            }

            return true;
        }
        protected virtual bool OnProcessMessageInternal(FFMsg_G2H message, IList<MonitorEntity_MsgTgt> monitorTargets)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "OnProcessMessageInternal(G2H)"))
            {
                bool result = default(bool);

                try
                {
                    if (monitorTargets == null || monitorTargets.Count == 0) return true;

                    // convert the monitor message from freeform message
                    MonMsg_G2H monMsg = MonitorEntityFactory.CreateEntity(message, monitorTargets);
                    if (monMsg == null)
                    {
                        method.Info("Unable to convert the monitor message from freeform message.");
                        return false;
                    }

                    // post the monitor message into monitor processor
                    if (!this.MonitorProcessor.ProcessG2HMessage(monMsg))
                    {
                        method.Info("Unable to post the message to monitor processor.");
                        return false;
                    }

                    result = true;
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
 protected virtual void OnParseEntityPart1(FFMsg_G2H msg, ref List <byte> buffer)
 {
     buffer.Add((byte)msg.DeviceType);
     buffer.Add(msg.MessageType.GetGmuIdInt8());
     buffer.Add(msg.Command.GetGmuIdInt8());
     buffer.Add(msg.SessionID.GetGmuIdInt8().CreateRequestResponseId(msg.IsResponseRequired));
     buffer.Add((byte)msg.TransactionID);
 }
 protected virtual void OnParseBufferPart1(FFMsg_G2H msg, byte[] buffer, FF_AppId_SessionIds sessionId, ref int offset)
 {
     msg.DeviceType  = (FF_GmuId_DeviceTypes)buffer[offset++];
     msg.MessageType = buffer.GetBytesToNumberUInt8(offset++, 1).GetAppId <FF_GmuId_G2H_MessageTypes, FF_AppId_G2H_MessageTypes>();
     msg.Command     = buffer.GetBytesToNumberUInt8(offset++, 1).GetAppId <FF_GmuId_G2H_Commands, FF_AppId_G2H_Commands>();
     msg.SessionID   = sessionId;
     offset++;
     msg.TransactionID = buffer.GetBytesToNumberUInt8(offset++, 1);
 }
        protected override void OnParseBufferPart2(FFMsg_G2H msg, byte[] buffer, ref int offset)
        {
            FFMsg_G2H_1 msg2 = msg as FFMsg_G2H_1;

            msg2.SegmentNumber = buffer.GetValue <ushort>(offset, 2);
            offset            += 2;
            msg2.SegmentCount  = buffer.GetValue <ushort>(offset, 2);
            offset            += 2;
        }
 protected override void OnModifyMessage(ILogMethod method, FFMsg_G2H message)
 {
     FFTgt_B2B_Encrypted target = message.GetTarget<FFTgt_B2B_Encrypted>();
     if (target == null ||
         target.EntityData == null)
     {
         throw new ArgumentNullException("No valid encrypted targets found");
     }
 }
        protected virtual void OnParseBufferPart3(FFMsg_G2H msg, byte[] buffer, ref int offset)
        {
            msg.DataLength = buffer.GetValue <ushort>(offset, _parentParser.DataLength);
            offset        += _parentParser.DataLength;
            msg.EntityData = buffer.GetValue <byte[]>(offset, msg.DataLength);
            offset        += msg.DataLength;

            msg.Checksum           = buffer.GetBytesToNumberUInt8(-1, 1);
            msg.ChecksumCalculated = FreeformHelper.CalculateCheckSum(buffer, 0, buffer.Length - 1);
        }
 internal static bool ProcessMessage(FFMsg_G2H request)
 {
     if (_executorType == 0)
     {
         return _executor.ProcessMessage(request);
     }
     else
     {
         FreeformExecutorFactory.ProcessMessage(request);
         return true;
     }
 }
        internal override void ParseEntityInternal(IFreeformEntity entity, ref List <byte> buffer)
        {
            FFMsg_G2H msg = entity as FFMsg_G2H;

            if (msg != null)
            {
                this.OnParseEntityPart1(msg, ref buffer);
                this.OnParseEntityPart2(msg, ref buffer);
                this.OnParseEntityPart3(msg, ref buffer);

                // Prefix the Ip address
                byte[] addressBytes = msg.IpAddress2.GetAddressBytes();
                buffer.InsertRange(0, addressBytes);
            }
        }
        protected virtual void OnParseEntityPart3(FFMsg_G2H msg, ref List <byte> buffer)
        {
            msg.EntityData = this.TargetParser.ParseTarget(msg);
            if (msg.EntityData == null)
            {
                msg.EntityData = new byte[msg.DataLength];
            }
            msg.DataLength = (ushort)msg.EntityData.Length;

#if !DATA_LEN_RECV_1
            buffer.SetValue(msg.DataLength, 2);
#else
            buffer.SetValue(msg.DataLength, 1);
#endif
            buffer.AddRange(msg.EntityData);
            buffer.CalculateAndStoreChecksum();
        }
        public bool ProcessMessage(FFMsg_G2H message)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessMessage(G2H)"))
            {
                bool result = default(bool);

                try
                {
                    result = this.ProcessMessageInternal(method, message);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        public bool ProcessMessage(FFMsg_G2H message, IList<MonitorEntity_MsgTgt> monitorTargets)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessMessage(G2H)"))
            {
                bool result = default(bool);

                try
                {
                    result = this.OnProcessMessageInternal(message, monitorTargets);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        public bool ProcessMessage(FFMsg_G2H message)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessMessage(G2H)"))
            {
                bool result = default(bool);

                try
                {
                    var sessionId = (int)message.SessionID;
                    result = _handlers.ContainsKey(sessionId) ? 
                        _handlers[sessionId].ProcessMessage(message) : 
                        _genericHandler.ProcessMessage(message);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        internal override IFreeformEntity CreateEntityInternal(FFCreateEntityRequest request)
        {
            if (!(request is FFCreateEntityRequest_G2H))
            {
                return(null);
            }

            // create the entity and parse
            FFCreateEntityRequest_G2H request2 = request as FFCreateEntityRequest_G2H;
            int       iCommand = (int)request2.Command;
            FFMsg_G2H msg      = this.GetParserFromAppId(iCommand).CreateEntity() as FFMsg_G2H;

            msg.IsSecured          = request2.IsSecured;
            msg.IsResponseRequired = request2.IsResponseRequired;
            msg.IpAddress          = request2.IPAddress;
            msg.Command            = (FF_AppId_G2H_Commands)iCommand;
            msg.MessageType        = request2.MessageType;
            msg.SessionID          = request2.SessionID;
            msg.TransactionID      = request2.TransactionID;
            return(msg);
        }
        public static FFMsg_G2H CreateG2HMessage(string ipAddress, FF_AppId_G2H_Commands command, FF_AppId_G2H_MessageTypes messageType,
                                                 FF_AppId_SessionIds sessionId, bool isResponseRequired,
                                                 params IFreeformEntity_MsgTgt[] targets)
        {
            FFMsg_G2H msg = FreeformEntityFactory.CreateEntity <FFMsg_G2H>(FF_FlowDirection.G2H,
                                                                           new FFCreateEntityRequest_G2H_ResponseRequired()
            {
                Command            = command,
                MessageType        = messageType,
                SessionID          = sessionId,
                IPAddress          = ipAddress,
                SkipTransactionId  = true,
                IsResponseRequired = isResponseRequired,
            });

            if (targets != null)
            {
                msg.AddTargets(targets);
            }
            return(msg);
        }
 protected virtual void OnParseEntityPart1(FFMsg_G2H msg, ref List<byte> buffer)
 {
     buffer.Add((byte)msg.DeviceType);
     buffer.Add(msg.MessageType.GetGmuIdInt8());
     buffer.Add(msg.Command.GetGmuIdInt8());
     buffer.Add(msg.SessionID.GetGmuIdInt8().CreateRequestResponseId(msg.IsResponseRequired));
     buffer.Add((byte)msg.TransactionID);
 }
        protected virtual void OnParseBufferPart3(FFMsg_G2H msg, byte[] buffer, ref int offset)
        {
            msg.DataLength = buffer.GetValue<ushort>(offset, _parentParser.DataLength);
            offset += _parentParser.DataLength;
            msg.EntityData = buffer.GetValue<byte[]>(offset, msg.DataLength);
            offset += msg.DataLength;

            msg.Checksum = buffer.GetBytesToNumberUInt8(-1, 1);
            msg.ChecksumCalculated = FreeformHelper.CalculateCheckSum(buffer, 0, buffer.Length - 1);
        }
 protected virtual void OnParseBufferPart2(FFMsg_G2H msg, byte[] buffer, ref int offset) { }
 protected virtual void OnParseBufferPart1(FFMsg_G2H msg, byte[] buffer, FF_AppId_SessionIds sessionId, ref int offset)
 {
     msg.DeviceType = (FF_GmuId_DeviceTypes)buffer[offset++];
     msg.MessageType = buffer.GetBytesToNumberUInt8(offset++, 1).GetAppId<FF_GmuId_G2H_MessageTypes, FF_AppId_G2H_MessageTypes>();
     msg.Command = buffer.GetBytesToNumberUInt8(offset++, 1).GetAppId<FF_GmuId_G2H_Commands, FF_AppId_G2H_Commands>();
     msg.SessionID = sessionId;
     offset++;
     msg.TransactionID = buffer.GetBytesToNumberUInt8(offset++, 1);
 }
 protected abstract bool ProcessMessageInternal(ILogMethod method, FFMsg_G2H message);
 protected override void OnParseBufferPart2(FFMsg_G2H msg, byte[] buffer, ref int offset)
 {
     FFMsg_G2H_1 msg2 = msg as FFMsg_G2H_1;
     msg2.SegmentNumber = buffer.GetValue<ushort>(offset, 2);
     offset += 2;
     msg2.SegmentCount = buffer.GetValue<ushort>(offset, 2);
     offset += 2;
 }
Ejemplo n.º 24
0
        void OnProcessG2HMessageFromWorker(FFMsg_G2H request)
        {
            bool proceed = true;

            if (request.SessionID != FF_AppId_SessionIds.GIM)
            {
                proceed = PopulateInstallationNo(request);
            }

            if (!proceed)
            {
                Log.Info("Freeform message received before GIM message.");
            }
            else
            {
                FFMsgHandlerFactory.Current.Execute(request);
            }
        }
Ejemplo n.º 25
0
        protected virtual IThreadPoolExecutor<FFMsg_G2H> GetExecutorG2H(FFMsg_G2H msg)
        {
            switch (msg.SessionID)
            {
                case FF_AppId_SessionIds.A1:
                    return _g2hExecutor_NonPrio;

                case FF_AppId_SessionIds.GIM:
                    return _g2hExecutor_GIM;

                default:
                    return _g2hExecutor_Prio;
            }
        }
Ejemplo n.º 26
0
        private bool PopulateInstallationNo(FFMsg_G2H message)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "UpdateInstallationNo"))
            {
                bool retval = default(bool);

                try
                {
                    string ipAddress = message.IpAddress;
                    if (_mapIPInstallation != null &&
                        _mapIPInstallation.ContainsKey(ipAddress))
                    {
                        message.InstallationNo = _mapIPInstallation[ipAddress];
                        retval = true;
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return retval;
            }
        }
 protected virtual void OnParseEntityPart2(FFMsg_G2H msg, ref List <byte> buffer)
 {
 }
        public static void ProcessMessage(FFMsg_G2H message)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage(G2H)"))
            {
                try
                {
                    FreeformExecutorBase executor = GetMessageType(message.SessionID);
                    bool result = false;

                    if (message.SessionID == FF_AppId_SessionIds.GIM)
                    {
                        result = executor.ProcessMessage(message);
                    }
                    else
                    {
                        if (UpdateInstallationNo(ref message))
                        {
                            result = executor.ProcessMessage(message);
                        }
                    }

                    if (!result)
                    {
                        Log.Info("Freeform message received before GIM message.");
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
 protected virtual void OnParseEntityPart2(FFMsg_G2H msg, ref List<byte> buffer) { }
Ejemplo n.º 30
0
        public virtual bool ProcessMessage(FFMsg_G2H request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessG2HMessage"))
            {
                bool result = false;

                try
                {
                    // find the queue executor by session id
                    IThreadPoolExecutor<FFMsg_G2H> executor = this.GetExecutorG2H(request);
                    executor.QueueWorkerItem(request);
                    result = true;
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        protected virtual void OnParseEntityPart3(FFMsg_G2H msg, ref List<byte> buffer)
        {
            msg.EntityData = this.TargetParser.ParseTarget(msg);
            if (msg.EntityData == null) msg.EntityData = new byte[msg.DataLength];
            msg.DataLength = (ushort)msg.EntityData.Length;

#if !DATA_LEN_RECV_1
            buffer.SetValue(msg.DataLength, 2);
#else
            buffer.SetValue(msg.DataLength, 1);
#endif
            buffer.AddRange(msg.EntityData);
            buffer.CalculateAndStoreChecksum();
        }
 protected virtual void OnModifyMessage(ILogMethod method, FFMsg_G2H message) { }
 protected override void OnParseEntityPart2(FFMsg_G2H msg, ref List<byte> buffer)
 {
     FFMsg_G2H_1 msg2 = msg as FFMsg_G2H_1;
     buffer.SetValue(msg2.SegmentCount, 2);
     buffer.SetValue(msg2.SegmentNumber, 2);
 }
 protected virtual void OnParseBufferPart2(FFMsg_G2H msg, byte[] buffer, ref int offset)
 {
 }