Esempio n. 1
0
        private async void FinishShot()
        {
            // Perform calibration if we haven't already
            CalibrationRecord record = await _calibration;

            try
            {
                await Task.Run(() => SaveFrameData());
            }
            catch (Exception e)
            {
                this.ClearFrames();

                var ea = new SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_writingShot, "An error occurred while saving", e);

                _writingShot = null;

                if (ShotSavedError != null)
                {
                    ShotSavedError(this, ea);
                }

                return;
            }

            _writingShot.Completed = true;

            string metadataPath = Path.Combine(_session.SessionPath, Session <TMetadata, TShot, TShotDefinition, TSavedItem> .METADATA_FILE);

            await Task.Run(() => JSONHelper.Instance.Serialize(_session.GetMetadata(), metadataPath));

            // Clear the frames to make sure we don't use them again
            this.ClearFrames();

            var ea2 = new SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_writingShot);

            _writingShot = null;

            if (ShotSavedSuccess != null)
            {
                ShotSavedSuccess(this, ea2);
            }

            PrepareForNextShot();

            if (_nextShot == null)
            {
                if (LastShotFinished != null)
                {
                    LastShotFinished(this, ea2);
                }
            }
        }
Esempio n. 2
0
        public virtual void FrameArrived(LiveFrame frame)
        {
            // When the first frame arrive, start the calibration operation. This won't work
            // if we try to do it right after calling _sensor.Open().
            if (_calibration == null)
            {
                _calibration = Calibrator.CalibrateAsync(_reader.Sensor);
            }

            if (_capturingShot == null)
            {
                return;
            }

            // (1) Serialize frame data

            if (_frameCount >= _frames.Length)
            {
                Console.WriteLine(string.Format("Too many frames! Got {0} but we only have room for {1}", _frameCount + 1, _frames.Length));
            }
            else
            {
                _frames[_frameCount].Update(frame, _serializer);
            }

            // Increment whether we saved the data or not (this allows an improved error message)
            _frameCount += 1;

            if (_frameCount < _capturingShot.ShotDefinition.MaximumFrameCount)
            {
                return;
            }

            // (2) Move to the next shot
            string message;

            if (!ValidateShot(out message))
            {
                this.ClearFrames();

                var ea2 = new SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_capturingShot, message);

                _capturingShot = null;

                if (ShotCompletedError != null)
                {
                    ShotCompletedError(this, ea2);
                }

                return;
            }

            var ea = new SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_capturingShot, message);

            _writingShot   = _capturingShot;
            _capturingShot = null;

            if (ShotCompletedSuccess != null)
            {
                ShotCompletedSuccess(this, ea);
            }

            FinishShot();
        }