Exemplo n.º 1
0
Arquivo: DVR.cs Projeto: mutita/anpr
        /// <summary>
        /// Given an image source file path, merge it into a destination file system
        ///  used to import files from a field drive and merge them into a central repository
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <param name="destPath"></param>
        /// <param name="fd"></param>
        public void MoveMergeFileToDVRStorage(PATHS.IMAGE_FILE_DATA srcFd, PATHS.IMAGE_FILE_DATA destFd)
        {
            if (PauseFlag.Pause)
            {
                return;
            }

            try
            {
                FileInfo fi = new FileInfo(srcFd.completePath);

                if (!FileAccessControl.DirectoryExists(destFd.dirOnly))
                {
                    char[] seperator = { '\\', '\\' };

                    string[] branches = destFd.dirOnly.Split(seperator);
                    string   path     = null;
                    for (int i = 0; i < branches.Count() - 1; i++)  // the last string in the array is the file name
                    {
                        if (branches[i].Length < 1)
                        {
                            continue;
                        }
                        path += (branches[i] + "\\");

                        if (!FileAccessControl.DirectoryExists(path))
                        {
                            FileAccessControl.CreateDirectory(path);
                        }
                    }
                }

                Paths.AccumulatedSize += fi.Length;

                FileAccessControl.FileMove(srcFd.completePath, destFd.completePath);
            }

            catch (Exception ex)
            {
                m_Log.Log("CopyFileToDVRStorage ex :" + ex.Message, ErrorLog.LOG_TYPE.FATAL);
            }
        }
Exemplo n.º 2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (!m_RepositoryEnabled)
            {
                MessageBox.Show("No repository connected, cannot search");
                return;
            }

            if (e.RowIndex < 0)
            {
                return;
            }

            m_CurrentRowIndex = e.RowIndex;

            try
            {
                string relativeFileName = dataGridView1.Rows[e.RowIndex].Cells["imagePath"].Value.ToString();

                // because of an bug (or not understoon reason), not all pictures are showing up in storage.
                // the work-around is to find a picture nearest the target picture using time stamps.

                PATHS.IMAGE_FILE_DATA fd = m_PathManager.ParseFileCompleteJpegPath(m_PathManager.GetCompleteFilePath(relativeFileName));

                if (fd == null)
                {
                    return;            // corrupted file data (relativeFileName is missing or not correctly formed)
                }
                if (!File.Exists(fd.completePath))
                {
                    TimeSpan ts                = new TimeSpan(0, 0, 0, 1, 500);
                    DateTime before            = fd.timeStamp.Subtract(ts);
                    DateTime after             = fd.timeStamp.Add(ts);
                    string[] jpegsAroundTarget = m_PathManager.GetAllJpegsInRange(before, after);
                    if (jpegsAroundTarget.Count() < 1)
                    {
                        MessageBox.Show("No images found near the target time");
                    }
                    else
                    {
                        string filePath = jpegsAroundTarget[jpegsAroundTarget.Count() / 2];
                        //                string filePath = m_PathManager.GetCompleteFilePath(relativeFileName);
                        {
                            trackBarZoomControl.Value = 400;
                            Image img = Image.FromFile(filePath);
                            m_ZoomPictureControl.Picture = img;

                            PushVideoRangeToVideoPlayer();
                        }
                    }
                }
                else
                {
                    trackBarZoomControl.Value = 400;
                    Image img = Image.FromFile(fd.completePath);
                    m_ZoomPictureControl.Picture = img;

                    PushVideoRangeToVideoPlayer();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("file IO exception: ex " + ex.Message);
            }

            GC.Collect(); // when scrolling down the table, can get out of memory exceptions
        }
Exemplo n.º 3
0
        void DumpImagesInRangeLoop()
        {
            int ReportStatusFileCountInterval = 200;

            List <SEARCH_RESULT> results = new List <SEARCH_RESULT>();

            SEARCH_STATUS status = new SEARCH_STATUS();

            status.phase        = SEARCH_PHASE.FINDING_ITEMS_IN_TIME_RANGE;
            status.totalCount   = 0;
            status.currentCount = 0;
            status.currentTime  = m_SearchStartTime;
            status.endTime      = m_SearchEndTime;
            status.startTime    = m_SearchStartTime;
            status.errorString  = null;
            m_SearchProgressCB(status);


            // get the list of log files in the search range
            PATHS.GET_ALL_JPEGS_IN_RANGE_PARAMS jpegGetParams = new PATHS.GET_ALL_JPEGS_IN_RANGE_PARAMS();
            jpegGetParams.start           = m_SearchStartTime;
            jpegGetParams.stop            = m_SearchEndTime;
            jpegGetParams.callBack        = HandleDumpAllJpegsProgressUpdate;
            jpegGetParams.updateFreq      = ReportStatusFileCountInterval;
            jpegGetParams.stopSearch      = (object)m_Stop;
            jpegGetParams.maxResultsCount = m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY;
            string[] allFilesInRange = m_PathManager.GetAllJpegsInRange(jpegGetParams);
            if (allFilesInRange == null)
            {
                status              = new SEARCH_STATUS();
                status.totalCount   = 0;
                status.currentCount = 0;
                status.currentTime  = m_SearchEndTime;
                status.endTime      = m_SearchEndTime;
                status.startTime    = m_SearchStartTime;
                status.errorString  = "No files found in time range";
                status.errorCode    = SEARCH_ERROR_CODES.NO_FILES_FOUND;
                m_SearchProgressCB(status);

                m_SearchStopped = true;
                m_SearchCompleteCB(null);
                return;
            }

            if (allFilesInRange.Length > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
            {
                status              = new SEARCH_STATUS();
                status.totalCount   = 0;
                status.currentCount = 0;
                status.currentTime  = m_SearchEndTime;
                status.endTime      = m_SearchEndTime;
                status.startTime    = m_SearchStartTime;
                status.errorCode    = SEARCH_ERROR_CODES.TOO_MANY_ENTRIES;
                status.errorString  = "Exceeded maximum search results(" + m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY.ToString() + "), reduce search range";
                m_SearchProgressCB(status);

                m_SearchStopped = true;
                m_SearchCompleteCB(null);
                return;
            }

            // notify user going to next phase


            status.phase        = SEARCH_PHASE.COMPARING_STRINGS;
            status.totalCount   = allFilesInRange.Count();
            status.currentCount = 0;
            status.currentTime  = m_SearchStartTime;
            status.endTime      = m_SearchEndTime;
            status.startTime    = m_SearchStartTime;
            status.errorString  = null;
            m_SearchProgressCB(status);

            // now do filter comparisons on all data
            int fileCount = 0;

            foreach (string file in allFilesInRange)
            {
                if (m_Stop)
                {
                    break;
                }

                PATHS.IMAGE_FILE_DATA fileData = m_PathManager.ParseFileCompleteJpegPath(file);


                if (fileData == null)
                {
                    continue;
                }

                EventLogFiles.EventLogFiles.PlateEventData pd = new EventLogFiles.EventLogFiles.PlateEventData();
                pd.eventType            = EventLogFiles.EventLogFiles.EVENT_TYPE.NON_EVENT;
                pd.GPSLatitude          = "No Position Available";
                pd.GPSLongitude         = "No Position Available";
                pd.jpegRelativeFilePath = "";
                pd.PSSName              = fileData.PSSName;
                pd.sourceChannelName    = fileData.SourceName;
                pd.timeStamp            = fileData.timeStamp;
                pd.jpegRelativeFilePath = fileData.relativePath;

                // if a camera name filter has been given, only include if there is a match, else include all entries

                if (m_CameraNameFilter.Length > 0)
                {
                    if (fileData.SourceName.ToUpper().Contains(m_CameraNameFilter.ToUpper()))
                    {
                        SEARCH_RESULT r = MakeSearchResult(pd, 0, "", "");
                        results.Add(r);
                    }
                }
                else
                {
                    SEARCH_RESULT r = MakeSearchResult(pd, 0, "", "");
                    results.Add(r);
                }

                if (fileCount++ % ReportStatusFileCountInterval == 0)
                {
                    status.currentCount = fileCount;
                    status.currentTime  = pd.timeStamp;

                    status.errorString = null;
                    m_SearchProgressCB(status);
                }
            }



            m_SearchStopped = true;
            m_SearchCompleteCB(results);
        }
Exemplo n.º 4
0
        void MoveFilesLoop()
        {
            // get first day
            DateTime day        = m_PathManager.GetFirstDay(m_ImportDrive);
            DateTime lastDay    = m_PathManager.GetLastDay(m_ImportDrive);
            TimeSpan oneDay     = new TimeSpan(1, 0, 0, 0);
            DateTime dayPlusOne = day.Add(oneDay);
            int      count      = 0;

            DateTime Aug_25 = new DateTime(2009, 8, 25);

            while (!m_Stop && !m_CancelMove.cancel)
            {
                // move a day

                // move all jpegs

                //    AddToListBox("collecting file names for day : "+day.ToString());

                if (day.Day == Aug_25.Day && day.Month == Aug_25.Month)
                {
                    int jj = day.Month;//breakpoint
                }

                string[] filesToMove = m_PathManager.GetAllJpegsInRange(m_ImportDrive, day, dayPlusOne);

                if (m_Stop || m_CancelMove.cancel)
                {
                    StopAndResetStates();
                    return;
                }

                if (filesToMove.Count() > 0)
                {
                    AddToListBox("starting move for day : " + day.ToString());
                }

                m_Phase = "Moving Images";


                foreach (string sourcPath in filesToMove)
                {
                    PATHS.IMAGE_FILE_DATA sourceFd = m_PathManager.ParseFileCompleteJpegPath(sourcPath);
                    PATHS.IMAGE_FILE_DATA destFd   = m_PathManager.GetCompleteFilePath(sourceFd, m_CentralRepository);

                    m_DVR.MoveMergeFileToDVRStorage(sourceFd, destFd);



                    count++;

                    if (count % 1000 == 0)
                    {
                        StatusCallBackHandler(count, sourceFd.timeStamp);
                    }

                    if (m_Stop || m_CancelMove.cancel)
                    {
                        StopAndResetStates();
                        return;
                    }
                }


                // move all event log files

                filesToMove = m_PathManager.GetAllLogFilesInRange(m_ImportDrive, day, dayPlusOne);

                if (m_Stop || m_CancelMove.cancel)
                {
                    StopAndResetStates();
                    return;
                }



                foreach (string sourcPath in filesToMove)
                {
                    PATHS.IMAGE_FILE_DATA sourceFd = m_PathManager.ParseFileCompleteLogfilePath(sourcPath);
                    PATHS.IMAGE_FILE_DATA destFd   = m_PathManager.GetCompleteFilePath(sourceFd, m_CentralRepository);

                    m_DVR.MoveMergeFileToDVRStorage(sourceFd, destFd);


                    count++;


                    if (m_Stop || m_CancelMove.cancel)
                    {
                        StopAndResetStates();
                        return;
                    }
                }


                day        = day.Add(oneDay);
                dayPlusOne = dayPlusOne.Add(oneDay);

                if (day.CompareTo(lastDay.Add(oneDay)) > 0)
                {
                    break;                         // we are finished
                }
            }

            if (m_Stop || m_CancelMove.cancel)
            {
                StopAndResetStates();
                return;
            }

            // now delete the directories that are now empty

            string oldestDay = m_DVR.Paths.GetOldestDayDir(m_ImportDrive);

            while (oldestDay != null)
            {
                m_DVR.FileAccessControl.DeleteDirectoryAndContents(oldestDay);

                oldestDay = m_DVR.Paths.GetOldestDayDir(m_ImportDrive);

                if (m_Stop || m_CancelMove.cancel)
                {
                    StopAndResetStates();
                    return;
                }
            }



            // tell the user we are finished


            AddToListBox("finsihed");
            SetStatusLabel("finsihed");

            m_CancelMove.cancel  = false;
            m_StartImportClicked = false;
        }