Beispiel #1
0
        public void TestStorageFlagParam()
        {
            StorageFlagParam param = new StorageFlagParam(new VideoInfo("objectId", 2), true);

            byte[]           buffer = StorageFlagParam.Encode(param);
            StorageFlagParam param2 = StorageFlagParam.Decode(buffer);

            AssertAreEqual(param, param2);

            StorageFlagParam param3 = new StorageFlagParam(new VideoInfo("objectId", 2, "test"), false);

            byte[]           buffer2 = StorageFlagParam.Encode(param3);
            StorageFlagParam param4  = StorageFlagParam.Decode(buffer2);

            AssertAreEqual(param3, param4);
        }
Beispiel #2
0
        private void Adapter_ReceiveCompleted(object sender, ReceiveEventArgs args)
        {
            if (args.ByteLength > 0)
            {
                SocketAdapter adapter = sender as SocketAdapter;
                using (MemoryStream ms = new MemoryStream(args.ReceivedBytes))
                {
                    int    code   = PacketBase.ReadInt(ms);
                    byte[] buffer = null;
                    switch ((ParamCode)code)
                    {
                    case ParamCode.TimePeriods:
                        buffer = getVideoTimePeriodsPacketBuffer(VideoBaseInfomParam.Decode(ms));
                        break;

                    case ParamCode.VideoPacket:
                        buffer = getVideoPacketBuffer(VideoDataParam.Decode(ms));
                        break;

                    case ParamCode.VideoBaseInfo:
                        VideoBaseInfomParam param = VideoBaseInfomParam.Decode(ms);
                        Common.Log.Logger.Default.Trace($"下载视频:{param.BeginTime} - {param.EndTime} - {param.VideoName} - {param.VideoId} - {param.StreamId} -- {adapter.RemoteEndPoint}");
                        _isDownload = true;
                        buffer      = getVideoBasePacketBuffer(param);
                        break;

                    case ParamCode.StorageFlag:
                        onStorageFlag(StorageFlagParam.Decode(ms));
                        break;

                    case ParamCode.StorageFlagAll:
                        buffer = getStorageFlagAll();
                        Console.WriteLine("StorageFlagAll: {0}", buffer.Length);
                        break;
                    }
                    if (buffer != null)
                    {
                        adapter.Send(code, buffer);
                    }
                }
            }
        }