Exemplo n.º 1
0
 static void AssertAreEqual(StorageFlagParam param, StorageFlagParam param2)
 {
     Assert.AreEqual(param.VideoId, param2.VideoId);
     Assert.AreEqual(param.StreamId, param2.StreamId);
     Assert.AreEqual(param.VideoName, param2.VideoName);
     Assert.AreEqual(param.StorageOn, param2.StorageOn);
 }
Exemplo n.º 2
0
        public void SetStorageFlag(string videoId, int streamId, bool storageOn)
        {
            EnsureStart();
            VideoInfo        vi  = new VideoInfo(videoId, streamId);
            StorageFlagParam sfp = new StorageFlagParam(vi, storageOn);

            Client.Send((int)ParamCode.StorageFlag, StorageFlagParam.Encode(sfp));
        }
Exemplo n.º 3
0
 public void Add(StorageFlagParam param)
 {
     Logger.Default.Trace("视频 {0}({3})  {1}  通道{2}", param.VideoName, param.StorageOn ? "开启" : "关闭", param.StreamId, param.VideoId);
     updateFlags(param);
     if (param.StorageOn)
     {
         add(param);
     }
     else
     {
         remove(param);
     }
 }
Exemplo n.º 4
0
        private void updateFlags(StorageFlagParam param)
        {
            bool _flagChanged = _flags.RemoveAll(_ => _.VideoId == param.VideoId && _.StreamId == param.StreamId) > 0;

            if (param.StorageOn)
            {
                _flags.Add(param);
                _flagChanged = true;
            }
            if (_flagChanged)
            {
                saveFlags();
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
                    }
                }
            }
        }
Exemplo n.º 7
0
 private void onStorageFlag(StorageFlagParam storageFlagParam)
 {
     StorageFlagsManager.Instance.Add(storageFlagParam);
 }