public override void Handle(T808ProtocolPackage package)
        {
            string fileKey = "upload-file";

            using (BytesReader reader = new BytesReader(package.RawData))
            {
                //移动索引到消息体
                reader.MoveIndex(package.BodyIndex);
                if (package.Index == 1)
                {
                    #region 解析多媒体事件消息

                    string path = Path.Combine(@Environment.CurrentDirectory, "file", package.DeviceGpsCode, "images", DateTime.Now.ToString("yyyyMMdd"));
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    EMedia mp = new EMedia();
                    mp.Id = reader.ReadInt32();
                    mp.Type = reader.Read()[0];
                    mp.Encoding = reader.Read()[0];
                    mp.EventType = reader.Read()[0];
                    mp.ChannelId = reader.Read()[0];
                    mp.FullFileName = Path.Combine(path, string.Format("{0}_{1}_{2}_{3}.{4}", mp.EventType, mp.ChannelId, mp.Id, DateTime.Now.ToString("yyyyMMddHHmmss"), mp.Ext));
                    package.Session[fileKey] = mp;

                    #endregion 解析媒体信息数据和定位数据
                }
                var file = package.Session[fileKey] as EMedia;
                if (file != null)
                {
                    var mediaData = reader.Read(reader.Data.Length - reader.Index - 2);
                    using (FileStream fs = new FileStream(file.FullFileName, FileMode.Append, FileAccess.Write))
                    {
                        fs.Write(mediaData, 0, mediaData.Length);
                    }
                }
            }

            //报警处理器中不再处理这个包
            package.IsCanceled = true;
            SendCommonResponse(package);
        }
        public override void Handle(T808ProtocolPackage package)
        {
            var fileKey = "upload-file";

            using (var reader = new BytesReader(package.RawData))
            {
                //移动索引到消息体
                reader.MoveIndex(package.BodyIndex);
                if (package.Index == 1)
                {
                    #region 解析媒体信息数据和定位数据

                    //只有第一个包携带有媒体信息数据和定位数据
                    var path = Path.Combine(@Environment.CurrentDirectory, "file", package.DeviceGpsCode, "images", DateTime.Now.ToString("yyyyMMdd"));
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    var mp = new EMedia
                    {
                        Id = reader.ReadInt32(),
                        Type = reader.Read()[0],
                        Encoding = reader.Read()[0],
                        EventType = reader.Read()[0],
                        ChannelId = reader.Read()[0]
                    };
                    mp.FullFileName = Path.Combine(path, string.Format("{0}_{1}_{2}_{3}.{4}", mp.EventType, mp.ChannelId, mp.Id, DateTime.Now.ToString("yyyyMMddHHmmss"), mp.Ext));
                    mp.Position = new EPosition();

                    //跳过报警数据
                    reader.MoveIndex(4);

                    var gpsStatus = (EnumGpsStatus)reader.ReadInt32();

                    if (gpsStatus.HasFlag(EnumGpsStatus.AccIsOn))
                    {
                        mp.Position.IsAccOn = true;
                    }
                    if (gpsStatus.HasFlag(EnumGpsStatus.GpsIsLocated))
                    {
                        mp.Position.IsLocated = true;
                    }
                    if (gpsStatus.HasFlag(EnumGpsStatus.SLat))
                    {
                        mp.Position.IsSLat = true;
                    }

                    if (gpsStatus.HasFlag(EnumGpsStatus.WLon))
                    {
                        mp.Position.IsWLon = true;
                    }
                    if (gpsStatus.HasFlag(EnumGpsStatus.OilBreak))
                    {
                        mp.Position.IsOilBreak = true;
                    }
                    if (gpsStatus.HasFlag(EnumGpsStatus.PowerBreak))
                    {
                        mp.Position.IsPowerBreak = true;
                    }

                    if (gpsStatus.HasFlag(EnumGpsStatus.Encrypted))
                    {
                        mp.Position.IsEmergency = true;
                    }
                    mp.Position.Latitude = reader.ReadInt32() / 1000000d;
                    mp.Position.Longitude = reader.ReadInt32() / 1000000d;
                    mp.Position.Height = reader.ReadInt16();
                    mp.Position.Speed = reader.ReadInt16() / 10.00;
                    mp.Position.Direction = reader.ReadInt16();
                    mp.Position.ReportTime = reader.ReadDateTimeByBCD();
                    package.Session[fileKey] = mp;

                    #endregion 解析媒体信息数据和定位数据
                }
                var file = package.Session[fileKey] as EMedia;
                if (file != null)
                {
                    var mediaData = reader.Read(reader.Data.Length - reader.Index - 2);
                    using (var fs = new FileStream(file.FullFileName, FileMode.Append, FileAccess.Write))
                    {
                        fs.Write(mediaData, 0, mediaData.Length);
                    }
                }
            }

            //报警处理器中不再处理这个包
            package.IsCanceled = true;
            SendCommonResponse(package);
        }