Ejemplo n.º 1
0
        public void MotionDelegateMethod(MotionDetectionEventArgs e)
        {
            string s = string.Empty;

            foreach (byte b in e.Matrix)
            {
                s += b + " ";
            }

            mmMotDetMatrix.Text = s.Trim();
            pbMotionLevel.Value = e.Level;
        }
Ejemplo n.º 2
0
 private void VideoEdit1_OnMotion(object sender, MotionDetectionEventArgs e)
 {
     BeginInvoke(new MotionDelegate(MotionDelegateMethod), e);
 }
Ejemplo n.º 3
0
        public void OnMotion(object sender, MotionDetectionEventArgs e)
        {
            if (e.Level > this.On_move_sensitivity)
            {
                //Console.WriteLine($"Motion Detection!!!   Matrix: {e.Matrix.Length.ToString()}   Level: {e.Level}");
                if (this.On_move_email)
                {
                    try
                    {
                        /*
                         * Console.WriteLine($"Motion Detected Send Email Message.  [Before]    " +
                         *  $"Time.now: {DateTime.Now}  Time.before: {last_email_date_onmove.AddMinutes(1)}");
                         */
                        // When Send Get the DateTime
                        if (DateTime.Now > last_email_date_onmove.AddMinutes(1))
                        {
                            last_email_date_onmove = DateTime.Now;

                            /*
                             * // Grab a Pic
                             * BitmapSource bmpS = this.video.Frame_GetCurrent();
                             * // BitmapSource to Stream
                             * MemoryStream stream = new MemoryStream();
                             * GetBitmap(bmpS).Save(stream, ImageFormat.Jpeg);
                             */

                            // Return to Sending Email
                            String host      = "";
                            int    port      = 587;
                            String fromEmail = MainWindow.email_send;
                            if (fromEmail.Contains("gmail"))
                            {
                                host = "smtp.gmail.com";
                            }
                            else if (fromEmail.Contains("yahoo"))
                            {
                                host = "smtp.mail.yahoo.com";
                            }
                            else if (fromEmail.Contains("live"))
                            {
                                host = "	smtp.live.com";
                            }
                            String fromPassword = MainWindow.pass_send;
                            String subject      = this.name;
                            String body         = $"[{this.name}]  Detect Motion at  [{DateTime.Now}]";
                            // Create a Message
                            MailMessage msg = new MailMessage();
                            msg.From = new MailAddress(fromEmail);

                            /*
                             * // Add Image to message OK
                             * System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Image.Jpeg);
                             * System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(stream, ct);
                             * attach.ContentDisposition.FileName = "img.jpeg";
                             * msg.Attachments.Add(attach);
                             */
                            // Add All Recievers
                            foreach (Users u in MainWindow.myUsers)
                            {
                                msg.To.Add(u.Email);
                                Console.WriteLine($"Send Email From: {fromEmail}  Pass: {fromPassword}  To: {u.Email}");
                            }
                            msg.Subject = subject;
                            msg.Body    = body;
                            // Create Email Connection Object
                            SmtpClient smtp = new SmtpClient(host)
                            {
                                Port                  = port,
                                EnableSsl             = true,
                                UseDefaultCredentials = true,
                                Credentials           = new NetworkCredential(fromEmail, fromPassword),
                                DeliveryMethod        = SmtpDeliveryMethod.Network
                            };
                            // Send Email
                            smtp.Send(msg);  // Doesn't Works
                        }
                    }
                    catch (SmtpException ex)
                    {
                        Console.WriteLine($"Source:{ex.Source}\nStackTrace:{ex.StackTrace}\n{ex.Message}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Source:{ex.Source}\nStackTrace:{ex.StackTrace}\n{ex.Message}");
                    }
                }
                if (this.On_move_pic)
                {
                    Console.WriteLine("Take Picture.");
                    this.Take_pic();
                }
                if (this.On_move_rec)
                {
                    Console.WriteLine("Start Recording.");
                    // Recording for some time
                    this.Recording = true;
                    Thread.Sleep(1000 * 10 * 60);
                    this.Recording = false;
                }
                if (this.On_move_sms)
                {
                    // Send SMS
                    if (DateTime.Now > last_email_date_onmove.AddMinutes(1))
                    {
                        last_email_date_onmove = DateTime.Now;
                        // Find your Account Sid and Token at https://account.apifonica.com/
                        Console.WriteLine($"Before Send SMS.   ssid: {MainWindow.twilioAccountSID}   token: {MainWindow.twilioAccountToken}");
                        TwilioClient.Init(MainWindow.twilioAccountSID, MainWindow.twilioAccountToken);
                        foreach (Users u in MainWindow.myUsers)
                        {
                            var message = MessageResource.Create(
                                body: $"[{this.name}]  Detect Motion at  [{DateTime.Now}]",
                                from: new Twilio.Types.PhoneNumber(MainWindow.twilioNumber),
                                to: new Twilio.Types.PhoneNumber(u.Phone)
                                );
                            Console.WriteLine($"Send SMS To: {message.Sid}.");
                        }
                    }
                }
            }
        }