Esempio n. 1
0
        /// <summary>
        /// Tests the systems capture and email functionality.
        /// </summary>
        /// <param name="sender">Sending button</param>
        /// <param name="e">Button args</param>
        private async void RunTestsExecuted()
        {
            try
            {
                if (captureTimer.IsEnabled)
                {
                    captureTimer.Stop();
                }

                IsNotRunningTest = false;
                var stream = new InMemoryRandomAccessStream();
                await MediaCaptureElement.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                await Task.Delay(10);

                List <IRandomAccessStream> streamTestList = new List <IRandomAccessStream>()
                {
                    stream
                };
                await SendAlertEmail(streamTestList, true);

                IsNotRunningTest = true;
                captureTimer.Start();
            }
            catch (Exception) { /*Working with hardware has a lot of exception cases.... nom nom nom*/ }
        }
Esempio n. 2
0
        /// <summary>
        /// Captures a photo and sends it off for analysis
        /// </summary>
        private async void TakePhoto()
        {
            try
            {
                lowLagCapture =
                    await MediaCaptureElement.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                CapturedPhoto capturedPhoto = await lowLagCapture.CaptureAsync();

                SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

                await lowLagCapture.FinishAsync();

                byte[] imageBytes = new byte[4 * softwareBitmap.PixelWidth * softwareBitmap.PixelHeight];
                softwareBitmap.CopyToBuffer(imageBytes.AsBuffer());

                bool isAlert = CheckForMotion(imageBytes);

                if (isAlert)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(softwareBitmap.PixelWidth, softwareBitmap.PixelHeight);
                    softwareBitmap.CopyToBuffer(writeableBitmap.PixelBuffer);
                    AlertDisplayImages.Add(new AlertDisplayImageModel()
                    {
                        AlertDisplayImage = writeableBitmap, AlertDisplayCaption = DateTime.Now.ToString()
                    });

                    delayTimer.Interval = new TimeSpan(0, 0, ConfigurationSettings.AppConfig.AlertDelay);

                    captureTimer.Stop();
                    delayTimer.Tick += OnDelayTimerTick;
                    delayTimer.Start();

                    // It seems silly that we need to capture a second image but the first image that was captured isn't in a format that can
                    // be easily emailed. This being the case, I decided it'd just be easier to grab another capture in the correct format and
                    // email it off. The delta between the images is negligable
                    var stream = new InMemoryRandomAccessStream();
                    await MediaCaptureElement.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                    await Task.Delay(10);

                    streamList.Add(stream);

                    if (AutoSaveAlertImages)
                    {
                    }

                    if (ConfigurationSettings.AppConfig.SendEmails && streamList.Count > ConfigurationSettings.AppConfig.AlertThreshold)
                    {
                        captureTimer.Stop();
                        await SendAlertEmail(streamList);

                        await Task.Delay(new TimeSpan(0, 1, 0));
                    }
                }
            }
            catch (Exception error)
            {
                // Getting random COM errors. Just eat it and continue. There's nothing I can do about this.
            }
        }