예제 #1
0
        public void TestVideoBaseFileRecorder()
        {
            string path = @"D:\读写测试\VideoBaseFileRecorder";

            FolderManager.DeleteDirectoryInfo(path);
            var downloadInfo = new DownloadInfoParam("ip", 10001, beginTime, beginTime.AddMinutes(30), "videoId", 0, path, "test");
            VideoBaseFileRecorder recorder = new VideoBaseFileRecorder(path);

            recorder.UpdateDownloadInfo(downloadInfo);
            Assert.IsNull(recorder.TimePeriods);
            Assert.IsNull(recorder.VideoBase);

            recorder.UpdateTimePeriods(packet);
            Assert.AreEqual(packet, recorder.TimePeriods);
            recorder.UpdateVideoBase(basePacket);
            Assert.AreEqual(basePacket, recorder.VideoBase);
            DownloadInfoParamTest.AssertAreEqual(downloadInfo, recorder.DownloadInfo);

            VideoBaseFileRecorder recorder1 = new VideoBaseFileRecorder(path);

            VideoBasePacketTest.AssertAreEqual(recorder.VideoBase, recorder1.VideoBase);
            VideoTimePeriodsPacketTest.AssertAreEqual(recorder.TimePeriods, recorder1.TimePeriods);

            FolderManager.DeleteDirectoryInfo(path);
        }
예제 #2
0
        public void TestVideoPackageRecorder()
        {
            FolderManager.DeleteDirectoryInfo(path);
            TimePeriodPacket[] tisAll       = new TimePeriodPacket[] { new TimePeriodPacket(begin, end) };
            TimePeriodPacket[] tisCompleted = null;

            using (VideoPackageRecorder recorder = new VideoPackageRecorder(path, TimeSpan.FromMinutes(1), tisAll, tisCompleted))
            {
                recorder.ProbeTime = end;
                check(recorder, false, false, 0, 0);
                recorder.SetVideoBaseInfo(new VideoBasePacket(new byte[5], begin, 10000));
                check(recorder, true, false, 0, 0);
                recorder.Set(null);
                for (int i = 0; i < 23; i++)
                {
                    recorder.Set(getVideoStreamsPacket(begin.AddSeconds(5 * i)));
                    check(recorder, true, false, 5 * (i + 1), 1);
                }
                recorder.Set(getVideoStreamsPacket(begin.AddSeconds(5 * 23)));
                check(recorder, true, true, 120, 1);


                recorder.Set(getVideoStreamsPacket(begin.AddSeconds(120)));
                check(recorder, true, true, 120, 1);

                recorder.Stop();
                recorder.Set(getVideoStreamsPacket(begin.AddSeconds(120)));
                check(recorder, true, true, 120, 1);
            }
            FolderManager.DeleteDirectoryInfo(path);
        }
예제 #3
0
        private void moveTo(string oldPath, string newPath, string oldFileName)
        {
            string oldName = Path.Combine(oldPath, oldFileName);
            string newName = Path.Combine(newPath, Name);

            if (new DirectoryInfo(newName).Exists)
            {
                throw new IOException(string.Format("指定路径已存在下载任务!{0}", newName));
            }
            new DirectoryInfo(newPath).Create();
            DirectoryInfo oldDir = new DirectoryInfo(oldName);

            if (oldDir.Root == new DirectoryInfo(newPath).Root)
            {
                oldDir.MoveTo(newName);//相同根路径移动
            }
            else
            {
                new DirectoryInfo(newName).Create();
                foreach (var file in oldDir.EnumerateFiles())
                {
                    string newFile = Path.Combine(newName, file.Name);
                    file.CopyTo(newFile);
                }
                FolderManager.DeleteDirectoryInfo(oldDir.FullName);
            }
        }
예제 #4
0
        public void TestFolderManager_InvalidPath()
        {
            Assert.IsFalse(FolderManager.ClearDirectoryInfoAll("i:\\"));
            Assert.IsFalse(FolderManager.ClearDirectoryInfoAll("abc"));
            string path = @"D:\视频录像\invalid position";

            Assert.IsFalse(FolderManager.DeleteDirectoryInfo(path));
            Assert.IsFalse(FolderManager.ClearDirectoryInfoAll(path));
        }
예제 #5
0
        public void TestFolderManager_GetIndexesPackets()
        {
            string path     = "D:\\读写测试\\GetIndexesPackets";
            var    sPackets = DownloadRecorderTest.Recorder(path);
            var    packets  = FolderManager.GetIndexesPackets(path);

            Assert.AreEqual(1, packets.Length);
            Assert.AreEqual(50 + 8 + 4 + 8, packets[0].StartIndex);
            Assert.AreEqual(sPackets.First(_ => _.Type == DataType.StreamDataKey).Time, packets[0].BeginTime);
            Assert.AreEqual(sPackets.Last().Time.AddSeconds(1), packets[0].EndTime);
            FolderManager.DeleteDirectoryInfo(path);
        }
예제 #6
0
        public static StreamPacket[] Recorder(string path)
        {
            FolderManager.DeleteDirectoryInfo(path);
            StreamPacket[]   sPackets = GetStreamPackets();
            DownloadRecorder recorder = new DownloadRecorder(path, TimeSpan.FromMinutes(15));

            for (int i = 0; i < sPackets.Length; i++)
            {
                recorder.Set(sPackets[i]);
            }
            recorder.FinishPackage(sPackets.Last().Time.AddSeconds(1));
            return(sPackets);
        }
예제 #7
0
        public void TestFolderManager_GetLastestTime()
        {
            string path = "D:\\读写测试\\GetLastestTime";

            FolderManager.DeleteDirectoryInfo(path);
            Assert.IsTrue(FolderManager.GetLastestTime(path) == DateTime.MinValue);
            new DirectoryInfo(path).Create();
            Assert.IsTrue(FolderManager.GetLastestTime(path) == DateTime.MinValue);
            string fileName = Path.Combine(path, "text.txt");

            new FileInfo(fileName).Create();
            DateTime lastestTime = FolderManager.GetLastestTime(path);

            Assert.IsTrue(lastestTime < DateTime.Now);
            Assert.IsTrue(lastestTime.AddSeconds(1) > DateTime.Now);
            FolderManager.DeleteDirectoryInfo(path);
        }
예제 #8
0
        public void TestFolderManager_DeleteDirectoryInfo()
        {
            BaseInfo.AddOldVideo();
            string path = @"D:\视频录像\videoID_003_2\2002\03\22";

            Directory.CreateDirectory(path);
            string filePath = Path.Combine(path, ".error");

            using (FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                Assert.IsFalse(FolderManager.DeleteDirectoryInfo(path));
                Assert.IsTrue(Directory.Exists(path));
            }
            Assert.IsTrue(FolderManager.DeleteDirectoryInfo(path));
            Assert.IsFalse(Directory.Exists(path));
            Assert.IsTrue(Directory.Exists(@"d:\视频录像\videoID_003_2\2002\03"));
        }
예제 #9
0
        public void TestDownloadRecorder()
        {
            string path = "D:\\读写测试\\TestDownloadRecorder";

            StreamPacket[] sPackets = Recorder(path);

            VideoStreamsPacket packet = FolderManager.GetVideoStreamsPacket(path, sPackets.First(_ => _.Type == DataType.StreamDataKey).Time.AddSeconds(1));

            Assert.AreEqual(sPackets.First(_ => _.Type == DataType.StreamDataKey).Time, packet.TimePeriod.BeginTime);
            Assert.AreEqual(sPackets.Last().Time.AddSeconds(1), packet.TimePeriod.EndTime);
            Assert.AreEqual(5, packet.VideoStreams.Length);
            for (int i = 0; i < packet.VideoStreams.Length; i++)
            {
                assertAreEqual(sPackets[i + 2], packet.VideoStreams[i]);
            }
            FolderManager.DeleteDirectoryInfo(path);
        }
예제 #10
0
        public void TestStorageSearcher_Search()
        {
            string videoId  = "dateTimeNow";
            int    streamId = 2;
            string path     = System.IO.Path.Combine(GlobalData.Path, $"{videoId}_{streamId}");

            FolderManager.DeleteDirectoryInfo(path);
            GlobalData.FileLengthSup = new TimeSpan(0, 15, 0);
            DateTime beginTime = DateTime.Now.Date;

            testVideoTimePeriodsPacket(videoId, streamId, 0);
            BaseInfo.addData(path, beginTime, 0, 600);

            testVideoTimePeriodsPacket(videoId, streamId, 1, 600);

            using (RecorderBase recorder = new DownloadRecorder(Path.Combine(path, $"{DateTime.Now.Year}\\{DateTime.Now.Month.ToString("00")}\\{DateTime.Now.Day.ToString("00")}"), GlobalData.FileLengthSup))
            {
                BaseInfo.recordAddSeconds(recorder, beginTime, 0, DataType.SysHead); //new
                BaseInfo.fillRecordBySeconds(recorder, beginTime, 600, 1200);
            }
            testVideoTimePeriodsPacket(videoId, streamId, 1, 1200);
            FolderManager.DeleteDirectoryInfo(path);
        }