[MethodImpl(MethodImplOptions.Synchronized)] // lock/unlock all thread from current instance object public virtual void EmailAlert(Bitmap captureImage) { try { if (EventOut != null) { dateEnd = DateTime.Now; String camLat = "x"; String camLong = "y"; VsData vsData = new VsData(CameraName, camLat, camLong, pcHost, "", 0, "", "", "", "", dateEnd, dateEnd, "", captureImage); EventOut(this, new VsDataEventArgs(vsData)); vsData.Dispose(); vsData = null; thumbCount = 0; thumbSave = false; } } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace); } }
[MethodImpl(MethodImplOptions.Synchronized)] // lock/unlock all thread from current instance object public virtual void DataAlert() { try { if (DataOut != null) { dateEnd = DateTime.Now; String camLat = "x"; String camLong = "y"; VsData vsData = new VsData(CameraName, camLat, camLong, pcHost, aviName, 0, dirName, "Motion detector", "Windows Media Encoder", "Windows Audio and Video Codecs 7.0", dateBegin, dateEnd, recDetail, thumbImage); DataOut(this, new VsDataEventArgs(vsData)); vsData.Dispose(); vsData = null; } } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace); } }
// On new frame ready //[MethodImpl(MethodImplOptions.Synchronized)] public void FrameIn(object sender, VsDataEventArgs e) { try { /* * if (dataBuffer.Count > 1000 / syncTimer) * { * VsData rm = (VsData)dataBuffer.Dequeue(); * rm.Dispose(); rm = null; * logger.Log(LogLevel.Warn, DateTime.Now.ToString() + "; frame removed from EmailGenerator"); * }*/ VsData img = (VsData)e.Data.Clone(); dataBuffer.Enqueue(img); } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);; } }
private void process_NewFrame(object stateInfo) { Thread.CurrentThread.Priority = ThreadPriority.Lowest; VsData lastData = null; try { // get new one if (dataBuffer.Count > 0) { lastData = (VsData)dataBuffer.Dequeue(); } if (lastData != null) { // save image DateTime dNow = DateTime.Now; string filename = String.Format("{0}_{1}_{2}_{3}_{4}_{5}.jpg", dNow.Year.ToString(), dNow.Month.ToString(), dNow.Day.ToString(), dNow.Hour.ToString(), dNow.Minute.ToString(), dNow.Second.ToString()); lastData.Image.Save(filename, ImageFormat.Jpeg); // send image SmtpClient mySmtpClient = null; MailMessage myMail = null; try { mySmtpClient = new SmtpClient(smtpHost); // set smtp-client with basicAuthentication mySmtpClient.UseDefaultCredentials = false; System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(smtpUser, smtpPasswd); mySmtpClient.Credentials = basicAuthenticationInfo; // add from,to mailaddresses MailAddress from = new MailAddress(emailFrom, "Personal Security Alert"); MailAddress to = new MailAddress(emailTo, "Yourself"); myMail = new System.Net.Mail.MailMessage(from, to); // add ReplyTo MailAddress replyto = new MailAddress(emailFrom); myMail.ReplyTo = replyto; // set subject and encoding myMail.Subject = "Test message"; myMail.SubjectEncoding = System.Text.Encoding.UTF8; // set body-message and encoding myMail.Subject = "àµ×͹! à˵ؼԴ»¡µÔ ¨Ò¡ Personal Security System"; myMail.Body = "<b> à˵ؼԴ»¡µÔ !!! </b><br> <b> </b> <br> <b> àÇÅÒ " + DateTime.Now.ToString() + " ´ÙàÍ¡ÊÒÃṺ </b>."; myMail.BodyEncoding = System.Text.Encoding.UTF8; // text or html // set file attachment for this e-mail message. Attachment data = new Attachment(filename, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(filename); disposition.ModificationDate = System.IO.File.GetLastWriteTime(filename); disposition.ReadDate = System.IO.File.GetLastAccessTime(filename); // Add the file attachment to this e-mail message. myMail.Attachments.Add(data); myMail.IsBodyHtml = true; mySmtpClient.Send(myMail); } catch (SmtpException err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace); } finally { if (mySmtpClient != null) { mySmtpClient = null; } } } } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);; } }
private void process_NewFrame(object stateInfo) { VsData lastData = null; Thread.CurrentThread.Priority = ThreadPriority.Lowest; try { // get new one if (dataBuffer.Count > 0) { lastData = (VsData)dataBuffer.Dequeue(); } if (lastData != null) { try { strConnect = String.Format("server={0};user id={1}; password={2}; database={3}; pooling=false", DataHost, DataUser, DataPasswd, DataDatabase); connectSQL = new MySqlConnection(strConnect); connectSQL.Open(); } catch (MySqlException err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);; if (connectSQL != null) { connectSQL.Dispose(); connectSQL = null; } } if (connectSQL != null) { /* * // Add image to database * // process * MemoryStream ms = new MemoryStream(); * lastData.Image.Save(ms, ImageFormat.Jpeg); * * byte[] imageIn = new byte[ms.Length]; * ms.Position = 0; * ms.Read(imageIn, 0, (int)ms.Length); * ms.Close(); * ms.Dispose(); * ms = null; */ // inogr image byte[] imageIn = new byte[1]; TableCheck(connectSQL); lastData.TableName = TableName; MySqlCommand cmdSQL = new MySqlCommand(lastData.Sql, connectSQL); try { cmdSQL.Parameters.Add(new MySqlParameter("?image", imageIn)); cmdSQL.Parameters.Add(new MySqlParameter("?imagesize", imageIn.Length)); cmdSQL.ExecuteNonQuery(); } catch (MySqlException err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);; } cmdSQL.Dispose(); } if (connectSQL != null) { try { connectSQL.Close(); connectSQL.Dispose(); connectSQL = null; } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);; } } } } catch (Exception err) { if (connectSQL != null) { connectSQL.Dispose(); connectSQL = null; } logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace);; } }