Ejemplo n.º 1
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null)
            {
                return(string.Empty);
            }
            if (values.Length != 2)
            {
                return(string.Empty);
            }
            var data = values[0] as byte[];

            if (data == null || data.Length == 0)
            {
                return(string.Empty);
            }
            //double width;
            //if (double.TryParse(values[1].ToString(), out width) == false) return string.Empty;

            return(DataContentHelper.DataContentConvert(data));
        }
Ejemplo n.º 2
0
        private void DoWork()
        {
            if (_bufferQueue.Length <= 5)
            {
                Pause();
            }
            int startIndex = ByteUtil.IndexOf(_bufferQueue.Data, _headBytes);

            if (startIndex > 0)
            {
                var removeBuffers = ByteUtil.InterceptByteArray(_bufferQueue.Data, 0, startIndex);
                Log.Info("\nSingle header error,startIndex : " + startIndex);
                Log.Info(string.Format("Buffer Queue[{0}]:{1}", _bufferQueue.Data.Length,
                                       DataContentHelper.DataContentConvert(_bufferQueue.Data)));
                Log.Info(string.Format("Remove buffers[{0}]:{1}", removeBuffers.Length,
                                       DataContentHelper.DataContentConvert(removeBuffers)));
                _bufferQueue.Remove(0, startIndex);
                Log.Info(string.Format("Remove buffers after[{0}]:{1}\n", _bufferQueue.Length,
                                       DataContentHelper.DataContentConvert(_bufferQueue.Data)));
                return;
            }
            if (startIndex == -1)
            {
                Pause();
                return;
            }

            byte[] lengthBytes  = ByteUtil.InterceptByteArray(_bufferQueue.Data, 2, 2);
            int    singleLength = BitConverter.ToUInt16(lengthBytes, 0);

            if (_bufferQueue.Length < singleLength)
            {
                Pause();
                return;
            }

            //信令长度足够时
            int  index   = 4;
            byte type    = _bufferQueue.Data[index];
            var  buffers = _bufferQueue.DequeueBytes(singleLength);

            if (buffers == null || buffers.Length == 0)
            {
                return;
            }

            var parser = new ParseFactory().CreateParser(type);

            if (parser != null)
            {
                try
                {
                    bool isSuccess = parser.TryParse(buffers);
                    if (isSuccess)
                    {
                        Log.Info(string.Format("Type:{0} parse {1}", type, "failed"));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(DataContentHelper.DataContentConvert(buffers));
                    Log.Error(parser.ToString());
                    Log.Error(ex);
                }
            }
        }