示例#1
0
        public VideoTimePeriodsPacket Search(DateTime beginTime, DateTime endTime, IVideoInfo videoInfo)
        {
            string path = GlobalData.VideoPath(videoInfo.VideoId, videoInfo.StreamId);

            DateTime[] dates            = VideoStoragerManager.GetFolderPaths(videoInfo.VideoId, videoInfo.StreamId, beginTime, endTime);
            List <TimePeriodPacket> tis = new List <TimePeriodPacket>();

            Parallel.ForEach(dates, date =>
            {
                string folder = Path.Combine(path, GlobalProcess.FolderPath(date));
                var array     = FolderManager.GetTimePeriods(folder);
                if (array.Length > 0)
                {
                    lock (tis)
                        tis.AddRange(array);
                }
            });
            if (endTime > DateTime.Now.Date)
            {
                tis.AddRange(findTodayLastest(path, endTime));
            }
            var timeCombines = TimePeriodManager.Combine(tis.ToArray());
            var validArray   = TimePeriodManager.GetIntersections(timeCombines, new TimePeriodPacket(beginTime, endTime));

            return(new VideoTimePeriodsPacket(videoInfo, validArray));
        }
示例#2
0
 public DownloadViewModel(IDownloadInfoExpand packet)
 {
     _downloadInfo    = packet.DownloadInfo;
     _all             = packet.TimePeriodsAll;
     _downloaded      = packet.TimePeriodsCompleted;
     GuidCode         = packet.GuidCode;
     Quality          = packet.Quality;
     Size             = getByteLengthString(packet.Size);
     IPAddress        = packet.DownloadInfo.SourceIp;
     BeginTime        = GlobalProcess.TimeFormatOfCn(packet.DownloadInfo.BeginTime);
     EndTime          = GlobalProcess.TimeFormatOfCn(packet.DownloadInfo.EndTime);
     DownloadTimeSpan = (packet.DownloadInfo.EndTime - packet.DownloadInfo.BeginTime).ToString();
     updateStatus(packet.DownloadStatus);
     IsLocalDownload = packet.IsLocalDownload;
     updateSlider();
     ErrorInfo = packet.ErrorInfo;
     updatedLastestTime(packet.UpdatedLastestTime);
     updateSpeed(packet.Speed);
     PlayingCommand   = new CommandDelegate(_ => Play());
     DeleteCommand    = new CommandDelegate(_ => Delete());
     GoTopCommand     = new CommandDelegate(_ => GoTop());
     OpenCommand      = new CommandDelegate(_ => Open());
     PropertyChanged += onPropertyChanged;
     if (packet.DownloadInfo.VideoName != null)
     {
         Name = string.Format("{0} ({1})", packet.DownloadInfo.VideoName, packet.Name);
     }
     else
     {
         Name = packet.Name;
     }
 }
示例#3
0
        public void TestGlobalProcess_GetFolderName()
        {
            TimePeriodPacket tpp        = new TimePeriodPacket(new DateTime(2016, 7, 25, 18, 15, 0), new DateTime(2016, 7, 25, 18, 16, 10));
            string           folderName = GlobalProcess.GetFolderName(tpp);

            Assert.AreEqual("录像_201607251815_201607251816", folderName);
        }
示例#4
0
        public static void Add1()
        {
            var    beginTime = new DateTime(2016, 3, 22, 23, 50, 1, 156);
            string videoId   = "videoId";
            int    streamId  = 2;
            string path      = System.IO.Path.Combine(GlobalData.Path, $"{videoId}_{streamId}");

            GlobalData.FileLengthSup = new TimeSpan(0, 5, 0);
            using (SyncRecorder recorder = new SyncRecorder(path))
            {
                recordAddMinutes(recorder, beginTime, 0, DataType.StreamDataKey);
                recordAddMinutes(recorder, beginTime, 1, DataType.SysHead);       //new
                recordAddMinutes(recorder, beginTime, 1, DataType.StreamDataKey);
                recordAddMinutes(recorder, beginTime, 2, DataType.StreamDataKey);
                recordAddMinutes(recorder, beginTime, 3, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 4, DataType.StreamDataKey);
                recordAddMinutes(recorder, beginTime, 5, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 6, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 7, DataType.StreamDataKey);  //new
                recordAddMinutes(recorder, beginTime, 8, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 9, DataType.SysHead);        //new
                recordAddMinutes(recorder, beginTime, 9, DataType.StreamDataKey);
                recordAddMinutes(recorder, beginTime, 10, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 11, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 12, DataType.StreamDataKey);  //new
                recordAddMinutes(recorder, beginTime, 13, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 14, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 15, DataType.StreamDataKey);
                recordAddMinutes(recorder, beginTime, 16, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 17, DataType.StreamData);
                recordAddMinutes(recorder, beginTime, 18, DataType.StopSign);
                writeError(Path.Combine(path, GlobalProcess.FolderPath(beginTime)), $"20100322235959999{GlobalProcess.IndexesFormat()}");
            }
        }
示例#5
0
        /// <summary>获取某通道视频在某时段对应的有效的文件夹列表</summary>
        public static DateTime[] GetFolderPaths(string videoId, int streamId, DateTime start, DateTime end)
        {
            List <DateTime> list = new List <DateTime>();
            string          path = GlobalData.VideoPath(videoId, streamId);

            if (Directory.Exists(path))
            {
                DateTime cur = start.Date;
                while (cur < end)
                {
                    DirectoryInfo dir = new DirectoryInfo(Path.Combine(path, GlobalProcess.FolderPath(cur)));
                    if (dir.Exists)
                    {
                        list.Add(cur);
                        cur = cur.AddDays(1);
                    }
                    else if (dir.Parent.Exists)
                    {
                        cur = cur.AddDays(1);
                    }
                    else if (dir.Parent.Parent.Exists)
                    {
                        cur = new DateTime(cur.Year, cur.Month, 1).AddMonths(1);
                    }
                    else
                    {
                        cur = new DateTime(cur.Year + 1, 1, 1);
                    }
                }
            }
            return(list.ToArray());
        }
示例#6
0
        private static void addErrorFile(string videoId, int streamId, DateTime date)
        {
            string path = Path.Combine(GlobalData.Path, $"{videoId}_{streamId}", GlobalProcess.FolderPath(date));

            Directory.CreateDirectory(path);
            writeError(path, $"{GlobalProcess.FileNameFromDate(date)}235959999{GlobalProcess.IndexesFormat()}");
            writeError(path, $"{GlobalProcess.FileNameFromDate(date)}235959999{GlobalProcess.RecFormat()}");
        }
示例#7
0
        public void TestGlobalProcess_FileNameTrans()
        {
            string indexesName = @"D:\视频录像\videoId_2\2016\03\22\20160322235101156.Indexes";
            string recName     = @"D:\视频录像\videoId_2\2016\03\22\20160322235101156.rec";

            Assert.AreEqual(recName, GlobalProcess.GetRecFileName(indexesName));
            Assert.AreEqual(indexesName, GlobalProcess.GetIndexesFileName(recName));
        }
示例#8
0
 public void TestGlobalProcess_IsYear()
 {
     Assert.IsTrue(GlobalProcess.IsYear("2016"));
     Assert.IsFalse(GlobalProcess.IsYear("201A"));
     Assert.IsFalse(GlobalProcess.IsYear("0000"));
     Assert.IsFalse(GlobalProcess.IsYear("10000"));
     Assert.IsFalse(GlobalProcess.IsYear("997"));
     Assert.IsFalse(GlobalProcess.IsYear("04"));;
 }
示例#9
0
        static long getAllSize(string folderPath, int headerLength)
        {
            DirectoryInfo dir = new DirectoryInfo(folderPath);

            FileInfo[] files  = dir.GetFiles("*" + GlobalProcess.RecFormat());
            long       length = files.Sum(_ => getStreamSize(_, headerLength));

            return(length);
        }
示例#10
0
 public void TestGlobalProcess_IsDay()
 {
     Assert.IsTrue(GlobalProcess.IsDay("31"));
     Assert.IsFalse(GlobalProcess.IsDay("2016"));
     Assert.IsFalse(GlobalProcess.IsDay("1A"));
     Assert.IsFalse(GlobalProcess.IsDay("32"));
     Assert.IsTrue(GlobalProcess.IsDay("01"));
     Assert.IsFalse(GlobalProcess.IsDay("00"));
 }
示例#11
0
 public void TestGlobalProcess_IsMonth()
 {
     Assert.IsTrue(GlobalProcess.IsMonth("12"));
     Assert.IsFalse(GlobalProcess.IsMonth("2016"));
     Assert.IsFalse(GlobalProcess.IsMonth("1A"));
     Assert.IsFalse(GlobalProcess.IsMonth("13"));
     Assert.IsTrue(GlobalProcess.IsMonth("01"));
     Assert.IsFalse(GlobalProcess.IsMonth("00"));
 }
示例#12
0
        public void TestFileManager_GetTimePeriods()
        {
            BaseInfo.AddData_videoId_003_2_20160330();
            DateTime time     = new DateTime(2016, 03, 30);
            string   fileName = Path.Combine(GlobalData.Path, @"videoID_003_2", GlobalProcess.FolderPath(time), $"{GlobalProcess.FileNameFromDate(time)}{GlobalProcess.SimpleIndexesFormat()}");

            Assert.IsNotNull(FileManager.GetTimePeriods(fileName));
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                Assert.IsNotNull(FileManager.GetTimePeriods(fileName));
        }
示例#13
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         GlobalProcess.performBondProfitsUpdate();
     }
     catch (Exception _ex)
     {
         Console.WriteLine("Error in Form1.Form1_Load: " + _ex.Message);
     }
 }
示例#14
0
        /// <summary>获取某通道视频在某时间点对应文件的视频头</summary>
        public static StreamPacket GetVideoHeader(string videoId, int streamId, DateTime time)
        {
            string        indexesFile = null;
            string        path        = getPath(videoId, streamId, time);
            IndexesPacket packet      = FolderManager.GetIndexesPacket(path, time, ref indexesFile);

            if (packet != null)
            {
                return(FileManager.GetVideoHeader(GlobalProcess.GetRecFileName(indexesFile)));
            }
            return(null);
        }
示例#15
0
        TimePeriodPacket[] findTodayLastest(string path, DateTime end)
        {
            string folder = Path.Combine(path, GlobalProcess.FolderPath(DateTime.Now));
            var    array  = FolderManager.GetIndexesFiles(folder);

            if (array.Length > 0)
            {
                string file    = array.Max();
                var    packets = FileManager.GetIndexesPackets(file);
                return(TimePeriodManager.Combine(packets));
            }
            return(new TimePeriodPacket[0]);
        }
示例#16
0
        static long getValidSize(string folderPath, DateTime beginTime, DateTime endTime, int headerLength)
        {
            DirectoryInfo dir = new DirectoryInfo(folderPath);

            FileInfo[] files  = dir.GetFiles("*" + GlobalProcess.RecFormat());
            long       length = 0;

            foreach (var file in files)
            {
                length += getSize(file, beginTime, endTime, headerLength);
            }
            return(length);
        }
示例#17
0
        /// <summary>获取某通道视频在某时段对应文件的首个视频头</summary>
        public static VideoBasePacket GetVideoBaseInfom(string videoId, int streamId, DateTime beginTime, DateTime endTime)
        {
            string path = GlobalData.VideoPath(videoId, streamId);

            DateTime[] dates = GetFolderPaths(videoId, streamId, beginTime, endTime);
            foreach (var date in dates)
            {
                var header = FolderManager.GetVideoHeader(Path.Combine(path, GlobalProcess.FolderPath(date)), beginTime, endTime);
                if (header != null && header.Type == DataType.SysHead)
                {
                    long length = getLength(path, dates, beginTime, endTime, StreamPacket.Encode(header).Length + 4);
                    return(new VideoBasePacket(header.Buffer, header.Time, length));
                }
            }
            return(null);
        }
示例#18
0
 /// <summary>
 /// 获取指定目录所有视频节点中的时间最早的子目录的名称(包括其路径)。
 /// </summary>
 /// <param name="folder">目录文件夹</param>
 /// <returns>目录文件夹下最早的视频子文件夹</returns>
 public static HistoryFolderInfo SearchEarliestSubfolder(string videoInfoPath)
 {
     try
     {
         string path      = videoInfoPath;
         string pathYear  = Directory.GetDirectories(path).Where(_ => GlobalProcess.IsYear(getFolderName(_))).Min();
         int    nYear     = int.Parse(getFolderName(pathYear));
         string pathMonth = Directory.GetDirectories(pathYear).Where(_ => GlobalProcess.IsMonth(getFolderName(_))).Min();
         int    nMonth    = int.Parse(getFolderName(pathMonth));
         string pathDay   = Directory.GetDirectories(pathMonth).Where(_ => GlobalProcess.IsDay(getFolderName(_))).Min();
         int    nDay      = int.Parse(getFolderName(pathDay));
         return(new HistoryFolderInfo(pathDay, new DateTime(nYear, nMonth, nDay)));
     }
     catch { }
     return(null);
 }
示例#19
0
        public void TestVideoStoragerManager_SearchEarliestSubfolder_One()
        {
            BaseInfo.AddOldVideo();
            string   videoId   = "videoID_003";
            int      streamId  = 2;
            string   path      = GlobalData.VideoPath(videoId, streamId);
            DateTime beginTime = new DateTime(2001, 3, 23, 01, 50, 1, 156);

            Directory.CreateDirectory(Path.Combine(path, @"10000\01\01"));
            Directory.CreateDirectory(Path.Combine(path, @"2001\1\01"));
            string earliestPath = Path.Combine(path, GlobalProcess.FolderPath(beginTime));
            var    info         = VideoStoragerManager.SearchEarliestSubfolder(path);

            Assert.IsNotNull(info);
            Assert.AreEqual(earliestPath, info.Path);
            Assert.AreEqual(beginTime.Date, info.Time);
        }
示例#20
0
        private void this_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(DownloadUri):
                URLInfo            = null;
                ErrorInfo          = null;
                IsEnabledDirectory = false;
                IsEnabledDownload  = false;
                VideoInfos         = new ObservableCollection <DownloadVideoInfo>();
                try
                {
                    URLInfo      = RemoteUrl.Parse(DownloadUri) as IRemoteUrl;
                    BeginTime    = toShowTime(URLInfo.BeginTime);
                    EndTime      = toShowTime(URLInfo.EndTime);
                    DownloadName = GlobalProcess.GetFolderName(URLInfo);

                    foreach (VideoInfo vi in URLInfo.VideoInfos)
                    {
                        VideoInfos.Add(new DownloadVideoInfo()
                        {
                            VideoId   = vi.VideoId,
                            VideoName = string.IsNullOrWhiteSpace(vi.VideoName)? "未知名称": vi.VideoName,
                            StreamId  = vi.StreamId,
                        });
                    }
                    if (!string.IsNullOrWhiteSpace(URLInfo.LocalPath))
                    {
                        DownloadDirectory = new DirectoryInfo(URLInfo.LocalPath).FullName;
                    }
                    else
                    {
                        IsEnabledDirectory = true;
                    }
                    IsEnabledDownload = true;
                }
                catch (Exception ex)
                {
                    ErrorInfo = ex.Message;
                    initData();
                }
                break;
            }
        }
示例#21
0
        static long getLength(string path, DateTime[] dates, DateTime beginTime, DateTime endTime, int headerLength)
        {
            long size = 0;

            for (int i = 0; i < dates.Length; i++)
            {
                var    date   = dates[i];
                string folder = Path.Combine(path, GlobalProcess.FolderPath(date));
                if (date > beginTime.Date && date < endTime.Date)
                {
                    size += getAllSize(folder, headerLength);
                }
                else
                {
                    size += getValidSize(folder, beginTime, endTime, headerLength);
                }
            }
            return(size);
        }
示例#22
0
        protected override void updateShortIndexes(TimePeriodPacket newTi)
        {
            List <TimePeriodPacket> shortIndexes = new List <TimePeriodPacket>();

            shortIndexes.Add(newTi);
            string simpleIndexesName = $"{GlobalProcess.FileNameFromDate(_fileStartTime)}{GlobalProcess.SimpleIndexesFormat()}";
            string fileName          = Path.Combine(_curFolder, simpleIndexesName);
            var    indexesDatas      = FileManager.GetTimePeriods(fileName);

            if (indexesDatas != null)
            {
                shortIndexes.AddRange(indexesDatas);
            }
            var newArray = TimePeriodManager.Combine(shortIndexes.ToArray());

            using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                for (int i = 0; i < newArray.Length; i++)
                {
                    writeBuffer(fs, TimePeriodPacket.Encode(newArray[i]));
                }
            }
        }
示例#23
0
        static long getSize(FileInfo fileInfo, DateTime beginTime, DateTime endTime, int headerLength)
        {
            long size = 0;

            try
            {
                string        indexes        = GlobalProcess.GetIndexesFileName(fileInfo.FullName);
                var           indexesPackets = FileManager.GetIndexesPackets(indexes);
                IndexesPacket first          = indexesPackets.FirstOrDefault(_ => _.EndTime >= beginTime);
                if (first != null)
                {
                    long          beginIndex = first.StartIndex;
                    long          endIndex   = fileInfo.Length;
                    IndexesPacket end        = indexesPackets.FirstOrDefault(_ => _.BeginTime >= endTime);
                    if (end != null)
                    {
                        endIndex = end.StartIndex;
                    }
                    size = endIndex - beginIndex;
                }
            }
            catch { }
            return(size);
        }
示例#24
0
 static string getPath(string videoId, int streamId, DateTime time)
 {
     return(Path.Combine(GlobalData.VideoPath(videoId, streamId), GlobalProcess.FolderPath(time), GlobalProcess.FileNameFromTime(time) + GlobalProcess.RecFormat()));
 }
示例#25
0
 private static string getPath(string videoId, int streamId, DateTime time)
 {
     return(Path.Combine(GlobalData.VideoPath(videoId, streamId), GlobalProcess.FolderPath(time)));
 }
示例#26
0
 protected override void updateFolderPath()
 {
     _curFolder = Path.Combine(_filePath, GlobalProcess.FolderPath(_fileStartTime));
 }
示例#27
0
        public void TestGlobalProcess_TimeFormatOfCn()
        {
            string cn = GlobalProcess.TimeFormatOfCn(new DateTime(2016, 5, 6, 10, 14, 15, 1));

            Assert.AreEqual("2016年05月06日10时14分15秒", cn);
        }
示例#28
0
 public void Test_GlobalProcess_FolderPath()
 {
     Assert.AreEqual(@"2016\03\29", GlobalProcess.FolderPath(new DateTime(2016, 3, 29, 11, 33, 20, 555)));
 }