コード例 #1
0
        /// <summary>
        /// search event log files for plates or motion events
        /// </summary>

        void SearchFilesLoop()
        {
            int      score;
            int      counter          = 0;
            DateTime lastTimeSearched = default(DateTime);

            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
            string[] allLogFilesInRange = m_PathManager.GetAllLogFilesInRange(m_SearchStartTime, m_SearchEndTime);
            if (allLogFilesInRange == null)
            {
                status.errorCode   = SEARCH_ERROR_CODES.NO_FILES_FOUND;
                status.errorString = "No event logs found in time 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   = allLogFilesInRange.Count();
            status.currentCount = 0;
            status.currentTime  = m_SearchStartTime;
            status.errorString  = null;
            m_SearchProgressCB(status);


            // go through the logs one by one, extracting all plate numbers
            foreach (string logFile in allLogFilesInRange)
            {
                try
                {
                    string[] lines = File.ReadAllLines(logFile);
                    foreach (string line in lines)
                    {
                        // search all the extracted plate numbers and compare to the search key

                        EventLogFiles.EventLogFiles.PlateEventData pd = null;
                        try
                        {
                            pd = m_EventLogs.ParseEventLogLine(line);
                        }
                        catch
                        {
                            status.currentCount = counter;
                            status.errorString  = "LogFile Parse error, file = " + logFile + ", line = " + line;
                            m_SearchProgressCB(status);

                            continue;
                        }

                        if (pd.eventType == EventLogFiles.EventLogFiles.EVENT_TYPE.MOTION && m_SearchType == SEARCH_TYPE.MOTION)
                        {
                            // if a camera name filter has been given, only search if there is a match, else search all entries

                            if (m_CameraNameFilter.Length > 0)
                            {
                                lastTimeSearched = pd.timeStamp;
                                if (pd.sourceChannelName.ToUpper().Contains(m_CameraNameFilter.ToUpper()))
                                {
                                    SEARCH_RESULT r = MakeSearchResult(pd, 0, "", "");
                                    results.Add(r);
                                    if (results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                SEARCH_RESULT r = MakeSearchResult(pd, 0, "", "");
                                results.Add(r);
                                if (results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                                {
                                    break;
                                }
                            }
                        }
                        else if (pd.eventType == EventLogFiles.EventLogFiles.EVENT_TYPE.PLATE && m_SearchType == SEARCH_TYPE.PLATE)
                        {
                            // if a camera name filter has been given, only search if there is a match, else search all entries
                            if (m_CameraNameFilter.Length > 0)
                            {
                                if (pd.sourceChannelName.ToUpper().Contains(m_CameraNameFilter.ToUpper()))
                                {
                                    foreach (string plateString in pd.plateNumbersLatinEquivalent)
                                    {
                                        if (pd.timeStamp.CompareTo(m_SearchStartTime) >= 0 && pd.timeStamp.CompareTo(m_SearchEndTime) <= 0)
                                        {
                                            lastTimeSearched = pd.timeStamp;
                                            score            = LPROCR_Wrapper.LPROCR_Lib.scoreMatch(m_SearchString, plateString);
                                            if (score >= m_MinMatchScore)
                                            {
                                                SEARCH_RESULT r = MakeSearchResult(pd, score, plateString, m_SearchString);
                                                results.Add(r);
                                                if (results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                        if (m_Stop)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (string plateString in pd.plateNumbersLatinEquivalent)
                                {
                                    if (pd.timeStamp.CompareTo(m_SearchStartTime) >= 0 && pd.timeStamp.CompareTo(m_SearchEndTime) <= 0)
                                    {
                                        lastTimeSearched = pd.timeStamp;
                                        score            = LPROCR_Wrapper.LPROCR_Lib.scoreMatch(m_SearchString, plateString);
                                        if (score >= m_MinMatchScore)
                                        {
                                            SEARCH_RESULT r = MakeSearchResult(pd, score, plateString, m_SearchString);
                                            results.Add(r);
                                            if (results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    if (m_Stop || results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (m_Stop || results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                        {
                            break;
                        }
                    }

                    // if a match is found over threshhold, add the meta data to the results list
                    if (m_Stop || results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    status.currentTime  = lastTimeSearched;
                    status.currentCount = counter;
                    status.errorString  = ex.Message;
                    m_SearchProgressCB(status);
                }

                counter++;

                status.currentCount = counter;
                status.currentTime  = lastTimeSearched;
                status.errorString  = null;


                m_SearchProgressCB(status);

                if (m_Stop || results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
                {
                    break;
                }
            }

            if (results.Count > m_AppData.MAX_SEARCH_RESULTS_TO_DISPLAY)
            {
                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(results);
        }
コード例 #2
0
ファイル: ImportImageDrive.cs プロジェクト: mutita/anpr
        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;
        }