public bool Send(UdpFreeformEntity udpEntity)
        {
            using (ILogMethod method = Log.LogMethod(LOGGER, this.DYN_MODULE_NAME, "Send"))
            {
                bool result = default(bool);

                try
                {
                    if (udpEntity == null)
                    {
                        method.Info("Unable to send message (request is empty).");
                        return(false);
                    }

                    byte[] rawData = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.H2G, udpEntity);
                    if (rawData == null ||
                        rawData.Length == 0)
                    {
                        method.Info("Unable to send message (rawData was null or zero length).");
                        return(false);
                    }

                    if (_configStore.LogRawFreeformMessages)
                    {
                        udpEntity.ProcessDate = DateTime.Now;
                        string udpEntityString = udpEntity.ToStringRaw(FF_FlowDirection.H2G);
                        Log.Info(udpEntityString);
                        LOGGER.WriteLogInfo(udpEntityString + Environment.NewLine);
                        LOGGER_UDP_SEND.WriteLogInfo(udpEntity.ProcessDate.ToStringSafe());
                        LOGGER_UDP_SEND.WriteLogInfo(udpEntityString + Environment.NewLine);
                    }

                    using (UdpSocketSendData sendData = new UdpSocketSendData()
                    {
                        IPAddress = udpEntity.Address,
                        PortNo = _configStore.TransmitPortNo,
                        Buffer = rawData,
                    })
                    {
                        result = _sockTransmitter.Transmit(sendData);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
Beispiel #2
0
        public bool Send(UdpFreeformEntity request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Send"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null)
                    {
                        method.Info("Unable to send message (request is empty).");
                        return(false);
                    }

                    byte[] rawData = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.G2H, request);
                    if (rawData == null ||
                        rawData.Length == 0)
                    {
                        method.Info("Unable to send message (rawData was null or zero length).");
                        return(false);
                    }

                    using (UdpSocketSendData sendData = new UdpSocketSendData()
                    {
                        IPAddress = Extensions.GetIpAddress(-1),
                        PortNo = _configStore.ReceivePortNo,
                        Buffer = rawData,
                    })
                    {
                        result = _sockTransmitter.Transmit(sendData);

                        if (this.AfterSendUdpEntityData != null)
                        {
                            byte[] rawDataWithoutIp = new byte[rawData.Length - 4];
                            Buffer.BlockCopy(rawData, 4, rawDataWithoutIp, 0, rawDataWithoutIp.Length);
                            request.RawData     = rawDataWithoutIp;
                            request.ProcessDate = DateTime.Now;
                            this.AfterSendUdpEntityData(request);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
        public bool Send(UdpFreeformEntity udpEntity)
        {
            using (ILogMethod method = Log.LogMethod(LOGGER, this.DYN_MODULE_NAME, "Send"))
            {
                bool result = default(bool);

                try
                {
                    if (udpEntity == null)
                    {
                        method.Info("Unable to send message (request is empty).");
                        return false;
                    }

                    byte[] rawData = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.H2G, udpEntity);
                    if (rawData == null ||
                        rawData.Length == 0)
                    {
                        method.Info("Unable to send message (rawData was null or zero length).");
                        return false;
                    }

                    if (_configStore.LogRawFreeformMessages)
                    {
                        udpEntity.ProcessDate = DateTime.Now;
                        string udpEntityString = udpEntity.ToStringRaw(FF_FlowDirection.H2G);
                        Log.Info(udpEntityString);
                        LOGGER.WriteLogInfo(udpEntityString + Environment.NewLine);
                        LOGGER_UDP_SEND.WriteLogInfo(udpEntity.ProcessDate.ToStringSafe());
                        LOGGER_UDP_SEND.WriteLogInfo(udpEntityString + Environment.NewLine);
                    }

                    using (UdpSocketSendData sendData = new UdpSocketSendData()
                    {
                        IPAddress = udpEntity.Address,
                        PortNo = _configStore.TransmitPortNo,
                        Buffer = rawData,
                    })
                    {
                        result = _sockTransmitter.Transmit(sendData);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        public bool Send(UdpFreeformEntity request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Send"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null)
                    {
                        method.Info("Unable to send message (request is empty).");
                        return false;
                    }

                    byte[] rawData = FreeformEntityFactory.CreateBuffer(FF_FlowDirection.G2H, request);
                    if (rawData == null ||
                        rawData.Length == 0)
                    {
                        method.Info("Unable to send message (rawData was null or zero length).");
                        return false;
                    }

                    using (UdpSocketSendData sendData = new UdpSocketSendData()
                    {
                        IPAddress = Extensions.GetIpAddress(-1),
                        PortNo = _configStore.ReceivePortNo,
                        Buffer = rawData,
                    })
                    {
                        result = _sockTransmitter.Transmit(sendData);

                        if (this.AfterSendUdpEntityData != null)
                        {
                            byte[] rawDataWithoutIp = new byte[rawData.Length - 4];
                            Buffer.BlockCopy(rawData, 4, rawDataWithoutIp, 0, rawDataWithoutIp.Length);
                            request.RawData = rawDataWithoutIp;
                            request.ProcessDate = DateTime.Now;
                            this.AfterSendUdpEntityData(request);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }