public void ProcessNewData(IItemInfo item)
        {
            mRecognizerFinishedEvent.Reset();
            using (IntervalsRecorderStrategy intervalsRecorder = new IntervalsRecorderStrategy())
                using (mRecorder = new Recorder(mRecordsDirectory, intervalsRecorder))
                    using (FileSystemWatcher fileSystemWatcher = new FileSystemWatcher())
                    {
                        fileSystemWatcher.Path = mRecordsDirectory;
                        fileSystemWatcher.EnableRaisingEvents = true;

                        /// Listening to records directory. In case new record created, insert
                        /// it into <see cref="mSubSoundsQueue"/>
                        fileSystemWatcher.Created += FileSystemWatcher_Created;
                        fileSystemWatcher.Renamed += FileSystemWatcher_Renamed;
                        fileSystemWatcher.Deleted += FileSystemWatcher_Deleted;
                        fileSystemWatcher.Changed += FileSystemWatcher_Changed;

                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();
                        mRecorder.Record();

                        RunDetectionAlgorithm(stopwatch);
                        stopwatch.Stop();
                    }

            mRecognizerFinishedEvent.Set();

            // Notifying that the recognizer finished working.
            RecognizerFinished.Invoke(
                this,
                new RecognizerFinishedEventArgs());
        }
        public void Stop(string stopReason)
        {
            RecognitionStatus = stopReason;
            if (!mIsStopped)
            {
                mShouldStop = true;

                // Waiting for ProcessNewData to finish.
                mRecognizerFinishedEvent.WaitOne();
                mIsStopped = true;
                mLogger.WriteLine($"{nameof(PopsRecognizer)} stopped. Stop Reason: {stopReason}");

                // Notifying that the recognizer finished working.
                RecognizerFinished.Invoke(
                    this,
                    new RecognizerFinishedEventArgs());
            }
        }
Esempio n. 3
0
 private void RecognizerShouldStop(object sender, RecognizerFinishedEventArgs e)
 {
     mShouldStop = false;
     e.Data      = $"Recognizer should stop since detected finished";
     RecognizerFinished.Invoke(this, e);
 }