Example #1
0
        private void Send()
        {
            this.started  = true;
            this.finished = false;
            try
            {
                do
                {
                    while (this.queue.Count > 0)
                    {
                        try
                        {
                            if (this.emailSender != null)
                            {
                                System.Text.StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.AppendLine("===");
                                stringBuilder.AppendLine("UID=" + Guid.NewGuid().ToString());

                                // ("UID", DbType.String
                                stringBuilder.AppendLine("Time=" + string.Format("'{0:yyyy-MM-dd HH:mm:ss}'", this.queue[0].LogTime));

                                // "Time", DbType.DateTime
                                stringBuilder.AppendLine("LogType=" + this.queue[0].LogType);

                                // "Category", DbType.String
                                stringBuilder.AppendLine("Class=" + this.queue[0].Class);

                                // "Class", DbType.String
                                stringBuilder.AppendLine("Method=" + this.queue[0].Method);

                                // "Function", DbType.String
                                stringBuilder.AppendLine("Description=" + this.queue[0].Description);

                                // "Description", DbType.String
                                stringBuilder.AppendLine("Sent=0");

                                // "Sent", DbType.Int32
                                foreach (KeyValuePair <DataColumn, object> keyValuePair in this.queue[0].StaticData)
                                {
                                    stringBuilder.AppendLine(keyValuePair.Key.ColumnName + "=" + keyValuePair.Value.ToString());
                                }

                                MailData messageData = new MailData();
                                var      with1       = messageData;
                                with1.Sender   = this.sender;
                                with1.Receiver = this.arrTo;
                                with1.Host     = this.host;
                                with1.Port     = this.port;
                                with1.Subject  = this.subject.Replace("$EVENTTYPE$", this.queue[0].LogType).Replace("$CLASS$", this.queue[0].Class).Replace("$METHOD$", this.queue[0].Method);
                                with1.Body     = stringBuilder.ToString();
                                stringBuilder  = null;
                                this.emailSender(messageData);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogData errorData = new LogData(this.GetType().Name, "Send", ex);
                            this.log.WriteWithoutEmail(errorData);
                        }

                        this.queue.RemoveAt(0);
                        Thread.Sleep(200);
                    }

                    this.logEvent.Reset();
                    this.logEvent.WaitOne();
                }while (this.started == true);
            }
            catch (Exception ex)
            {
                LogData errorData = new LogData(this.GetType().Name, "Send", ex);
                this.log.WriteWithoutEmail(errorData);
                this.started = false;
            }

            this.finished = true;
        }
Example #2
0
File: EMail.cs Project: v1i1/proekt
 private void Send()
 {
     _Started  = true;
     _Finished = false;
     try
     {
         do
         {
             while (_Queue.Count > 0)
             {
                 try
                 {
                     if (_eMailSender != null)
                     {
                         System.Text.StringBuilder vStrBuilder = new System.Text.StringBuilder();
                         vStrBuilder.AppendLine("===");
                         vStrBuilder.AppendLine("UID=" + System.Guid.NewGuid().ToString());
                         //     ("UID", DbType.String
                         vStrBuilder.AppendLine("Time=" + String.Format("'{0:yyyy-MM-dd HH:mm:ss}'", _Queue[0].DateTime));
                         //   "Time", DbType.DateTime
                         vStrBuilder.AppendLine("LogType=" + _Queue[0].LogType);
                         //       "Category", DbType.String))
                         vStrBuilder.AppendLine("Class=" + _Queue[0].InClass);
                         //         "Class", DbType.String
                         vStrBuilder.AppendLine("Method=" + _Queue[0].Method);
                         //        "Function", DbType.String
                         vStrBuilder.AppendLine("Description=" + _Queue[0].Description);
                         //   "Description", DbType.String
                         vStrBuilder.AppendLine("Sent=0");
                         //                 "Sent", DbType.Int32
                         foreach (System.Collections.Generic.KeyValuePair <DataColumn, object> vKeyValuePair in _Queue[0].StaticData)
                         {
                             vStrBuilder.AppendLine(vKeyValuePair.Key.ColumnName + "=" + vKeyValuePair.Value.ToString());
                         }
                         MailData vMessageData = new MailData();
                         var      _with1       = vMessageData;
                         _with1.From    = _From;
                         _with1.To      = _arrTo;
                         _with1.Host    = _Host;
                         _with1.Port    = _Port;
                         _with1.Subject = _Subject.Replace("$EVENTTYPE$", _Queue[0].LogType).Replace("$CLASS$", _Queue[0].InClass).Replace("$METHOD$", _Queue[0].Method);
                         _with1.Body    = vStrBuilder.ToString();
                         vStrBuilder    = null;
                         _eMailSender(vMessageData);
                     }
                 }
                 catch (Exception Ex)
                 {
                     LogData vErrData = new LogData(this.GetType().Name, "Send", Ex);
                     _Log.WriteWithoutEmail(vErrData);
                 }
                 _Queue.RemoveAt(0);
                 Thread.Sleep(200);
             }
             _LogEvent.Reset();
             _LogEvent.WaitOne();
         } while (_Started == true);
     }
     catch (Exception ex)
     {
         LogData vErrData = new LogData(this.GetType().Name, "Send", ex);
         _Log.WriteWithoutEmail(vErrData);
         _Started = false;
     }
     _Finished = true;
 }